ATLAS Offline Software
Loading...
Searching...
No Matches
TagInfoMgr Class Reference

This is a Athena service which manages detector description tag information. More...

#include <TagInfoMgr.h>

Inheritance diagram for TagInfoMgr:
Collaboration diagram for TagInfoMgr:

Classes

class  SvcFactory
 Allow the factory class access to the constructor. More...

Public Member Functions

 TagInfoMgr (const std::string &name, ISvcLocator *pSvcLocator)
 Constructor with parameters:
 ~TagInfoMgr ()
Basic service methods
virtual StatusCode initialize () override
virtual StatusCode start () override
virtual StatusCode finalize () override
Method to allow clients add in tags as: tag name, tag value
virtual StatusCode addTag (const std::string &tagName, const std::string &tagValue) override
 Method to allow clients add in tags as: tag name, tag value.
virtual StatusCode removeTagFromInput (const std::string &tagName) override
 Method to allow clients to remove a tag which may have come in on the input.
virtual std::string findTag (const std::string &name) const override final
 Find tag by name, return by value.
virtual std::string findInputTag (const std::string &name) const override final
 Find tag by its name - for input tags, return by value.
virtual NameTagPairVec getInputTags () const override final
 Return a vector with all current input tags.
virtual std::string dumpTagInfoToStr () const override final
 Dump the content of the current TagInfo to std::string for debug.
virtual void printTags (MsgStream &log) const override final
 Printout method.
virtual void addListener (Listener *listener) override final
 Add a Listener to the notification list for TagInfo changes.
virtual void removeListener (Listener *listener) override final
 Remove a Listener from the notification list for TagInfo changes.

TagInfo management methods:

class SvcFactory< TagInfoMgr >
 forward declaration
Gaudi::Property< std::map< std::string, std::string > > m_extraTagValuePairs { this, "ExtraTagValuePairs", {}, "key/value pairs to be added" }
 Extra tags/values pairs added in my jobOptions.
std::map< std::string, std::string > m_extraTagValuePairsViaInterface
 Extra tags/values pairs added in via interface.
std::set< std::string > m_tagsToBeRemoved
 Extra tags to be removed.
ServiceHandle< StoreGateSvcm_storeGate { this, "StoreGateSvc", "StoreGateSvc" }
 The event store.
ServiceHandle< StoreGateSvcm_detStore { this, "DetectorStore", "DetectorStore" }
 The detector store.
ServiceHandle< IIOVDbSvcm_iovDbSvc { this, "IOVDbSvc", "IOVDbSvc" }
 Access to IOVDbSvc interface - used to register callback.
PublicToolHandle< IIOVDbMetaDataToolm_metaDataTool { this, "IOVDbMetaDataTool", "IOVDbMetaDataTool" }
 Access to iov meta data tool.
bool m_isFirstBeginRun { true }
 Flag to identify the first BeginRun incident.
EventIDBase::number_type m_conditionsRun { EventIDBase::UNDEFNUM }
 conditionsRun from the first BeginRun incident (HLT)
EventIDBase::number_type m_currentRun { EventIDBase::UNDEFNUM }
 current run number from BeginRun incident
IOVRange m_lastIOVRange { IOVRange(IOVTime(), IOVTime()) }
 IOVRange of last TagInfo added to the file meta data.
TagInfo m_tagInfo
 The Tags.
std::set< Listener * > m_listeners
 List of listeners notified when the TagInfo changed.
std::shared_mutex m_mutex ATLAS_THREAD_SAFE
 mutex to protect internal data in MT
void handle (const Incident &incident) override final
StatusCode updateTagInfo ()
 Update Tags when input tags (/TagInfo in-file metadata) change.
void notifyListeners () const
 Notify all listeners that the Tags were updated.
 TagInfoMgr ()
 TagInfoMgr (const TagInfoMgr &)
TagInfoMgroperator= (const TagInfoMgr &)
StatusCode getRunNumber (unsigned int &runNumber)
StatusCode fillTagInfo (const CondAttrListCollection *tagInfoCond)
StatusCode fillMetaData (const CondAttrListCollection *tagInfoCond)

Detailed Description

This is a Athena service which manages detector description tag information.

It maintains a TagInfo object in the Detector Store with current tag values.

The tags to fill the TagInfo object may come from a variety of sources: i.e. the tags specified by the GeoModelSvc and IOVDbSvc, or the tags stored in the incoming EventInfo object, or the TagInfo object itself may be in the IOV DB. The TagInfoMgr itself only adds in tags from the incoming event. Others are added by external clients.

The interface provides a 'input' method to allow client to add in their own tags:

virtual StatusCode addTag(const std::string& tagName, const std::string& tagValue) = 0;

The full set of tags in TagInfo are copied each event into EventInfo (specifically EventType) to be written out in the event stream. Currently, the tags are NOT written to the IOV DB via the TagInfoMgr.

Definition at line 67 of file TagInfoMgr.h.

Constructor & Destructor Documentation

◆ TagInfoMgr() [1/3]

TagInfoMgr::TagInfoMgr ( const std::string & name,
ISvcLocator * pSvcLocator )

Constructor with parameters:

Definition at line 42 of file TagInfoMgr.cxx.

42 :
43 base_class(name, pSvcLocator)
44{}

◆ ~TagInfoMgr()

TagInfoMgr::~TagInfoMgr ( )

