ATLAS Offline Software
TriggerSelectorAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 #include "TriggerSelectorAlg.h"
9 
10 #include "TrigDecisionTool/TrigDecisionTool.h" // rel 15
11 #include "TrigDecisionEvent/TrigDecision.h" // rel 15
12 
13 #include "TROOT.h"
14 
15 TriggerSelectorAlg::TriggerSelectorAlg(const std::string& name, ISvcLocator* pSvcLocator)
16  : AthAlgorithm(name, pSvcLocator)
17  , m_tdTool("Trig::TrigDecisionTool/TrigDecisionTool")
18  , m_TriggerRegistryTool("TriggerRegistryTool")
19  , m_trigpar(0)
20  , m_counter(0)
21  , m_accept(0)
22  , m_applyTriggerSelection(false)
23 {
24  declareProperty( "TriggerSelection", m_regexpr );
25  declareProperty( "TriggerSelectionRegistration", m_regexprRegistrationOnly );
26  declareProperty( "CounterPrescale", m_prescale = 1000 );
27 }
28 
29 
31 {
32  // cleanup
33  if (m_trigpar!=0) { delete[] m_trigpar; m_trigpar=0; }
34 }
35 
36 
38 {
39  ATH_MSG_DEBUG ("initialize()");
40 
41  Root::TMsgLogger::SetMinLevel(static_cast<Root::TMsgLevel>(msgLevel()));
42 
44  if (!m_regexprRegistrationOnly.empty() && m_regexpr.empty()) {
47  } else if (m_regexprRegistrationOnly.empty() && !m_regexpr.empty()) {
49  } else if (!m_regexprRegistrationOnly.empty() && !m_regexpr.empty()) {
50  ATH_MSG_WARNING ("initialize() :: Both TriggerSelectionRegistration and TriggerSelection are set. Ignoring TriggerSelectionRegistration.");
53  } else { // default in case nothing is set, pass through mode
54  m_regexpr = "1";
56  }
57 
59  ATH_MSG_INFO ("initialize() :: Trigger selection set to pass-through mode.");
60 
62  if ( m_TriggerRegistryTool.retrieve().isFailure() ) {
64  (m_TriggerRegistryTool.propertyName() << ": Failed to retrieve tool "
65  << m_TriggerRegistryTool.type());
66  return StatusCode::FAILURE;
67  } else {
69  (m_TriggerRegistryTool.propertyName() << ": Retrieved tool "
70  << m_TriggerRegistryTool.type());
71  }
72 
73  int formOk = m_formula.setFormula(m_regexpr.c_str()) ;
74 
75  if ( 0!=formOk ) {
76  ATH_MSG_ERROR ("Cannot parse regular expression : " << m_regexpr << " . Return Failure.");
77  return StatusCode::FAILURE;
78  }
79 
80  // get trigger names from formula
82  m_trigpar = new double[m_formula.getNPars()];
83 
85  {
86  std::ostringstream tmp;
87  tmp << "Sequence" << m_TriggerRegistryTool->getTriggerSelectorRegistry().size();
88  m_myname = tmp.str();
89  };
90 
92  ATH_MSG_INFO ("initialize() :: Now registering this Trigger Selector with unique name <" << m_myname << ">.");
93  bool regOk = m_TriggerRegistryTool->registerTriggerSelector(m_myname,m_regexpr,m_par);
94  if (!regOk) {
95  ATH_MSG_ERROR ("initialize() :: Failure to register this Trigger Selector with name <" << m_myname << ">. Return failure.");
96  return StatusCode::FAILURE;
97  }
98 
99  ATH_MSG_DEBUG ("initialize() successful");
100 
101  return StatusCode::SUCCESS;
102 }
103 
104 
105 StatusCode
107 {
108  ATH_MSG_DEBUG ("execute()");
109 
111  if( m_tdTool.retrieve().isFailure()) {
112  ATH_MSG_ERROR ("Could not retrieve TrigDecisionTool. Return Failure.");
113  return StatusCode::FAILURE;
114  } else {
115  ATH_MSG_DEBUG ("Successfully retrieved TrigDecisionTool.");
116  }
117  }
118 
119  if (m_counter % m_prescale == 0)
120  ATH_MSG_INFO ("Now processing event : " << m_counter);
121  m_counter++ ;
122 
123  // Filling trigger map
124  std::list<TString>::iterator tnItr = m_par.begin() ;
125  for (unsigned int i=0; tnItr!=m_par.end(); ++tnItr, ++i) {
126  bool isPassed(true);
127  if (m_applyTriggerSelection) isPassed = m_tdTool->isPassed(tnItr->Data());
128  m_trigpar[i] = static_cast<double>(isPassed);
129  ATH_MSG_DEBUG ("Trigger name : " << *tnItr << " = " << m_trigpar[i]);
130  }
131 
132  // evaluate trigger regular expression
133  double dummy(0);
134  bool pass(true);
135  if (m_applyTriggerSelection) pass = static_cast<bool>(m_formula.EvalPar(&dummy,m_trigpar));
136  this->setFilterPassed (pass); // skip execution of following algs for this event
137  if (pass) ++m_accept;
138 
139  ATH_MSG_DEBUG ("Event accepted? " << pass);
140 
141  ATH_MSG_DEBUG ("execute() successful");
142 
143  return StatusCode::SUCCESS;
144 }
145 
146 
148 {
149  ATH_MSG_DEBUG ("finalize()");
150 
151  ATH_MSG_INFO ("Processed " << m_counter << " events, accepted " << m_accept << " events.");
152 
153  ATH_MSG_DEBUG ("finalize() successful");
154 
155  return StatusCode::SUCCESS;
156 }
157 
158 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
Root::RegularFormula::getNPars
unsigned int getNPars() const
Definition: RegularFormula.h:45
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TriggerSelectorAlg::initialize
StatusCode initialize()
Definition: TriggerSelectorAlg.cxx:37
Root::RegularFormula::getParNames
const std::list< TString > & getParNames() const
Definition: RegularFormula.h:46
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
ITriggerRegistryTool.h
TriggerSelectorAlg::m_regexpr
std::string m_regexpr
Definition: TriggerSelectorAlg.h:47
TrigDecisionTool.h
TriggerSelectorAlg::m_tdTool
ToolHandle< Trig::TrigDecisionTool > m_tdTool
Definition: TriggerSelectorAlg.h:38
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TriggerSelectorAlg::execute
StatusCode execute()
Definition: TriggerSelectorAlg.cxx:106
lumiFormat.i
int i
Definition: lumiFormat.py:92
TrigDecision.h
TriggerSelectorAlg::m_par
std::list< TString > m_par
Definition: TriggerSelectorAlg.h:48
TriggerSelectorAlg::m_regexprRegistrationOnly
std::string m_regexprRegistrationOnly
Definition: TriggerSelectorAlg.h:47
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TriggerSelectorAlg::m_formula
Root::RegularFormula m_formula
Definition: TriggerSelectorAlg.h:49
Root::TMsgLevel
TMsgLevel
Definition: TMsgLogger.h:42
Root::RegularFormula::setFormula
Int_t setFormula(const char *expression)
Definition: RegularFormula.cxx:128
python.xAODType.dummy
dummy
Definition: xAODType.py:4
TriggerSelectorAlg::m_myname
std::string m_myname
Definition: TriggerSelectorAlg.h:52
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
TriggerSelectorAlg::m_counter
unsigned int m_counter
Definition: TriggerSelectorAlg.h:43
AthAlgorithm
Definition: AthAlgorithm.h:47
TriggerSelectorAlg::m_applyTriggerSelection
bool m_applyTriggerSelection
Definition: TriggerSelectorAlg.h:50
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TriggerSelectorAlg::m_TriggerRegistryTool
ToolHandle< ITriggerRegistryTool > m_TriggerRegistryTool
Definition: TriggerSelectorAlg.h:39
TriggerSelectorAlg::~TriggerSelectorAlg
virtual ~TriggerSelectorAlg()
Definition: TriggerSelectorAlg.cxx:30
TriggerSelectorAlg::m_trigpar
double * m_trigpar
Definition: TriggerSelectorAlg.h:41
TriggerSelectorAlg::finalize
StatusCode finalize()
Definition: TriggerSelectorAlg.cxx:147
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TriggerSelectorAlg::m_prescale
unsigned int m_prescale
Definition: TriggerSelectorAlg.h:45
TriggerSelectorAlg.h
TMsgLogger.h
TriggerSelectorAlg::TriggerSelectorAlg
TriggerSelectorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TriggerSelectorAlg.cxx:15
TriggerSelectorAlg::m_accept
unsigned int m_accept
Definition: TriggerSelectorAlg.h:44
Root::TMsgLogger::SetMinLevel
static void SetMinLevel(TMsgLevel minLevel)
Definition: TMsgLogger.h:96