/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Private Types | Private Member Functions | Private Attributes
TrigReadProc Class Reference

Pull version of TsTriggerAlg + ROsReadoutAlg. More...

#include <TrigReadProc.h>

Inheritance diagram for TrigReadProc:
Inheritance graph
[legend]
Collaboration diagram for TrigReadProc:
Collaboration graph
[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
< ElecHeader
ElecData
 Fifteen stuff.
typedef HeaderStageData
< SimReadoutHeader
SimReadoutData

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

Fifteen stuff.

Definition at line 71 of file TrigReadProc.h.

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.

    : StageProcessor<SimReadoutHeader>(name,pSvcLocator)
{
    // trigger
    m_trigToolNames.push_back("TsMultTriggerTool");
    declareProperty("TrigTools",m_trigToolNames,
                    "Tools to generate Triggers");
    declareProperty("TriggerFilter",m_trigFilterName="TsSortTool",
                    "Tool to do final filtering / combining of triggers");
    
    // readout
    m_roToolNames.push_back("ROsFeeReadoutTool");
    m_roToolNames.push_back("ROsFecReadoutTool");
    declareProperty("RoTools",m_roToolNames,
                    "Tools to generate Triggers");
    declareProperty("TrigPackagerTool",m_roTrigPackName="ROsTriggerDataPackerTool",
                    "Tool to convert trigger commands from TrigSim to TriggerDataPackage");
    
    // Fast trigger and readout simulation
    declareProperty("FastTrigReadSimTool", m_fastToolName = "FastTrigReadSimTool" , "Fast trigger and readout simulation tool");

}
TrigReadProc::~TrigReadProc ( ) [virtual]

Definition at line 38 of file TrigReadProc.cc.

{
}

Member Function Documentation

StatusCode TrigReadProc::initialize ( ) [virtual]

Fifteen initialization

Reimplemented from StageProcessor< DayaBay::SimReadoutHeader >.

Definition at line 42 of file TrigReadProc.cc.

{
    StatusCode sc = StageProcessor<SimReadoutHeader>::initialize();
    if (sc.isFailure()) return sc;

    // trigger
    for (size_t ind=0; ind < m_trigToolNames.size(); ++ind) {
        std::string tgr = m_trigToolNames[ind];
        try {
            m_trigTools.push_back(tool<ITsTriggerTool>(tgr));
        }
        catch(const GaudiException& exg) {
            fatal() << "Failed to get Trigger Tool: \"" << tgr << "\"" << endreq;
            return StatusCode::FAILURE;
        }
        info () << "Added trigger tool " << tgr << endreq;
    }
    try {
        m_triggerSorter = tool<ITsTriggerTool>(m_trigFilterName);
    }
    catch(const GaudiException& exg){
        fatal() << "Failed to get TriggerFilterTool: \"" << m_trigFilterName 
                << "\"" << endreq;
        return StatusCode::FAILURE;
    }


    // readout
    try{
        m_roTrigPackTool = tool<IROsTriggerDataPackerTool>(m_roTrigPackName);
    }catch(const GaudiException& exg){
        fatal() << "Failed to get Readout Trigger Package Tool: \"" 
                << m_roTrigPackName << "\"" << endreq;
        return StatusCode::FAILURE;
    }
    
    for (size_t ind=0; ind < m_roToolNames.size(); ++ind) {
        std::string rotool = m_roToolNames[ind];
        try {
            m_roTools.push_back(tool<IROsReadoutTool>(rotool));
        }
        catch(const GaudiException& exg) {
            fatal() << "Failed to get Readout Tool: \"" << rotool << "\"" << endreq;
            return StatusCode::FAILURE;
        }
        info () << "Added readout tool " << rotool << endreq;
    }

    // Fast trigger and readout simulation tool
    m_fastTool = tool<IFastTrigReadSimTool>(m_fastToolName);
    info() << "Added fast simulation tool: " << m_fastToolName << endreq;

    m_currentTime=0;
    m_SimRODataList.clear();


    return StatusCode::SUCCESS;
}
StatusCode TrigReadProc::execute ( ) [virtual]

the core part begins ///////// determine localtime, it is not m_CurrentTime

delta t

localtime must go beyond lower stage to make sure output is safe

pulling event from lower stage

delete the data pulled out generate some new data This process is like to take some input after use then produce new data

Instead of being called through sysExecute, they are called explicitly here.

for this stage

+++++++++++++++++++++++++++++++++++++++++++++

Check if this is from MuonProphet fast electronic simulation

if( pPulse->pulseCollection().size() ==0 && pCrate->crates().size() == 0 ) {

One ElecHeader -> one SimHeader -> one GenHeader

+++++++++++++++++++++++++++++++++++++++++++++

find out the min time

get the data with smallest time push it into current stage and delete it.

Definition at line 102 of file TrigReadProc.cc.

{
    debug()<<"executing... "<<endreq;
    // Only do anything if the current stage time has advanced beyond
    // the last time we ran.
    static bool first_time = true;
    if (!first_time && m_currentTime > thisStage()->currentTime()) {
        return StatusCode::SUCCESS;
    }
    
    FFTimeStamp tm(0,0);
    FFTimeStamp dt(0,0); 
    FFTimeStamp localtime(0,0);

    SimReadoutData::DataList::iterator SimROit;

    if(first_time) {
        // nothing to do here
    } else {
        SimROit=m_SimRODataList.begin();
        localtime=SimROit->first;
    }

    //debug()<<"A: local time= "<<localtime<<endreq;
    //debug()<<"A: lower stage time= "<<m_lowerStage->currentTime()<<endreq;
    while(first_time||localtime>=lowerStage()->currentTime()) {
        first_time=false;
        //debug() << "In while loop, pulling data from lower Stage ......" << endreq;

        IStageData* pIStageData=0;
        StatusCode sc = lowerStage()->nextElement(pIStageData);  // pulling out
        if (sc.isFailure()) {
            error() << "Failed to pull ElecHeader" << endreq;
            return sc;
        }

        ElecData* pElecData=0;
        try{
            pElecData = dynamic_cast<ElecData*>(pIStageData);
        }
        catch(...) {
            error() << "Failed to get GnrtrData pointer" <<endreq;
        }

        //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        // delete the used one                                                                                                            
        tm=pElecData->time();
        //debug() << "data pulled out from lower stage has time: "<<tm<<endreq;

        preExecute();
        SimReadoutData*   pSimROData=0;   
        
        // Do trigger readout simulation
        // get eheader
        ElecHeader* ehead = &(pElecData->header());
        debug()<<"ehead at "<<ehead<<endreq;

        bool G4Noble = false;
        const DayaBay::ElecPulseHeader* pPulse = ehead -> pulseHeader();
        const DayaBay::ElecCrateHeader* pCrate = ehead -> crateHeader();
        if( pPulse == 0 && pCrate == 0 ) {
            debug()<<"input header size " << ehead->inputHeaders().size()<<endreq;
            const DayaBay::IHeader* iSheader = (ehead  -> inputHeaders()) [0];
            const DayaBay::IHeader* iGheader = (iSheader->inputHeaders()) [0];
            const DayaBay::GenHeader* genHeader = dynamic_cast<const DayaBay::GenHeader*>(iGheader);
            const HepMC::GenEvent* genEvent = genHeader->event();

            if( genEvent )  {
                HepMC::GenEvent::particle_const_iterator pci, pci_end = genEvent->particles_end();

                for( pci = genEvent->particles_begin(); pci != pci_end; ++pci )  {
                    if( (*pci)->pdg_id() == 13 || (*pci)->pdg_id() == -13 )  {   // muon
                        if( (*pci)->status() != MpMuonFate::kNeedSim )   {   //  geant4-noble particle
                            G4Noble = true;
                        }
                    }
                }
            }
        }

        // define output header
        SimReadoutHeader* srhead=MakeHeaderObject();
        debug()<<"exec num "<<srhead->execNumber()<<endreq;

        if(G4Noble) {
            // do fast trigger and readout simulation
            sc = this->fastTrigReadSim( ehead, srhead );
            if (sc.isFailure()) return sc;
            debug()<<"exec num "<<srhead->execNumber()<<endreq;
        } else {
            // do trigger and readout simulation
            sc = this->TR_execute( ehead, srhead );
            if (sc.isFailure()) return sc;
            debug()<<"exec num "<<srhead->execNumber()<<endreq;
        }

        // define SimReadoutData
        pSimROData=new SimReadoutData(*srhead);
        debug()<<"exec num "<<srhead->execNumber()<<endreq;

        this->AppendInputHeader( ehead );

        postExecute();

        // It will not be used again
        delete pElecData; pElecData = 0;

        //debug() << "new data generated at time: "<< pSimData->time()<< endreq;
        //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

        // push back into a local store
        m_SimRODataList.insert(SimReadoutData::DataList::value_type(pSimROData->time(),pSimROData));

        SimROit=m_SimRODataList.begin();
        localtime=SimROit->first;
        //debug()<<"B: local time= "<<localtime<<endreq;
        //debug()<<"B: lower stage time= "<<m_lowerStage->currentTime()<<endreq;
    }

    m_currentTime=localtime;
    //debug() << "m_CurrentTime= "<< m_CurrentTime << endreq;


    SimROit=m_SimRODataList.begin();
    debug() << "to grep: new data pushed out at time " << SimROit->first << endreq;
    debug() << "New SimReadoutHeader at "<<&(SimROit->second->header())<<endreq;
    debug() << "It has "<<SimROit->second->header().readouts().size()<<" readouts"<<endreq;
    debug() << "TimeStamp "<<SimROit->second->header().timeStamp()<<endreq;
    debug() << "Earliest  "<<SimROit->second->header().earliest()<<endreq;
    debug() << "Latest    "<<SimROit->second->header().latest()<<endreq;

    thisStage()->pushElement(SimROit->second);
    this->registerData(*(SimROit->second));
    m_SimRODataList.erase(SimROit);


    return StatusCode::SUCCESS;
}
StatusCode TrigReadProc::finalize ( ) [virtual]

Definition at line 260 of file TrigReadProc.cc.

{
    // trigger
    for (size_t ind=0; ind < m_trigTools.size(); ++ind) {
        m_trigTools[ind]->release();
    }
    m_trigTools.clear();
    m_triggerSorter->release();
    
    // readout
    for (size_t ind=0; ind < m_roTools.size(); ++ind) {
        m_roTools[ind]->release();
    }
    m_roTools.clear();

    return this->StageProcessor<SimReadoutHeader>::finalize();
}
StatusCode TrigReadProc::runTrigSim ( const ElecHeader elecHeader,
SimTrigHeader *&  trigHeader 
) [private]

Definition at line 278 of file TrigReadProc.cc.

{
    thead->setCommandHeader(new SimTrigCommandHeader(thead));
        
    //set triggers to have same validity range as the crate it belongs to.
    thead->setContext(ehead.context());
    thead->setTimeStamp(ehead.timeStamp());
    thead->setEarliest(ehead.earliest());
    thead->setLatest(ehead.latest());
    debug()<<"runTrigSim "<<thead->earliest()<<endreq;
    
    // Let each tool do its thing on the event
    for (size_t ind = 0; ind< m_trigTools.size(); ++ind) {
        debug () << "Running trigger tool #" << ind << " " << m_trigToolNames[ind] << endreq;

        StatusCode sc = m_trigTools[ind]->mutate(thead,ehead);
        if (sc.isFailure()) {
            fatal() << "Trigger Tool " << m_trigToolNames[ind] 
                    << " failed" << endreq;
            delete thead; thead = 0;
            return StatusCode::FAILURE;
        }
    }
    if ( m_triggerSorter->mutate(thead,ehead).isFailure()){
        fatal() << "Trigger Tool " << m_triggerSorter
                << " failed" << endreq;
        return StatusCode::FAILURE;
    }
    
    return StatusCode::SUCCESS;
}
StatusCode TrigReadProc::runReadoutSim ( const ElecHeader elecHeader,
const SimTrigHeader trigHeader,
SimReadoutHeader *&  sroHeader 
) [private]

empty trigger data package object (use tool to fill it)

fill trigger data packages

Definition at line 311 of file TrigReadProc.cc.

{
    //    srhead = new SimReadoutHeader;
    srhead->setContext(ehead.context());
    srhead->setTimeStamp(ehead.timeStamp());
    srhead->setEarliest(ehead.earliest());
    srhead->setLatest(ehead.latest());
    debug()<<"runReadoutSim "<<srhead->earliest()<<endreq;
    
    // fill roHeader With TriggerDataPackage
    //  With this way of doing it the individual readout tools theoretically
    //  no longer need to know about the trigger header.
    debug() <<"Creating Trigger Data Packages" << endreq;
    std::vector<DayaBay::ReadoutTriggerDataPkg*> trigPkgs;
    m_roTrigPackTool->fillDataPackages(trigPkgs,thead);
    
    // Let each tool do its thing on the event
    for (size_t ind = 0; ind< m_roTools.size(); ++ind) {

        debug () << "Running readout tool #" << ind << " " << m_roToolNames[ind] << endreq;

        debug()<<"before mutate: exec num "<<srhead->execNumber()<<endreq;
        StatusCode sc = m_roTools[ind]->mutate(srhead,trigPkgs,ehead);
        if (sc.isFailure()) {
            fatal() << "Readout Tool " << m_roToolNames[ind] 
                    << " failed" << endreq;
            delete srhead; srhead = 0;
            return StatusCode::FAILURE;
        }
    }

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

Definition at line 349 of file TrigReadProc.cc.

{
    StatusCode sc;
    debug() << "Runing Trigger and Readout Simulation" << endreq;

    {
        const ElecPulseHeader::PulseCollectionMap& pcmap = ehead->pulseHeader()->pulseCollection();
        debug() << "TR_execute() got " << pcmap.size() << " pulse collections:\n";
        ElecPulseHeader::PulseCollectionMap::const_iterator it, done=pcmap.end();
        for (it=pcmap.begin(); it != done; ++it) {
            debug() << "\tdetector: " << it->first << " has " << it->second->pulses().size() << "\n";
        }
        debug() << endreq;
    }


    SimTrigHeader* thead = new SimTrigHeader;
    sc = this->runTrigSim(*ehead,thead);
    if (sc.isFailure() || !thead) {
        error() << "fillReadouts(): Failed to run TrigRead" << endreq;
        return StatusCode::FAILURE;
    }
    put(thead,thead->defaultLocation());
    // set input headers
    std::vector<const DayaBay::IHeader*> iElecHeaders;
    iElecHeaders.push_back(ehead);
    thead->setInputHeaders(iElecHeaders);
    // set execution number
    thead->setExecNumber(srhead->execNumber());


    debug()<<"exec num "<<srhead->execNumber()<<endreq;
    sc = this->runReadoutSim(*ehead,*thead,srhead);
    if (sc.isFailure() || !srhead) {
        error() << "fillReadouts(): Failed to run ReadoutSim" << endreq;
        return StatusCode::FAILURE;
    }
    // set input headers
    AppendInputHeader(thead);

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

Set time and context

Definition at line 392 of file TrigReadProc.cc.

{
    SimTrigHeader *sthead = new SimTrigHeader;

    StatusCode sc;
    sc = this->m_fastTool->mutate( srhead, sthead, *ehead );
    if (sc.isFailure()) return sc;

    sthead->setContext( ehead->context());
    sthead->setTimeStamp( ehead->timeStamp());
    sthead->setEarliest( ehead->earliest());
    sthead->setLatest( ehead->latest());
    //debug()<<"sthead earliest "<<sthead->earliest()<<endreq;

    srhead->setContext( ehead->context());
    srhead->setTimeStamp( ehead->timeStamp());
    srhead->setEarliest( ehead->earliest());
    srhead->setLatest( ehead->latest());
    //debug()<<"srhead earliest "<<srhead->earliest()<<endreq;

    // put trigger header into TES
    put( sthead, sthead->defaultLocation());

    // set input headers
    std::vector<const DayaBay::IHeader*> iElecHeaders;
    iElecHeaders.push_back( ehead );
    sthead->setInputHeaders( iElecHeaders );

    // set execution number
    sthead->setExecNumber(srhead->execNumber());

    // set input headers
    AppendInputHeader( sthead );

    return StatusCode::SUCCESS;
}
StatusCode StageProcessor< class >::registerData ( IStageData data) [inherited]
IStage * StageProcessor< class >::thisStage ( ) [inherited]
IStage * StageProcessor< class >::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.

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.

Definition at line 68 of file TrigReadProc.h.

This is for Consumer&Producer only.

For new generated data.

Definition at line 76 of file TrigReadProc.h.

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.

Definition at line 83 of file TrigReadProc.h.

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 Fri May 16 2014 10:21:52 for TrigReadProc by doxygen 1.7.4