| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

TrigReadProc Class Reference

Pull version of TsTriggerAlg + ROsReadoutAlg. More...

#include <TrigReadProc.h>

Inheritance diagram for TrigReadProc:

[legend]
Collaboration diagram for TrigReadProc:
[legend]
List of all members.

Public Member Functions

 TrigReadProc (const std::string &name, ISvcLocator *pSvcLocator)
virtual ~TrigReadProc ()
virtual StatusCode initialize ()
virtual StatusCode execute ()
virtual StatusCode finalize ()
StatusCode registerData (IStageData &data)
IStagethisStage ()
IStagelowerStage ()

Private Types

typedef HeaderStageData< ElecHeaderElecData
 Fifteen stuff.
typedef HeaderStageData< SimReadoutHeaderSimReadoutData

Private Member Functions

StatusCode runTrigSim (const ElecHeader &elecHeader, SimTrigHeader *&trigHeader)
StatusCode runReadoutSim (const ElecHeader &elecHeader, const SimTrigHeader &trigHeader, SimReadoutHeader *&sroHeader)
StatusCode TR_execute (const ElecHeader *ehead, SimReadoutHeader *&srhead)
StatusCode fastTrigReadSim (const ElecHeader *ehead, SimReadoutHeader *&srhead)

Private Attributes

std::vector< std::string > m_trigToolNames
 Triggering.
std::vector< ITsTriggerTool * > m_trigTools
std::string m_trigFilterName
ITsTriggerToolm_triggerSorter
std::vector< std::string > m_roToolNames
 Readoutering.
std::vector< IROsReadoutTool * > m_roTools
std::string m_roTrigPackName
IROsTriggerDataPackerToolm_roTrigPackTool
SimReadoutData::DataList m_SimRODataList
 This is for Consumer&Producer only.
FFTimeStamp m_currentTime
 The earliest (smallest) time which this has provided.
std::string m_fastToolName
 Fast trigger and readout simulation tool.
IFastTrigReadSimToolm_fastTool
const SimReadoutHeaderm_currentSRHeader

Detailed Description

Pull version of TsTriggerAlg + ROsReadoutAlg.

One ElecHeader generates one SimTrigHeader then together give one SimReadoutHeader. The real number of trigger commands and SimReadouts could be zero to N.

Zhe Wang Jan 15, 2009

Add fast trigger and readout simulation for MuonProphet muons. Zhe Wang Mar 12, 2010

A major upgrade to handle the overlap of MuonProphet fast simulated muon and normal simulated hits Zhe Wang May 18, 2010

Definition at line 44 of file TrigReadProc.h.


Member Typedef Documentation

typedef HeaderStageData<ElecHeader> TrigReadProc::ElecData [private]

Fifteen stuff.

Definition at line 71 of file TrigReadProc.h.

typedef HeaderStageData<SimReadoutHeader> TrigReadProc::SimReadoutData [private]

Definition at line 72 of file TrigReadProc.h.


Constructor & Destructor Documentation

TrigReadProc::TrigReadProc ( const std::string &  name,
ISvcLocator pSvcLocator 
)

Definition at line 15 of file TrigReadProc.cc.

00016     : StageProcessor<SimReadoutHeader>(name,pSvcLocator)
00017 {
00018     // trigger
00019     m_trigToolNames.push_back("TsMultTriggerTool");
00020     declareProperty("TrigTools",m_trigToolNames,
00021                     "Tools to generate Triggers");
00022     declareProperty("TriggerFilter",m_trigFilterName="TsSortTool",
00023                     "Tool to do final filtering / combining of triggers");
00024     
00025     // readout
00026     m_roToolNames.push_back("ROsFeeReadoutTool");
00027     m_roToolNames.push_back("ROsFecReadoutTool");
00028     declareProperty("RoTools",m_roToolNames,
00029                     "Tools to generate Triggers");
00030     declareProperty("TrigPackagerTool",m_roTrigPackName="ROsTriggerDataPackerTool",
00031                     "Tool to convert trigger commands from TrigSim to TriggerDataPackage");
00032     
00033     // Fast trigger and readout simulation
00034     declareProperty("FastTrigReadSimTool", m_fastToolName = "FastTrigReadSimTool" , "Fast trigger and readout simulation tool");
00035 
00036 }

