ATLAS Offline Software
Loading...
Searching...
No Matches
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
51passRunLB( 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
73passRunLB( const xAOD::EventInfo& event,
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
91passRunLB( 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
144StatusCode
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
165 fileName = PathResolverFindCalibFile( fname );
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading a decoration on an object.
std::string PathResolverFindXMLFile(const std::string &logical_file_name)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
ServiceHandle< StoreGateSvc > & evtStore()
Gaudi::Property< bool > m_useRandomRunNumber
Gaudi::Property< bool > m_passthrough
StatusCode readXMLs(Root::TGRLCollection &grl, const std::vector< std::string > &files)
Helper function reading in the specified files into a GRL object.
Gaudi::Property< std::vector< std::string > > m_goodrunslistVec
virtual bool eventPassesFilter() const
ISkimmingTool method: will retrieve eventInfo from storegate and use that with above methods.
GoodRunsListSelectionTool(const std::string &name="GoodRunsListsSelectionTool")
Gaudi::Property< std::vector< std::string > > m_blackrunslistVec
virtual StatusCode initialize()
Initialize AlgTool.
SG::ReadDecorHandleKey< xAOD::EventInfo > m_randomRunNumberKey
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.
SG::ReadDecorHandleKey< xAOD::EventInfo > m_randomLumiBlockKey
Gaudi::Property< bool > m_rejectanybrl
static void SetMinLevel(TMsgLevel minLevel)
Definition TMsgLogger.h:92
Handle class for reading a decoration on an object.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
bool eventType(EventType type) const
Check for one particular bitmask value.
@ IS_SIMULATION
true: simulation, false: data
std::vector< std::string > files
file names and file pointers
Definition hcg.cxx:50
TMsgLevel
Definition TMsgLogger.h:37
EventInfo_v1 EventInfo
Definition of the latest event info version.
MsgStream & msg
Definition testRead.cxx:32