ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
DataQuality
GoodRunsLists
Root
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):
8
#include "
PathResolver/PathResolver.h
"
9
#include <
AsgDataHandles/ReadDecorHandle.h
>
10
11
// Local include(s):
12
#include "
GoodRunsLists/GoodRunsListSelectionTool.h
"
13
#include "
GoodRunsLists/TGoodRunsListReader.h
"
14
#include "
GoodRunsLists/TMsgLogger.h
"
15
16
GoodRunsListSelectionTool::GoodRunsListSelectionTool
(
const
std::string& name )
17
:
asg
::
AsgTool
( name ) {}
18
19
StatusCode
GoodRunsListSelectionTool::initialize
() {
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() );
27
Root::TMsgLogger::SetMinLevel
( 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:
40
ATH_CHECK
(
readXMLs
(
m_grlcollection
,
m_goodrunslistVec
) );
41
ATH_CHECK
(
readXMLs
(
m_brlcollection
,
m_blackrunslistVec
) );
42
43
ATH_CHECK
(
m_randomRunNumberKey
.initialize(
m_useRandomRunNumber
));
44
ATH_CHECK
(
m_randomLumiBlockKey
.initialize(
m_useRandomRunNumber
));
45
46
// Return gracefully:
47
return
StatusCode::SUCCESS;
48
}
49
50
bool
GoodRunsListSelectionTool::
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:
63
if
( ei->
eventType
(
xAOD::EventInfo::IS_SIMULATION
) ) {
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
72
bool
GoodRunsListSelectionTool::
73
passRunLB
(
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();
79
if
(
m_useRandomRunNumber
){
80
SG::ReadDecorHandle<xAOD::EventInfo, unsigned int>
randomRunNumber(
m_randomRunNumberKey
);
81
SG::ReadDecorHandle<xAOD::EventInfo, unsigned int>
randomLumiBlock(
m_randomLumiBlockKey
);
82
runNumber = randomRunNumber(event);
83
lumiBlock = randomLumiBlock(event);
84
}
85
86
return
passRunLB
( runNumber, lumiBlock, grlnameVec, brlnameVec );
87
}
88
89
90
bool
GoodRunsListSelectionTool::
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
144
StatusCode
145
GoodRunsListSelectionTool::readXMLs
(
Root::TGRLCollection
& grl,
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:
156
Root::TGoodRunsListReader
reader;
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
193
bool
GoodRunsListSelectionTool::eventPassesFilter
(
const
EventContext&
/*ctx*/
)
const
{
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
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition
AthMsgStreamMacros.h:34
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
ReadDecorHandle.h
Handle class for reading a decoration on an object.
GoodRunsListSelectionTool.h
PathResolver.h
PathResolverFindXMLFile
std::string PathResolverFindXMLFile(const std::string &logical_file_name)
Definition
PathResolver.cxx:315
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition
PathResolver.cxx:325
TGoodRunsListReader.h
TMsgLogger.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition
AthCommonDataStore.h:85
GoodRunsListSelectionTool::m_useRandomRunNumber
Gaudi::Property< bool > m_useRandomRunNumber
Definition
GoodRunsListSelectionTool.h:106
GoodRunsListSelectionTool::m_passthrough
Gaudi::Property< bool > m_passthrough
Definition
GoodRunsListSelectionTool.h:104
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
GoodRunsListSelectionTool::m_goodrunslistVec
Gaudi::Property< std::vector< std::string > > m_goodrunslistVec
Definition
GoodRunsListSelectionTool.h:97
GoodRunsListSelectionTool::m_brlcollection
Root::TGRLCollection m_brlcollection
Definition
GoodRunsListSelectionTool.h:101
GoodRunsListSelectionTool::GoodRunsListSelectionTool
GoodRunsListSelectionTool(const std::string &name="GoodRunsListsSelectionTool")
Definition
GoodRunsListSelectionTool.cxx:16
GoodRunsListSelectionTool::m_blackrunslistVec
Gaudi::Property< std::vector< std::string > > m_blackrunslistVec
Definition
GoodRunsListSelectionTool.h:98
GoodRunsListSelectionTool::initialize
virtual StatusCode initialize()
Initialize AlgTool.
Definition
GoodRunsListSelectionTool.cxx:19
GoodRunsListSelectionTool::m_randomRunNumberKey
SG::ReadDecorHandleKey< xAOD::EventInfo > m_randomRunNumberKey
Definition
GoodRunsListSelectionTool.h:109
GoodRunsListSelectionTool::eventPassesFilter
virtual bool eventPassesFilter(const EventContext &ctx) const
ISkimmingTool method: will retrieve eventInfo from storegate and use that with above methods.
Definition
GoodRunsListSelectionTool.cxx:193
GoodRunsListSelectionTool::m_grlcollection
Root::TGRLCollection m_grlcollection
Definition
GoodRunsListSelectionTool.h:100
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
GoodRunsListSelectionTool::m_randomLumiBlockKey
SG::ReadDecorHandleKey< xAOD::EventInfo > m_randomLumiBlockKey
Definition
GoodRunsListSelectionTool.h:111
GoodRunsListSelectionTool::m_boolop
Gaudi::Property< int > m_boolop
Definition
GoodRunsListSelectionTool.h:103
GoodRunsListSelectionTool::m_rejectanybrl
Gaudi::Property< bool > m_rejectanybrl
Definition
GoodRunsListSelectionTool.h:105
Root::TGRLCollection
Definition
TGRLCollection.h:24
Root::TGoodRunsListReader
Definition
TGoodRunsListReader.h:34
Root::TMsgLogger::SetMinLevel
static void SetMinLevel(TMsgLevel minLevel)
Definition
TMsgLogger.h:92
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition
StoreGate/StoreGate/ReadDecorHandle.h:94
asg::AsgTool::AsgTool
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition
AsgTool.cxx:58
xAOD::EventInfo_v1::eventType
bool eventType(EventType type) const
Check for one particular bitmask value.
xAOD::EventInfo_v1::IS_SIMULATION
@ IS_SIMULATION
true: simulation, false: data
Definition
EventInfo_v1.h:151
files
std::vector< std::string > files
file names and file pointers
Definition
hcg.cxx:52
Root::TMsgLevel
TMsgLevel
Definition
TMsgLogger.h:37
Root::BoolOperation
BoolOperation
Definition
TGRLCollection.h:22
asg
Definition
DataHandleTestTool.h:28
xAOD::EventInfo
EventInfo_v1 EventInfo
Definition of the latest event info version.
Definition
IEventInfoCnvTool.h:16
msg
MsgStream & msg
Definition
testRead.cxx:32
Generated on
for ATLAS Offline Software by
1.17.0