TrigReadProc::~TrigReadProc (  )  [virtual]

Definition at line 38 of file TrigReadProc.cc.

00039 {
00040 }


Member Function Documentation

StatusCode TrigReadProc::initialize (  )  [virtual]

Reimplemented from StageProcessor< DayaBay::SimReadoutHeader >.

Definition at line 42 of file TrigReadProc.cc.

00043 {
00044     StatusCode sc = StageProcessor<SimReadoutHeader>::initialize();
00045     if (sc.isFailure()) return sc;
00046 
00047     // trigger
00048     for (size_t ind=0; ind < m_trigToolNames.size(); ++ind) {
00049         std::string tgr = m_trigToolNames[ind];
00050         try {
00051             m_trigTools.push_back(tool<ITsTriggerTool>(tgr));
00052         }
00053         catch(const GaudiException& exg) {
00054             fatal() << "Failed to get Trigger Tool: \"" << tgr << "\"" << endreq;
00055             return StatusCode::FAILURE;
00056         }
00057         info () << "Added trigger tool " << tgr << endreq;
00058     }
00059     try {
00060         m_triggerSorter = tool<ITsTriggerTool>(m_trigFilterName);
00061     }
00062     catch(const GaudiException& exg){
00063         fatal() << "Failed to get TriggerFilterTool: \"" << m_trigFilterName 
00064                 << "\"" << endreq;
00065         return StatusCode::FAILURE;
00066     }
00067 
00068 
00069     // readout
00070     try{
00071         m_roTrigPackTool = tool<IROsTriggerDataPackerTool>(m_roTrigPackName);
00072     }catch(const GaudiException& exg){
00073         fatal() << "Failed to get Readout Trigger Package Tool: \"" 
00074                 << m_roTrigPackName << "\"" << endreq;
00075         return StatusCode::FAILURE;
00076     }
00077     
00078     for (size_t ind=0; ind < m_roToolNames.size(); ++ind) {
00079         std::string rotool = m_roToolNames[ind];
00080         try {
00081             m_roTools.push_back(tool<IROsReadoutTool>(rotool));
00082         }
00083         catch(const GaudiException& exg) {
00084             fatal() << "Failed to get Readout Tool: \"" << rotool << "\"" << endreq;
00085             return StatusCode::FAILURE;
00086         }
00087         info () << "Added readout tool " << rotool << endreq;
00088     }
00089 
00090     // Fast trigger and readout simulation tool
00091     m_fastTool = tool<IFastTrigReadSimTool>(m_fastToolName);
00092     info() << "Added fast simulation tool: " << m_fastToolName << endreq;
00093 
00095     m_currentTime=0;
00096     m_SimRODataList.clear();
00097 
00098 
00099     return StatusCode::SUCCESS;
00100 }

StatusCode TrigReadProc::execute (  )  [virtual]

Definition at line 102 of file TrigReadProc.cc.

