ATLAS Offline Software
Classes | Public Member Functions | List of all members
TagInfoMgr Class Reference

This is a Athena service which manages detector description tag information. It maintains a TagInfo object in the Detector Store with current tag values. 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: More...
 
 ~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. More...
 
virtual StatusCode removeTagFromInput (const std::string &tagName) override
 Method to allow clients to remove a tag which may have come in on the input. More...
 
virtual std::string findTag (const std::string &name) const override final
 Find tag by name, return by value. More...
 
virtual std::string findInputTag (const std::string &name) const override final
 Find tag by its name - for input tags, return by value. More...
 
virtual NameTagPairVec getInputTags () const override final
 Return a vector with all current input tags. More...
 
virtual std::string dumpTagInfoToStr () const override final
 Dump the content of the current TagInfo to std::string for debug. More...
 
virtual void printTags (MsgStream &log) const override final
 Printout method. More...
 
virtual void addListener (Listener *listener) override final
 Add a Listener to the notification list for TagInfo changes. More...
 
virtual void removeListener (Listener *listener) override final
 Remove a Listener from the notification list for TagInfo changes. More...
 

TagInfo management methods:

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

690 {
691  std::unique_lock guard(m_mutex);
692  m_listeners.insert( listener );
693 }

◆ 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 623 of file TagInfoMgr.cxx.

624 {
625  // Add name/value to input vector
626  ATH_MSG_DEBUG("addTag - adding name/value pairs: " << tagName << " " << tagValue);
627  std::unique_lock guard( m_mutex );
628  m_extraTagValuePairsViaInterface[tagName]=tagValue;
629  return StatusCode::SUCCESS;
630 }

◆ dumpTagInfoToStr()

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

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

Definition at line 673 of file TagInfoMgr.cxx.

674 {
675  std::shared_lock guard(m_mutex);
676  return m_tagInfo.str();
677 }

◆ 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;
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);
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());
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);
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 }

◆ 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 
124  CondAttrListCollection::const_iterator itr = tagInfoCond->begin();
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
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 }

◆ 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 657 of file TagInfoMgr.cxx.

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

◆ findTag()

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

Find tag by name, return by value.

Definition at line 646 of file TagInfoMgr.cxx.

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

◆ getInputTags()

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

Return a vector with all current input tags.

Definition at line 665 of file TagInfoMgr.cxx.

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

◆ 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 }

◆ 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 
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");
542  notifyListeners();
543  }
544  else if ((inc.type() == IncidentType::BeginInputFile || inc.type() == IncidentType::BeginRun)
545  && !m_isFirstBeginRun)
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  }
552  notifyListeners();
553  }
554 }

◆ initialize()

StatusCode TagInfoMgr::initialize ( )
overridevirtual

Definition at line 50 of file TagInfoMgr.cxx.

51 {
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  const auto listeners = m_listeners;
565  m_mutex.unlock_shared();
566 
567  for( auto listener : listeners ) {
568  listener->tagInfoUpdated();
569  }
570 }

◆ operator=()

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

◆ printTags()

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

Printout method.

Definition at line 681 of file TagInfoMgr.cxx.

682 {
683  std::shared_lock guard(m_mutex);
685 }

◆ removeListener()

void TagInfoMgr::removeListener ( Listener *  listener)
finaloverridevirtual

Remove a Listener from the notification list for TagInfo changes.

Definition at line 696 of file TagInfoMgr.cxx.

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

◆ 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 636 of file TagInfoMgr.cxx.

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

◆ 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 574 of file TagInfoMgr.cxx.

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

Friends And Related Function Documentation

◆ 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.

◆ 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.

◆ m_detStore

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

The detector store.

Definition at line 166 of file TagInfoMgr.h.

◆ m_extraTagValuePairs

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

Extra tags/values pairs added in my jobOptions.

Definition at line 154 of file TagInfoMgr.h.

◆ 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.

◆ m_isFirstBeginRun

bool TagInfoMgr::m_isFirstBeginRun { true }
private

Flag to identify the first BeginRun incident.

Definition at line 175 of file TagInfoMgr.h.

◆ 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.

◆ 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.

◆ m_storeGate

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

The event store.

Definition at line 163 of file TagInfoMgr.h.

