ATLAS Offline Software
CreateLumiBlockCollectionFromFile.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "GaudiKernel/ISvcLocator.h"
7 #include "GaudiKernel/IIncidentSvc.h"
8 #include "GaudiKernel/IIoComponentMgr.h"
10 
14 #include "CoolKernel/IObject.h"
15 
16 #include <memory>
17 
19 // ********************************************************************************************************************
20  : AthAlgorithm(name, pSvcLocator)
21  , m_lastRun(9999999)
22  , m_lastLumiBlock(9999999)
23  , m_lastIOVTime(0)
24  , m_metaStore("StoreGateSvc/MetaDataStore", name)
25 {
26 }
27 
29 //*******************************************************
30 {
31  ATH_MSG_INFO( "initialize() and create listeners" );
32 
35 
36  ATH_CHECK( m_metaStore.retrieve() );
37 
38  // Set to be listener for MetaDataStop
39  ServiceHandle<IIncidentSvc> incSvc("IncidentSvc", this->name());
40  ATH_CHECK( incSvc.retrieve() );
41  incSvc->addListener(this, "MetaDataStop", 50); // pri has to be > 20 to be
42  // before MetaDataSvc and AthenaOutputStream.
43 
44  ServiceHandle<IIoComponentMgr> ioMgr("IoComponentMgr", this->name());
45  ATH_CHECK( ioMgr.retrieve() );
46  if (!ioMgr->io_register(this).isSuccess()) {
47  ATH_MSG_FATAL("Could not register myself with the IoComponentMgr");
48  return(StatusCode::FAILURE);
49  }
50 
51  m_LumiBlockInfo.clear();
52 
53  if(m_streamName.empty()) {
54  ATH_MSG_INFO( "No streamName specified" );
55  }
56 
57  return StatusCode::SUCCESS;
58 }
59 
60 
62 //*******************************************************
63 {
64  ATH_MSG_VERBOSE( "execute()" );
65 
66  // Check for event header
68 
69  // check is only useful for serial running; remove when MT scheduler used
70  if(!evt.isValid()) {
71  ATH_MSG_FATAL("Failed to retrieve "<< m_eventInfoKey.key());
72  return StatusCode::FAILURE;
73  }
74 
75  if(m_lastRun!=evt->runNumber() ||
76  m_lastLumiBlock!=evt->lumiBlock()) {
77 
78  IOVTime iovtime(evt->runNumber(),evt->lumiBlock());
79  RLBMap::iterator mitr;
80  mitr=m_LumiBlockInfo.find(iovtime);
81  if (mitr==m_LumiBlockInfo.end()) {
83  ATH_MSG_INFO( "Fill LumiBlockInfo with NEvents="<<nEvents);
84  inOut lbInOut(nEvents,1);
85  m_LumiBlockInfo[iovtime] = lbInOut;
86  }
87  else {
88  m_LumiBlockInfo[iovtime].second++;
89  }
90 
91  m_lastRun=evt->runNumber();
92  m_lastLumiBlock=evt->lumiBlock();
93  m_lastIOVTime=iovtime;
94  }
95  else {
97  }
98 
99  return StatusCode::SUCCESS;
100 }
101 
102 //*****************************************************
104 // *****************************************************
105 {
106  ATH_MSG_VERBOSE( "finalize()" );
107  return StatusCode::SUCCESS;
108 }
109 
110 
111 //*********************************************************************
113 // ********************************************************************
114 {
115  // Create the LumiBlockCollection
116 
117  std::unique_ptr<xAOD::LumiBlockRangeContainer> piovComplete = std::make_unique<xAOD::LumiBlockRangeContainer>();
118  std::unique_ptr<xAOD::LumiBlockRangeAuxContainer> piovCompleteAux = std::make_unique<xAOD::LumiBlockRangeAuxContainer>();
119  piovComplete->setStore( piovCompleteAux.get() );
120 
121  std::unique_ptr<xAOD::LumiBlockRangeContainer> piovUnfinished = std::make_unique<xAOD::LumiBlockRangeContainer>();
122  std::unique_ptr<xAOD::LumiBlockRangeAuxContainer> piovUnfinishedAux = std::make_unique<xAOD::LumiBlockRangeAuxContainer>();
123  piovUnfinished->setStore( piovUnfinishedAux.get() );
124 
125  std::unique_ptr<xAOD::LumiBlockRangeContainer> piovSuspect = std::make_unique<xAOD::LumiBlockRangeContainer>();
126  std::unique_ptr<xAOD::LumiBlockRangeAuxContainer> piovSuspectAux = std::make_unique<xAOD::LumiBlockRangeAuxContainer>();
127  piovSuspect->setStore( piovSuspectAux.get() );
128 
129  for (std::pair<const IOVTime, inOut>& p : m_LumiBlockInfo) {
131 
132  // Decide which collection it goes into depending on whether the LB is complete
133  // =============================================================================
134  // Suspect LB's have more events read than the DB says should be there
135  if(!m_checkEventsExpected || p.second.second == p.second.first) {
136  piovComplete->push_back(iovr);
137  }
138  else if(p.second.second > p.second.first) {
139  piovSuspect->push_back(iovr);
140  }
141  else {
142  piovUnfinished->push_back(iovr);
143  }
144  iovr->setStartRunNumber(p.first.run());
145  iovr->setStartLumiBlockNumber(p.first.event());
146  iovr->setStopRunNumber(p.first.run());
147  iovr->setStopLumiBlockNumber(p.first.event());
148  iovr->setEventsExpected(p.second.first);
149  iovr->setEventsSeen(p.second.second);
150  }
151 
152  if(!piovComplete->empty()) {
153  ATH_MSG_INFO( "Number of Complete LumiBlocks:" << piovComplete->size() );
154  for(const xAOD::LumiBlockRange* lbr : *piovComplete) {
155  ATH_MSG_INFO("\t [ ("
156  << lbr->startRunNumber() << "," << lbr->startLumiBlockNumber()
157  << "):("
158  << lbr->startRunNumber() << "," << lbr->startLumiBlockNumber()
159  << ") eventsSeen = " << lbr->eventsSeen()
160  << ", eventsExpected = " << lbr->eventsExpected()
161  << " ]");
162  }
163  }
164 
165  if(!piovUnfinished->empty()) {
166  ATH_MSG_INFO( "Number of Unfinished LumiBlocks:" << piovUnfinished->size() );
167  for(const xAOD::LumiBlockRange* lbr : *piovUnfinished) {
168  ATH_MSG_INFO("\t [ ("
169  << lbr->startRunNumber() << "," << lbr->startLumiBlockNumber()
170  << "):("
171  << lbr->startRunNumber() << "," << lbr->startLumiBlockNumber()
172  << ") eventsSeen = " << lbr->eventsSeen()
173  << ", eventsExpected = " << lbr->eventsExpected()
174  << " ]");
175  }
176  }
177 
178  if(!piovSuspect->empty()) {
179  ATH_MSG_INFO( "Number of Suspect LumiBlocks:" << piovSuspect->size() );
180  for(const xAOD::LumiBlockRange* lbr : *piovSuspect) {
181  ATH_MSG_INFO("\t [ ("
182  << lbr->startRunNumber() << "," << lbr->startLumiBlockNumber()
183  << "):("
184  << lbr->startRunNumber() << "," << lbr->startLumiBlockNumber()
185  << ") eventsSeen = " << lbr->eventsSeen()
186  << ", eventsExpected = " << lbr->eventsExpected()
187  << " ]");
188  }
189  }
190 
191  // Store the LumiBlockCollection in the metadata store
192  // =======================================================
193  if(!piovComplete->empty()) {
194  ATH_CHECK( m_metaStore->record( std::move(piovComplete), m_LBColl_name ) );
195  ATH_CHECK( m_metaStore->record( std::move(piovCompleteAux), m_LBColl_name + "Aux." ) );
196  }
197 
198  if(!piovUnfinished->empty()) {
199  ATH_CHECK( m_metaStore->record( std::move(piovUnfinished), m_unfinishedLBColl_name ) );
200  ATH_CHECK( m_metaStore->record( std::move(piovUnfinishedAux), m_unfinishedLBColl_name + "Aux." ) );
201  }
202 
203  if(!piovSuspect->empty()) {
204  ATH_CHECK( m_metaStore->record( std::move(piovSuspect), m_suspectLBColl_name ) );
205  ATH_CHECK( m_metaStore->record( std::move(piovSuspectAux), m_suspectLBColl_name + "Aux." ) );
206  }
207 
208  // Then clear m_LumiBlockInfo. This is in case we decide to store the
209  // LBColl separately for each input or output file.
210  m_LumiBlockInfo.clear();
211  return StatusCode::SUCCESS;
212 }
213 
214 // *******************************************************************
216 // ********************************************************************
217 {
218  if(inc.type() == "MetaDataStop") {
219  ATH_MSG_INFO( " finishUp: write lumiblocks to meta data store " );
220  if(!m_LumiBlockInfo.empty()) {
221  if(fillLumiBlockCollection().isFailure()) {
222  ATH_MSG_ERROR( "Could not fill lumiblock collections" );
223  }
224  }
225  }
226  else {
227  ATH_MSG_INFO( "Unknown Incident: " << inc.type() );
228  }
229 }
230 
232 {
233  uint32_t nEvents{0};
234 
235  if (m_streamName.empty()) return nEvents;
236 
238 
240  CondAttrListCollection::const_iterator last = attrListColl->end();
242  for (; it != last; ++it) {
243  if (attrListColl->name_size()>0) {
244  CondAttrListCollection::name_const_iterator nitr=attrListColl->chanNamePair((*it).first);
245  int chan = (*it).first;
246  std::string theName = nitr->second;
247  ATH_MSG_INFO( "channel " << chan << " name " << theName);
248  if(theName==m_streamName) {
249  match=it;
250  break;
251  }
252  }
253  }
254  // Make sure we found it
255  if (match == last) {
256  ATH_MSG_INFO( "Stream " << m_streamName << " not found in /GLOBAL/FILECOUNT/PROMPT !" );
257  return nEvents;
258  }
259 
260  // OK, get number of events
261  const coral::AttributeList& attrList = (*match).second;
262 
263  // Check data availability
264  if (attrList["NEventRec"].isNull()) {
265  ATH_MSG_INFO( " NEventRec not in database. Set it to 0 " );
266  return nEvents;
267  }
268 
269  cool::Int32 nev = attrList["NEventRec"].data<cool::Int32>();
270  nEvents = (uint32_t) nev;
271  ATH_MSG_INFO( "database returns NEventRec=" << nev );
272 
273  return nEvents;
274 }
275 
276 
278  ATH_MSG_INFO("I/O reinitialization...");
279  m_LumiBlockInfo.clear();
280  m_lastRun = 9999999;
281  m_lastLumiBlock = 9999999;
282 
283  return StatusCode::SUCCESS;
284 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
nEvents
const int nEvents
Definition: fbtTestBasics.cxx:77
CondAttrListCollection::end
const_iterator end() const
Definition: CondAttrListCollection.h:315
xAOD::LumiBlockRange_v1::setStopLumiBlockNumber
void setStopLumiBlockNumber(uint32_t value)
Set the luminosity block of the stop time of the range.
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
CreateLumiBlockCollectionFromFile::handle
virtual void handle(const Incident &incident) override
Incident service handle listening for MetaDataStop.
Definition: CreateLumiBlockCollectionFromFile.cxx:215
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
CreateLumiBlockCollectionFromFile::m_LumiBlockInfo
RLBMap m_LumiBlockInfo
Definition: CreateLumiBlockCollectionFromFile.h:98
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAOD::LumiBlockRange_v1::setStopRunNumber
void setStopRunNumber(uint32_t value)
Set the run number of the stop time of the range.
CreateLumiBlockCollectionFromFile::m_LBColl_name
Gaudi::Property< std::string > m_LBColl_name
Definition: CreateLumiBlockCollectionFromFile.h:74
CreateLumiBlockCollectionFromFile::execute
virtual StatusCode execute() override
Definition: CreateLumiBlockCollectionFromFile.cxx:61
skel.it
it
Definition: skel.GENtoEVGEN.py:396
xAOD::LumiBlockRange_v1::setStartRunNumber
void setStartRunNumber(uint32_t value)
Set the run number of the start time of the range.
CreateLumiBlockCollectionFromFile::finalize
virtual StatusCode finalize() override
Definition: CreateLumiBlockCollectionFromFile.cxx:103
CondAttrListCollection::begin
const_iterator begin() const
Access to Chan/AttributeList pairs via iterators.
Definition: CondAttrListCollection.h:309
CreateLumiBlockCollectionFromFile::m_lastLumiBlock
uint32_t m_lastLumiBlock
Definition: CreateLumiBlockCollectionFromFile.h:101
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
CreateLumiBlockCollectionFromFile::m_checkEventsExpected
Gaudi::Property< bool > m_checkEventsExpected
Definition: CreateLumiBlockCollectionFromFile.h:89
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
CreateLumiBlockCollectionFromFile::m_suspectLBColl_name
Gaudi::Property< std::string > m_suspectLBColl_name
Definition: CreateLumiBlockCollectionFromFile.h:84
AthenaAttributeList.h
CreateLumiBlockCollectionFromFile::CreateLumiBlockCollectionFromFile
CreateLumiBlockCollectionFromFile(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CreateLumiBlockCollectionFromFile.cxx:18
CreateLumiBlockCollectionFromFile::io_reinit
virtual StatusCode io_reinit() override
Callback method to reinitialize the internal state of the component for I/O purposes (e....
Definition: CreateLumiBlockCollectionFromFile.cxx:277
CreateLumiBlockCollectionFromFile.h
xAOD::LumiBlockRange
LumiBlockRange_v1 LumiBlockRange
Declare the latest version of the class.
Definition: LumiBlockRange.h:16
CondAttrListCollection::name_const_iterator
ChanNameMap::const_iterator name_const_iterator
Definition: CondAttrListCollection.h:69
IOVTime
Basic time unit for IOVSvc. Hold time as a combination of run and event numbers.
Definition: IOVTime.h:33
xAOD::LumiBlockRange_v1::setEventsExpected
void setEventsExpected(uint32_t value)
Set the number of expected events in this luminosity block range.
CreateLumiBlockCollectionFromFile::getNEventsFromDb
uint32_t getNEventsFromDb()
Definition: CreateLumiBlockCollectionFromFile.cxx:231
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CreateLumiBlockCollectionFromFile::initialize
virtual StatusCode initialize() override
Definition: CreateLumiBlockCollectionFromFile.cxx:28
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::LumiBlockRange_v1::setEventsSeen
void setEventsSeen(uint32_t value)
Set the number of seen/processed events in this luminosity block range.
CreateLumiBlockCollectionFromFile::m_lastIOVTime
IOVTime m_lastIOVTime
Definition: CreateLumiBlockCollectionFromFile.h:102
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
AthAlgorithm
Definition: AthAlgorithm.h:47
CreateLumiBlockCollectionFromFile::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition: CreateLumiBlockCollectionFromFile.h:59
CondAttrListCollection::name_size
name_size_type name_size() const
number of Chan/Name pairs
Definition: CondAttrListCollection.h:377
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
CreateLumiBlockCollectionFromFile::inOut
std::pair< uint32_t, uint32_t > inOut
Definition: CreateLumiBlockCollectionFromFile.h:96
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CreateLumiBlockCollectionFromFile::fillLumiBlockCollection
StatusCode fillLumiBlockCollection()
Fill metaDataStore and ntuples.
Definition: CreateLumiBlockCollectionFromFile.cxx:112
LArCellNtuple.nev
int nev
Definition: LArCellNtuple.py:135
xAOD::LumiBlockRange_v1
Class describing a luminosity block range.
Definition: LumiBlockRange_v1.h:33
CondAttrListCollection::const_iterator
ChanAttrListMap::const_iterator const_iterator
Definition: CondAttrListCollection.h:63
CreateLumiBlockCollectionFromFile::m_unfinishedLBColl_name
Gaudi::Property< std::string > m_unfinishedLBColl_name
Definition: CreateLumiBlockCollectionFromFile.h:79
CondAttrListCollection::chanNamePair
name_const_iterator chanNamePair(ChanNum chanNum) const
Access to Chan/Name pairs via channel number: returns map iterator.
Definition: CondAttrListCollection.h:357
LumiBlockRangeContainer.h
CreateLumiBlockCollectionFromFile::m_metaStore
ServiceHandle< StoreGateSvc > m_metaStore
Definition: CreateLumiBlockCollectionFromFile.h:104
CreateLumiBlockCollectionFromFile::m_rchk
SG::ReadCondHandleKey< CondAttrListCollection > m_rchk
Definition: CreateLumiBlockCollectionFromFile.h:64
CreateLumiBlockCollectionFromFile::m_streamName
Gaudi::Property< std::string > m_streamName
Definition: CreateLumiBlockCollectionFromFile.h:69
LumiBlockRangeAuxContainer.h
StoreGateSvc.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
CreateLumiBlockCollectionFromFile::m_lastRun
uint32_t m_lastRun
Definition: CreateLumiBlockCollectionFromFile.h:100
xAOD::LumiBlockRange_v1::setStartLumiBlockNumber
void setStartLumiBlockNumber(uint32_t value)
Set the luminosity block of the start time of the range.
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356
ServiceHandle< IIncidentSvc >