00103 {
00104     debug()<<"executing... "<<endreq;
00105     // Only do anything if the current stage time has advanced beyond
00106     // the last time we ran.
00107     static bool first_time = true;
00108     if (!first_time && m_currentTime > thisStage()->currentTime()) {
00109         return StatusCode::SUCCESS;
00110     }
00111     
00114     FFTimeStamp tm(0,0);
00115     FFTimeStamp dt(0,0); 
00116     FFTimeStamp localtime(0,0);
00117 
00118     SimReadoutData::DataList::iterator SimROit;
00119 
00120     if(first_time) {
00121         // nothing to do here
00122     } else {
00123         SimROit=m_SimRODataList.begin();
00124         localtime=SimROit->first;
00125     }
00126 
00128     //debug()<<"A: local time= "<<localtime<<endreq;
00129     //debug()<<"A: lower stage time= "<<m_lowerStage->currentTime()<<endreq;
00130     while(first_time||localtime>=lowerStage()->currentTime()) {
00131         first_time=false;
00133         //debug() << "In while loop, pulling data from lower Stage ......" << endreq;
00134 
00135         IStageData* pIStageData=0;
00136         StatusCode sc = lowerStage()->nextElement(pIStageData);  // pulling out
00137         if (sc.isFailure()) {
00138             error() << "Failed to pull ElecHeader" << endreq;
00139             return sc;
00140         }
00141 
00142         ElecData* pElecData=0;
00143         try{
00144             pElecData = dynamic_cast<ElecData*>(pIStageData);
00145         }
00146         catch(...) {
00147             error() << "Failed to get GnrtrData pointer" <<endreq;
00148         }
00149 
00150         //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
00157         // delete the used one                                                                                                            
00158         tm=pElecData->time();
00159         //debug() << "data pulled out from lower stage has time: "<<tm<<endreq;
00160 
00162         preExecute();
00163         SimReadoutData*   pSimROData=0;   
00164         
00166         // Do trigger readout simulation
00167         // get eheader
00168         ElecHeader* ehead = &(pElecData->header());
00169         debug()<<"ehead at "<<ehead<<endreq;
00170 
00172         bool G4Noble = false;
00173         const DayaBay::ElecPulseHeader* pPulse = ehead -> pulseHeader();
00174         const DayaBay::ElecCrateHeader* pCrate = ehead -> crateHeader();
00176         if( pPulse == 0 && pCrate == 0 ) {
00178             debug()<<"input header size " << ehead->inputHeaders().size()<<endreq;
00179             const DayaBay::IHeader* iSheader = (ehead  -> inputHeaders()) [0];
00180             const DayaBay::IHeader* iGheader = (iSheader->inputHeaders()) [0];
00181             const DayaBay::GenHeader* genHeader = dynamic_cast<const DayaBay::GenHeader*>(iGheader);
00182             const HepMC::GenEvent* genEvent = genHeader->event();
00183 
00184             if( genEvent )  {
00185                 HepMC::GenEvent::particle_const_iterator pci, pci_end = genEvent->particles_end();
00186 
00187                 for( pci = genEvent->particles_begin(); pci != pci_end; ++pci )  {
00188                     if( (*pci)->pdg_id() == 13 || (*pci)->pdg_id() == -13 )  {   // muon
00189                         if( (*pci)->status() != MpMuonFate::kNeedSim )   {   //  geant4-noble particle
00190                             G4Noble = true;
00191                         }
00192                     }
00193                 }
00194             }
00195         }
00196 
00197         // define output header
00198         SimReadoutHeader* srhead=MakeHeaderObject();
00199         debug()<<"exec num "<<srhead->execNumber()<<endreq;
00200 
00201         if(G4Noble) {
00202             // do fast trigger and readout simulation
00203             sc = this->fastTrigReadSim( ehead, srhead );
00204             if (sc.isFailure()) return sc;
00205             debug()<<"exec num "<<srhead->execNumber()<<endreq;
00206         } else {
00207             // do trigger and readout simulation
00208             sc = this->TR_execute( ehead, srhead );
00209             if (sc.isFailure()) return sc;
00210             debug()<<"exec num "<<srhead->execNumber()<<endreq;
00211         }
00212 
00213         // define SimReadoutData
00214         pSimROData=new SimReadoutData(*srhead);
00215         debug()<<"exec num "<<srhead->execNumber()<<endreq;
00217 
00218         this->AppendInputHeader( ehead );
00219 
00220         postExecute();
00221 
00222         // It will not be used again
00223         delete pElecData; pElecData = 0;
00224 
00225         //debug() << "new data generated at time: "<< pSimData->time()<< endreq;
00226         //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
00227 
00228         // push back into a local store
00229         m_SimRODataList.insert(SimReadoutData::DataList::value_type(pSimROData->time(),pSimROData));
00230 
00232         SimROit=m_SimRODataList.begin();
00233         localtime=SimROit->first;
00234         //debug()<<"B: local time= "<<localtime<<endreq;
00235         //debug()<<"B: lower stage time= "<<m_lowerStage->currentTime()<<endreq;
00236     }
00237 
00238     m_currentTime=localtime;
00239     //debug() << "m_CurrentTime= "<< m_CurrentTime << endreq;
00240 
00243 
00244     SimROit=m_SimRODataList.begin();
00245     debug() << "to grep: new data pushed out at time " << SimROit->first << endreq;
00246     debug() << "New SimReadoutHeader at "<<&(SimROit->second->header())<<endreq;
00247     debug() << "It has "<<SimROit->second->header().readouts().size()<<" readouts"<<endreq;
00248     debug() << "TimeStamp "<<SimROit->second->header().timeStamp()<<endreq;
00249     debug() << "Earliest  "<<SimROit->second->header().earliest()<<endreq;
00250     debug() << "Latest    "<<SimROit->second->header().latest()<<endreq;
00251 
00252     thisStage()->pushElement(SimROit->second);
00253     this->registerData(*(SimROit->second));
00254     m_SimRODataList.erase(SimROit);
00255 
00256 
00257     return StatusCode::SUCCESS;
00258 }