Definition at line 46 of file TagInfoMgr.cxx.

47{}

◆ TagInfoMgr() [2/3]

TagInfoMgr::TagInfoMgr ( )
private

◆ TagInfoMgr() [3/3]

TagInfoMgr::TagInfoMgr ( const TagInfoMgr & )
private

Member Function Documentation

◆ addListener()

void TagInfoMgr::addListener ( Listener * listener)
finaloverridevirtual

Add a Listener to the notification list for TagInfo changes.

Definition at line 690 of file TagInfoMgr.cxx.

691{
692 std::unique_lock guard(m_mutex);
693 m_listeners.insert( listener );
694}
std::set< Listener * > m_listeners
List of listeners notified when the TagInfo changed.
Definition TagInfoMgr.h:190

◆ addTag()

StatusCode TagInfoMgr::addTag ( const std::string & tagName,
const std::string & tagValue )
overridevirtual

Method to allow clients add in tags as: tag name, tag value.

Definition at line 624 of file TagInfoMgr.cxx.

625{
626 // Add name/value to input vector
627 ATH_MSG_DEBUG("addTag - adding name/value pairs: " << tagName << " " << tagValue);
628 std::unique_lock guard( m_mutex );
629 m_extraTagValuePairsViaInterface[tagName]=tagValue;
630 return StatusCode::SUCCESS;
631}
#define ATH_MSG_DEBUG(x)
std::map< std::string, std::string > m_extraTagValuePairsViaInterface
Extra tags/values pairs added in via interface.
Definition TagInfoMgr.h:157

◆ dumpTagInfoToStr()

std::string TagInfoMgr::dumpTagInfoToStr ( ) const
finaloverridevirtual

Dump the content of the current TagInfo to std::string for debug.

Definition at line 674 of file TagInfoMgr.cxx.

675{
676 std::shared_lock guard(m_mutex);
677 return m_tagInfo.str();
678}
TagInfo m_tagInfo
The Tags.
Definition TagInfoMgr.h:187

◆ fillMetaData()

StatusCode TagInfoMgr::fillMetaData ( const CondAttrListCollection * tagInfoCond)
private

Register folder in the IOV Db MetaData

Definition at line 281 of file TagInfoMgr.cxx.

282{
283 // fillMetaData is called at the beginning of the job and for each
284 // new file being read in.
285 //
286 // Fill IOV object in metadata store with information from tag
287 // info.
288 //
289 // For the IOV we use the IOV from the input conditions. For the first input
290 // file, we use the incoming IOV if the current run falls within the IOV
291 // range. If not we set the IOV to runNumber to runNumber + 1. For
292 // subsequent input files, if the runNumber falls within the previous IOV
293 // range, then we set the new IOV to [runNumber, lastStop), otherwise the
294 // IOV is set to [runNumber, runNumber+1). This latter is used for the
295 // zerobias overlaying.
296 //
297
298 ATH_MSG_DEBUG( "entering fillMetaData");
299
300 // Get run number for IOV
301 EventIDBase::number_type runNumber = EventIDBase::UNDEFNUM;
302
303 if( m_currentRun != EventIDBase::UNDEFNUM ) {
305 }
306 else if( m_conditionsRun != EventIDBase::UNDEFNUM ) {
307 // Not completely sure of the use-case for the setting of the conditions run number, but
308 // this will be used if the current run number has not been set. RDS 2020/08
310 ATH_MSG_INFO( "fillMetaData: Using conditions run number: " << m_conditionsRun << " rather then current run number: " << m_currentRun);
311 } else {
312 // For simulation, we may be in the initialization phase and
313 // must get the run number from the event selector
314 if (StatusCode::SUCCESS != getRunNumber (runNumber)) {
315 ATH_MSG_ERROR( "fillMetaData: Could not get event info neither via retrieve nor from the EventSelectror");
316 return (StatusCode::FAILURE);
317 }
318 }
319
320 // Copy tags to AttributeList
321 coral::AttributeList attrList;
323 m_tagInfo.getTags(pairs);
324 ATH_MSG_DEBUG( "fillMetaData: Adding value/tag pairs to file meta data: ");
325 for (unsigned int i = 0; i < pairs.size(); ++i) {
326 attrList.extend(pairs[i].first, "string");
327 attrList[pairs[i].first].setValue(pairs[i].second);
328 ATH_MSG_DEBUG( pairs[i].first << " " << pairs[i].second);
329 }
330
331 // Fill collection
332 CondAttrListCollection* attrListColl = new CondAttrListCollection(true);
333 attrListColl->add(0, attrList);
334 // Set IOV:
335
336 if (tagInfoCond) {
337 // set to the IOV of the incoming conditions
338 // if run num is in previous IOV, set new IOV to be [runNum, lastStop)
339 IOVTime testTime(runNumber, 0);
340 IOVTime start = m_lastIOVRange.start();
341 IOVTime stop = m_lastIOVRange.stop();
342 bool isFirstIOVCheck = false;
343 if (!start.isValid() || !stop.isValid()) {
344 // Start of job, set lastIOVRange to the incoming IOV
345 IOVRange minRange = tagInfoCond->minRange();
346 start = minRange.start();
347 stop = minRange.stop();
348 ATH_MSG_DEBUG( "IOV minRange from IOVMetaData: " << tagInfoCond->minRange());
349 m_lastIOVRange = IOVRange(start, stop);
350 isFirstIOVCheck = true;
351 }
352 if (m_lastIOVRange.isInRange(testTime)) {
353 // set start to runNumber after the
354 if (!isFirstIOVCheck) start = testTime;
355 ATH_MSG_DEBUG( "fillMetaData: run number is in previous IOVRange: " << runNumber << " " << m_lastIOVRange);
356 }
357 else {
358 // Out of range
359 start = testTime;
360 stop = IOVTime(runNumber + 1, 0);
361 ATH_MSG_DEBUG( "fillMetaData: run number is outside of previous IOVRange: " << runNumber << " " << m_lastIOVRange << ". Reset range to run number.");
362 }
363 attrListColl->addNewStart(start);
364 attrListColl->addNewStop (stop);
365 m_lastIOVRange = IOVRange(start, stop);
366 ATH_MSG_DEBUG( "fillMetaData: start, stop: " << start << " " << stop);
367 }
368 else {
369 // set to the IOV of this run to run+1
370 attrListColl->addNewStart(IOVTime(runNumber, 0));
371 attrListColl->addNewStop(IOVTime(runNumber + 1, 0));
372 }
373
375 if (StatusCode::SUCCESS != m_metaDataTool->registerFolder("/TagInfo")) {
376 ATH_MSG_ERROR( "fillMetaData: Unable to register folder for TagInfo with meta data tool ");
377 return StatusCode::FAILURE;
378 }
379
380 // Add payload
381 if (StatusCode::SUCCESS != m_metaDataTool->addPayload("/TagInfo", attrListColl)) {
382 ATH_MSG_ERROR( "fillMetaData: Unable to register folder for TagInfo with meta data tool ");
383 return StatusCode::FAILURE;
384 }
385
386 return StatusCode::SUCCESS;
387
388}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
void addNewStart(const IOVTime &start)
Add new start time to minRange - make sure that start is >= to new start.
bool add(ChanNum chanNum, const AttributeList &attributeList)
Adding in chan/attrList pairs.
void addNewStop(const IOVTime &stop)
Add new stop time to minRange - make sure that stop is <= to new stop.
const IOVRange & minRange() const
Current minimal IOVRange.
std::vector< NameTagPair > NameTagPairVec
Definition EventType.h:101
const IOVTime & stop() const
Definition IOVRange.h:39
const IOVTime & start() const
Definition IOVRange.h:38
EventIDBase::number_type m_conditionsRun
conditionsRun from the first BeginRun incident (HLT)
Definition TagInfoMgr.h:178
StatusCode getRunNumber(unsigned int &runNumber)
EventIDBase::number_type m_currentRun
current run number from BeginRun incident
Definition TagInfoMgr.h:181
PublicToolHandle< IIOVDbMetaDataTool > m_metaDataTool
Access to iov meta data tool.
Definition TagInfoMgr.h:172
IOVRange m_lastIOVRange
IOVRange of last TagInfo added to the file meta data.
Definition TagInfoMgr.h:184
virtual StatusCode start() override

