ATLAS Offline Software
GRLTriggerSelectorAlg.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 
9 
11 #include "TrigDecisionTool/TrigDecisionTool.h" // rel 15
12 #include "TrigDecisionEvent/TrigDecision.h" // rel 15
13 #include "TROOT.h"
14 
15 GRLTriggerSelectorAlg::GRLTriggerSelectorAlg(const std::string& name, ISvcLocator* pSvcLocator)
16  : AthAlgorithm(name, pSvcLocator)
17  , m_GoodRunsListSelectorTool("GoodRunsListSelectorTool")
18  , m_TriggerRegistryTool("TriggerRegistryTool")
19  , m_tdTool("Trig::TrigDecisionTool")
20  , m_gcounter(0)
21  , m_gaccept(0)
22  , m_tcounter(0)
23  , m_taccept(0)
24  , m_trigpar(0)
25  , m_applyTriggerSelection(false)
26 {
27  declareProperty( "GoodRunsListArray", m_grlnameVec );
28  declareProperty( "BlackRunsListArray", m_brlnameVec );
29  declareProperty( "TriggerSelection", m_regexpr );
30  declareProperty( "TriggerSelectionRegistration", m_regexprRegistrationOnly );
31  declareProperty( "CounterPrescale", m_prescale = 1000 );
32 }
33 
34 
36 {
37  // cleanup
38  if (m_trigpar!=0) { delete[] m_trigpar; m_trigpar=0; }
39 }
40 
41 
43 {
44  ATH_MSG_DEBUG ("initialize()");
45 
46  Root::TMsgLogger::SetMinLevel(static_cast<Root::TMsgLevel>(msgLevel()));
47 
49  {
50  std::ostringstream tmp;
51  tmp << "Sequence" << m_GoodRunsListSelectorTool->getGRLSelectorRegistry().size();
52  m_myname = tmp.str();
53  };
54 
56 
58  if ( m_GoodRunsListSelectorTool.retrieve().isFailure() ) {
60  (m_GoodRunsListSelectorTool.propertyName() << ": Failed to retrieve tool "
61  << m_GoodRunsListSelectorTool.type());
62  return StatusCode::FAILURE;
63  } else {
65  (m_GoodRunsListSelectorTool.propertyName() << ": Retrieved tool "
66  << m_GoodRunsListSelectorTool.type());
67  }
68 
70  ATH_MSG_INFO ("initialize() :: Now registering this GRL Selector with unique name <" << m_myname << ">.");
71  bool regOk = m_GoodRunsListSelectorTool->registerGRLSelector(m_myname,m_grlnameVec,m_brlnameVec);
72  if (!regOk) {
73  ATH_MSG_ERROR ("initialize() :: Failure to register this GRL Selector with name <" << m_myname << ">. Return failure.");
74  return StatusCode::FAILURE;
75  }
76 
78 
80  if (!m_regexprRegistrationOnly.empty() && m_regexpr.empty()) {
83  } else if (m_regexprRegistrationOnly.empty() && !m_regexpr.empty()) {
85  } else if (!m_regexprRegistrationOnly.empty() && !m_regexpr.empty()) {
86  ATH_MSG_WARNING ("initialize() :: Both TriggerSelectionRegistration and TriggerSelection are set. Ignoring TriggerSelectionRegistration.");
89  } else { // default in case nothing is set, pass through mode
90  m_regexpr = "1";
92  }
93 
95  ATH_MSG_INFO ("initialize() :: Trigger selection set to pass-through mode.");
96 
98  if ( m_TriggerRegistryTool.retrieve().isFailure() ) {
100  (m_TriggerRegistryTool.propertyName() << ": Failed to retrieve tool "
101  << m_TriggerRegistryTool.type());
102  return StatusCode::FAILURE;
103  } else {
105  (m_TriggerRegistryTool.propertyName() << ": Retrieved tool "
106  << m_TriggerRegistryTool.type());
107  }
108 
109  int formOk = m_formula.setFormula(m_regexpr.c_str()) ;
110 
111  if ( 0!=formOk ) {
112  ATH_MSG_ERROR ("Cannot parse regular expression : " << m_regexpr << " . Return Failure.");
113  return StatusCode::FAILURE;
114  }
115 
116  // get trigger names from formula
118  m_trigpar = new double[m_formula.getNPars()];
119 
121  ATH_MSG_INFO ("initialize() :: Now registering this Trigger Selector with unique name <" << m_myname << ">.");
122  regOk = m_TriggerRegistryTool->registerTriggerSelector(m_myname,m_regexpr,m_par);
123  if (!regOk) {
124  ATH_MSG_ERROR ("initialize() :: Failure to register this Trigger Selector with name <" << m_myname << ">. Return failure.");
125  return StatusCode::FAILURE;
126  }
127 
129 
130  ATH_MSG_DEBUG ("initialize() successful");
131 
132  return StatusCode::SUCCESS;
133 }
134 
135 
136 StatusCode
138 {
139  ATH_MSG_DEBUG ("execute()");
140 
142 
143  if (m_gcounter % m_prescale == 0)
144  ATH_MSG_INFO ("Now processing event passing GRL selection : " << m_gcounter);
145  m_gcounter++ ;
146 
147  bool statusOk = m_GoodRunsListSelectorTool->passThisRunLB(m_grlnameVec,m_brlnameVec);
148  this->setFilterPassed (statusOk); // This skips the execution of following algs for this event
149  if (statusOk) ++m_gaccept;
150  else { return StatusCode::SUCCESS; }
151 
153 
155  if( m_tdTool.retrieve().isFailure()) {
156  ATH_MSG_ERROR ("Could not retrieve TrigDecisionTool. Return Failure.");
157  return StatusCode::FAILURE;
158  } else {
159  ATH_MSG_DEBUG ("Successfully retrieved TrigDecisionTool.");
160  }
161  }
162 
163  if (m_tcounter % m_prescale == 0)
164  ATH_MSG_INFO ("Now processing event passing Trigger selection : " << m_tcounter);
165  m_tcounter++ ;
166 
167  // Filling trigger map
168  std::list<TString>::iterator tnItr = m_par.begin() ;
169  for (unsigned int i=0; tnItr!=m_par.end(); ++tnItr, ++i) {
170  bool isPassed(true);
171  if (m_applyTriggerSelection) { isPassed = m_tdTool->isPassed(tnItr->Data()); }
172  m_trigpar[i] = static_cast<double>(isPassed);
173  ATH_MSG_DEBUG ("Trigger name : " << *tnItr << " = " << m_trigpar[i]);
174  }
175 
176  // evaluate trigger regular expression
177  double dummy(0);
178  bool pass(true);
179  if (m_applyTriggerSelection) pass = static_cast<bool>(m_formula.EvalPar(&dummy,m_trigpar));
180  this->setFilterPassed (pass); // skip execution of following algs for this event
181  if (pass) ++m_taccept;
182 
184 
185  ATH_MSG_DEBUG ("Event accepted? " << pass);
186 
187  ATH_MSG_DEBUG ("execute() successful");
188 
189  return StatusCode::SUCCESS;
190 }
191 
192 
194 {
195  ATH_MSG_DEBUG ("finalize()");
196 
197  ATH_MSG_INFO ("GRL : Processed " << m_gcounter << " events, accepted " << m_gaccept << " events.");
198  ATH_MSG_INFO ("Trigger : Processed " << m_tcounter << " events, accepted " << m_taccept << " events.");
199 
200  ATH_MSG_DEBUG ("finalize() successful");
201 
202  return StatusCode::SUCCESS;
203 }
204 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
GRLTriggerSelectorAlg::m_regexprRegistrationOnly
std::string m_regexprRegistrationOnly
Definition: GRLTriggerSelectorAlg.h:56
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
Root::RegularFormula::getNPars
unsigned int getNPars() const
Definition: RegularFormula.h:45
GRLTriggerSelectorAlg::finalize
StatusCode finalize()
Definition: GRLTriggerSelectorAlg.cxx:193
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
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
IGoodRunsListSelectorTool.h
ITriggerRegistryTool.h
GRLTriggerSelectorAlg.h
GRLTriggerSelectorAlg::m_prescale
unsigned int m_prescale
Definition: GRLTriggerSelectorAlg.h:44
GRLTriggerSelectorAlg::m_par
std::list< TString > m_par
Definition: GRLTriggerSelectorAlg.h:57
TrigDecisionTool.h
GRLTriggerSelectorAlg::m_tdTool
ToolHandle< Trig::TrigDecisionTool > m_tdTool
Definition: GRLTriggerSelectorAlg.h:42
GRLTriggerSelectorAlg::m_tcounter
unsigned int m_tcounter
Definition: GRLTriggerSelectorAlg.h:47
GRLTriggerSelectorAlg::m_myname
std::string m_myname
Definition: GRLTriggerSelectorAlg.h:52
GRLTriggerSelectorAlg::m_GoodRunsListSelectorTool
ToolHandle< IGoodRunsListSelectorTool > m_GoodRunsListSelectorTool
Definition: GRLTriggerSelectorAlg.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
TrigDecision.h
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
GRLTriggerSelectorAlg::m_taccept
unsigned int m_taccept
Definition: GRLTriggerSelectorAlg.h:48
Root::TMsgLevel
TMsgLevel
Definition: TMsgLogger.h:42
Root::RegularFormula::setFormula
Int_t setFormula(const char *expression)
Definition: RegularFormula.cxx:128
GRLTriggerSelectorAlg::GRLTriggerSelectorAlg
GRLTriggerSelectorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: GRLTriggerSelectorAlg.cxx:15
python.xAODType.dummy
dummy
Definition: xAODType.py:4
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
GRLTriggerSelectorAlg::m_TriggerRegistryTool
ToolHandle< ITriggerRegistryTool > m_TriggerRegistryTool
Definition: GRLTriggerSelectorAlg.h:41
AthAlgorithm
Definition: AthAlgorithm.h:47
GRLTriggerSelectorAlg::m_brlnameVec
std::vector< std::string > m_brlnameVec
Definition: GRLTriggerSelectorAlg.h:51
GRLTriggerSelectorAlg::execute
StatusCode execute()
Definition: GRLTriggerSelectorAlg.cxx:137
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
GRLTriggerSelectorAlg::m_grlnameVec
std::vector< std::string > m_grlnameVec
Definition: GRLTriggerSelectorAlg.h:50
GRLTriggerSelectorAlg::m_formula
Root::RegularFormula m_formula
Definition: GRLTriggerSelectorAlg.h:58
GRLTriggerSelectorAlg::m_applyTriggerSelection
bool m_applyTriggerSelection
Definition: GRLTriggerSelectorAlg.h:59
GRLTriggerSelectorAlg::m_trigpar
double * m_trigpar
Definition: GRLTriggerSelectorAlg.h:54
GRLTriggerSelectorAlg::m_gcounter
unsigned int m_gcounter
Definition: GRLTriggerSelectorAlg.h:45
GRLTriggerSelectorAlg::m_gaccept
unsigned int m_gaccept
Definition: GRLTriggerSelectorAlg.h:46
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
GRLTriggerSelectorAlg::initialize
StatusCode initialize()
Definition: GRLTriggerSelectorAlg.cxx:42
TMsgLogger.h
GRLTriggerSelectorAlg::~GRLTriggerSelectorAlg
virtual ~GRLTriggerSelectorAlg()
Definition: GRLTriggerSelectorAlg.cxx:35
Root::TMsgLogger::SetMinLevel
static void SetMinLevel(TMsgLevel minLevel)
Definition: TMsgLogger.h:96
GRLTriggerSelectorAlg::m_regexpr
std::string m_regexpr
Definition: GRLTriggerSelectorAlg.h:56