StatusCode TrigReadProc::finalize (  )  [virtual]

Definition at line 260 of file TrigReadProc.cc.

00261 {
00262     // trigger
00263     for (size_t ind=0; ind < m_trigTools.size(); ++ind) {
00264         m_trigTools[ind]->release();
00265     }
00266     m_trigTools.clear();
00267     m_triggerSorter->release();
00268     
00269     // readout
00270     for (size_t ind=0; ind < m_roTools.size(); ++ind) {
00271         m_roTools[ind]->release();
00272     }
00273     m_roTools.clear();
00274 
00275     return this->StageProcessor<SimReadoutHeader>::finalize();
00276 }

StatusCode TrigReadProc::runTrigSim ( const ElecHeader elecHeader,
SimTrigHeader *&  trigHeader 
) [private]

Definition at line 278 of file TrigReadProc.cc.

00280 {
00281     thead->setCommandHeader(new SimTrigCommandHeader(thead));
00282         
00283     //set triggers to have same validity range as the crate it belongs to.
00284     thead->setContext(ehead.context());
00285     thead->setTimeStamp(ehead.timeStamp());
00286     thead->setEarliest(ehead.earliest());
00287     thead->setLatest(ehead.latest());
00288     debug()<<"runTrigSim "<<thead->earliest()<<endreq;
00289     
00290     // Let each tool do its thing on the event
00291     for (size_t ind = 0; ind< m_trigTools.size(); ++ind) {
00292         debug () << "Running trigger tool #" << ind << " " << m_trigToolNames[ind] << endreq;
00293 
00294         StatusCode sc = m_trigTools[ind]->mutate(thead,ehead);
00295         if (sc.isFailure()) {
00296             fatal() << "Trigger Tool " << m_trigToolNames[ind] 
00297                     << " failed" << endreq;
00298             delete thead; thead = 0;
00299             return StatusCode::FAILURE;
00300         }
00301     }
00302     if ( m_triggerSorter->mutate(thead,ehead).isFailure()){
00303         fatal() << "Trigger Tool " << m_triggerSorter
00304                 << " failed" << endreq;
00305         return StatusCode::FAILURE;
00306     }
00307     
00308     return StatusCode::SUCCESS;
00309 }