◆ 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:
CondAttrListCollection::minRange
const IOVRange & minRange() const
Current minimal IOVRange.
Definition: CondAttrListCollection.h:438
TagInfoMgr::start
virtual StatusCode start() override
Definition: TagInfoMgr.cxx:81
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
CondAttrListCollection::end
const_iterator end() const
Definition: CondAttrListCollection.h:315
TagInfoMgr::m_storeGate
ServiceHandle< StoreGateSvc > m_storeGate
The event store.
Definition: TagInfoMgr.h:163
EventType::get_detdescr_tags
void get_detdescr_tags(NameTagPairVec &pairs) const
Access DetDescr tags.
Definition: EventType.cxx:113
IOVRange
Validity Range object. Holds two IOVTimes (start and stop)
Definition: IOVRange.h:30
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TagInfo::addTag
StatusCode addTag(const NameTagPair &pair, bool override=false)
addTag for current tags - returns failure if tag name exists and override == false
Definition: TagInfo.cxx:175
TagInfo::findInputTag
void findInputTag(const std::string &name, std::string &tag) const
Find tag by its name - for input tags, return in the reference argument.
Definition: TagInfo.cxx:106
Atlas::ExtendedEventContext::conditionsRun
EventIDBase::number_type conditionsRun() const
Definition: ExtendedEventContext.h:38
CondAttrListCollection::addNewStop
void addNewStop(const IOVTime &stop)
Add new stop time to minRange - make sure that stop is <= to new stop
Definition: CondAttrListCollection.h:518
TagInfo::addInputTag
StatusCode addInputTag(const NameTagPair &pair, bool override=false)
addInputTag for input tags - returns failure if tag name exists and override == false
Definition: TagInfo.cxx:181
initialize
void initialize()
Definition: run_EoverP.cxx:894
IOVRange::start
const IOVTime & start() const
Definition: IOVRange.h:38
IOVRange::isInRange
bool isInRange(const IOVTime &t) const
Definition: IOVRange.h:41
TagInfo::getTags
void getTags(NameTagPairVec &pairs) const
Fill vector with all current tags.
Definition: TagInfo.cxx:117
TagInfoMgr::m_conditionsRun
EventIDBase::number_type m_conditionsRun
conditionsRun from the first BeginRun incident (HLT)
Definition: TagInfoMgr.h:178
TagInfo::printTags
void printTags(MsgStream &log) const
Printout method:
Definition: TagInfo.cxx:192
TagInfoMgr::fillMetaData
StatusCode fillMetaData(const CondAttrListCollection *tagInfoCond)
Definition: TagInfoMgr.cxx:281
TagInfoMgr::m_extraTagValuePairsViaInterface
std::map< std::string, std::string > m_extraTagValuePairsViaInterface
Extra tags/values pairs added in via interface.
Definition: TagInfoMgr.h:157
CondAttrListCollection::begin
const_iterator begin() const
Access to Chan/AttributeList pairs via iterators.
Definition: CondAttrListCollection.h:309
AtlasMcWeight::number_type
unsigned int number_type
Definition: AtlasMcWeight.h:20
athena.value
value
Definition: athena.py:124
TagInfo::str
std::string str() const
String representation.
Definition: TagInfo.cxx:207
CondAttrListCollection::addNewStart
void addNewStart(const IOVTime &start)
Add new start time to minRange - make sure that start is >= to new start.
Definition: CondAttrListCollection.h:508
PixelModuleFeMask_create_db.stop
int stop
Definition: PixelModuleFeMask_create_db.py:76
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
TagInfoMgr::updateTagInfo
StatusCode updateTagInfo()
Update Tags when input tags (/TagInfo in-file metadata) change.
Definition: TagInfoMgr.cxx:574
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
python.CreateTierZeroArgdict.pairs
pairs
Definition: CreateTierZeroArgdict.py:201
Atlas::getExtendedEventContext
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
Definition: ExtendedEventContext.cxx:32
IOVRange::stop
const IOVTime & stop() const
Definition: IOVRange.h:39
IOVTime
Basic time unit for IOVSvc. Hold time as a combination of run and event numbers.
Definition: IOVTime.h:33
TagInfoMgr::m_currentRun
EventIDBase::number_type m_currentRun
current run number from BeginRun incident
Definition: TagInfoMgr.h:181
EventType::NameTagPair
std::pair< std::string, std::string > NameTagPair
Definition: EventType.h:100
TagInfo
This class contains the list of currently valid tags for detector description - GeoModel and IOV/Cond...
Definition: TagInfo.h:41
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
python.BunchSpacingUtils.lb
lb
Definition: BunchSpacingUtils.py:88
lumiFormat.i
int i
Definition: lumiFormat.py:85
EventType::NameTagPairVec
std::vector< NameTagPair > NameTagPairVec
Definition: EventType.h:101
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
EventInfo::event_ID
EventID * event_ID()
the unique identification of the event.
Definition: EventInfo/EventInfo/EventInfo.h:224
TagInfoMgr::m_tagInfo
TagInfo m_tagInfo
The Tags.
Definition: TagInfoMgr.h:187
TagInfoMgr::m_extraTagValuePairs
Gaudi::Property< std::map< std::string, std::string > > m_extraTagValuePairs
Extra tags/values pairs added in my jobOptions.
Definition: TagInfoMgr.h:154
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
run
Definition: run.py:1
TagInfoMgr::m_isFirstBeginRun
bool m_isFirstBeginRun
Flag to identify the first BeginRun incident.
Definition: TagInfoMgr.h:175
IOVTime::setTimestamp
void setTimestamp(uint64_t timestamp) noexcept
Definition: IOVTime.cxx:72
TagInfoMgr::m_lastIOVRange
IOVRange m_lastIOVRange
IOVRange of last TagInfo added to the file meta data.
Definition: TagInfoMgr.h:184
TagInfo::getInputTags
void getInputTags(NameTagPairVec &pairs) const
Fill reference vector with all current input tags.
Definition: TagInfo.cxx:127
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
TagInfoMgr::m_listeners
std::set< Listener * > m_listeners
List of listeners notified when the TagInfo changed.
Definition: TagInfoMgr.h:190
EventInfo
This class provides general information about an event. Event information is provided by the accessor...
Definition: EventInfo/EventInfo/EventInfo.h:43
CondAttrListCollection::size
size_type size() const
number of Chan/AttributeList pairs
Definition: CondAttrListCollection.h:322
TagInfoMgr::m_detStore
ServiceHandle< StoreGateSvc > m_detStore
The detector store.
Definition: TagInfoMgr.h:166
TagInfoMgr::getRunNumber
StatusCode getRunNumber(unsigned int &runNumber)
Definition: TagInfoMgr.cxx:392
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
TagInfoMgr::notifyListeners
void notifyListeners() const
Notify all listeners that the Tags were updated.
Definition: TagInfoMgr.cxx:559
TagInfoMgr::m_metaDataTool
PublicToolHandle< IIOVDbMetaDataTool > m_metaDataTool
Access to iov meta data tool.
Definition: TagInfoMgr.h:172
TagInfoMgr::fillTagInfo
StatusCode fillTagInfo(const CondAttrListCollection *tagInfoCond)
Definition: TagInfoMgr.cxx:96
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CondAttrListCollection::const_iterator
ChanAttrListMap::const_iterator const_iterator
Definition: CondAttrListCollection.h:63
TagInfoMgr::m_iovDbSvc
ServiceHandle< IIOVDbSvc > m_iovDbSvc
Access to IOVDbSvc interface - used to register callback.
Definition: TagInfoMgr.h:169
DeMoScan.first
bool first
Definition: DeMoScan.py:536
DEBUG
#define DEBUG
Definition: page_access.h:11
IOVTime::setRunEvent
void setRunEvent(uint32_t run, uint32_t event) noexcept
Definition: IOVTime.cxx:96
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
LArNewCalib_DelayDump_OFC_Cali.eventSelector
eventSelector
Definition: LArNewCalib_DelayDump_OFC_Cali.py:112
TagInfoMgr::m_tagsToBeRemoved
std::set< std::string > m_tagsToBeRemoved
Extra tags to be removed.
Definition: TagInfoMgr.h:160
TagInfo::findTag
void findTag(const std::string &name, std::string &tag) const
Find tag by its name - for current tags, returning in the reference argument.
Definition: TagInfo.cxx:95
CondAttrListCollection::add
bool add(ChanNum chanNum, const AttributeList &attributeList)
Adding in chan/attrList pairs.
Definition: CondAttrListCollection.h:452
EventInfo::event_type
EventType * event_type()
the type of the event, e.g. simulation, testbeam, etc
Definition: EventInfo/EventInfo/EventInfo.h:234
ServiceHandle< IIncidentSvc >