ATLAS Offline Software
GoodRunsListSelectionTool.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 // $Id$
6 
7 // Framework include(s):
10 
11 // Local include(s):
15 
17  : asg::AsgTool( name ) {}
18 
20 
21  // Tell the user what's happening:
22  ATH_MSG_DEBUG( "Initialising tool" );
23 
24  // Set the output level of the underlying code:
25  const Root::TMsgLevel level =
26  static_cast< Root::TMsgLevel >( msg().level() );
28 
29  // Reset the pass-through mode setting:
30  if( m_goodrunslistVec.size() || m_blackrunslistVec.size() ) {
31  m_passthrough = false;
32  }
33 
34  // Warn about pass-through mode:
35  if( m_passthrough ) {
36  ATH_MSG_WARNING( "Set to pass-through mode." );
37  }
38 
39  // Read in the XML files:
42 
45 
46  // Return gracefully:
47  return StatusCode::SUCCESS;
48 }
49 
51 passRunLB( const std::vector< std::string >& grlnameVec,
52  const std::vector< std::string >& brlnameVec ) const {
53 
54  // Retrieve the xAOD::EventInfo object:
55  const xAOD::EventInfo* ei = 0;
56  if( ! evtStore()->retrieve( ei, "EventInfo" ).isSuccess() ) {
57  ATH_MSG_WARNING( "Couldn't access xAOD::EventInfo object. Using "
58  "pass-through mode..." );
59  return true;
60  }
61 
62  // MC events should not be filtered by this tool:
64  ATH_MSG_VERBOSE( "MC event is accepted by the tool" );
65  return true;
66  }
67 
68  // Use this object:
69  return passRunLB( *ei, grlnameVec, brlnameVec );
70 }
71 
74  const std::vector< std::string >& grlnameVec,
75  const std::vector< std::string >& brlnameVec ) const {
76 
77  int runNumber = event.runNumber();
78  int lumiBlock = event.lumiBlock();
82  runNumber = randomRunNumber(event);
83  lumiBlock = randomLumiBlock(event);
84  }
85 
86  return passRunLB( runNumber, lumiBlock, grlnameVec, brlnameVec );
87 }
88 
89 
91 passRunLB( int runNumber, int lumiBlockNr,
92  const std::vector< std::string >& grlnameVec,
93  const std::vector< std::string >& brlnameVec ) const {
94 
95  ATH_MSG_VERBOSE( "passRunLB()" );
96 
97  // pass through
98  if( m_passthrough ) {
99  ATH_MSG_VERBOSE( "passRunLB() :: Pass through mode." );
100  return true;
101  }
102 
103  // decision based on merged blackrunslist
104  if( m_rejectanybrl &&
105  m_brlcollection.HasRunLumiBlock( runNumber, lumiBlockNr ) ) {
106  ATH_MSG_VERBOSE( "passRunLB() :: Event rejected by (_any_ of) merged "
107  "black runs list." );
108  return false;
109  }
110 
111  // decision based on specific blackrunlists
112  if( ( ! m_rejectanybrl ) && brlnameVec.size() ) {
113  for( const std::string& brlname : brlnameVec ) {
114  auto brl_itr = m_brlcollection.find( brlname );
115  if( brl_itr == m_brlcollection.end() ) {
116  continue;
117  }
118  if( brl_itr->HasRunLumiBlock( runNumber, lumiBlockNr ) ) {
119  ATH_MSG_VERBOSE( "passRunLB() :: Event rejected by specific ("
120  << brlname << ") black runs list." );
121  return false;
122  }
123  }
124  }
125 
126  // decision based on specific goodrunlists
127  for( const std::string& grlname : grlnameVec ) {
128  auto grl_itr = m_grlcollection.find( grlname );
129  if( grl_itr == m_grlcollection.end() ) {
130  continue;
131  }
132  if( grl_itr->HasRunLumiBlock( runNumber, lumiBlockNr ) ) {
133  ATH_MSG_VERBOSE( "passRunLB() :: Event accepted by specific ("
134  << grlname << ") good runs list." );
135  return true;
136  }
137  }
138 
139  // If we got this far, the decision needs to be made based on the combined
140  // GRL:
141  return m_grlcollection.HasRunLumiBlock( runNumber, lumiBlockNr );
142 }
143 
146  const std::vector< std::string >& files ) {
147 
148  // If there are no files specified, then let's just clean the GRL object,
149  // and return:
150  if( files.empty() ) {
151  grl.clear();
152  return StatusCode::SUCCESS;
153  }
154 
155  // The reader object used:
157 
158  // Set up the files:
159  for( const std::string& fname : files ) {
160 
161  // Find the file:
162  std::string fileName = PathResolverFindXMLFile( fname );
163  if( fileName == "" ) {
164  //try with CalibArea
166  if(fileName=="") {
167  ATH_MSG_FATAL( "Couldn't find file: " << fname );
168  return StatusCode::FAILURE;
169  }
170  }
171  ATH_MSG_DEBUG( "Reading file: " << fileName << " (" << fname << ")" );
172 
173  // Add it to the reader:
174  reader.AddXMLFile( fileName );
175  }
176 
177  // (Try to) Interpret all the XML files:
178  if( ! reader.Interpret() ) {
179  ATH_MSG_ERROR( "There was an error parsing the GRL XML file(s)" );
180  return StatusCode::FAILURE;
181  }
182 
183  // Merge the GRLs into one:
184  const Root::BoolOperation op =
185  static_cast< Root::BoolOperation >( m_boolop.value() );
186  grl = reader.GetMergedGRLCollection( op );
187 
188  // Return gracefully:
189  return StatusCode::SUCCESS;
190 }
191 
192 #ifndef XAOD_STANDALONE
194  const xAOD::EventInfo* ei = 0;
195  if( evtStore()->retrieve( ei , "EventInfo" ).isFailure() ) {
196  ATH_MSG_ERROR("Unable to retrieve EventInfo, returning false");
197  return false;
198  }
199  return passRunLB( *ei );
200 }
201 #endif
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
Root::TGoodRunsListReader
Definition: TGoodRunsListReader.h:34
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
GoodRunsListSelectionTool::initialize
virtual StatusCode initialize()
Initialize AlgTool.
Definition: GoodRunsListSelectionTool.cxx:19
GoodRunsListSelectionTool::m_rejectanybrl
Gaudi::Property< bool > m_rejectanybrl
Definition: GoodRunsListSelectionTool.h:105
GoodRunsListSelectionTool::readXMLs
StatusCode readXMLs(Root::TGRLCollection &grl, const std::vector< std::string > &files)
Helper function reading in the specified files into a GRL object.
Definition: GoodRunsListSelectionTool.cxx:145
asg
Definition: DataHandleTestTool.h:28
GoodRunsListSelectionTool::eventPassesFilter
virtual bool eventPassesFilter() const
ISkimmingTool method: will retrieve eventInfo from storegate and use that with above methods.
Definition: GoodRunsListSelectionTool.cxx:193
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::EventInfo_v1::IS_SIMULATION
@ IS_SIMULATION
true: simulation, false: data
Definition: EventInfo_v1.h:151
GoodRunsListSelectionTool::m_useRandomRunNumber
Gaudi::Property< bool > m_useRandomRunNumber
Definition: GoodRunsListSelectionTool.h:106
Root::TGRLCollection::find
std::vector< TGoodRunsList >::iterator find(const TString &name)
Definition: TGRLCollection.cxx:226
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
grl
Definition: ZLumiScripts/grid/grl.py:1
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
GoodRunsListSelectionTool::m_brlcollection
Root::TGRLCollection m_brlcollection
Definition: GoodRunsListSelectionTool.h:101
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
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
generateReferenceFile.files
files
Definition: generateReferenceFile.py:12
GoodRunsListSelectionTool::m_goodrunslistVec
Gaudi::Property< std::vector< std::string > > m_goodrunslistVec
Definition: GoodRunsListSelectionTool.h:97
Root::TMsgLevel
TMsgLevel
Definition: TMsgLogger.h:42
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Root::TGRLCollection::HasRunLumiBlock
Bool_t HasRunLumiBlock(const Int_t &runnr, const Int_t &lumiblocknr) const
Definition: TGRLCollection.cxx:100
Root::TGRLCollection
Definition: TGRLCollection.h:29
GoodRunsListSelectionTool::GoodRunsListSelectionTool
GoodRunsListSelectionTool(const std::string &name="GoodRunsListsSelectionTool")
Definition: GoodRunsListSelectionTool.cxx:16
GoodRunsListSelectionTool::m_boolop
Gaudi::Property< int > m_boolop
Definition: GoodRunsListSelectionTool.h:103
GoodRunsListSelectionTool::m_randomRunNumberKey
SG::ReadDecorHandleKey< xAOD::EventInfo > m_randomRunNumberKey
Definition: GoodRunsListSelectionTool.h:109
PathResolver.h
GoodRunsListSelectionTool.h
dqt_zlumi_pandas.grlname
string grlname
Definition: dqt_zlumi_pandas.py:88
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
GoodRunsListSelectionTool::m_blackrunslistVec
Gaudi::Property< std::vector< std::string > > m_blackrunslistVec
Definition: GoodRunsListSelectionTool.h:98
TGoodRunsListReader.h
GoodRunsListSelectionTool::m_grlcollection
Root::TGRLCollection m_grlcollection
Definition: GoodRunsListSelectionTool.h:100
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
python.AthDsoLogger.fname
string fname
Definition: AthDsoLogger.py:67
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
GoodRunsListSelectionTool::passRunLB
virtual bool passRunLB(const std::vector< std::string > &grlnameVec=std::vector< std::string >(), const std::vector< std::string > &brlnameVec=std::vector< std::string >()) const
Check if the current event passes the selection.
Definition: GoodRunsListSelectionTool.cxx:51
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
ReadDecorHandle.h
Handle class for reading a decoration on an object.
TMsgLogger.h
collisions.reader
reader
read the goodrunslist xml file(s)
Definition: collisions.py:22
Root::BoolOperation
BoolOperation
Definition: TGRLCollection.h:27
xAOD::lumiBlock
setTeId lumiBlock
Definition: L2StandAloneMuon_v1.cxx:327
GoodRunsListSelectionTool::m_passthrough
Gaudi::Property< bool > m_passthrough
Definition: GoodRunsListSelectionTool.h:104
xAOD::EventInfo_v1::eventType
bool eventType(EventType type) const
Check for one particular bitmask value.
Root::TMsgLogger::SetMinLevel
static void SetMinLevel(TMsgLevel minLevel)
Definition: TMsgLogger.h:96
GoodRunsListSelectionTool::m_randomLumiBlockKey
SG::ReadDecorHandleKey< xAOD::EventInfo > m_randomLumiBlockKey
Definition: GoodRunsListSelectionTool.h:111