ATLAS Offline Software
GoodRunsListSelectorTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
10 #include "GoodRunsLists/StrUtil.h"
11 
13 
14 #include "GaudiKernel/MsgStream.h"
15 
16 #include "TFormula.h"
17 #include "TSystem.h"
18 
19 #include <sys/stat.h>
20 
21 using namespace std;
22 
23 GoodRunsListSelectorTool::GoodRunsListSelectorTool( const std::string& type, const std::string& name, const IInterface* parent )
24  : AthAlgTool( type, name, parent )
25  , m_reader(0)
26  , m_boolop(0)
27  , m_passthrough(true)
28  , m_verbose(false)
29  , m_rejectanybrl(false)
30  , m_eventselectormode(false)
31 {
32  declareInterface<IGoodRunsListSelectorTool>(this);
33  declareInterface<IAthenaEvtLoopPreSelectTool>(this);
34 
35  declareProperty( "GoodRunsListVec", m_goodrunslistVec, "list of input xml files" );
36  declareProperty( "BlackRunsListVec", m_blackrunslistVec, "list of input xml files" );
37  declareProperty( "BoolOperation", m_boolop );
38  declareProperty( "PassThrough", m_passthrough = true);
39  declareProperty( "VerboseDetStatus", m_verbose = false);
40  declareProperty( "RejectBlackRunsInEventSelector", m_rejectanybrl = false );
41  declareProperty( "EventSelectorMode", m_eventselectormode = false );
42 
46 }
47 
48 
50 {
51  if (m_grlcollection!=0) delete m_grlcollection;
52  if (m_brlcollection!=0) delete m_brlcollection;
53  if (m_reader!=0) delete m_reader;
54 
55  // delete all the formula pntrs in the map
56  while ( ! m_dqformula.empty() ) {
57  std::map< std::string,TFormula* >::iterator itr= m_dqformula.begin();
58  TFormula* form = (*itr).second;
59  m_dqformula.erase(itr);
60  delete form;
61  }
62 }
63 
64 
66 GoodRunsListSelectorTool::queryInterface( const InterfaceID& riid, void** ppvIf )
67 {
69  *ppvIf = (IGoodRunsListSelectorTool*)this;
70  addRef();
71  return StatusCode::SUCCESS;
72  }
73 
74  return AthAlgTool::queryInterface( riid, ppvIf );
75 }
76 
77 
80 {
81  ATH_MSG_DEBUG ("initialize() ");
82 
83  Root::TMsgLogger::SetMinLevel(static_cast<Root::TMsgLevel>(msgLevel()));
84 
86  if (!m_goodrunslistVec.empty() || !m_blackrunslistVec.empty() || m_usecool)
87  m_passthrough=false;
88 
90  if (m_passthrough) ATH_MSG_WARNING ("Set to pass-through mode.");
91 
94  for (itr=m_goodrunslistVec.begin(); itr!=m_goodrunslistVec.end() && !m_usecool; ++itr) {
95  //const char* fname;
96  std::string fname;
97  if ( itr->find("/")==0 || itr->find("$")==0 || itr->find(".")==0 || itr->find(":")!=string::npos ) {
98  fname = gSystem->ExpandPathName( itr->c_str() );
99  }
100  else {
101  fname = (PathResolverFindXMLFile( *itr ));
102  }
103  if ( !fileExists(fname.c_str()) ) {
104  ATH_MSG_ERROR ("Cannot open file : " << fname);
105  return StatusCode::FAILURE;
106  }
107  }
108  for (itr=m_blackrunslistVec.begin(); itr!=m_blackrunslistVec.end() && !m_usecool; ++itr) {
109  //const char* fname;
110  std::string fname;
111  if ( itr->find("/")==0 || itr->find("$")==0 || itr->find(".")==0 || itr->find(":")!=string::npos ) {
112  fname = gSystem->ExpandPathName( itr->c_str() );
113  }
114  else {
115  fname = (PathResolverFindXMLFile( *itr ));
116  }
117  if ( !fileExists(fname.c_str()) ) {
118  ATH_MSG_ERROR ("Cannot open file : " << fname);
119  return StatusCode::FAILURE;
120  }
121  }
123  if ( !m_goodrunslistVec.empty() ) {
124  m_reader->Reset();
125  for (itr=m_goodrunslistVec.begin(); itr!=m_goodrunslistVec.end() && !m_usecool; ++itr) {
126  //const char* fname;
127  std::string fname;
128  if ( itr->find("/")==0 || itr->find("$")==0 || itr->find(".")==0 || itr->find(":")!=string::npos ) {
129  fname = gSystem->ExpandPathName( itr->c_str() );
130  }
131  else {
132  fname = (PathResolverFindXMLFile( *itr ));
133  }
134  m_reader->AddXMLFile(fname);
135  }
136  m_reader->Interpret();
138  *m_grlcollection = m_reader->GetMergedGRLCollection(static_cast<Root::BoolOperation>(m_boolop));
139  }
140  if ( !m_blackrunslistVec.empty() ) {
141  m_reader->Reset();
142  for (itr=m_blackrunslistVec.begin(); itr!=m_blackrunslistVec.end() && !m_usecool; ++itr) {
143  //const char* fname;
144  std::string fname;
145  if ( itr->find("/")==0 || itr->find("$")==0 || itr->find(".")==0 || itr->find(":")!=string::npos ) {
146  fname = gSystem->ExpandPathName( itr->c_str() );
147  }
148  else {
149  fname = (PathResolverFindXMLFile( *itr ));
150  }
151  m_reader->AddXMLFile(fname);
152  }
153  m_reader->Interpret();
155  *m_brlcollection = m_reader->GetMergedGRLCollection(static_cast<Root::BoolOperation>(m_boolop));
156  }
157 
158  return StatusCode::SUCCESS;
159 }
160 
161 
162 bool
163 GoodRunsListSelectorTool::passEvent(const EventIDBase& pEvent)
164 {
165  ATH_MSG_DEBUG ("passEvent() ");
166 
167  auto eventNumber = pEvent.event_number();
168  int runNumber = pEvent.run_number();
169  int lumiBlockNr = pEvent.lumi_block();
170  auto timeStamp = pEvent.time_stamp();
171 
172  ATH_MSG_DEBUG ("passEvent() :: run number = " << runNumber <<
173  " ; event number = " << eventNumber <<
174  " ; lumiblock number = " << lumiBlockNr <<
175  " ; timestamp = " << timeStamp
176  );
177 
179  bool pass(false);
180  if (m_passthrough) {
181  ATH_MSG_DEBUG ("passEvent() :: Pass through mode.");
182  pass = true;
183  }
185  else {
186  pass = this->passRunLB(runNumber,lumiBlockNr);
187  }
188 
189  return pass;
190 }
191 
192 
193 bool
194 GoodRunsListSelectorTool::passThisRunLB( const std::vector<std::string>& grlnameVec,
195  const std::vector<std::string>& brlnameVec )
196 {
197  ATH_MSG_DEBUG ("passThisRunLB() ");
198 
199  const EventContext& ctx = Gaudi::Hive::currentContext();
200 
201  int eventNumber = ctx.eventID().event_number();
202  int runNumber = ctx.eventID().run_number();
203  int lumiBlockNr = ctx.eventID().lumi_block();
204  int timeStamp = ctx.eventID().time_stamp();
205 
206  ATH_MSG_DEBUG ("passThisRunLB() :: run number = " << runNumber <<
207  " ; event number = " << eventNumber <<
208  " ; lumiblock number = " << lumiBlockNr <<
209  " ; timestamp = " << timeStamp
210  );
211 
213  bool pass(false);
214  if (m_passthrough) {
215  ATH_MSG_DEBUG ("passThisRunLB() :: Pass through mode.");
216  pass = true;
217  }
219  else {
220  pass = this->passRunLB(runNumber,lumiBlockNr,grlnameVec,brlnameVec);
221  }
222 
223  return pass;
224 }
225 
226 
227 bool
229  const std::vector<std::string>& grlnameVec,
230  const std::vector<std::string>& brlnameVec )
231 {
232  ATH_MSG_DEBUG ("passRunLB() ");
233 
235  if (m_passthrough) {
236  ATH_MSG_DEBUG ("passRunLB() :: Pass through mode.");
237  return true;
238  }
239 
241  if ( m_rejectanybrl && m_eventselectormode ) {
242  if ( m_brlcollection->HasRunLumiBlock(runNumber,lumiBlockNr) ) {
243  ATH_MSG_DEBUG ("passRunLB() :: Event rejected by (_any_ of) merged black runs list.");
244  return false;
245  }
247  } else if (!brlnameVec.empty()) {
248  bool reject(false);
249  std::vector<Root::TGoodRunsList>::const_iterator brlitr;
250  for (unsigned int i=0; i<brlnameVec.size() && !reject; ++i) {
251  brlitr = m_brlcollection->find(brlnameVec[i]);
252  if (brlitr!=m_brlcollection->end())
253  reject = brlitr->HasRunLumiBlock(runNumber,lumiBlockNr);
254  }
255  if (reject) {
256  ATH_MSG_DEBUG ("passRunLB() :: Event rejected by specific black runs list.");
257  return false;
258  }
259  }
260 
262  if (!grlnameVec.empty()) {
263  bool pass(false);
264  std::vector<Root::TGoodRunsList>::const_iterator grlitr;
265  for (unsigned int i=0; i<grlnameVec.size() && !pass; ++i) {
266  grlitr = m_grlcollection->find(grlnameVec[i]);
267  if (grlitr!=m_grlcollection->end())
268  pass = grlitr->HasRunLumiBlock(runNumber,lumiBlockNr);
269  }
270  if (pass) {
271  ATH_MSG_DEBUG ("passRunLB() :: Event accepted by specific good runs list.");
272  return true;
273  }
275  } else if (m_grlcollection->HasRunLumiBlock(runNumber,lumiBlockNr)) {
276  ATH_MSG_DEBUG ("passRunLB() :: Event accepted by (_any_ of) merged good runs list.");
277  return true;
278  }
279 
280  ATH_MSG_DEBUG ("passRunLB() :: Event rejected, not in (any) good runs list.");
281  return false;
282 }
283 
284 
287 {
288  ATH_MSG_DEBUG ("finalize() ");
289  return StatusCode::SUCCESS;
290 }
291 
292 
293 bool
295 {
296  struct stat info;
297  int ret = -1;
298 
299  //get the file attributes
300  ret = stat(fileName, &info);
301 
302  if(ret == 0) {
305  //if (info.st_size == 0) return false;
306  //else
307  return true;
308  } else {
310  return false;
311  }
312 }
313 
314 
315 bool
316 GoodRunsListSelectorTool::registerGRLSelector(const std::string& name, const std::vector<std::string>& grlnameVec, const std::vector<std::string>& brlnameVec)
317 {
318  if (m_registry.find(name)!=m_registry.end()) {
319  ATH_MSG_WARNING ("registerGRLSelector() :: GRL selector with name <" << name << "> already registered. Return false.");
320  return false;
321  }
322 
324  if (!brlnameVec.empty()) {
325  std::vector<Root::TGoodRunsList>::const_iterator brlitr;
326  for (unsigned int i=0; i<brlnameVec.size(); ++i) {
327  brlitr = m_brlcollection->find(brlnameVec[i]);
328  if (brlitr==m_brlcollection->end()) {
329  ATH_MSG_ERROR ("registerGRLSelector() :: requested BRL object with name <" << brlnameVec[i] << "> not found. Have you provided an object name from the BRL xml-file(s)?");
330  return false;
331  }
332  }
333  }
334 
336  if (!grlnameVec.empty()) {
337  std::vector<Root::TGoodRunsList>::const_iterator grlitr;
338  for (unsigned int i=0; i<grlnameVec.size(); ++i) {
339  grlitr = m_grlcollection->find(grlnameVec[i]);
340  if (grlitr==m_grlcollection->end()) {
341  ATH_MSG_ERROR ("registerGRLSelector() :: requested GRL object with name <" << grlnameVec[i] << "> not found. Have you provided an object name from the GRL xml-file(s)?");
342  return false;
343  }
344  }
345  }
346 
347  ATH_MSG_DEBUG ("registerGRLSelector() :: GRL selector with name <" << name << "> registered.");
348  m_registry[name] = vvPair(grlnameVec,brlnameVec);
349  return true;
350 }
grepfile.info
info
Definition: grepfile.py:38
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
Root::TGoodRunsListReader
Definition: TGoodRunsListReader.h:34
GoodRunsListSelectorTool::m_boolop
int m_boolop
Definition: GoodRunsListSelectorTool.h:87
TGRLCollection.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
GoodRunsListSelectorTool::m_grlcollection
Root::TGRLCollection * m_grlcollection
Definition: GoodRunsListSelectorTool.h:80
GoodRunsListSelectorTool::fileExists
bool fileExists(const char *fileName)
Definition: GoodRunsListSelectorTool.cxx:294
GoodRunsListSelectorTool::m_rejectanybrl
bool m_rejectanybrl
Definition: GoodRunsListSelectorTool.h:91
GoodRunsListSelectorTool::m_goodrunslistVec
std::vector< std::string > m_goodrunslistVec
Definition: GoodRunsListSelectorTool.h:77
GoodRunsListSelectorTool::~GoodRunsListSelectorTool
virtual ~GoodRunsListSelectorTool()
Definition: GoodRunsListSelectorTool.cxx:49
GoodRunsListSelectorTool::m_eventselectormode
bool m_eventselectormode
Definition: GoodRunsListSelectorTool.h:92
IGoodRunsListSelectorTool
Definition: IGoodRunsListSelectorTool.h:19
GoodRunsListSelectorTool::finalize
StatusCode finalize()
Finalize AlgTool.
Definition: GoodRunsListSelectorTool.cxx:286
vvPair
std::pair< std::vector< std::string >, std::vector< std::string > > vvPair
Definition: IGoodRunsListSelectorTool.h:13
GoodRunsListSelectorTool::passRunLB
bool passRunLB(int runNumber, int lumiBlockNr, const std::vector< std::string > &grlnameVec=std::vector< std::string >(), const std::vector< std::string > &brlnameVec=std::vector< std::string >())
called for each event by GoodRunsListSelectorAlg to decide if the event should be passed
Definition: GoodRunsListSelectorTool.cxx:228
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
ret
T ret(T t)
Definition: rootspy.cxx:260
GoodRunsListSelectorTool::registerGRLSelector
bool registerGRLSelector(const std::string &name, const std::vector< std::string > &grlnameVec, const std::vector< std::string > &brlnameVec)
register grl/brl combination
Definition: GoodRunsListSelectorTool.cxx:316
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
GoodRunsListSelectorTool::queryInterface
StatusCode queryInterface(const InterfaceID &riid, void **ppvIf)
To allow access to the IGoodRunsListSelectorTool interface.
Definition: GoodRunsListSelectorTool.cxx:66
PathResolverFindXMLFile
std::string PathResolverFindXMLFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:374
Root::TMsgLevel
TMsgLevel
Definition: TMsgLogger.h:42
GoodRunsListSelectorTool::m_brlcollection
Root::TGRLCollection * m_brlcollection
Definition: GoodRunsListSelectorTool.h:81
test_pyathena.parent
parent
Definition: test_pyathena.py:15
xAOD::eventNumber
eventNumber
Definition: EventInfo_v1.cxx:124
GoodRunsListSelectorTool::GoodRunsListSelectorTool
GoodRunsListSelectorTool(const std::string &, const std::string &, const IInterface *)
Definition: GoodRunsListSelectorTool.cxx:23
beamspotman.stat
stat
Definition: beamspotman.py:266
Root::TGRLCollection
Definition: TGRLCollection.h:29
GoodRunsListSelectorTool::passEvent
bool passEvent(const EventIDBase &pEvent)
called for each event by EventSelector to decide if the event should be passed
Definition: GoodRunsListSelectorTool.cxx:163
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
GoodRunsListSelectorTool::passThisRunLB
bool passThisRunLB(const std::vector< std::string > &grlnameVec=std::vector< std::string >(), const std::vector< std::string > &brlnameVec=std::vector< std::string >())
called for each event by GoodRunsListSelectorAlg to decide if the event should be passed
Definition: GoodRunsListSelectorTool.cxx:194
StrUtil.h
TGoodRunsListReader.h
IGoodRunsListSelectorTool::interfaceID
static const InterfaceID & interfaceID()
Definition: IGoodRunsListSelectorTool.h:22
xAOD::timeStamp
setEventNumber timeStamp
Definition: EventInfo_v1.cxx:128
python.AthDsoLogger.fname
string fname
Definition: AthDsoLogger.py:67
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
GoodRunsListSelectorTool::m_blackrunslistVec
std::vector< std::string > m_blackrunslistVec
Definition: GoodRunsListSelectorTool.h:78
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
GoodRunsListSelectorTool.h
This file contains the class definition for the GoodRunsListSelectorTool class.
TMsgLogger.h
GoodRunsListSelectorTool::m_passthrough
bool m_passthrough
Definition: GoodRunsListSelectorTool.h:88
AthAlgTool
Definition: AthAlgTool.h:26
Root::BoolOperation
BoolOperation
Definition: TGRLCollection.h:27
GoodRunsListSelectorTool::initialize
StatusCode initialize()
Initialize AlgTool.
Definition: GoodRunsListSelectorTool.cxx:79
GoodRunsListSelectorTool::m_verbose
bool m_verbose
Definition: GoodRunsListSelectorTool.h:90
GoodRunsListSelectorTool::m_reader
Root::TGoodRunsListReader * m_reader
Definition: GoodRunsListSelectorTool.h:83
Root::TMsgLogger::SetMinLevel
static void SetMinLevel(TMsgLevel minLevel)
Definition: TMsgLogger.h:96
fileExists
bool fileExists(const std::string &filename)
Definition: main_comphistfiles.cxx:57