StatusCode TrigReadProc::runReadoutSim ( const ElecHeader elecHeader,
const SimTrigHeader trigHeader,
SimReadoutHeader *&  sroHeader 
) [private]

Definition at line 311 of file TrigReadProc.cc.

00314 {
00315     //    srhead = new SimReadoutHeader;
00316     srhead->setContext(ehead.context());
00317     srhead->setTimeStamp(ehead.timeStamp());
00318     srhead->setEarliest(ehead.earliest());
00319     srhead->setLatest(ehead.latest());
00320     debug()<<"runReadoutSim "<<srhead->earliest()<<endreq;
00321     
00322     // fill roHeader With TriggerDataPackage
00323     //  With this way of doing it the individual readout tools theoretically
00324     //  no longer need to know about the trigger header.
00325     debug() <<"Creating Trigger Data Packages" << endreq;
00327     std::vector<DayaBay::ReadoutTriggerDataPkg*> trigPkgs;
00329     m_roTrigPackTool->fillDataPakages(trigPkgs,thead);
00330     
00331     // Let each tool do its thing on the event
00332     for (size_t ind = 0; ind< m_roTools.size(); ++ind) {
00333 
00334         debug () << "Running readout tool #" << ind << " " << m_roToolNames[ind] << endreq;
00335 
00336         debug()<<"before mutate: exec num "<<srhead->execNumber()<<endreq;
00337         StatusCode sc = m_roTools[ind]->mutate(srhead,trigPkgs,ehead);
00338         if (sc.isFailure()) {
00339             fatal() << "Readout Tool " << m_roToolNames[ind] 
00340                     << " failed" << endreq;
00341             delete srhead; srhead = 0;
00342             return StatusCode::FAILURE;
00343         }
00344     }
00345 
00346     return StatusCode::SUCCESS;
00347 }

StatusCode TrigReadProc::TR_execute ( const ElecHeader ehead,
SimReadoutHeader *&  srhead 
) [private]

Definition at line 349 of file TrigReadProc.cc.

00350 {
00351     StatusCode sc;
00352     debug() << "Runing Trigger and Readout Simulation" << endreq;
00353 
00354     {
00355         const ElecPulseHeader::PulseCollectionMap& pcmap = ehead->pulseHeader()->pulseCollection();
00356         debug() << "TR_execute() got " << pcmap.size() << " pulse collections:\n";
00357         ElecPulseHeader::PulseCollectionMap::const_iterator it, done=pcmap.end();
00358         for (it=pcmap.begin(); it != done; ++it) {
00359             debug() << "\tdetector: " << it->first << " has " << it->second->pulses().size() << "\n";
00360         }
00361         debug() << endreq;
00362     }
00363 
00364 
00365     SimTrigHeader* thead = new SimTrigHeader;
00366     sc = this->runTrigSim(*ehead,thead);
00367     if (sc.isFailure() || !thead) {
00368         error() << "fillReadouts(): Failed to run TrigRead" << endreq;
00369         return StatusCode::FAILURE;
00370     }
00371     put(thead,thead->defaultLocation());
00372     // set input headers
00373     std::vector<const DayaBay::IHeader*> iElecHeaders;
00374     iElecHeaders.push_back(ehead);
00375     thead->setInputHeaders(iElecHeaders);
00376     // set execution number
00377     thead->setExecNumber(srhead->execNumber());
00378 
00379 
00380     debug()<<"exec num "<<srhead->execNumber()<<endreq;
00381     sc = this->runReadoutSim(*ehead,*thead,srhead);
00382     if (sc.isFailure() || !srhead) {
00383         error() << "fillReadouts(): Failed to run ReadoutSim" << endreq;
00384         return StatusCode::FAILURE;
00385     }
00386     // set input headers
00387     AppendInputHeader(thead);
00388 
00389     return StatusCode::SUCCESS;
00390 }

