ATLAS Offline Software
Loading...
Searching...
No Matches
GoodRunsListSelectorTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5
10#include "GaudiKernel/MsgStream.h"
11
12
13#include "TSystem.h"
14#include <sys/stat.h>
15
16using namespace std;
17
18
19StatusCode
21{
22 ATH_MSG_DEBUG ("initialize() ");
23
24 Root::TMsgLogger::SetMinLevel(static_cast<Root::TMsgLevel>(msgLevel()));
25
27 if (!m_goodrunslistVec.empty() || !m_blackrunslistVec.empty())
28 m_passthrough=false;
29
31 if (m_passthrough) ATH_MSG_WARNING ("Set to pass-through mode.");
32
34 std::vector<std::string>::iterator itr;
35 for (itr=m_goodrunslistVec.begin(); itr!=m_goodrunslistVec.end(); ++itr) {
36 std::string fname;
37 if ( itr->find('/')==0 || itr->find('$')==0 || itr->find('.')==0 || itr->find(':')!=string::npos ) {
38 fname = gSystem->ExpandPathName( itr->c_str() );
39 }
40 else {
41 fname = (PathResolverFindXMLFile( *itr ));
42 }
43 if ( !fileExists(fname.c_str()) ) {
44 ATH_MSG_ERROR ("Cannot open file : " << fname);
45 return StatusCode::FAILURE;
46 }
47 }
48 for (itr=m_blackrunslistVec.begin(); itr!=m_blackrunslistVec.end(); ++itr) {
49 std::string fname;
50 if ( itr->find('/')==0 || itr->find('$')==0 || itr->find('.')==0 || itr->find(':')!=string::npos ) {
51 fname = gSystem->ExpandPathName( itr->c_str() );
52 }
53 else {
54 fname = (PathResolverFindXMLFile( *itr ));
55 }
56 if ( !fileExists(fname.c_str()) ) {
57 ATH_MSG_ERROR ("Cannot open file : " << fname);
58 return StatusCode::FAILURE;
59 }
60 }
62 if ( !m_goodrunslistVec.empty() ) {
63 m_reader->Reset();
64 for (itr=m_goodrunslistVec.begin(); itr!=m_goodrunslistVec.end(); ++itr) {
65 std::string fname;
66 if ( itr->find('/')==0 || itr->find('$')==0 || itr->find('.')==0 || itr->find(':')!=string::npos ) {
67 fname = gSystem->ExpandPathName( itr->c_str() );
68 }
69 else {
70 fname = (PathResolverFindXMLFile( *itr ));
71 }
72 m_reader->AddXMLFile(fname);
73 }
74 m_reader->Interpret();
76 *m_grlcollection = m_reader->GetMergedGRLCollection(static_cast<Root::BoolOperation>(m_boolop.value()));
77 }
78 if ( !m_blackrunslistVec.empty() ) {
79 m_reader->Reset();
80 for (itr=m_blackrunslistVec.begin(); itr!=m_blackrunslistVec.end(); ++itr) {
81 std::string fname;
82 if ( itr->find('/')==0 || itr->find('$')==0 || itr->find('.')==0 || itr->find(':')!=string::npos ) {
83 fname = gSystem->ExpandPathName( itr->c_str() );
84 }
85 else {
86 fname = (PathResolverFindXMLFile( *itr ));
87 }
88 m_reader->AddXMLFile(fname);
89 }
90 m_reader->Interpret();
92 *m_brlcollection = m_reader->GetMergedGRLCollection(static_cast<Root::BoolOperation>(m_boolop.value()));
93 }
94
95 return StatusCode::SUCCESS;
96}
97
98
99bool
100GoodRunsListSelectorTool::passEvent(const EventIDBase& pEvent)
101{
102 ATH_MSG_DEBUG ("passEvent() ");
103
104 auto eventNumber = pEvent.event_number();
105 int runNumber = pEvent.run_number();
106 int lumiBlockNr = pEvent.lumi_block();
107 auto timeStamp = pEvent.time_stamp();
108
109 ATH_MSG_DEBUG ("passEvent() :: run number = " << runNumber <<
110 " ; event number = " << eventNumber <<
111 " ; lumiblock number = " << lumiBlockNr <<
112 " ; timestamp = " << timeStamp
113 );
114
116 bool pass(false);
117 if (m_passthrough) {
118 ATH_MSG_DEBUG ("passEvent() :: Pass through mode.");
119 pass = true;
120 }
122 else {
123 pass = this->passRunLB(runNumber,lumiBlockNr);
124 }
125
126 return pass;
127}
128
129
130bool
131GoodRunsListSelectorTool::passThisRunLB( const std::vector<std::string>& grlnameVec,
132 const std::vector<std::string>& brlnameVec )
133{
134 ATH_MSG_DEBUG ("passThisRunLB() ");
135
136 const EventContext& ctx = Gaudi::Hive::currentContext();
137
138 int eventNumber = ctx.eventID().event_number();
139 int runNumber = ctx.eventID().run_number();
140 int lumiBlockNr = ctx.eventID().lumi_block();
141 int timeStamp = ctx.eventID().time_stamp();
142
143 ATH_MSG_DEBUG ("passThisRunLB() :: run number = " << runNumber <<
144 " ; event number = " << eventNumber <<
145 " ; lumiblock number = " << lumiBlockNr <<
146 " ; timestamp = " << timeStamp
147 );
148
150 bool pass(false);
151 if (m_passthrough) {
152 ATH_MSG_DEBUG ("passThisRunLB() :: Pass through mode.");
153 pass = true;
154 }
156 else {
157 pass = this->passRunLB(runNumber,lumiBlockNr,grlnameVec,brlnameVec);
158 }
159
160 return pass;
161}
162
163
164bool
165GoodRunsListSelectorTool::passRunLB( int runNumber, int lumiBlockNr,
166 const std::vector<std::string>& grlnameVec,
167 const std::vector<std::string>& brlnameVec )
168{
169 ATH_MSG_DEBUG ("passRunLB() ");
170
172 if (m_passthrough) {
173 ATH_MSG_DEBUG ("passRunLB() :: Pass through mode.");
174 return true;
175 }
176
179 if ( m_brlcollection->HasRunLumiBlock(runNumber,lumiBlockNr) ) {
180 ATH_MSG_DEBUG ("passRunLB() :: Event rejected by (_any_ of) merged black runs list.");
181 return false;
182 }
184 } else if (!brlnameVec.empty()) {
185 bool reject(false);
186 std::vector<Root::TGoodRunsList>::const_iterator brlitr;
187 for (unsigned int i=0; i<brlnameVec.size() && !reject; ++i) {
188 brlitr = m_brlcollection->find(brlnameVec[i]);
189 if (brlitr!=m_brlcollection->end())
190 reject = brlitr->HasRunLumiBlock(runNumber,lumiBlockNr);
191 }
192 if (reject) {
193 ATH_MSG_DEBUG ("passRunLB() :: Event rejected by specific black runs list.");
194 return false;
195 }
196 }
197
199 if (!grlnameVec.empty()) {
200 bool pass(false);
201 std::vector<Root::TGoodRunsList>::const_iterator grlitr;
202 for (unsigned int i=0; i<grlnameVec.size() && !pass; ++i) {
203 grlitr = m_grlcollection->find(grlnameVec[i]);
204 if (grlitr!=m_grlcollection->end())
205 pass = grlitr->HasRunLumiBlock(runNumber,lumiBlockNr);
206 }
207 if (pass) {
208 ATH_MSG_DEBUG ("passRunLB() :: Event accepted by specific good runs list.");
209 return true;
210 }
212 } else if (m_grlcollection->HasRunLumiBlock(runNumber,lumiBlockNr)) {
213 ATH_MSG_DEBUG ("passRunLB() :: Event accepted by (_any_ of) merged good runs list.");
214 return true;
215 }
216
217 ATH_MSG_DEBUG ("passRunLB() :: Event rejected, not in (any) good runs list.");
218 return false;
219}
220
221
222StatusCode
224{
225 ATH_MSG_DEBUG ("finalize() ");
226 return StatusCode::SUCCESS;
227}
228
229
230bool
232{
233 struct stat info;
234 int ret = -1;
235
236 //get the file attributes
237 ret = stat(fileName, &info);
238
239 if(ret == 0) {
242 //if (info.st_size == 0) return false;
243 //else
244 return true;
245 } else {
247 return false;
248 }
249}
250
251
252bool
253GoodRunsListSelectorTool::registerGRLSelector(const std::string& name, const std::vector<std::string>& grlnameVec, const std::vector<std::string>& brlnameVec)
254{
255 if (m_registry.find(name)!=m_registry.end()) {
256 ATH_MSG_WARNING ("registerGRLSelector() :: GRL selector with name <" << name << "> already registered. Return false.");
257 return false;
258 }
259
261 if (!brlnameVec.empty()) {
262 std::vector<Root::TGoodRunsList>::const_iterator brlitr;
263 for (unsigned int i=0; i<brlnameVec.size(); ++i) {
264 brlitr = m_brlcollection->find(brlnameVec[i]);
265 if (brlitr==m_brlcollection->end()) {
266 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)?");
267 return false;
268 }
269 }
270 }
271
273 if (!grlnameVec.empty()) {
274 std::vector<Root::TGoodRunsList>::const_iterator grlitr;
275 for (unsigned int i=0; i<grlnameVec.size(); ++i) {
276 grlitr = m_grlcollection->find(grlnameVec[i]);
277 if (grlitr==m_grlcollection->end()) {
278 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)?");
279 return false;
280 }
281 }
282 }
283
284 ATH_MSG_DEBUG ("registerGRLSelector() :: GRL selector with name <" << name << "> registered.");
285 m_registry[name] = vvPair(grlnameVec,brlnameVec);
286 return true;
287}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
This file contains the class definition for the GoodRunsListSelectorTool class.
std::pair< std::vector< std::string >, std::vector< std::string > > vvPair
std::string PathResolverFindXMLFile(const std::string &logical_file_name)
bool registerGRLSelector(const std::string &name, const std::vector< std::string > &grlnameVec, const std::vector< std::string > &brlnameVec)
register grl/brl combination
std::unique_ptr< Root::TGRLCollection > m_brlcollection
Gaudi::Property< bool > m_eventselectormode
Gaudi::Property< std::vector< std::string > > m_blackrunslistVec
Gaudi::Property< int > m_boolop
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
bool passEvent(const EventIDBase &pEvent)
called for each event by EventSelector to decide if the event should be passed
Gaudi::Property< bool > m_passthrough
bool fileExists(const char *fileName)
Gaudi::Property< bool > m_rejectanybrl
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
StatusCode finalize()
Finalize AlgTool.
std::unique_ptr< Root::TGRLCollection > m_grlcollection
std::unique_ptr< Root::TGoodRunsListReader > m_reader
Gaudi::Property< std::vector< std::string > > m_goodrunslistVec
StatusCode initialize()
Initialize AlgTool.
std::map< std::string, vvPair > m_registry
static void SetMinLevel(TMsgLevel minLevel)
Definition TMsgLogger.h:92
TMsgLevel
Definition TMsgLogger.h:37
STL namespace.