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

In This Package:

TsSortTool.cc

Go to the documentation of this file.
00001 #include "TsSortTool.h"
00002 
00003 #include "Conventions/Site.h"
00004 #include "Conventions/Trigger.h"
00005 
00006 #include "Event/ElecCrateHeader.h"
00007 #include "Event/ElecFeeCrate.h"
00008 
00009 #include "Event/SimTrigCommand.h"
00010 #include "Event/SimTrigCommandHeader.h"
00011 #include "Event/SimTrigCommandCollection.h"
00012 #include "CLHEP/Units/SystemOfUnits.h"
00013 
00014 TsSortTool::TsSortTool(const std::string& type,
00015                                              const std::string& name, 
00016                                              const IInterface* parent)
00017     : GaudiTool(type,name,parent)
00018 {
00019   declareInterface< ITsTriggerTool >(this) ;
00020   declareProperty("RecoveryTime",m_recoveryCycles=60,
00021                   "Number of 80MHz clock cycles for trigger dead time");
00022   declareProperty("SortTriggers",m_active=true,
00023                   "If set to true the tool will sort the trigger commands.");
00024 }
00025 
00026 TsSortTool::~TsSortTool(){}
00027 
00028 StatusCode TsSortTool::initialize()
00029 {
00030   debug() << "Initializing TsSortTool" << endreq;
00031   return StatusCode::SUCCESS;
00032 }
00033 
00034 StatusCode TsSortTool::finalize()
00035 {
00036   debug() << "Finalizing TsSortTool" << endreq;
00037   return StatusCode::SUCCESS;
00038 }
00039 
00040 StatusCode TsSortTool::mutate(DayaBay::SimTrigHeader* trigHeader,
00041                                          const DayaBay::ElecHeader& elecHeader)
00042 {     
00043   if ( !m_active ){
00044       debug() << "TsSortTool is not active, so doing nothing" << endreq;
00045       return StatusCode::SUCCESS;
00046   }
00047   
00048   debug() << "running mutate()" << endreq;
00049   const DayaBay::SimTrigCommandHeader *tch = trigHeader->commandHeader();
00050   const DayaBay::SimTrigCommandHeader::detCollMap trigCollMap 
00051                                                           = tch->collections();
00052   DayaBay::SimTrigCommandHeader::detCollMap::const_iterator trigIt;  
00053   //Loop over All trigger Collections
00054   for(trigIt  = trigCollMap.begin(); trigIt != trigCollMap.end(); ++trigIt)
00055   {
00056     DayaBay::Detector det(trigIt->first);
00057     debug() << "found " << (trigIt->second)->commands().size()
00058             << " commands for " << det.detName() << endreq;
00059 
00060     // Skip sorting if less than 2 triggers exist.
00061     if( (trigIt->second)->commands().size()<2 ) continue;
00062     DayaBay::SimTrigCommandCollection *triggerColl = 
00063                const_cast<DayaBay::SimTrigCommandCollection*>(trigIt->second);
00064 
00065     // sort the trigger commands by clock cycle
00066     triggerColl->sort();
00067 
00068     DayaBay::SimTrigCommandCollection::CommandContainer& detTriggers = 
00069         const_cast<DayaBay::SimTrigCommandCollection::CommandContainer&>(triggerColl->commands());
00070 
00071     DayaBay::SimTrigCommandCollection::CommandContainer reducedTriggerColl;
00072     DayaBay::SimTrigCommand* prevTrigger = detTriggers[0];
00073     reducedTriggerColl.push_back(prevTrigger);
00074     for(unsigned int trigIdx=1; trigIdx<detTriggers.size(); trigIdx++){
00075       unsigned int prevcycle = prevTrigger->clockCycle();
00076       unsigned int thiscycle = (detTriggers[trigIdx])->clockCycle();
00077       if( (thiscycle-prevcycle)<m_recoveryCycles ){
00078         // Remove this trigger since it occurs too soon after previous trigger
00079         verbose() << "Combining trigger at " << thiscycle << " with trigger at " 
00080                   << prevcycle << endreq;
00081         // Update the trigger type
00082         DayaBay::Trigger::TriggerType_t type = (detTriggers[trigIdx])->type();
00083         int newtype = (int) (type | prevTrigger->type()); // update its type
00084         prevTrigger->setType( (DayaBay::Trigger::TriggerType_t) newtype );
00085         delete detTriggers[trigIdx];
00086         detTriggers[trigIdx]=0;
00087       }else{
00088         prevTrigger = detTriggers[trigIdx];
00089         reducedTriggerColl.push_back(prevTrigger);
00090       }
00091     }
00092     triggerColl->setCommands( reducedTriggerColl );
00093 
00094     verbose() << "Done Sorting. "  << endreq;
00095   }
00096 
00097   return StatusCode::SUCCESS;                               
00098 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:50:03 2011 for TrigSim by doxygen 1.4.7