ATLAS Offline Software
Classes | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
MetaDataSvc Class Reference

Manages the content of the metadata stores. More...

#include <MetaDataSvc.h>

Inheritance diagram for MetaDataSvc:
Collaboration diagram for MetaDataSvc:

Classes

class  ToolLockGuard
 

Public Member Functions

 MetaDataSvc (const std::string &name, ISvcLocator *pSvcLocator)
 Standard Service Constructor. More...
 
virtual ~MetaDataSvc ()
 Destructor. More...
 
virtual StatusCode prepareOutput ()
 Makes the metadata store ready for output. More...
 
virtual void handle (const Incident &incident) override
 react to file incidents. More...
 
StatusCode transitionMetaDataFile (const std::string &outputConn, bool disconnect)
 Transition output metadata file - fire MeteDataStop incident to transition OutputStream and disconnect now if requested. More...
 
virtual StatusCode io_reinit () override
 Implements IIoComponent interface sets m_outputPrepared to false and prints some information. More...
 
StatusCode rootOpenAction (FILEMGR_CALLBACK_ARGS)
 
virtual StoreGateSvcoutputDataStore () const override final
 
virtual const std::string currentRangeID () const override final
 
CLID remapMetaContCLID (const CLID &item_id) const
 
void lockTools () const
 
void unlockTools () const
 
void recordHook (const std::type_info &) override
 
void removeHook (const std::type_info &) override
 
