#include #include #include #include #include #include #include #include #include #include // Processors #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace RAT; #include using namespace std; namespace RAT { // Helper func defined in ConstructUserProc.cc and overridden by user - Still needed? PGJ Processor* construct_user_proc(std::string userProcName); } ProcBlockManager::ProcBlockManager( ProcBlock *theMainBlock ) : fMainBlock( theMainBlock ) { fLastProc = NULL; // Build UI commands G4UIdirectory* ratDir = new G4UIdirectory("/rat/"); ratDir->SetGuidance(" control commands"); fAddProcCmd = new G4UIcmdWithAString( "/rat/proc",this ); fAddProcCmd->SetGuidance( "Add a processor to the analysis stack" ); fAddProcCmd->SetParameterName( "procname",false ); fDeferAddProcCmd = new G4UIcmdWithAString( "/rat/proclast",this ); fDeferAddProcCmd->SetGuidance( "Add a processor to the end of the current analysis stack" ); fDeferAddProcCmd->SetParameterName( "procname",false ); fIfCmd = new G4UIcmdWithAString( "/rat/proc/if",this ); fIfCmd->SetGuidance( "Add a condition on a processor to the analysis stack" ); fIfCmd->SetParameterName( "procname",false ); fElseCmd = new G4UIcommand( "/rat/proc/else", this); fElseCmd->SetGuidance( "Add the false condition to the previous conditional processor on the analysis stack." ); fEndBlockCmd = new G4UIcommand( "/rat/proc/endblock", this); fEndBlockCmd->SetGuidance( "End the processor block on the analysis stack." ); fEndIfCmd = new G4UIcommand( "/rat/proc/endif", this); fEndIfCmd->SetGuidance( "End the conditional if processor block on the analysis stack." ); fEndWhileCmd = new G4UIcommand( "/rat/proc/endwhile", this); fEndWhileCmd->SetGuidance( "End the conditional while processor block on the analysis stack." ); fWhileCmd = new G4UIcmdWithAString( "/rat/proc/while",this ); fWhileCmd->SetGuidance( "Add a conditional loop on a processor to the analysis stack" ); fWhileCmd->SetParameterName( "procname",false ); // set proc parameter command G4UIparameter* aParam; fSetCmd = new G4UIcommand("/rat/procset", this); fSetCmd->SetGuidance("Set parameter for most recent processor"); aParam = new G4UIparameter("param", 's', false); //required fSetCmd->SetParameter(aParam); aParam = new G4UIparameter("newvalue", 's', false); //required fSetCmd->SetParameter(aParam); // ----------------Create processor allocator table----------------- // I/O fProcAllocators["outroot"] = new ProcAllocatorTmpl; fProcAllocators["outnet"] = new ProcAllocatorTmpl; fProcAllocators["outntuple"] = new ProcAllocatorTmpl; fProcAllocators["eventlist"] = new ProcAllocatorTmpl; // Fitters fProcAllocators["fitter"] = new ProcAllocatorTmpl; fProcAllocators["classifier"] = new ProcAllocatorTmpl; fProcAllocators["scintFitter"] = new ProcAllocatorTmpl; fProcAllocators["waterFitter"] = new ProcAllocatorTmpl; fProcAllocators["partialFitter"] = new ProcAllocatorTmpl; fProcAllocators["partialWaterFitter"] = new ProcAllocatorTmpl; fProcAllocators["defaultfitter"] = new ProcAllocatorTmpl; // DAQ fProcAllocators["frontend"]= new ProcAllocatorTmpl; fProcAllocators["trigger"]= new ProcAllocatorTmpl; fProcAllocators["eventbuilder"]= new ProcAllocatorTmpl; fProcAllocators["simpledaq"]= new ProcAllocatorTmpl; // Misc fProcAllocators["burst"] = new ProcAllocatorTmpl; fProcAllocators["count"] = new ProcAllocatorTmpl; fProcAllocators["numberProcessed"] = new ProcAllocatorTmpl; fProcAllocators["prune"] = new ProcAllocatorTmpl; fProcAllocators["pruneTrack"] = new ProcAllocatorTmpl; fProcAllocators["tellieMonitoring"] = new ProcAllocatorTmpl; // Conditional analysis fProcAllocators["triggerEfficiency"] = new ProcAllocatorTmpl; fProcAllocators["nhitCut"] = new ProcAllocatorTmpl; fProcAllocators["scintEdepCut"] = new ProcAllocatorTmpl; fProcAllocators["classifierCut"] = new ProcAllocatorTmpl; fProcAllocators["fitValidityCut"] = new ProcAllocatorTmpl; fProcAllocators["fitEnergyCut"] = new ProcAllocatorTmpl; fProcAllocators["secondaryNhitsCut"] = new ProcAllocatorTmpl; fProcAllocators["dataCleaningCut"] = new ProcAllocatorTmpl; fProcAllocators["radiusCut"] = new ProcAllocatorTmpl; fProcAllocators["trigTypeSelector"] = new ProcAllocatorTmpl; fProcAllocators["cherenkovCountCut"] = new ProcAllocatorTmpl; fProcAllocators["dcaProc"] = new ProcAllocatorTmpl; // Calibration fProcAllocators["calibratePMT"]= new ProcAllocatorTmpl; fProcAllocators["chanSWStatusProc"]= new ProcAllocatorTmpl; fProcAllocators["chanSWStatusCalib"]= new ProcAllocatorTmpl; fProcAllocators["sanitychecks"]= new ProcAllocatorTmpl; fProcAllocators["genECA"]= new ProcAllocatorTmpl; fProcAllocators["genPCA"]= new ProcAllocatorTmpl; fProcAllocators["pmtnoiseproc"] = new ProcAllocatorTmpl; fProcAllocators["datacleaning"] = new ProcAllocatorTmpl; fProcAllocators["PMTjitter"] = new ProcAllocatorTmpl; fProcAllocators["triggerclockjumpproc"] = new ProcAllocatorTmpl; fProcAllocators["reconstructClocks"] = new ProcAllocatorTmpl; fProcAllocators["flagChannels"] = new ProcAllocatorTmpl; fProcAllocators["produceRunTable"] = new ProcAllocatorTmpl; fProcAllocators["taggedSource"] = new ProcAllocatorTmpl; fProcAllocators["dqpmtproc"] = new ProcAllocatorTmpl; fProcAllocators["dqoccupancybytrigger"] = new ProcAllocatorTmpl; fProcAllocators["dqrunproc"] = new ProcAllocatorTmpl; fProcAllocators["dqtimeproc"] = new ProcAllocatorTmpl; fProcAllocators["dqtellieproc"] = new ProcAllocatorTmpl; fProcAllocators["dqlaserballproc"] = new ProcAllocatorTmpl; fProcAllocators["dqsmellieproc"] = new ProcAllocatorTmpl; fProcAllocators["dqN16proc"] = new ProcAllocatorTmpl; fProcAllocators["dqtriggerproc"] = new ProcAllocatorTmpl; fProcAllocators["PCATellieMonitoring"] = new ProcAllocatorTmpl; fProcAllocators["reactornuosc"] = new ProcAllocatorTmpl; fProcAllocators["pingcratesproc"] = new ProcAllocatorTmpl; fProcAllocators["dropoutevaluator"] = new ProcAllocatorTmpl; // Calibration -> Optical fProcAllocators["socdata"] = new ProcAllocatorTmpl; fProcAllocators["socpeakfind"] = new ProcAllocatorTmpl; fProcAllocators["socfitter"] = new ProcAllocatorTmpl; fProcAllocators["outsoc"] = new ProcAllocatorTmpl; // Escape Hatch fProcAllocators["python"] = new ProcAllocatorTmpl; // ----------------------------------------------------------------- } ProcBlockManager::~ProcBlockManager() { // UI commands delete fAddProcCmd; delete fDeferAddProcCmd; delete fIfCmd; delete fElseCmd; delete fWhileCmd; delete fEndBlockCmd; delete fEndIfCmd; delete fEndWhileCmd; delete fSetCmd; // fProcAllocators std::map::iterator allocator = fProcAllocators.begin(); while (allocator != fProcAllocators.end()) { delete allocator->second; // allocator points to pair<>, // Processor object is the second item in pair ++allocator; } // Do not delete fMainBlock, owned by Gsim } G4String ProcBlockManager::GetCurrentValue(G4UIcommand * command) { Log::Die( "ProcBlockManager::GetCurrentValue: Get value not supported on " + command->GetCommandPath() ); return G4String( "You should never see this." ); } void ProcBlockManager::SetNewValue( G4UIcommand* command, G4String newValue ) { if( command == fAddProcCmd ) { SelectProcessor( newValue ); fMainBlock->AddProcessorCommand( fLastProc ); } else if( command == fDeferAddProcCmd ) { SelectProcessor( newValue ); fMainBlock->AddProcessorCommand( fLastProc ); } else if( command == fIfCmd ) { SelectProcessor( newValue ); fMainBlock->IfCommand( fLastProc ); } else if( command == fWhileCmd ) { SelectProcessor( newValue ); fMainBlock->WhileCommand( fLastProc ); } else if( command == fElseCmd ) fMainBlock->ElseCommand(); else if( command == fEndBlockCmd ) fMainBlock->EndCommand( ProcBlock::eEndBlock ); else if( command == fEndIfCmd ) fMainBlock->EndCommand( ProcBlock::eEndIf ); else if( command == fEndWhileCmd ) fMainBlock->EndCommand( ProcBlock::eEndWhile ); else if (command == fSetCmd) DoProcSetCmd(newValue); else Log::Die( "ProcBlockManager::SetNewValue: Invalid command " + command->GetCommandPath() ); } void ProcBlockManager::SelectProcessor( const std::string& procname ) { info << YELLOW << "ProcBlockManager::DoProcCmd: Initializing processor " << CLR << procname << "\n"; // Is this a user processor? (starts with "user") if( procname.find("user") == 0 ) { fLastProc = construct_user_proc(procname); } else if( fProcAllocators.count( procname ) > 0 ) { // Crazy syntax required because we have a list of pointers to functors, // rather than just a list of functors. Had to use pointers because // of the polymorphism. C++ makes OOP ugly. fLastProc = (*fProcAllocators[procname])(); } else { Log::Die( "ProcBlockManager::DoProcCmd: Failed to construct processor " + procname ); } } void ProcBlockManager::DoProcSetCmd( const std::string& cmdstring ) { Tokenizer t(cmdstring); std::string indentifierChars = "."; // Extra characters to count as part of the identifier if (t.Next(indentifierChars) != Tokenizer::TYPE_IDENTIFIER) Log::Die("ProcBlockManager::DoProcSetCmd: Invalid param name in /rat/procset " + cmdstring); std::string param(t.Token()); try { switch (t.Next()) { case Tokenizer::TYPE_INTEGER: fLastProc->SetI(param, t.AsInt()); break; case Tokenizer::TYPE_DOUBLE: fLastProc->SetD(param, t.AsDouble()); break; case Tokenizer::TYPE_STRING: fLastProc->SetS(param, t.Token()); break; default: Log::Die("ProcBlockManager::DoProcSetCmd: Invalid value in /rat/procset " + cmdstring); } } catch (Processor::ParamUnknown &pu) { Log::Die("ProcBlockManager::DoProcSetCmd: Parameter unknown: " + pu.fParam); } catch (Processor::ParamInvalid &pi) { Log::Die("ProcBlockManager::DoProcSetCmd: Invalid value for parameter " + pi.fParam + ": " + pi.fMsg); } }