ATLAS Offline Software
GoodRunsListSelectionTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id$
6 
7 // Framework include(s):
9 
10 // Local include(s):
14 
16  : asg::AsgTool( name ) {
17 
18  declareProperty( "GoodRunsListVec", m_goodrunslistVec );
19  declareProperty( "BlackRunsListVec", m_blackrunslistVec );
20 
21  declareProperty( "BoolOperation", m_boolop = 0 );
22  declareProperty( "PassThrough", m_passthrough = true );
23  declareProperty( "RejectBlackRunsInEventSelector", m_rejectanybrl = false );
24 }
25 
27 
28  // Tell the user what's happening:
29  ATH_MSG_DEBUG( "Initialising tool" );
30 
31  // Set the output level of the underlying code:
32  const Root::TMsgLevel level =
33  static_cast< Root::TMsgLevel >( msg().level() );
35 
36  // Reset the pass-through mode setting:
37  if( m_goodrunslistVec.size() || m_blackrunslistVec.size() ) {
38  m_passthrough = false;
39  }
40 
41  // Warn about pass-through mode:
42  if( m_passthrough ) {
43  ATH_MSG_WARNING( "Set to pass-through mode." );
44  }
45 
46  // Read in the XML files:
49 
50  // Return gracefully:
51  return StatusCode::SUCCESS;
52 }
53 
55 passRunLB( const std::vector< std::string >& grlnameVec,
56  const std::vector< std::string >& brlnameVec ) const {
57 
58  // Retrieve the xAOD::EventInfo object:
59  const xAOD::EventInfo* ei = 0;
60  if( ! evtStore()->retrieve( ei, "EventInfo" ).isSuccess() ) {
61  ATH_MSG_WARNING( "Couldn't access xAOD::EventInfo object. Using "
62  "pass-through mode..." );
63  return true;
64  }
65 
66  // MC events should not be filtered by this tool:
68  ATH_MSG_VERBOSE( "MC event is accepted by the tool" );
69  return true;
70  }
71 
72  // Use this object:
73  return passRunLB( *ei, grlnameVec, brlnameVec );
74 }
75 
78  const std::vector< std::string >& grlnameVec,
79  const std::vector< std::string >& brlnameVec ) const {
80 
81  return passRunLB( event.runNumber(), event.lumiBlock(),
82  grlnameVec, brlnameVec );
83 }
84 
85 
87 passRunLB( int runNumber, int lumiBlockNr,
88  const std::vector< std::string >& grlnameVec,
89  const std::vector< std::string >& brlnameVec ) const {
90 
91  ATH_MSG_VERBOSE( "passRunLB()" );
92 
93  // pass through
94  if( m_passthrough ) {
95  ATH_MSG_VERBOSE( "passRunLB() :: Pass through mode." );
96  return true;
97  }
98 
99  // decision based on merged blackrunslist
100  if( m_rejectanybrl &&
101  m_brlcollection.HasRunLumiBlock( runNumber, lumiBlockNr ) ) {
102  ATH_MSG_VERBOSE( "passRunLB() :: Event rejected by (_any_ of) merged "
103  "black runs list." );
104  return false;
105  }
106 
107  // decision based on specific blackrunlists
108  if( ( ! m_rejectanybrl ) && brlnameVec.size() ) {
109  for( const std::string& brlname : brlnameVec ) {
110  auto brl_itr = m_brlcollection.find( brlname );
111  if( brl_itr == m_brlcollection.end() ) {
112  continue;
113  }
114  if( brl_itr->HasRunLumiBlock( runNumber, lumiBlockNr ) ) {
115  ATH_MSG_VERBOSE( "passRunLB() :: Event rejected by specific ("
116  << brlname << ") black runs list." );
117  return false;
118  }
119  }
120  }
121 
122  // decision based on specific goodrunlists
123  for( const std::string& grlname : grlnameVec ) {
124  auto grl_itr = m_grlcollection.find( grlname );
125  if( grl_itr == m_grlcollection.end() ) {
126  continue;
127  }
128  if( grl_itr->HasRunLumiBlock( runNumber, lumiBlockNr ) ) {
129  ATH_MSG_VERBOSE( "passRunLB() :: Event accepted by specific ("
130  << grlname << ") good runs list." );
131  return true;
132  }
133  }
134 
135  // If we got this far, the decision needs to be made based on the combined
136  // GRL:
137  return m_grlcollection.HasRunLumiBlock( runNumber, lumiBlockNr );
138 }
139 
142  const std::vector< std::string >& files ) {
143 
144  // If there are no files specified, then let's just clean the GRL object,
145  // and return:
146  if( files.empty() ) {
147  grl.clear();
148  return StatusCode::SUCCESS;
149  }
150 
151  // The reader object used:
153 
154  // Set up the files:
155  for( const std::string& fname : files ) {
156 
157  // Find the file:
158  std::string fileName = PathResolverFindXMLFile( fname );
159  if( fileName == "" ) {
160  //try with CalibArea
162  if(fileName=="") {
163  ATH_MSG_FATAL( "Couldn't find file: " << fname );
164  return StatusCode::FAILURE;
165  }
166  }
167  ATH_MSG_DEBUG( "Reading file: " << fileName << " (" << fname << ")" );
168 
169  // Add it to the reader:
170  reader.AddXMLFile( fileName );
171  }
172 
173  // (Try to) Interpret all the XML files:
174  if( ! reader.Interpret() ) {
175  ATH_MSG_ERROR( "There was an error parsing the GRL XML file(s)" );
176  return StatusCode::FAILURE;
177  }
178 
179  // Merge the GRLs into one:
180  const Root::BoolOperation op =
181  static_cast< Root::BoolOperation >( m_boolop );
182  grl = reader.GetMergedGRLCollection( op );
183 
184  // Return gracefully:
185  return StatusCode::SUCCESS;
186 }
187 
188 #ifndef XAOD_STANDALONE
190  const xAOD::EventInfo* ei = 0;
191  if( evtStore()->retrieve( ei , "EventInfo" ).isFailure() ) {
192  ATH_MSG_ERROR("Unable to retrieve EventInfo, returning false");
193  return false;
194  }
195  return passRunLB( *ei );
196 }
197 #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:26
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
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:141
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:189
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
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:99
GoodRunsListSelectionTool::m_goodrunslistVec
std::vector< std::string > m_goodrunslistVec
Definition: GoodRunsListSelectionTool.h:95
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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
GoodRunsListSelectionTool::m_boolop
int m_boolop
Definition: GoodRunsListSelectionTool.h:101
generateReferenceFile.files
files
Definition: generateReferenceFile.py:12
Root::TMsgLevel
TMsgLevel
Definition: TMsgLogger.h:42
GoodRunsListSelectionTool::m_blackrunslistVec
std::vector< std::string > m_blackrunslistVec
Definition: GoodRunsListSelectionTool.h:96
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:15
PathResolver.h
GoodRunsListSelectionTool.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
GoodRunsListSelectionTool::m_passthrough
bool m_passthrough
Definition: GoodRunsListSelectionTool.h:102
TGoodRunsListReader.h
GoodRunsListSelectionTool::m_grlcollection
Root::TGRLCollection m_grlcollection
Definition: GoodRunsListSelectionTool.h:98
GoodRunsListSelectionTool::m_rejectanybrl
bool m_rejectanybrl
Definition: GoodRunsListSelectionTool.h:103
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:55
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
TMsgLogger.h
collisions.reader
reader
read the goodrunslist xml file(s)
Definition: collisions.py:22
Root::BoolOperation
BoolOperation
Definition: TGRLCollection.h:27
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