std::string removeStreamFromKey (std::string &key)
 check if the metadata object key contains Stream name (added by SharedWriter in MetaDataSvc) remove stream part from the key (i.e. More...
 
virtual std::set< std::string > getPerStreamKeysFor (const std::string &key) const override final
 Get all per-stream Key variants created for in-file metadata object with original key If no stream-specific keys are found, it returns the original key. More...
 
virtual StatusCode initialize () override
 initialize the metadata service at the beginning of the job More...
 
virtual StatusCode stop () override
 stop the metadata service More...
 
virtual StatusCode finalize () override
 finalize the metadata service at the end of the job More...
 
virtual StatusCode newMetadataSource (const Incident &)
 Fills the input metadata store with the content of the new input file. More...
 
virtual StatusCode retireMetadataSource (const Incident &)
 Allows metadata tools to act before an input file is closed. More...
 
virtual StatusCode prepareOutput (const std::string &outputName)
 Makes the metadata store ready for output with SharedWriter Calls the metaDataStop method of all MetaDataTool interfaces in m_metaDataTool. More...
 
virtual StatusCode shmProxy (const std::string &filename) override
 Loads file metadata from memory shared between streams in SharedWriter This function clears the input and output metadata stores. More...
 
StatusCode preLoadAddresses (StoreID::type, IAddressProvider::tadList &) override
 does nothing. More...
 
StatusCode loadAddresses (StoreID::type storeID, IAddressProvider::tadList &tads) override
 loads addresses of versioned metadata object. More...
 
StatusCode updateAddress (StoreID::type, SG::TransientAddress *, const EventContext &) override
 always fails More...
 

Private Member Functions

StatusCode addProxyToInputMetaDataStore (const std::string &tokenStr)
 
StatusCode initInputMetaDataStore (const std::string &fileName)
 Initialize input metadata store - can be called directly or via BeginInputFile incident. More...
 

Private Attributes

ServiceHandle< StoreGateSvcm_inputDataStore
 
ServiceHandle< StoreGateSvcm_outputDataStore
 
ServiceHandle< IAddressCreator > m_addrCrtr { this, "ConversionService", "AthenaPoolCnvSvc" }
 
ServiceHandle< IFileMgr > m_fileMgr
 
ServiceHandle< IIncidentSvc > m_incSvc
 
ServiceHandle< OutputStreamSequencerSvcm_outSeqSvc
 
ServiceHandle< IClassIDSvc > m_classIDSvc {"ClassIDSvc", name()}
 
long m_storageType {0L}
 
bool m_clearedInputDataStore {true}
 
bool m_clearedOutputDataStore {false}
 
bool m_allowMetaDataStop {false}
 
bool m_outputPrepared {false}
 
std::map< std::string_view, CLIDm_persToClid {}
 
std::set< CLIDm_handledClasses {}
 
std::map< std::string, std::set< std::string > > m_streamKeys {}
 
Gaudi::Property< std::string > m_metaDataCont {this, "MetaDataContainer", ""}
 MetaDataContainer, POOL container name for MetaData. More...
 
PublicToolHandleArray< IMetaDataToolm_metaDataTools {this, "MetaDataTools", {}}
 MetaDataTools, vector with the MetaData tools. More...
 

Static Private Attributes

static constexpr std::string_view m_streamInKeyMark {"__STREAM["}
 marker string for embedding stream name in MetaData object keys for SharedWriter server More...
 

Detailed Description

Manages the content of the metadata stores.

This service orchestrates the reading of metadata from input files and its propagation to the output with the help of the IMetaDataTool interfaces in m_metaDataTools. The MetaDataSvc reacts to BeginInputFile and EndInputFile incidents. It relies on the AthenaPoolCnvSvc (or whatever persistency service) to call the the appropriate prepareOutput method when committing the MetaDataStore content to the output file.

On BeginInputFile it clears the InputMetaDataStore and populates it with content from the new input file. The beginInputFile methods of all tools are called to allow required actions on the metadata objects.

On EndInputFile the MetaDataSvc calls the endInputFile methods of all the interfaces in m_metaDataTools .

In jobs with multiple parallel output streams (SharedWriter) the metadata content from multiple streams is put into the output MetaDataStore. To do this the The MetaDataSvc accesses the memory shared with the output streams, and adds the content of their MetaDataStore to the shared InputMetaDataStore. This is done by the client calling shmProxy for each object to be added to the MetaDataStore. Afterwards the client must also fire BeginInputFile and EndInputFile incidents to allow the MetaDataTools to move their objects from the InputMetaDataStore to the MetaDataStore taking care of possible merges.

Example configuration:

ca.addService(CompFactory.StoreGateSvc("MetaDataStore"))
ca.addService(CompFactory.StoreGateSvc("InputMetaDataStore"))
metaDataSvc = CompFactory.MetaDataSvc("MetaDataSvc")
ca.addService(
CompFactory.ProxyProviderSvc(ProviderNames=["MetaDataSvc"]))
metaDataSvc.MetaDataTools += [someMetaDataTool]
See also
IMetaDataTool
AthenaPoolCnvSvc

Definition at line 84 of file MetaDataSvc.h.

Constructor & Destructor Documentation

◆ MetaDataSvc()

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

Standard Service Constructor.

Definition at line 54 of file MetaDataSvc.cxx.

55  : base_class( name, pSvcLocator )
56  , m_inputDataStore( "StoreGateSvc/InputMetaDataStore", name )
57  , m_outputDataStore( "StoreGateSvc/MetaDataStore", name )
58  , m_fileMgr( "FileMgr", name )
59  , m_incSvc( "IncidentSvc", name )
60  , m_outSeqSvc( "OutputStreamSequencerSvc", name )
61  , m_persToClid{ { "DataHeader_p5", 222376821 },
62  { "EventStreamInfo_p3", 167728019 },
63  { "ByteStreamMetadataContainer_p1", 1076128893 },
64  { "IOVMetaDataContainer_p1", 1316383046 },
65  { "xAOD::EventFormat_v1", 243004407 },
66  { "xAOD::CutBookkeeperContainer_v1", 1234982351 },
67  { "xAOD::CutBookkeeperAuxContainer_v1", 1147935274 },
68  { "xAOD::TriggerMenuContainer_v1", 1107011239 },
69  { "DataVector<xAOD::TriggerMenu_v1>", 1107011239 },
70  { "xAOD::TriggerMenuAuxContainer_v1", 1212409402 },
71  { "xAOD::TriggerMenuJsonContainer_v1", 1221262614 },
72  { "DataVector<xAOD::TriggerMenuJson_v1>", 1221262614 },
73  { "xAOD::TriggerMenuJsonAuxContainer_v1", 373045213 },
74  { "xAOD::LumiBlockRangeContainer_v1", 1115934851 },
75  { "DataVector<xAOD::LumiBlockRange_v1>", 1115934851 },
76  { "xAOD::LumiBlockRangeAuxContainer_v1", 1251061086 },
77  { "xAOD::FileMetaData_v1", 178309087 },
78  { "xAOD::FileMetaDataAuxInfo_v1", 73252552 },
79  { "xAOD::RingSetConfContainer_v1", 1157997427 },
80  { "DataVector<xAOD::RingSetConf_v1>", 1157997427 },
81  { "xAOD::RingSetConfAuxContainer_v1", 1307745126 },
82  { "xAOD::TruthMetaDataContainer_v1", 1188015687 },
83  { "DataVector<xAOD::TruthMetaData_v1>", 1188015687 },
84  { "xAOD::TruthMetaDataAuxContainer_v1", 1094306618 } } {}

◆ ~MetaDataSvc()

MetaDataSvc::~MetaDataSvc ( )
virtualdefault

Destructor.

Member Function Documentation

◆ addProxyToInputMetaDataStore()

StatusCode MetaDataSvc::addProxyToInputMetaDataStore ( const std::string &  tokenStr)
private

Definition at line 416 of file MetaDataSvc.cxx.

416  {
417  std::string fileName = tokenStr.substr(tokenStr.find("[FILE=") + 6);
418  leftString(fileName, ']');
419  std::string className = tokenStr.substr(tokenStr.find("[PNAME=") + 7);
420  leftString(className, ']');
421  std::string contName = tokenStr.substr(tokenStr.find("[CONT=") + 6);
422  leftString(contName,']');
423  std::size_t pos1 = contName.find('(');
424  std::string keyName = contName.substr(pos1 + 1, contName.size() - pos1 - 2);
425  std::size_t pos2 = keyName.find('/');
426  if (pos2 != std::string::npos) keyName = keyName.substr(pos2 + 1);
427  std::string numName = tokenStr.substr(tokenStr.find("[NUM=") + 5);
428  leftString(numName,']');
429  unsigned long num = 0;
430  std::istringstream iss(numName);
431  iss >> num;
432  CLID clid = m_persToClid[className];
433 
434  // make stream-unique keys for infile metadata objects
435  // AthenaOutputStream will use this to distribute objects to the right stream (and restore the original key)
436  if( clid == 178309087 ) { // FileMetaData
437  std::string newName = std::format("{}{}{}{}", keyName, m_streamInKeyMark, fileName, "]");
438  ATH_MSG_DEBUG("Recording " << keyName << " as " << newName);
439  m_streamKeys[keyName].insert(newName);
440  keyName = std::move(newName);
441  }
442  if( clid == 73252552 ) { // FileMetaDataAuxInfo
443  std::string newName = std::format("{}{}{}]{}",
444  keyName.substr(0, keyName.find(RootAuxDynIO::AUX_POSTFIX)),
446  fileName,
448  ATH_MSG_DEBUG("Recording " << keyName << " as " << newName);
449  m_streamKeys[keyName].insert(newName);
450  keyName = std::move(newName);
451  }
452  const std::string par[3] = { "SHM" , keyName , std::move(className) };
453  const unsigned long ipar[2] = { num , 0 };
454  IOpaqueAddress* opqAddr = nullptr;
455  SG::DataProxy* dp = m_inputDataStore->proxy(clid, keyName);
456  if (dp != nullptr) {
457  ATH_MSG_DEBUG("Resetting duplicate proxy for: " << clid << "#" << keyName << " from file: " << fileName);
458  dp->reset();
459  }
460  if (!m_addrCrtr->createAddress(m_storageType, clid, par, ipar, opqAddr).isSuccess()) {
461  ATH_MSG_FATAL("addProxyToInputMetaDataStore: Cannot create address for " << tokenStr);
462  return(StatusCode::FAILURE);
463  }
464  if (m_inputDataStore->recordAddress(keyName, opqAddr).isFailure()) {
465  delete opqAddr; opqAddr = nullptr;
466  ATH_MSG_FATAL("addProxyToInputMetaDataStore: Cannot create proxy for " << tokenStr);
467  return(StatusCode::FAILURE);
468  }
469  if (m_inputDataStore->accessData(clid, keyName) == nullptr) {
470  ATH_MSG_FATAL("addProxyToInputMetaDataStore: Cannot access data for " << tokenStr);
471  return(StatusCode::FAILURE);
472  }
473  if (keyName.find(RootAuxDynIO::AUX_POSTFIX) != std::string::npos
474  && m_inputDataStore->symLink(clid, keyName, 187169987).isFailure()) {
475  ATH_MSG_WARNING("addProxyToInputMetaDataStore: Cannot symlink to AuxStore for " << tokenStr);
476  }
477  return(StatusCode::SUCCESS);
478 }

◆ currentRangeID()

const std::string MetaDataSvc::currentRangeID ( ) const
finaloverridevirtual

Definition at line 550 of file MetaDataSvc.cxx.

551 {
552  return m_outSeqSvc.isValid()? m_outSeqSvc->currentRangeID() : "";
553 }

◆ finalize()

StatusCode MetaDataSvc::finalize ( )
overridevirtual

finalize the metadata service at the end of the job

Definition at line 144 of file MetaDataSvc.cxx.

144  {
145  // Release IncidentService
146  if (!m_incSvc.release().isSuccess()) {
147  ATH_MSG_WARNING("Cannot release IncidentService.");
148  }
149  // Release FileMgr
150  if (!m_fileMgr.release().isSuccess()) {
151  ATH_MSG_WARNING("Cannot release FileMgr.");
152  }
153  // Release AddressCreator
154  if (!m_addrCrtr.release().isSuccess()) {
155  ATH_MSG_WARNING("Cannot release AddressCreator.");
156  }
157  // Release OutputMetaDataStore
158  if (!m_outputDataStore.release().isSuccess()) {
159  ATH_MSG_WARNING("Cannot release OutputMetaDataStore.");
160  }
161  // Release InputMetaDataStore
162  if (!m_inputDataStore.release().isSuccess()) {
163  ATH_MSG_WARNING("Cannot release InputMetaDataStore.");
164  }
165  return(StatusCode::SUCCESS);
166 }

◆ getPerStreamKeysFor()

std::set< std::string > MetaDataSvc::getPerStreamKeysFor ( const std::string &  key) const
finaloverridevirtual

Get all per-stream Key variants created for in-file metadata object with original key If no stream-specific keys are found, it returns the original key.

Definition at line 408 of file MetaDataSvc.cxx.

408  {
409  if (!m_streamKeys.contains(key)) {
410  return {key};
411  }
412  return m_streamKeys.at(key);
413 }

◆ handle()

void MetaDataSvc::handle ( const Incident &  incident)
overridevirtual

react to file incidents.

calls newMetadataSource on BeginInputFile and retireMetadataSource on EndInputFile. Does

Parameters
incidentis expected to be BeginInputFile or EndInputFile

Definition at line 320 of file MetaDataSvc.cxx.

320  {
321  const FileIncident* fileInc = dynamic_cast<const FileIncident*>(&inc);
322  if (fileInc == nullptr) {
323  ATH_MSG_ERROR("Unable to get FileName from EndInputFile incident");
324  return;
325  }
326  const std::string fileName = fileInc->fileName();
327  ATH_MSG_DEBUG("handle() " << inc.type() << " for " << fileName);
328 
329  if (inc.type() == "FirstInputFile") {
330  // Register open/close callback actions
331  using namespace boost::placeholders;
332  Io::bfcn_action_t boa = boost::bind(&MetaDataSvc::rootOpenAction, this, _1,_2);
333  if (m_fileMgr->regAction(std::move(boa), Io::OPEN).isFailure()) {
334  ATH_MSG_FATAL("Cannot register ROOT file open action with FileMgr.");
335  }
336  if (!initInputMetaDataStore(fileName).isSuccess()) {
337  ATH_MSG_WARNING("Unable to initialize InputMetaDataStore");
338  }
339  } else if (inc.type() == "BeginInputFile" || inc.type() == "BeginInputMemFile") {
340  if(newMetadataSource(inc).isFailure()) {
341  ATH_MSG_ERROR("Could not process new metadata source " << fileName);
342  }
343  } else if (inc.type() == "EndInputFile" || inc.type() == "EndInputMemFile") {
344  if(retireMetadataSource(inc).isFailure()) {
345  ATH_MSG_ERROR("Could not retire metadata source " << fileName);
346  }
347  }
348 }

◆ initialize()

StatusCode MetaDataSvc::initialize ( )
overridevirtual

initialize the metadata service at the beginning of the job

Definition at line 90 of file MetaDataSvc.cxx.

90  {
91  ATH_MSG_INFO("Initializing " << name());
92 
93  // Retrieve InputMetaDataStore
94  ATH_CHECK( m_inputDataStore.retrieve() );
95  // Retrieve OutputMetaDataStore
96  ATH_CHECK( m_outputDataStore.retrieve() );
97  // Retrieve AddressCreator
98  ATH_CHECK( m_addrCrtr.retrieve() );
99 
100  AthCnvSvc* cnvSvc = dynamic_cast<AthCnvSvc*>(m_addrCrtr.operator->());
101  if (cnvSvc) {
102  m_storageType = cnvSvc->repSvcType();
103  } else {
104  ATH_MSG_WARNING("Cannot get ConversionSvc Interface.");
105  }
106  // Get FileMgr
107  ATH_CHECK( m_fileMgr.retrieve() );
108 
109  // Set to be listener for end of event
110  ATH_CHECK( m_incSvc.retrieve() );
111 
112  ATH_CHECK( m_metaDataTools.retrieve() );
113  ATH_MSG_INFO("Found " << m_metaDataTools);
114 
115  m_incSvc->addListener(this, "FirstInputFile", 80, true);
116  m_incSvc->addListener(this, "BeginInputFile", 80, true);
117  m_incSvc->addListener(this, "EndInputFile", 10, true);
118  m_incSvc->addListener(this, "BeginInputMemFile", 80, true);
119  m_incSvc->addListener(this, "EndInputMemFile", 10, true);
120 
121  // Register this service for 'I/O' events
122  ServiceHandle<IIoComponentMgr> iomgr("IoComponentMgr", this->name());
123  ATH_CHECK( iomgr.retrieve() );
124  ATH_CHECK( iomgr->io_register(this) );
125 
126  ServiceHandle<Gaudi::Interfaces::IOptionsSvc> joSvc("JobOptionsSvc", name());
127  if (!joSvc.retrieve().isSuccess()) {
128  ATH_MSG_WARNING("Cannot get JobOptionsSvc.");
129  } else {
130  if (joSvc->has("EventSelector.InputCollections")) {
131  // Get EventSelector to force in-time initialization and FirstInputFile incident
132  ServiceHandle<IEvtSelector> evtsel("EventSelector", this->name());
133  if (!evtsel.retrieve().isSuccess()) {
134  ATH_MSG_WARNING("Cannot get EventSelector.");
135  }
136  }
137  }
138  // retrieve the output sequences service (EventService) if available
139  m_outSeqSvc.retrieve().ignore();
140 
141  return(StatusCode::SUCCESS);
142 }

◆ initInputMetaDataStore()

StatusCode MetaDataSvc::initInputMetaDataStore ( const std::string &  fileName)
private

Initialize input metadata store - can be called directly or via BeginInputFile incident.

Definition at line 480 of file MetaDataSvc.cxx.

480  {
481  ATH_MSG_DEBUG("initInputMetaDataStore: file name " << fileName);
482  m_clearedInputDataStore = false;
483  // Load proxies for InputMetaDataStore
484  if (m_metaDataCont.value().empty()) {
485  ATH_MSG_DEBUG("MetaDataSvc called without MetaDataContainer set.");
486  return(StatusCode::SUCCESS);
487  }
488  if (fileName.starts_with( "BSF:")) {
489  ATH_MSG_DEBUG("MetaDataSvc called for non ROOT file.");
490  } else if (fileName.compare(0, 3, "SHM")==0) {
491  ATH_MSG_DEBUG("MetaDataSvc called for shared memory.");
492  } else {
493  const std::string par[2] = {
494  fileName,
495  std::format("{}(DataHeader)", m_metaDataCont.value())
496  };
497  const std::string parOld[2] = {
498  fileName,
499  std::format("{}{}", m_metaDataCont.value(), "DataHeader")
500  };
501  for (int verNumber = 0; verNumber < 100; verNumber++) {
502  SG::VersionedKey myVersKey(name(), verNumber);
503  if (m_inputDataStore->contains<DataHeader>(myVersKey)) {
504  ATH_MSG_DEBUG("initInputMetaDataStore: MetaData Store already contains DataHeader, key = " << myVersKey);
505  } else {
506  const unsigned long ipar[2] = { (unsigned long)verNumber , 0 };
507  IOpaqueAddress* opqAddr = nullptr;
508  if (!m_addrCrtr->createAddress(m_storageType, ClassID_traits<DataHeader>::ID(), par, ipar, opqAddr).isSuccess()) {
509  if (!m_addrCrtr->createAddress(m_storageType, ClassID_traits<DataHeader>::ID(), parOld, ipar, opqAddr).isSuccess()) {
510  break;
511  }
512  }
513  if (m_inputDataStore->recordAddress(myVersKey, opqAddr).isFailure()) {
514  delete opqAddr; opqAddr = nullptr;
515  ATH_MSG_WARNING("initInputMetaDataStore: Cannot create proxy for DataHeader, key = " << myVersKey);
516  }
517  }
518  }
519  std::list<SG::TransientAddress*> tList;
521  for (SG::TransientAddress* tad : tList) {
522  CLID clid = tad->clID();
523  ATH_MSG_VERBOSE("initInputMetaDataStore: add proxy for clid = " << clid << ", key = " << tad->name());
524  if (m_inputDataStore->contains(tad->clID(), tad->name())) {
525  ATH_MSG_DEBUG("initInputMetaDataStore: MetaData Store already contains clid = " << clid << ", key = " << tad->name());
526  } else {
527  if (!m_inputDataStore->recordAddress(tad->name(), tad->address())) {
528  ATH_MSG_ERROR("initInputMetaDataStore: Cannot create proxy for clid = " << clid << ", key = " << tad->name());
529  return StatusCode::FAILURE;
530  }
531  }
532 
533  for (CLID tclid : tad->transientID()) {
534  if (tclid != clid) {
535  if (m_inputDataStore->symLink (clid, tad->name(), tclid).isFailure()) {
536  ATH_MSG_WARNING("Cannot make autosymlink from " <<
537  clid << "/" << tad->name() << " to " << tclid);
538  }
539  }
540  }
541  delete tad;
542  }
543  tList.clear();
544  }
545  ATH_MSG_DEBUG("Loaded input meta data store proxies");
546  return(StatusCode::SUCCESS);
547 }

◆ io_reinit()

StatusCode MetaDataSvc::io_reinit ( )
overridevirtual

Implements IIoComponent interface sets m_outputPrepared to false and prints some information.

Returns
SUCCESS
See also
IIoComponent

Definition at line 379 of file MetaDataSvc.cxx.

379  {
380  ATH_MSG_INFO("I/O reinitialization...");
381  ATH_MSG_DEBUG("Dumping InputMetaDataStore: " << m_inputDataStore->dump());
382  ATH_MSG_DEBUG("Dumping OutputMetaDataStore: " << m_outputDataStore->dump());
383  for (const auto& tool : m_metaDataTools) {
384  ATH_MSG_INFO("Attached MetaDataTool: " << tool->name());
385  }
386  m_outputPrepared = false;
387  return(StatusCode::SUCCESS);
388 }

◆ loadAddresses()

StatusCode MetaDataSvc::loadAddresses ( StoreID::type  storeID,
IAddressProvider::tadList tads 
)
override

loads addresses of versioned metadata object.

loops over all versions of the DataHeader and adds addresses of objects from DataHeaderElements to the tads with a version corresponding to version number of the DataHeader that contained them.

See also
ObjectWithVersion
DataHeader
Parameters
storeID[IN] the identity of the store
tads[OUT] list of addresses to objects from versions keys
Returns
FAILURE the DataHeader could not be retrieved, else SUCCESS

Definition at line 178 of file MetaDataSvc.cxx.

178  {
179  if (storeID != StoreID::METADATA_STORE) { // should this (also) run in the INPUT_METADATA_STORE?
180  return(StatusCode::SUCCESS);
181  }
182  // Put Additional MetaData objects into Input MetaData Store using VersionedKey
183  std::list<SG::ObjectWithVersion<DataHeader> > allVersions;
184  StatusCode sc = m_inputDataStore->retrieveAllVersions(allVersions, name());
185  if (!sc.isSuccess()) {
186  ATH_MSG_WARNING("Could not retrieve all versions for DataHeader, will not read Metadata");
187  } else {
188  int verNumber = -1;
189  for (SG::ObjectWithVersion<DataHeader>& obj : allVersions) {
190  ++verNumber;
191  const DataHeader* dataHeader = obj.dataObject.cptr();
192  if (dataHeader == nullptr) {
193  ATH_MSG_ERROR("Could not get DataHeader, will not read Metadata");
194  return(StatusCode::FAILURE);
195  }
196  for (const DataHeaderElement& dhe : *dataHeader) {
197  const CLID clid = dhe.getPrimaryClassID();
198  if (clid != ClassID_traits<DataHeader>::ID()) {
199  SG::VersionedKey myVersObjKey(dhe.getKey(), verNumber);
200  std::string key = dhe.getKey();
201  if (verNumber != 0) {
202  key = myVersObjKey;
203  }
204  tads.push_back(dhe.getAddress(key));
205  }
206  }
207  }
208  }
209  return(StatusCode::SUCCESS);
210 }

◆ lockTools()

void MetaDataSvc::lockTools ( ) const

Definition at line 601 of file MetaDataSvc.cxx.

601  {
602  ATH_MSG_DEBUG("Locking metadata tools");
603  for(auto& tool : m_metaDataTools ) {
604  const ILockableTool *lockable = dynamic_cast<const ILockableTool*>( tool.get() );
605  if( lockable ) lockable->lock_shared();
606  }
607 }

◆ newMetadataSource()

StatusCode MetaDataSvc::newMetadataSource ( const Incident &  inc)
virtual

Fills the input metadata store with the content of the new input file.

Once the GUID and name of the input file are determined from the incident this function blocks stopping the MetaDataSvc by setting m_allowMetaDataStop to false. Then attempts first to clear the input metadata store and prepare it for the metadata tools by calling initInputMetaDataStore. The loops over all MetaDataTool interfaces in m_metaDataTools and calls their beginInputFile implementations.

See also
initInputMetaDataStore()
m_metaDataTools
Parameters
incThe BeginInputFile incident fired on opening a new file
Returns
FAILURE when inc is not a file incident, the input metadata store cannot be set up, or a MetaDataTool fails. Otherwise SUCCESS.

Definition at line 212 of file MetaDataSvc.cxx.

213 {
214  const FileIncident* fileInc = dynamic_cast<const FileIncident*>(&inc);
215  if (fileInc == nullptr) {
216  ATH_MSG_ERROR("Unable to get FileName from EndInputFile incident");
217  return StatusCode::FAILURE;
218  }
219  const std::string guid = fileInc->fileGuid();
220  const std::string fileName = fileInc->fileName();
221  m_allowMetaDataStop = false;
222  if (!fileName.starts_with( "BSF:")) {
223  // the input file is _not_ bytestream
225  if (!m_inputDataStore->clearStore().isSuccess()) {
226  ATH_MSG_WARNING("Unable to clear input MetaData Proxies");
227  }
229  }
231  }
232  StatusCode rc{StatusCode::SUCCESS};
233  for (auto& tool : m_metaDataTools) {
234  ATH_MSG_DEBUG(" calling beginInputFile on " << tool->name() << " for GUID \"" << guid << "\"");
235  if (tool->beginInputFile(guid).isFailure()) {
236  ATH_MSG_ERROR("Unable to call beginInputFile for " << tool->name());
237  rc = StatusCode::FAILURE;
238  }
239  }
240  return rc;
241 }

◆ outputDataStore()

virtual StoreGateSvc* MetaDataSvc::outputDataStore ( ) const
inlinefinaloverridevirtual

Definition at line 235 of file MetaDataSvc.h.

235  {
236  return &*m_outputDataStore;
237  }

◆ preLoadAddresses()

StatusCode MetaDataSvc::preLoadAddresses ( StoreID::type  ,
IAddressProvider::tadList  
)
inlineoverride

does nothing.

Parameters
storeID[IN] store ID, this function only preloads detector store addresses.
tads[OUT] list of the transient addresses which were preloaded.
Returns
SUCCESS

Definition at line 184 of file MetaDataSvc.h.

185  {
186  return StatusCode::SUCCESS;
187  }

◆ prepareOutput()

StatusCode MetaDataSvc::prepareOutput ( )
virtual

Makes the metadata store ready for output.

Calls the metaDataStop method of all MetaDataTool interfaces in m_metaDataTool. Then release the metadata tools. This implementation assumes SharedWriter is not being used.

Returns
SUCCESS unless a MetaDataTool fails, then FAILURE

Definition at line 260 of file MetaDataSvc.cxx.

261 {
262  if (m_outputPrepared) {
263  return StatusCode::SUCCESS;
264  }
265 
266  StatusCode rc{StatusCode::SUCCESS};
267  for (auto& tool : m_metaDataTools) {
268  ATH_MSG_DEBUG(" calling metaDataStop for " << tool->name());
269  if (tool->metaDataStop().isFailure()) {
270  ATH_MSG_ERROR("Unable to call metaDataStop for " << tool->name());
271  rc = StatusCode::FAILURE;
272  }
273  }
274  if (!m_metaDataTools.release().isSuccess()) {
275  ATH_MSG_WARNING("Cannot release " << m_metaDataTools);
276  }
277 
278  m_outputPrepared = true;
279  return rc;
280 }

◆ recordHook()

void MetaDataSvc::recordHook ( const std::type_info &  typeInfo)
override

Definition at line 576 of file MetaDataSvc.cxx.

576  {
577  const std::string& typeName = System::typeinfoName(typeInfo);
578  ATH_MSG_VERBOSE("Handling record event of type " << typeName);
579 
580  CLID itemID = 0;
581  if (m_classIDSvc->getIDOfTypeInfoName(typeName, itemID).isSuccess()) {
582  auto result = m_handledClasses.insert(itemID);
583  if (result.second)
584  ATH_MSG_DEBUG("MetaDataSvc will handle " << typeName
585  << " ClassID: " << itemID);
586  }
587 }

◆ remapMetaContCLID()

CLID MetaDataSvc::remapMetaContCLID ( const CLID item_id) const

Definition at line 556 of file MetaDataSvc.cxx.

557 {
558  if (!m_handledClasses.contains(itemID)) {
559  ATH_MSG_DEBUG("Not translating metadata item ID #" << itemID);
560  return itemID;
561  }
562 
563  std::string itemName;
564  CLID contID = 0;
565  if (m_classIDSvc->getTypeNameOfID(itemID, itemName).isSuccess()) {
566  const std::string contName = std::format("MetaCont<{}>", itemName);
567  ATH_MSG_DEBUG("Transforming " << contName << " to " << itemName
568  << " for output");
569  if (m_classIDSvc->getIDOfTypeName(contName, contID).isSuccess())
570  return contID;
571  }
572 
573  return itemID;
574 }

◆ removeHook()

void MetaDataSvc::removeHook ( const std::type_info &  typeInfo)
override

Definition at line 589 of file MetaDataSvc.cxx.

589  {
590  const std::string& typeName = System::typeinfoName(typeInfo);
591  ATH_MSG_VERBOSE("Handling removal event of type " << typeName);
592 
593  CLID itemID = 0;
594  if (m_classIDSvc->getIDOfTypeInfoName(typeName, itemID).isSuccess()) {
595  if (0 < m_handledClasses.erase(itemID))
596  ATH_MSG_DEBUG("MetaDataSvc will no longer handle " << typeName
597  << " ClassID: " << itemID);
598  }
599 }

◆ removeStreamFromKey()

std::string MetaDataSvc::removeStreamFromKey ( std::string &  key)

check if the metadata object key contains Stream name (added by SharedWriter in MetaDataSvc) remove stream part from the key (i.e.

modify the parameter) and return it

Definition at line 396 of file MetaDataSvc.cxx.

396  {
397  size_t pos = key.find(m_streamInKeyMark);
398  if( pos==std::string::npos ) return "";
399  size_t epos = key.find(']', pos);
400  size_t spos = pos + m_streamInKeyMark.size();
401  std::string stream = key.substr( spos, epos - spos );
402  //cppcheck-suppress uselessCallsSubstr
403  key = key.substr(0, pos) + key.substr(epos+1);
404  return stream;
405 }

◆ retireMetadataSource()

StatusCode MetaDataSvc::retireMetadataSource ( const Incident &  inc)
virtual

Allows metadata tools to act before an input file is closed.

Grabs the file GUID then calls the the endInputFile method of all metadata tools in m_metaDataTools providing the GUID as argument.

Parameters
incis a file incident fired before closing an input file
Returns
SUCCESS unless a MetaDataTool fails, then FAILURE

Definition at line 243 of file MetaDataSvc.cxx.

244 {
245  const FileIncident* fileInc = dynamic_cast<const FileIncident*>(&inc);
246  if (fileInc == nullptr) {
247  ATH_MSG_ERROR("Unable to get FileName from EndInputFile incident");
248  return StatusCode::FAILURE;
249  }
250  const std::string guid = fileInc->fileGuid();
251  ATH_MSG_DEBUG("retireMetadataSource: " << fileInc->fileName());
252  for (auto& tool : m_metaDataTools) {
253  ATH_MSG_DEBUG(" calling endInputFile on " << tool->name() << " for GUID \"" << guid << "\"");
254  ATH_CHECK(tool->endInputFile(guid));
255  }
256  m_allowMetaDataStop = true;
257  return StatusCode::SUCCESS;
258 }

◆ rootOpenAction()

StatusCode MetaDataSvc::rootOpenAction ( FILEMGR_CALLBACK_ARGS  )

Definition at line 390 of file MetaDataSvc.cxx.

390  {
391  return(StatusCode::SUCCESS);
392 }

◆ stop()

StatusCode MetaDataSvc::stop ( )
overridevirtual

stop the metadata service

Definition at line 169 of file MetaDataSvc.cxx.

169  {
170  ATH_MSG_DEBUG("MetaDataSvc::stop()");
171  // Fire metaDataStopIncident
172  Incident metaDataStopIncident(name(), "MetaDataStop");
173  m_incSvc->fireIncident(metaDataStopIncident);
174  return(StatusCode::SUCCESS);
175 }

◆ transitionMetaDataFile()

StatusCode MetaDataSvc::transitionMetaDataFile ( const std::string &  outputConn,
bool  disconnect 
)

Transition output metadata file - fire MeteDataStop incident to transition OutputStream and disconnect now if requested.

Definition at line 352 of file MetaDataSvc.cxx.

353 {
354  ATH_MSG_DEBUG("transitionMetaDataFile: " << outputConn );
355 
356  // this is normally called through EndInputFile inc, simulate it for EvSvc
357  FileIncident inc("transitionMetaDataFile", "EndInputFile", "dummyMetaInputFileName", "");
359 
360  // Reset flag to allow calling prepareOutput again at next transition
361  m_outputPrepared = false;
362 
363  Incident metaDataStopIncident(name(), "MetaDataStop");
364  m_incSvc->fireIncident(metaDataStopIncident);
365 
366  if( disconnect ) {
367  AthCnvSvc* cnvSvc = dynamic_cast<AthCnvSvc*>(m_addrCrtr.operator->());
368  if (cnvSvc) {
369  if (!cnvSvc->disconnectOutput(outputConn).isSuccess()) {
370  ATH_MSG_WARNING("Cannot get disconnect Output Files");
371  }
372  }
373  }
374 
375  return(StatusCode::SUCCESS);
376 }

◆ unlockTools()

void MetaDataSvc::unlockTools ( ) const

Definition at line 609 of file MetaDataSvc.cxx.

609  {
610  ATH_MSG_DEBUG("Unlocking metadata tools");
611  for(auto& tool : m_metaDataTools ) {
612  const ILockableTool *lockable = dynamic_cast<const ILockableTool*>( tool.get() );
613  if( lockable ) lockable->unlock_shared();
614  }
615 }

◆ updateAddress()

StatusCode MetaDataSvc::updateAddress ( StoreID::type  ,
SG::TransientAddress ,
const EventContext &   
)
inlineoverride

always fails

Parameters
storeID[IN] the identity of the store
tad[IN] transient address to be updated
ctx[IN] current event's context information
Returns
FAILURE

Definition at line 208 of file MetaDataSvc.h.

210  {
211  return StatusCode::FAILURE;
212  }

Member Data Documentation

◆ m_addrCrtr

ServiceHandle<IAddressCreator> MetaDataSvc::m_addrCrtr { this, "ConversionService", "AthenaPoolCnvSvc" }
private

Definition at line 300 of file MetaDataSvc.h.

◆ m_allowMetaDataStop

bool MetaDataSvc::m_allowMetaDataStop {false}
private

Definition at line 309 of file MetaDataSvc.h.

◆ m_classIDSvc

ServiceHandle<IClassIDSvc> MetaDataSvc::m_classIDSvc {"ClassIDSvc", name()}
private

Definition at line 304 of file MetaDataSvc.h.

◆ m_clearedInputDataStore

bool MetaDataSvc::m_clearedInputDataStore {true}
private

Definition at line 307 of file MetaDataSvc.h.

◆ m_clearedOutputDataStore

bool MetaDataSvc::m_clearedOutputDataStore {false}
private

Definition at line 308 of file MetaDataSvc.h.

◆ m_fileMgr

ServiceHandle<IFileMgr> MetaDataSvc::m_fileMgr
private

Definition at line 301 of file MetaDataSvc.h.

◆ m_handledClasses

std::set<CLID> MetaDataSvc::m_handledClasses {}
private

Definition at line 313 of file MetaDataSvc.h.

◆ m_incSvc

ServiceHandle<IIncidentSvc> MetaDataSvc::m_incSvc
private

Definition at line 302 of file MetaDataSvc.h.

◆ m_inputDataStore

ServiceHandle<StoreGateSvc> MetaDataSvc::m_inputDataStore
private

Definition at line 298 of file MetaDataSvc.h.

◆ m_metaDataCont

Gaudi::Property<std::string> MetaDataSvc::m_metaDataCont {this, "MetaDataContainer", ""}
private

MetaDataContainer, POOL container name for MetaData.

Definition at line 321 of file MetaDataSvc.h.

◆ m_metaDataTools

PublicToolHandleArray<IMetaDataTool> MetaDataSvc::m_metaDataTools {this, "MetaDataTools", {}}
private

MetaDataTools, vector with the MetaData tools.

Definition at line 323 of file MetaDataSvc.h.

◆ m_outputDataStore

ServiceHandle<StoreGateSvc> MetaDataSvc::m_outputDataStore
private

Definition at line 299 of file MetaDataSvc.h.

◆ m_outputPrepared

bool MetaDataSvc::m_outputPrepared {false}
private

Definition at line 310 of file MetaDataSvc.h.

◆ m_outSeqSvc

ServiceHandle<OutputStreamSequencerSvc> MetaDataSvc::m_outSeqSvc
private

Definition at line 303 of file MetaDataSvc.h.

◆ m_persToClid

std::map<std::string_view, CLID> MetaDataSvc::m_persToClid {}
private

Definition at line 311 of file MetaDataSvc.h.

◆ m_storageType

long MetaDataSvc::m_storageType {0L}
private

Definition at line 306 of file MetaDataSvc.h.

◆ m_streamInKeyMark

constexpr std::string_view MetaDataSvc::m_streamInKeyMark {"__STREAM["}
staticconstexprprivate

marker string for embedding stream name in MetaData object keys for SharedWriter server

Definition at line 315 of file MetaDataSvc.h.

◆ m_streamKeys

std::map< std::string, std::set<std::string> > MetaDataSvc::m_streamKeys {}
private

Definition at line 317 of file MetaDataSvc.h.


The documentation for this class was generated from the following files:
TileDCSDataPlotter.dp
dp
Definition: TileDCSDataPlotter.py:842
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
get_generator_info.result
result
Definition: get_generator_info.py:21
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
RootAuxDynIO::AUX_POSTFIX
constexpr char AUX_POSTFIX[]
Common post-fix for the names of auxiliary containers in StoreGate.
Definition: RootAuxDynDefs.h:12
MetaDataSvc::m_storageType
long m_storageType
Definition: MetaDataSvc.h:306
vtune_athena.format
format
Definition: vtune_athena.py:14
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
MetaDataSvc::m_clearedInputDataStore
bool m_clearedInputDataStore
Definition: MetaDataSvc.h:307
SG::TransientAddress
Definition: TransientAddress.h:32
ILockableTool::lock_shared
virtual void lock_shared() const =0
Lock the tool.
MetaDataSvc::m_inputDataStore
ServiceHandle< StoreGateSvc > m_inputDataStore
Definition: MetaDataSvc.h:298
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MetaDataSvc::m_metaDataCont
Gaudi::Property< std::string > m_metaDataCont
MetaDataContainer, POOL container name for MetaData.
Definition: MetaDataSvc.h:321
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
DataHeaderElement
This class provides a persistent form for the TransientAddress.
Definition: DataHeader.h:37
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MetaDataSvc::m_outputPrepared
bool m_outputPrepared
Definition: MetaDataSvc.h:310
Athena::typeinfoName
std::string typeinfoName(const std::type_info &ti)
Convert a type_info to a demangled string.
Definition: AthenaKernel/src/ClassName.cxx:23
ILockableTool::unlock_shared
virtual void unlock_shared() const =0
Unlock the tool.
MetaDataSvc::newMetadataSource
virtual StatusCode newMetadataSource(const Incident &)
Fills the input metadata store with the content of the new input file.
Definition: MetaDataSvc.cxx:212
DataHeader
This class provides the layout for summary information stored for data written to POOL.
Definition: DataHeader.h:126
MetaDataSvc::m_addrCrtr
ServiceHandle< IAddressCreator > m_addrCrtr
Definition: MetaDataSvc.h:300
MetaDataSvc::initInputMetaDataStore
StatusCode initInputMetaDataStore(const std::string &fileName)
Initialize input metadata store - can be called directly or via BeginInputFile incident.
Definition: MetaDataSvc.cxx:480
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MetaDataSvc::m_outputDataStore
ServiceHandle< StoreGateSvc > m_outputDataStore
Definition: MetaDataSvc.h:299
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
SG::VersionedKey
a StoreGateSvc key with a version number. Notice that StoreGate does not order multiple instances of ...
Definition: SGVersionedKey.h:31
MetaDataSvc::m_allowMetaDataStop
bool m_allowMetaDataStop
Definition: MetaDataSvc.h:309
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:37
MetaDataSvc::m_streamKeys
std::map< std::string, std::set< std::string > > m_streamKeys
Definition: MetaDataSvc.h:317
ILockableTool
Provide an interface for locking and unlocking a tool externally.
Definition: ILockableTool.h:25
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MetaDataSvc::m_fileMgr
ServiceHandle< IFileMgr > m_fileMgr
Definition: MetaDataSvc.h:301
MetaDataSvc::m_metaDataTools
PublicToolHandleArray< IMetaDataTool > m_metaDataTools
MetaDataTools, vector with the MetaData tools.
Definition: MetaDataSvc.h:323
MetaDataSvc::retireMetadataSource
virtual StatusCode retireMetadataSource(const Incident &)
Allows metadata tools to act before an input file is closed.
Definition: MetaDataSvc.cxx:243
StoreID::METADATA_STORE
@ METADATA_STORE
Definition: StoreID.h:29
plotmaker.keyName
keyName
Definition: plotmaker.py:145
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
pool_uuid.guid
guid
Definition: pool_uuid.py:112
trigbs_pickEvents.num
num
Definition: trigbs_pickEvents.py:76
MetaDataSvc::m_incSvc
ServiceHandle< IIncidentSvc > m_incSvc
Definition: MetaDataSvc.h:302
MetaDataSvc::m_persToClid
std::map< std::string_view, CLID > m_persToClid
Definition: MetaDataSvc.h:311
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:28
MakeNewFileFromOldAndSubstitution.newName
dictionary newName
Definition: ICHEP2016/MakeNewFileFromOldAndSubstitution.py:95
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:452
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:16
MetaDataSvc::m_streamInKeyMark
static constexpr std::string_view m_streamInKeyMark
marker string for embedding stream name in MetaData object keys for SharedWriter server
Definition: MetaDataSvc.h:315
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
jobOptions.epos
epos
Definition: jobOptions.crmc.py:50
MetaDataSvc::rootOpenAction
StatusCode rootOpenAction(FILEMGR_CALLBACK_ARGS)
Definition: MetaDataSvc.cxx:390
ReadCalibFromCool.typeName
typeName
Definition: ReadCalibFromCool.py:477
AthCnvSvc::repSvcType
virtual long repSvcType() const override
Retrieve the class type of the data store the converter uses.
Definition: AthCnvSvc.cxx:143
AthCnvSvc::disconnectOutput
virtual StatusCode disconnectOutput(const std::string &output)
Disconnect output files from the service.
Definition: AthCnvSvc.cxx:408
jobOptions.fileName
fileName
Definition: jobOptions.SuperChic_ALP2.py:39
SG::ObjectWithVersion
associate a data object with its VersionedKey The object is held by a ReadHandle to delay its retriev...
Definition: SGVersionedKey.h:17
python.PyAthena.obj
obj
Definition: PyAthena.py:132
SG::DataProxy
Definition: DataProxy.h:45
LArL1Calo_ComputeHVCorr.className
className
Definition: LArL1Calo_ComputeHVCorr.py:135
AthCnvSvc
Definition: AthCnvSvc.h:66
MetaDataSvc::loadAddresses
StatusCode loadAddresses(StoreID::type storeID, IAddressProvider::tadList &tads) override
loads addresses of versioned metadata object.
Definition: MetaDataSvc.cxx:178
MetaDataSvc::m_classIDSvc
ServiceHandle< IClassIDSvc > m_classIDSvc
Definition: MetaDataSvc.h:304
python.trfValidateRootFile.rc
rc
Definition: trfValidateRootFile.py:375
ServiceHandle< IIoComponentMgr >
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
MetaDataSvc::m_handledClasses
std::set< CLID > m_handledClasses
Definition: MetaDataSvc.h:313
MetaDataSvc::m_outSeqSvc
ServiceHandle< OutputStreamSequencerSvc > m_outSeqSvc
Definition: MetaDataSvc.h:303