◆ fillTagInfo()

StatusCode TagInfoMgr::fillTagInfo ( const CondAttrListCollection * tagInfoCond)
private

Definition at line 96 of file TagInfoMgr.cxx.

97{
98
99 // Fill tag info
100 //
101 // We first fill normal tag and input tags with tags coming from
102 // either the EventInfo object or the tag info object coming
103 // from COOL
104 //
105 // Then we fill in tags with list of extra tags which are the
106 // current tags for this job. These normally will "over ride"
107 // the tags coming from either COOL/EventInfo. And, of course,
108 // they are not saved as input tags.
109 //
110
111 // Get the messaging service, print where you are
112 ATH_MSG_DEBUG( "fillTagInfo: ");
113 // clear existing tags
114 m_tagInfo = TagInfo();
115
116 // Add tags to TagInfo
117
118 if (tagInfoCond) {
119 // Coming from COOL
120 ATH_MSG_DEBUG( "fillTagInfo: - reading Tags from infile IOV metadata");
121
122 // tagInfoCond->dump();
123
125 if (itr != tagInfoCond->end()) {
126 const coral::AttributeList& attrList = (*itr).second;
127 coral::AttributeList::const_iterator itAttrList = attrList.begin();
128 coral::AttributeList::const_iterator itLast = attrList.end();
129 for (; itAttrList != itLast; ++itAttrList) {
130 // Add current tags:
131 // -----------------
132 // Assumption is that tags from file meta data should
133 // be the "first ones in" and there should not be any
134 // clash with existing tags. Return WARNING if this
135 // happens
136 const std::string& name = (*itAttrList).specification().name();
137 const std::string& value = (*itAttrList).data<std::string>();
138 // First make sure that this tag name is not on the
139 // list of those to be removed
140 if (m_tagsToBeRemoved.find(name) == m_tagsToBeRemoved.end()) {
141 if (m_tagInfo.addTag(EventType::NameTagPair(name, value)).isFailure()) {
142 ATH_MSG_WARNING( "fillTagInfo: Unable to add value/tag to TagInfo "
143 << name << " " << value);
144 }
145 ATH_MSG_DEBUG( "fillTagInfo: Added name/tag to TagInfo "
146 << name << " " << value);
147 }
148 else
149 ATH_MSG_DEBUG( "fillTagInfo: Did NOT add tag - on remove list: name/tag: "
150 << name << " " << value);
151
152 // Duplicate as input tags:
153 // ------------------------
154 // Assumption is that tags from file meta data should
155 // be the "first ones in" and there should not be any
156 // clash with existing tags. Return WARNING if this
157 // happens
158 if (m_tagInfo.addInputTag(EventType::NameTagPair(name, value)).isFailure()) {
159 ATH_MSG_WARNING( "fillTagInfo: Unable to add value/tag to TagInfo as input tag "
160 << name << " " << value);
161 }
162 ATH_MSG_DEBUG( "fillTagInfo: Added value/tag to TagInfo as input tag "
163 << name << " " << value);
164 }
165 }
166 else {
167 // error!
168 ATH_MSG_DEBUG( "fillTagInfo: Could not get attribute list");
169 return (StatusCode::FAILURE);
170 }
171 }
172 else {
173 // **********************************************************
174 // Get tags from EventInfo/EventType
175 // **********************************************************
176 // ***** NOTE: THIS PART IS FOR BACKWARDS COMPATIBILITY *****
177 // ***** TAGS ARE NOW WRITTEN TO FILE META DATA *****
178 // ***** THIS CAN BE REMOVED WHEN NO FILES ARE *****
179 // ***** READ WITH TAGS IN EVENT INFO *****
180 // ***** RDS 04/2009 *****
181 // **********************************************************
182 //MN: 2021-2022 and still not clear what to do with this part
183
184 ATH_MSG_DEBUG( "fillTagInfo: Reading Tags from EventInfo");
185 const EventInfo* evtH = m_storeGate->tryConstRetrieve<EventInfo>();
186 if( !evtH ) {
187 // For simulation, we may be in the initialzation phase
188 // and we cannot get EventInfo. We simply skip this step,
189 // assuming that most times the information is coming in
190 // via conditions/file meta data.
191 ATH_MSG_DEBUG( "fillTagInfo: Could not find EventInfo - skipping the filling of TagInfo from input EventInfo");
192 }
193 else {
194 ATH_MSG_DEBUG( "fillTagInfo: Event ID: ["
195 << evtH->event_ID()->run_number() << ","
196 << evtH->event_ID()->event_number() << ":"
197 << evtH->event_ID()->time_stamp() << "] " );
199 evtH->event_type()->get_detdescr_tags(pairs1);
200
201 if(pairs1.size()) {
202 ATH_MSG_DEBUG( "fillTagInfo: Pairs from EventType:");
203 }
204 else {
205 ATH_MSG_DEBUG( "fillTagInfo: EventInfo/EventType has no tags");
206 }
207 for (unsigned int i = 0; i < pairs1.size(); ++i) {
208 ATH_MSG_DEBUG( "fillTagInfo: " << pairs1[i].first << " : "
209 << pairs1[i].second
210 );
211 // Add current tags:
212 // -----------------
213 // Assumption is that EventInfo tags should be the
214 // "first ones in" and there should not be any clash
215 // with existing tags. Return ERROR if this happens
216
217 // First make sure that this tag name is not on the
218 // list of those to be removed
219 std::string& name = pairs1[i].first;
220 if (m_tagsToBeRemoved.find(name) == m_tagsToBeRemoved.end()) {
221 if (m_tagInfo.addTag(pairs1[i]).isFailure()) {
222 ATH_MSG_ERROR( "fillTagInfo: Unable to add tag to TagInfo: name/tag "
223 << pairs1[i].first << " : "
224 << pairs1[i].second);
225 return (StatusCode::FAILURE);
226 }
227 else ATH_MSG_DEBUG( "fillTagInfo: Added name/tag to TagInfo "
228 << pairs1[i].first << " : "
229 << pairs1[i].second );
230 } else
231 ATH_MSG_DEBUG( "fillTagInfo: Did NOT add tag - on remove list: name/tag: "
232 << pairs1[i].first << " : "
233 << pairs1[i].second );
234
235 // Duplicate as input tags:
236 // ------------------------
237 // Assumption is that EventInfo tags should be the
238 // "first ones in" and there should not be any clash
239 // with existing tags. Return ERROR if this happens
240 if (m_tagInfo.addInputTag(pairs1[i]).isFailure()) {
241 ATH_MSG_ERROR( "fillTagInfo: Unable to add input tag to TagInfo: name/tag "
242 << pairs1[i].first << " : "
243 << pairs1[i].second);
244 return (StatusCode::FAILURE);
245 }
246 }
247 ATH_MSG_DEBUG( "fillTagInfo: Added EventInfo tags to TagInfo current/input");
248
249 }
250 }
251
252 // Dump out contents of TagInfo
253 ATH_MSG_DEBUG( "fillTagInfo: print out tags before adding extra tags");
255
256
257 // Add in any extra tag value pairs if specified
258 std::map<std::string,std::string> valueTagPairs(m_extraTagValuePairs);
259 // Add in pairs from interface
260 for (auto & tv : m_extraTagValuePairsViaInterface) {
261 valueTagPairs[tv.first]=tv.second;
262 }
263
264 for (auto& tv : valueTagPairs) {
265 ATH_MSG_DEBUG( "fillTagInfo: Adding extra value/tag pair: " << tv.first << " " << tv.second);
266 if (m_tagInfo.addTag(EventType::NameTagPair(tv.first,tv.second), true).isFailure()) {
267 ATH_MSG_WARNING( "fillTagInfo: Extra value/tag not added to TagInfo ");
268 }
269 }
270
271 // Dump out contents of TagInfo
272 ATH_MSG_DEBUG( "fillTagInfo: print out tags");
274
275 return StatusCode::SUCCESS;
276
277}
#define ATH_MSG_WARNING(x)
const_iterator end() const
const_iterator begin() const
Access to Chan/AttributeList pairs via iterators.
ChanAttrListMap::const_iterator const_iterator
EventID * event_ID()
the unique identification of the event.
EventType * event_type()
the type of the event, e.g. simulation, testbeam, etc
void get_detdescr_tags(NameTagPairVec &pairs) const
Access DetDescr tags.
std::pair< std::string, std::string > NameTagPair
Definition EventType.h:100
ServiceHandle< StoreGateSvc > m_storeGate
The event store.
Definition TagInfoMgr.h:163
Gaudi::Property< std::map< std::string, std::string > > m_extraTagValuePairs
Extra tags/values pairs added in my jobOptions.
Definition TagInfoMgr.h:154
std::set< std::string > m_tagsToBeRemoved
Extra tags to be removed.
Definition TagInfoMgr.h:160
EventInfo_v1 EventInfo
Definition of the latest event info version.

