00001 #include "TsFilterTool.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 TsFilterTool::TsFilterTool(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=24,
00021 "Number of nhit (80MHz) clock cycles for trigger dead time");
00022 declareProperty("ApplyFilter",m_active=false,
00023 "If set to true the tool will filter trigger commands.");
00024 }
00025
00026 TsFilterTool::~TsFilterTool(){}
00027
00028 StatusCode TsFilterTool::initialize()
00029 {
00030 debug() << "Initializing TsFilterTool" << endreq;
00031 return StatusCode::SUCCESS;
00032 }
00033
00034 StatusCode TsFilterTool::finalize()
00035 {
00036 debug() << "Finalizing TsFilterTool" << endreq;
00037 return StatusCode::SUCCESS;
00038 }
00039
00040 StatusCode TsFilterTool::mutate(DayaBay::SimTrigHeader* trigHeader,
00041 const DayaBay::ElecHeader& elecHeader)
00042 {
00043 if ( !m_active ){
00044 debug() << "TsFilterTool 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
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 DayaBay::SimTrigCommandCollection *triggerColl =
00061 const_cast<DayaBay::SimTrigCommandCollection*>(trigIt->second);
00062
00063
00064 triggerColl->sort();
00065
00066 DayaBay::SimTrigCommandCollection::CommandContainer& detTriggers =
00067 const_cast<DayaBay::SimTrigCommandCollection::CommandContainer&>(triggerColl->commands());
00068
00069 DayaBay::SimTrigCommandCollection::CommandContainer::iterator tcIt;
00070
00071 int prevCycle=-1;
00072 for(tcIt=detTriggers.begin();tcIt!=detTriggers.end();){
00073 verbose() << "Trigger: " << **tcIt << endreq;
00074 int thiscycle = (*tcIt)->clockCycle();
00075 if(thiscycle == prevCycle){
00076 verbose() << "Combining trigger with the previous one"
00077 << **tcIt << endreq;
00078
00079
00080 DayaBay::Trigger::TriggerType_t type = (*tcIt)->type();
00081 tcIt = detTriggers.erase(tcIt);
00082 --tcIt;
00083 int newtype = (int) (type | (*tcIt)->type());
00084 (*tcIt)->setType( (DayaBay::Trigger::TriggerType_t) newtype );
00085 ++tcIt;
00086
00087 }else if ((unsigned int) (thiscycle-prevCycle) < m_recoveryCycles ){
00088
00089
00090 verbose() << "Removing trigger that occured during recovery window "
00091 << **tcIt << endreq;
00092 tcIt = detTriggers.erase(tcIt);
00093
00094 }else{
00095
00096 prevCycle=thiscycle;
00097 ++tcIt;
00098 }
00099 }
00100 verbose() << "Done Filtering. " << *triggerColl << endreq;
00101 }
00102
00103 return StatusCode::SUCCESS;
00104 }