StatusCode TrigReadProc::fastTrigReadSim ( const ElecHeader ehead,
SimReadoutHeader *&  srhead 
) [private]

Definition at line 392 of file TrigReadProc.cc.

00393 {
00394     SimTrigHeader *sthead = new SimTrigHeader;
00395 
00396     StatusCode sc;
00397     sc = this->m_fastTool->mutate( srhead, sthead, *ehead );
00398     if (sc.isFailure()) return sc;
00399 
00401     sthead->setContext( ehead->context());
00402     sthead->setTimeStamp( ehead->timeStamp());
00403     sthead->setEarliest( ehead->earliest());
00404     sthead->setLatest( ehead->latest());
00405     //debug()<<"sthead earliest "<<sthead->earliest()<<endreq;
00406 
00407     srhead->setContext( ehead->context());
00408     srhead->setTimeStamp( ehead->timeStamp());
00409     srhead->setEarliest( ehead->earliest());
00410     srhead->setLatest( ehead->latest());
00411     //debug()<<"srhead earliest "<<srhead->earliest()<<endreq;
00412 
00413     // put trigger header into TES
00414     put( sthead, sthead->defaultLocation());
00415 
00416     // set input headers
00417     std::vector<const DayaBay::IHeader*> iElecHeaders;
00418     iElecHeaders.push_back( ehead );
00419     sthead->setInputHeaders( iElecHeaders );
00420 
00421     // set execution number
00422     sthead->setExecNumber(srhead->execNumber());
00423 
00424     // set input headers
00425     AppendInputHeader( sthead );
00426 
00427     return StatusCode::SUCCESS;
00428 }

StatusCode StageProcessor< DayaBay::SimReadoutHeader >::registerData ( IStageData data  )  [inherited]

IStage * StageProcessor< DayaBay::SimReadoutHeader >::thisStage (  )  [inherited]

IStage * StageProcessor< DayaBay::SimReadoutHeader >::lowerStage (  )  [inherited]


Member Data Documentation

std::vector<std::string> TrigReadProc::m_trigToolNames [private]

Triggering.

Definition at line 57 of file TrigReadProc.h.

std::vector<ITsTriggerTool*> TrigReadProc::m_trigTools [private]

Definition at line 58 of file TrigReadProc.h.

std::string TrigReadProc::m_trigFilterName [private]

Definition at line 60 of file TrigReadProc.h.

ITsTriggerTool* TrigReadProc::m_triggerSorter [private]

Definition at line 61 of file TrigReadProc.h.

std::vector<std::string> TrigReadProc::m_roToolNames [private]

Readoutering.

Definition at line 64 of file TrigReadProc.h.

std::vector<IROsReadoutTool*> TrigReadProc::m_roTools [private]

Definition at line 65 of file TrigReadProc.h.

std::string TrigReadProc::m_roTrigPackName [private]

Definition at line 67 of file TrigReadProc.h.

IROsTriggerDataPackerTool* TrigReadProc::m_roTrigPackTool [private]

Definition at line 68 of file TrigReadProc.h.

SimReadoutData::DataList TrigReadProc::m_SimRODataList [private]

This is for Consumer&Producer only.

For new generated data.

Definition at line 76 of file TrigReadProc.h.

FFTimeStamp TrigReadProc::m_currentTime [private]

The earliest (smallest) time which this has provided.

Definition at line 79 of file TrigReadProc.h.

std::string TrigReadProc::m_fastToolName [private]

Fast trigger and readout simulation tool.

Definition at line 82 of file TrigReadProc.h.

IFastTrigReadSimTool* TrigReadProc::m_fastTool [private]

Definition at line 83 of file TrigReadProc.h.

const SimReadoutHeader* TrigReadProc::m_currentSRHeader [private]

Definition at line 104 of file TrigReadProc.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 21:02:48 2011 for TrigReadProc by doxygen 1.4.7