◆ finalize()

StatusCode TagInfoMgr::finalize ( )
overridevirtual

Definition at line 88 of file TagInfoMgr.cxx.

89{
90 ATH_MSG_DEBUG( "finalize()");
91 return StatusCode::SUCCESS;
92}

◆ findInputTag()

std::string TagInfoMgr::findInputTag ( const std::string & name) const
finaloverridevirtual

Find tag by its name - for input tags, return by value.

Definition at line 658 of file TagInfoMgr.cxx.

659{
660 std::shared_lock guard(m_mutex);
661 return m_tagInfo.findInputTag(name);
662}

◆ findTag()

std::string TagInfoMgr::findTag ( const std::string & name) const
finaloverridevirtual

Find tag by name, return by value.

Definition at line 647 of file TagInfoMgr.cxx.

648{
649 std::shared_lock guard(m_mutex);
650 const auto iter = m_extraTagValuePairsViaInterface.find(name);
651 if( iter != m_extraTagValuePairsViaInterface.end() ) {
652 return iter->second;
653 }
654 return m_tagInfo.findTag(name);
655}

◆ getInputTags()

ITagInfoMgr::NameTagPairVec TagInfoMgr::getInputTags ( ) const
finaloverridevirtual

Return a vector with all current input tags.

Definition at line 666 of file TagInfoMgr.cxx.

