ATLAS Offline Software
GoodRunsListSelectorTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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  : base_class( 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  declareProperty( "GoodRunsListVec", m_goodrunslistVec, "list of input xml files" );
33  declareProperty( "BlackRunsListVec", m_blackrunslistVec, "list of input xml files" );
34  declareProperty( "BoolOperation", m_boolop );
35  declareProperty( "PassThrough", m_passthrough = true);
36  declareProperty( "VerboseDetStatus", m_verbose = false);
37  declareProperty( "RejectBlackRunsInEventSelector", m_rejectanybrl = false );
38  declareProperty( "EventSelectorMode", m_eventselectormode = false );
39 
43 }
44 
45 
47 {
48  if (m_grlcollection!=0) delete m_grlcollection;
49  if (m_brlcollection!=0) delete m_brlcollection;
50  if (m_reader!=0) delete m_reader;
51 
52  // delete all the formula pntrs in the map
53  while ( ! m_dqformula.empty() ) {
54  std::map< std::string,TFormula* >::iterator itr= m_dqformula.begin();
55  TFormula* form = (*itr).second;
56  m_dqformula.erase(itr);
57  delete form;
58  }
59 }
60 
61 
64 {
65  ATH_MSG_DEBUG ("initialize() ");
66 
67  Root::TMsgLogger::SetMinLevel(static_cast<Root::TMsgLevel>(msgLevel()));
68 
70  if (!m_goodrunslistVec.empty() || !m_blackrunslistVec.empty() || m_usecool)
71  m_passthrough=false;
72 
74  if (m_passthrough) ATH_MSG_WARNING ("Set to pass-through mode.");
75 
78  for (itr=m_goodrunslistVec.begin(); itr!=m_goodrunslistVec.end() && !m_usecool; ++itr) {
79  //const char* fname;
80  std::string fname;
81  if ( itr->find("/")==0 || itr->find("$")==0 || itr->find(".")==0 || itr->find(":")!=string::npos ) {
82  fname = gSystem->ExpandPathName( itr->c_str() );
83  }
84  else {
85  fname = (PathResolverFindXMLFile( *itr ));
86  }
87  if ( !fileExists(fname.c_str()) ) {
88  ATH_MSG_ERROR ("Cannot open file : " << fname);
89  return StatusCode::FAILURE;
90  }
91  }
92  for (itr=m_blackrunslistVec.begin(); itr!=m_blackrunslistVec.end() && !m_usecool; ++itr) {
93  //const char* fname;
94  std::string fname;
95  if ( itr->find("/")==0 || itr->find("$")==0 || itr->find(".")==0 || itr->find(":")!=string::npos ) {
96  fname = gSystem->ExpandPathName( itr->c_str() );
97  }
98  else {
99  fname = (PathResolverFindXMLFile( *itr ));
100  }
101  if ( !fileExists(fname.c_str()) ) {
102  ATH_MSG_ERROR ("Cannot open file : " << fname);
103  return StatusCode::FAILURE;
104  }
105  }
107  if ( !m_goodrunslistVec.empty() ) {
108  m_reader->Reset();
109  for (itr=m_goodrunslistVec.begin(); itr!=m_goodrunslistVec.end() && !m_usecool; ++itr) {
110  //const char* fname;
111  std::string fname;
112  if ( itr->find("/")==0 || itr->find("$")==0 || itr->find(".")==0 || itr->find(":")!=string::npos ) {
113  fname = gSystem->ExpandPathName( itr->c_str() );
114  }
115  else {
116  fname = (PathResolverFindXMLFile( *itr ));
117  }
118  m_reader->AddXMLFile(fname);
119  }
120  m_reader->Interpret();
122  *m_grlcollection = m_reader->GetMergedGRLCollection(static_cast<Root::BoolOperation>(m_boolop));
123  }
124  if ( !m_blackrunslistVec.empty() ) {
125  m_reader->Reset();
126  for (itr=m_blackrunslistVec.begin(); itr!=m_blackrunslistVec.end() && !m_usecool; ++itr) {
127  //const char* fname;
128  std::string fname;
129  if ( itr->find("/")==0 || itr->find("$")==0 || itr->find(".")==0 || itr->find(":")!=string::npos ) {
130  fname = gSystem->ExpandPathName( itr->c_str() );
131  }
132  else {
133  fname = (PathResolverFindXMLFile( *itr ));
134  }
135  m_reader->AddXMLFile(fname);
136  }
137  m_reader->Interpret();
139  *m_brlcollection = m_reader->GetMergedGRLCollection(static_cast<Root::BoolOperation>(m_boolop));
140  }
141 
142  return StatusCode::SUCCESS;
143 }
144 
145 
146 bool
147 GoodRunsListSelectorTool::passEvent(const EventIDBase& pEvent)
148 {
149  ATH_MSG_DEBUG ("passEvent() ");
150 
151  auto eventNumber = pEvent.event_number();
152  int runNumber = pEvent.run_number();
153  int lumiBlockNr = pEvent.lumi_block();
154  auto timeStamp = pEvent.time_stamp();
155 
156  ATH_MSG_DEBUG ("passEvent() :: run number = " << runNumber <<
157  " ; event number = " << eventNumber <<
158  " ; lumiblock number = " << lumiBlockNr <<
159  " ; timestamp = " << timeStamp
160  );
161 
163  bool pass(false);
164  if (m_passthrough) {
165  ATH_MSG_DEBUG ("passEvent() :: Pass through mode.");
166  pass = true;
167  }
169  else {
170  pass = this->passRunLB(runNumber,lumiBlockNr);
171  }
172 
173  return pass;
174 }
175 
176 
177 bool
178 GoodRunsListSelectorTool::passThisRunLB( const std::vector<std::string>& grlnameVec,
179  const std::vector<std::string>& brlnameVec )
180 {
181  ATH_MSG_DEBUG ("passThisRunLB() ");
182 
183  const EventContext& ctx = Gaudi::Hive::currentContext();
184 
185  int eventNumber = ctx.eventID().event_number();
186  int runNumber = ctx.eventID().run_number();
187  int lumiBlockNr = ctx.eventID().lumi_block();
188  int timeStamp = ctx.eventID().time_stamp();
189 
190  ATH_MSG_DEBUG ("passThisRunLB() :: run number = " << runNumber <<
191  " ; event number = " << eventNumber <<
192  " ; lumiblock number = " << lumiBlockNr <<
193  " ; timestamp = " << timeStamp
194  );
195 
197  bool pass(false);
198  if (m_passthrough) {
199  ATH_MSG_DEBUG ("passThisRunLB() :: Pass through mode.");
200  pass = true;
201  }
203  else {
204  pass = this->passRunLB(runNumber,lumiBlockNr,grlnameVec,brlnameVec);
205  }
206 
207  return pass;
208 }
209 
210 
211 bool
213  const std::vector<std::string>& grlnameVec,
214  const std::vector<std::string>& brlnameVec )
215 {
216  ATH_MSG_DEBUG ("passRunLB() ");
217 
219  if (m_passthrough) {
220  ATH_MSG_DEBUG ("passRunLB() :: Pass through mode.");
221  return true;
222  }
223 
225  if ( m_rejectanybrl && m_eventselectormode ) {
226  if ( m_brlcollection->HasRunLumiBlock(runNumber,lumiBlockNr) ) {
227  ATH_MSG_DEBUG ("passRunLB() :: Event rejected by (_any_ of) merged black runs list.");
228  return false;
229  }
231  } else if (!brlnameVec.empty()) {
232  bool reject(false);
233  std::vector<Root::TGoodRunsList>::const_iterator brlitr;
234  for (unsigned int i=0; i<brlnameVec.size() && !reject; ++i) {
235  brlitr = m_brlcollection->find(brlnameVec[i]);
236  if (brlitr!=m_brlcollection->end())
237  reject = brlitr->HasRunLumiBlock(runNumber,lumiBlockNr);
238  }
239  if (reject) {
240  ATH_MSG_DEBUG ("passRunLB() :: Event rejected by specific black runs list.");
241  return false;
242  }
243  }
244 
246  if (!grlnameVec.empty()) {
247  bool pass(false);
248  std::vector<Root::TGoodRunsList>::const_iterator grlitr;
249  for (unsigned int i=0; i<grlnameVec.size() && !pass; ++i) {
250  grlitr = m_grlcollection->find(grlnameVec[i]);
251  if (grlitr!=m_grlcollection->end())
252  pass = grlitr->HasRunLumiBlock(runNumber,lumiBlockNr);
253  }
254  if (pass) {
255  ATH_MSG_DEBUG ("passRunLB() :: Event accepted by specific good runs list.");
256  return true;
257  }
259  } else if (m_grlcollection->HasRunLumiBlock(runNumber,lumiBlockNr)) {
260  ATH_MSG_DEBUG ("passRunLB() :: Event accepted by (_any_ of) merged good runs list.");
261  return true;
262  }
263 
264  ATH_MSG_DEBUG ("passRunLB() :: Event rejected, not in (any) good runs list.");
265  return false;
266 }
267 
268 
271 {
272  ATH_MSG_DEBUG ("finalize() ");
273  return StatusCode::SUCCESS;
274 }
275 
276 
277 bool
279 {
280  struct stat info;
281  int ret = -1;
282 
283  //get the file attributes
284  ret = stat(fileName, &info);
285 
286  if(ret == 0) {
289  //if (info.st_size == 0) return false;
290  //else
291  return true;
292  } else {
294  return false;
295  }
296 }
297 
298 
299 bool
300 GoodRunsListSelectorTool::registerGRLSelector(const std::string& name, const std::vector<std::string>& grlnameVec, const std::vector<std::string>& brlnameVec)
301 {
302  if (m_registry.find(name)!=m_registry.end()) {
303  ATH_MSG_WARNING ("registerGRLSelector() :: GRL selector with name <" << name << "> already registered. Return false.");
304  return false;
305  }
306 
308  if (!brlnameVec.empty()) {
309  std::vector<Root::TGoodRunsList>::const_iterator brlitr;
310  for (unsigned int i=0; i<brlnameVec.size(); ++i) {
311  brlitr = m_brlcollection->find(brlnameVec[i]);
312  if (brlitr==m_brlcollection->end()) {
313  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)?");
314  return false;
315  }
316  }
317  }
318 
320  if (!grlnameVec.empty()) {
321  std::vector<Root::TGoodRunsList>::const_iterator grlitr;
322  for (unsigned int i=0; i<grlnameVec.size(); ++i) {
323  grlitr = m_grlcollection->find(grlnameVec[i]);
324  if (grlitr==m_grlcollection->end()) {
325  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)?");
326  return false;
327  }
328  }
329  }
330 
331  ATH_MSG_DEBUG ("registerGRLSelector() :: GRL selector with name <" << name << "> registered.");
332  m_registry[name] = vvPair(grlnameVec,brlnameVec);
333  return true;
334 }
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:78
TGRLCollection.h
GoodRunsListSelectorTool::m_grlcollection
Root::TGRLCollection * m_grlcollection
Definition: GoodRunsListSelectorTool.h:71
GoodRunsListSelectorTool::fileExists
bool fileExists(const char *fileName)
Definition: GoodRunsListSelectorTool.cxx:278
GoodRunsListSelectorTool::m_rejectanybrl
bool m_rejectanybrl
Definition: GoodRunsListSelectorTool.h:82
GoodRunsListSelectorTool::m_goodrunslistVec
std::vector< std::string > m_goodrunslistVec
Definition: GoodRunsListSelectorTool.h:68
GoodRunsListSelectorTool::~GoodRunsListSelectorTool
virtual ~GoodRunsListSelectorTool()
Definition: GoodRunsListSelectorTool.cxx:46
GoodRunsListSelectorTool::m_eventselectormode
bool m_eventselectormode
Definition: GoodRunsListSelectorTool.h:83
GoodRunsListSelectorTool::finalize
StatusCode finalize()
Finalize AlgTool.
Definition: GoodRunsListSelectorTool.cxx:270
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:212
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:85
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:300
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
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:72
test_pyathena.parent
parent
Definition: test_pyathena.py:15
xAOD::eventNumber
eventNumber
Definition: EventInfo_v1.cxx:124
CreateTrfArgs.fileExists
def fileExists(fp)
Definition: CreateTrfArgs.py:4
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:147
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
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:178
StrUtil.h
TGoodRunsListReader.h
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:69
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:79
Root::BoolOperation
BoolOperation
Definition: TGRLCollection.h:27
GoodRunsListSelectorTool::initialize
StatusCode initialize()
Initialize AlgTool.
Definition: GoodRunsListSelectorTool.cxx:63
GoodRunsListSelectorTool::m_verbose
bool m_verbose
Definition: GoodRunsListSelectorTool.h:81
GoodRunsListSelectorTool::m_reader
Root::TGoodRunsListReader * m_reader
Definition: GoodRunsListSelectorTool.h:74
Root::TMsgLogger::SetMinLevel
static void SetMinLevel(TMsgLevel minLevel)
Definition: TMsgLogger.h:96