ATLAS Offline Software
Loading...
Searching...
No Matches
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
18CreateLumiBlockCollectionFromFile::CreateLumiBlockCollectionFromFile(const std::string& name, ISvcLocator* pSvcLocator)
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
33 ATH_CHECK(m_eventInfoKey.initialize());
34 ATH_CHECK(m_rchk.initialize(!m_streamName.empty()));
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()) {
82 uint32_t nEvents = getNEventsFromDb();
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
239 CondAttrListCollection::const_iterator it = attrListColl->begin();
240 CondAttrListCollection::const_iterator last = attrListColl->end();
241 CondAttrListCollection::const_iterator match = 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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
ChanAttrListMap::const_iterator const_iterator
ChanNameMap::const_iterator name_const_iterator
virtual void handle(const Incident &incident) override
Incident service handle listening for MetaDataStop.
Gaudi::Property< std::string > m_unfinishedLBColl_name
StatusCode fillLumiBlockCollection()
Fill metaDataStore and ntuples.
CreateLumiBlockCollectionFromFile(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< std::string > m_suspectLBColl_name
SG::ReadCondHandleKey< CondAttrListCollection > m_rchk
virtual StatusCode io_reinit() override
Callback method to reinitialize the internal state of the component for I/O purposes (e....
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Basic time unit for IOVSvc.
Definition IOVTime.h:33
void setStopRunNumber(uint32_t value)
Set the run number of the stop time of the range.
void setEventsSeen(uint32_t value)
Set the number of seen/processed events in this luminosity block range.
void setStartRunNumber(uint32_t value)
Set the run number of the start time of the range.
void setEventsExpected(uint32_t value)
Set the number of expected events in this luminosity block range.
void setStartLumiBlockNumber(uint32_t value)
Set the luminosity block of the start time of the range.
void setStopLumiBlockNumber(uint32_t value)
Set the luminosity block of the stop time of the range.
const int nEvents
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition hcg.cxx:357
LumiBlockRange_v1 LumiBlockRange
Declare the latest version of the class.