667{
668 std::shared_lock guard(m_mutex);
669 return m_tagInfo.getInputTags();
670}

◆ getRunNumber()

StatusCode TagInfoMgr::getRunNumber ( unsigned int & runNumber)
private

Definition at line 392 of file TagInfoMgr.cxx.

393{
394 // check if EventSelector is being used to override run numbers if
395 // so, we return the runNumber from the properties of the
396 // EventSelector
397
398 // Get run number parameter from the EventSelector
399 ATH_MSG_DEBUG( "getRunNumber: check if tag is set in jobOpts");
400 // Get name of event selector from the application manager to
401 // make sure we get the one for MC signal events
402 SmartIF<IProperty> appMgr(serviceLocator()->service("ApplicationMgr"));
403 ATH_CHECK( appMgr.isValid() );
404
405 StringProperty property("EvtSel", "");
406 StatusCode sc = appMgr->getProperty(&property);
407 if (!sc.isSuccess()) {
408 ATH_MSG_ERROR( "getRunNumber: unable to get EvtSel: found " << property.value());
409 return StatusCode::FAILURE;
410 }
411 // Get EventSelector for ApplicationMgr
412 std::string eventSelector = property.value();
413 SmartIF<IProperty> evtSel(serviceLocator()->service(eventSelector));
414 ATH_CHECK( evtSel.isValid() );
415
416 BooleanProperty overrideRunNumber = BooleanProperty("OverrideRunNumber", false);
417 sc = evtSel->getProperty(&overrideRunNumber);
418 if (!sc.isSuccess()) {
419 // Not all EventSelectors have this property, but we should
420 // not get here if the ES is not one for simulation => return failure
421 ATH_MSG_WARNING( "getRunNumber: unable to get OverrideRunNumber property from EventSelector ");
422 return StatusCode::FAILURE;
423 }
424 if (overrideRunNumber.value()) {
425 IntegerProperty runNumberProp = IntegerProperty("RunNumber", 0);
426 sc = evtSel->getProperty(&runNumberProp);
427 if (!sc.isSuccess()) {
428 ATH_MSG_ERROR( "getRunNumber: unable to get RunNumber from EventSelector: found "
429 << runNumberProp.value());
430 return StatusCode::FAILURE;
431 }
432 else {
433 runNumber = runNumberProp.value();
434 ATH_MSG_DEBUG( "getRunNumber: Run number: "
435 << runNumber << " obtained from "
436 << eventSelector);
437 }
438 }
439 else {
440 ATH_MSG_ERROR( "getRunNumber: OverrideRunNumber from EventSelector is false ");
441 return StatusCode::FAILURE;
442 }
443 return StatusCode::SUCCESS;
444}
#define ATH_CHECK
Evaluate an expression and check for errors.
static Double_t sc
::StatusCode StatusCode
StatusCode definition for legacy code.

◆ handle()

void TagInfoMgr::handle ( const Incident & incident)
finaloverride

This method is called at the both the BeginRun and BeginInputFile incidents:

1) For the first begin run, we retrieve the TagInfo and set up IOVDbSvc so that is can use TagInfo to define its hierarchical tags. The member m_currentRun is saved to be used for the IOV in fillMetaData.

2) Then whenever a new file is opened (BeginInputFile), we use the TagInfo object from the detector store to "re-fill" and overwrite the newly merged TagInfo meta data in the output meta data store. We receive BeginInputFile AFTER the IOVDbMetaDataTool has done this automatic merging, so that we can safely overwrite with the desired TagInfo information for this job/run. As well, if there is a second BeginRun during the processing, here we update m_currentRun and overwrite again the TagInfo in the
meta store with the new run which will just extend the IOV of the TagInfo meta data.

Definition at line 449 of file TagInfoMgr.cxx.

449 {
450
473
474 // Get the messaging service, print where you are
475 ATH_MSG_DEBUG( "handle: received incident of type " << inc.type()
476 << " from " << inc.source());
477
478 const EventIDBase eventID = inc.context().eventID();
479
480 if (inc.type() == IncidentType::BeginRun) {
481 // For begin run, reset the current run number
482
483 // get conditionsRun from the Context - can be used if no EventID in the SG (for HLT)
485
486 // Set current run number to be used for fillMetaData
487 m_currentRun = eventID.run_number();
488
489 ATH_MSG_DEBUG( "handle: BeginRun incident - Event ID: ["
490 << eventID.run_number() << ","
491 << eventID.lumi_block() << ":"
492 << eventID.time_stamp() << "] ");
493 if( m_conditionsRun != EventIDBase::UNDEFNUM ) {
494 ATH_MSG_DEBUG( "handle: conditionsRun = " << m_conditionsRun);
495 }
496 if( m_currentRun != EventIDBase::UNDEFNUM ) {
497 ATH_MSG_DEBUG( "handle: currentRun = " << m_currentRun);
498 }
499 }
500
501 // At first BeginRun we retrieve TagInfo and trigger IOVDbSvc to use it
502 if (inc.type() == IncidentType::BeginRun && m_isFirstBeginRun) {
503
504 // No longer first BeginRun
505 m_isFirstBeginRun = false;
506
507 // For the moment, we must set IOVDbSvc into the BeginRun
508 // state to be able to access TagInfo from the file meta data
509
510 // create IOV time from current event coming in with BeginRun incident
511 EventIDBase::number_type run = eventID.run_number();
512 EventIDBase::number_type lb = eventID.lumi_block();
513 IOVTime curTime;
514 curTime.setRunEvent(run, lb);
515
516 // save both seconds and ns offset for timestamp
517 uint64_t nsTime = eventID.time_stamp()*1000000000LL;
518 nsTime += eventID.time_stamp_ns_offset();
519 curTime.setTimestamp(nsTime);
520
521 if (StatusCode::SUCCESS != m_iovDbSvc->signalBeginRun(curTime, inc.context()))
522 {
523 ATH_MSG_ERROR( "Unable to signal begin run to IOVDbSvc");
524 throw GaudiException( "Unable to signal begin run to IOVDbSvc", "TagInfoMgr::handle", StatusCode::FAILURE );
525 }
526 ATH_MSG_DEBUG( "Signaled begin run to IOVDbSvc " << curTime);
527
528 // For BeginRun, update TagInfo
529 if( updateTagInfo().isFailure() ) {
530 throw GaudiException( "updateTagInfo ERROR:", "TagInfoMgr::handle", StatusCode::FAILURE );
531 }
532
533 // May have pre-existing TagInfo with incorrect IOV
534 // range. Try dropping and retrieving again.
535 // bool sc = m_iovDbSvc->dropObject("/TagInfo"); //MN: No idea what that was supposed to do
536
537 // Process TagInfo by IOVDbSvc
538 if (m_iovDbSvc->processTagInfo().isFailure() ) {
539 throw GaudiException( "iovDbSvc::processTagInfo ERROR", "TagInfoMgr::handle", StatusCode::FAILURE );
540 }
541 ATH_MSG_DEBUG( "handle: TagInfo successfully processed by IOVDbSvc to register callback");
543 }
544 else if ((inc.type() == IncidentType::BeginInputFile || inc.type() == IncidentType::BeginRun)
546 {
547 // For a new file incident or a subsequent begin run incident, we must "refill" the meta
548 // data store with the current value of the TagInfo folder in the detector store.
549 if( updateTagInfo().isFailure() ) {
550 throw GaudiException( "updateTagInfo ERROR:", "TagInfoMgr::handle", StatusCode::FAILURE );
551 }
553 }
554}
EventIDBase::number_type conditionsRun() const
void setRunEvent(uint32_t run, uint32_t event) noexcept
Definition IOVTime.cxx:96
void setTimestamp(uint64_t timestamp) noexcept
Definition IOVTime.cxx:72
StatusCode updateTagInfo()
Update Tags when input tags (/TagInfo in-file metadata) change.
bool m_isFirstBeginRun
Flag to identify the first BeginRun incident.
Definition TagInfoMgr.h:175
void notifyListeners() const
Notify all listeners that the Tags were updated.
ServiceHandle< IIOVDbSvc > m_iovDbSvc
Access to IOVDbSvc interface - used to register callback.
Definition TagInfoMgr.h:169
int lb
Definition globals.cxx:23
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.

◆ initialize()

StatusCode TagInfoMgr::initialize ( )
overridevirtual

Definition at line 50 of file TagInfoMgr.cxx.

51{
52 ATH_CHECK( AthService::initialize() );
53
54 // Get the messaging service, print where you are
55 ATH_MSG_DEBUG( "initialize()");
56
57 if (msgLvl(MSG::DEBUG)) {
58 ATH_MSG_DEBUG( "ExtraTagValuePairs " );
59 for (auto& tv : m_extraTagValuePairs) {
60 ATH_MSG_DEBUG( " Value/tag pair: " << tv.first << " " << tv.second );
61 }
62 }
63
64 // To copy TagInfo to EventInfo, we set listener to the
65 // IncidentSvc for BeginRun and BeginInputFile
66 ServiceHandle<IIncidentSvc> incSvc("IncidentSvc", name());
67
68 // Add BeginRun to trigger tag extraction and writing to output
69 // file meta data
70 incSvc->addListener( this, "BeginRun", 100);
71
72 // Add BeginInputFile to trigger refilling meta data store after a new input file - priority has
73 // to be < 50 to be run after IOVDbMetaDataTool (triggered by MetaDataSvc), which is merging
74 // the input meta data from the new file into the output file metadata.
75 incSvc->addListener(this, "BeginInputFile", 50); //
76
77 return StatusCode::SUCCESS;
78}

◆ notifyListeners()

void TagInfoMgr::notifyListeners ( ) const

Notify all listeners that the Tags were updated.

Definition at line 559 of file TagInfoMgr.cxx.

560{
561 ATH_MSG_DEBUG( "notifyListeners (" << m_listeners.size() <<" registered)");
562
563 m_mutex.lock_shared();
564 // Make a copy to use outside of the lock.
565 const std::set<Listener*> listeners = m_listeners;
566 m_mutex.unlock_shared();
567
568 for( auto listener : listeners ) {
569 listener->tagInfoUpdated();
570 }
571}

◆ operator=()

TagInfoMgr & TagInfoMgr::operator= ( const TagInfoMgr & )
private

◆ printTags()

void TagInfoMgr::printTags ( MsgStream & log) const
finaloverridevirtual

Printout method.

Definition at line 682 of file TagInfoMgr.cxx.

683{
684 std::shared_lock guard(m_mutex);
685 m_tagInfo.printTags(log);
686}

◆ removeListener()

void TagInfoMgr::removeListener ( Listener * listener)
finaloverridevirtual

Remove a Listener from the notification list for TagInfo changes.

Definition at line 697 of file TagInfoMgr.cxx.

698{
699 std::unique_lock guard(m_mutex);
700 m_listeners.erase( listener );
701}

◆ removeTagFromInput()

StatusCode TagInfoMgr::removeTagFromInput ( const std::string & tagName)
overridevirtual

Method to allow clients to remove a tag which may have come in on the input.

Definition at line 637 of file TagInfoMgr.cxx.

638{
639 // Add name/value to input vector
640 ATH_MSG_DEBUG( "removeTagFromInput - adding tag name to be removed: " << tagName);
641 std::unique_lock guard( m_mutex );
642 m_tagsToBeRemoved.insert(tagName);
643 return StatusCode::SUCCESS;
644}

◆ start()

StatusCode TagInfoMgr::start ( )
overridevirtual

Definition at line 81 of file TagInfoMgr.cxx.

82{
83 ATH_MSG_DEBUG( "start()");
84 return StatusCode::SUCCESS;
85}

◆ updateTagInfo()

StatusCode TagInfoMgr::updateTagInfo ( )

Update Tags when input tags (/TagInfo in-file metadata) change.

Definition at line 575 of file TagInfoMgr.cxx.

575 {
576
577 // Fill the TagInfo object
578 // The tag info may come from either the input file meta data or
579 // the currently available EventInfo object
580 ATH_MSG_DEBUG( "updateTagInfo: getting /TagInfo");
581
582 // Check whether TagInfo is coming from file meta data or the
583 // input event
584 const CondAttrListCollection* attrListColl = 0;
585 if (m_detStore->contains<CondAttrListCollection>("/TagInfo")) {
586 if (m_detStore->retrieve( attrListColl, "/TagInfo" ).isFailure() ) {
587 ATH_MSG_ERROR( "updateTagInfo: No TagInfo meta data in DetectorStore");
588 return StatusCode::FAILURE ;
589 }
590 else {
591 ATH_MSG_DEBUG( "updateTagInfo: Retrieved TagInfo meta data from detStore. size " << attrListColl->size());
592 }
593 }
594 else {
595 ATH_MSG_DEBUG( "updateTagInfo: det store does NOT contain AttrListColl for TagInfo");
596 }
597
598 // Fill TagInfo from (file meta data) conditions if they exist. If
599 // they are empty, we restore from the saved TagInfo
600 // information. Otherwise we fill from from event info (OLD and
601 // most likely not used anymore. RDS 08/2012).
602 if (attrListColl && attrListColl->size() == 0) {
603 ATH_MSG_DEBUG( "updateTagInfo: /TagInfo empty - do nothing");
605 return StatusCode::SUCCESS;
606 }
607
608 std::unique_lock guard(m_mutex);
609 ATH_CHECK( fillTagInfo(attrListColl) );
610 if (attrListColl) ATH_MSG_DEBUG( "updateTagInfo: Filled TagInfo from file meta data ");
611 else ATH_MSG_DEBUG( "updateTagInfo: Filled TagInfo from input event ");
612
613 // Copy TagInfo to meta data store for writing to file meta data
614 ATH_CHECK( fillMetaData(attrListColl) );
615 ATH_MSG_DEBUG( "updateTagInfo: Wrote TagInfo to MetaDataStore ");
616
617 return StatusCode::SUCCESS;
618}
size_type size() const
number of Chan/AttributeList pairs
StatusCode fillTagInfo(const CondAttrListCollection *tagInfoCond)
StatusCode fillMetaData(const CondAttrListCollection *tagInfoCond)
ServiceHandle< StoreGateSvc > m_detStore
The detector store.
Definition TagInfoMgr.h:166

◆ SvcFactory< TagInfoMgr >

friend class SvcFactory< TagInfoMgr >
friend

forward declaration

Definition at line 123 of file TagInfoMgr.h.

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::shared_mutex m_mutex TagInfoMgr::ATLAS_THREAD_SAFE
mutableprivate

mutex to protect internal data in MT

Definition at line 193 of file TagInfoMgr.h.

◆ m_conditionsRun

EventIDBase::number_type TagInfoMgr::m_conditionsRun { EventIDBase::UNDEFNUM }
private

conditionsRun from the first BeginRun incident (HLT)

Definition at line 178 of file TagInfoMgr.h.

178{ EventIDBase::UNDEFNUM };

◆ m_currentRun

EventIDBase::number_type TagInfoMgr::m_currentRun { EventIDBase::UNDEFNUM }
private

current run number from BeginRun incident

Definition at line 181 of file TagInfoMgr.h.

181{ EventIDBase::UNDEFNUM };

◆ m_detStore

ServiceHandle<StoreGateSvc> TagInfoMgr::m_detStore { this, "DetectorStore", "DetectorStore" }
private

The detector store.

Definition at line 166 of file TagInfoMgr.h.

166{ this, "DetectorStore", "DetectorStore" };

◆ m_extraTagValuePairs

Gaudi::Property<std::map<std::string,std::string> > TagInfoMgr::m_extraTagValuePairs { this, "ExtraTagValuePairs", {}, "key/value pairs to be added" }
private

Extra tags/values pairs added in my jobOptions.

Definition at line 154 of file TagInfoMgr.h.

154{ this, "ExtraTagValuePairs", {}, "key/value pairs to be added" };

◆ m_extraTagValuePairsViaInterface

std::map<std::string,std::string> TagInfoMgr::m_extraTagValuePairsViaInterface
private

Extra tags/values pairs added in via interface.

Definition at line 157 of file TagInfoMgr.h.

◆ m_iovDbSvc

ServiceHandle<IIOVDbSvc> TagInfoMgr::m_iovDbSvc { this, "IOVDbSvc", "IOVDbSvc" }
private

Access to IOVDbSvc interface - used to register callback.

Definition at line 169 of file TagInfoMgr.h.

169{ this, "IOVDbSvc", "IOVDbSvc" };

◆ m_isFirstBeginRun

bool TagInfoMgr::m_isFirstBeginRun { true }
private

Flag to identify the first BeginRun incident.

Definition at line 175 of file TagInfoMgr.h.

175{ true };

◆ m_lastIOVRange

IOVRange TagInfoMgr::m_lastIOVRange { IOVRange(IOVTime(), IOVTime()) }
private

IOVRange of last TagInfo added to the file meta data.

Definition at line 184 of file TagInfoMgr.h.

184{ IOVRange(IOVTime(), IOVTime()) };

◆ m_listeners

std::set< Listener* > TagInfoMgr::m_listeners
private

List of listeners notified when the TagInfo changed.

Definition at line 190 of file TagInfoMgr.h.

◆ m_metaDataTool

PublicToolHandle<IIOVDbMetaDataTool> TagInfoMgr::m_metaDataTool { this, "IOVDbMetaDataTool", "IOVDbMetaDataTool" }
private

Access to iov meta data tool.

Definition at line 172 of file TagInfoMgr.h.

172{ this, "IOVDbMetaDataTool", "IOVDbMetaDataTool" };

◆ m_storeGate

ServiceHandle<StoreGateSvc> TagInfoMgr::m_storeGate { this, "StoreGateSvc", "StoreGateSvc" }
private

The event store.

Definition at line 163 of file TagInfoMgr.h.

163{ this, "StoreGateSvc", "StoreGateSvc" };

◆ m_tagInfo

TagInfo TagInfoMgr::m_tagInfo
private

The Tags.

Definition at line 187 of file TagInfoMgr.h.

◆ m_tagsToBeRemoved

std::set<std::string> TagInfoMgr::m_tagsToBeRemoved
private

Extra tags to be removed.

Definition at line 160 of file TagInfoMgr.h.


The documentation for this class was generated from the following files: