ATLAS Offline Software
MetaDataSvc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 #include "MetaDataSvc.h"
11 
12 #include "Gaudi/Interfaces/IOptionsSvc.h"
13 #include "GaudiKernel/IAlgTool.h"
14 #include "GaudiKernel/IEvtSelector.h"
15 #include "GaudiKernel/IIncidentSvc.h"
16 #include "GaudiKernel/IIoComponentMgr.h"
17 #include "GaudiKernel/IOpaqueAddress.h"
18 #include "GaudiKernel/FileIncident.h"
19 #include "GaudiKernel/System.h"
20 
22 #include "StoreGate/StoreGateSvc.h"
23 #include "SGTools/SGVersionedKey.h"
26 
28 
29 #include <vector>
30 #include <sstream>
31 
32 #include "boost/bind/bind.hpp"
33 
34 
35 namespace {
43  bool leftString(std::string& s, char sc) {
44  if (const auto pos = s.find(sc); pos != std::string::npos) {
45  s.resize(pos);
46  return true;
47  }
48  return false;
49  }
50 }
51 
52 
53 //________________________________________________________________________________
54 MetaDataSvc::MetaDataSvc( const std::string& name, ISvcLocator* pSvcLocator )
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 } } {}
85 
86 //________________________________________________________________________________
87 MetaDataSvc::~MetaDataSvc() = default;
88 
89 //__________________________________________________________________________
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 
119  // Register this service for 'I/O' events
120  ServiceHandle<IIoComponentMgr> iomgr("IoComponentMgr", this->name());
121  ATH_CHECK( iomgr.retrieve() );
122  ATH_CHECK( iomgr->io_register(this) );
123 
124  ServiceHandle<Gaudi::Interfaces::IOptionsSvc> joSvc("JobOptionsSvc", name());
125  if (!joSvc.retrieve().isSuccess()) {
126  ATH_MSG_WARNING("Cannot get JobOptionsSvc.");
127  } else {
128  if (joSvc->has("EventSelector.InputCollections")) {
129  // Get EventSelector to force in-time initialization and FirstInputFile incident
130  ServiceHandle<IEvtSelector> evtsel("EventSelector", this->name());
131  if (!evtsel.retrieve().isSuccess()) {
132  ATH_MSG_WARNING("Cannot get EventSelector.");
133  }
134  }
135  }
136  // retrieve the output sequences service (EventService) if available
137  m_outSeqSvc.retrieve().ignore();
138 
139  return(StatusCode::SUCCESS);
140 }
141 //__________________________________________________________________________
143  // Release IncidentService
144  if (!m_incSvc.release().isSuccess()) {
145  ATH_MSG_WARNING("Cannot release IncidentService.");
146  }
147  // Release FileMgr
148  if (!m_fileMgr.release().isSuccess()) {
149  ATH_MSG_WARNING("Cannot release FileMgr.");
150  }
151  // Release AddressCreator
152  if (!m_addrCrtr.release().isSuccess()) {
153  ATH_MSG_WARNING("Cannot release AddressCreator.");
154  }
155  // Release OutputMetaDataStore
156  if (!m_outputDataStore.release().isSuccess()) {
157  ATH_MSG_WARNING("Cannot release OutputMetaDataStore.");
158  }
159  // Release InputMetaDataStore
160  if (!m_inputDataStore.release().isSuccess()) {
161  ATH_MSG_WARNING("Cannot release InputMetaDataStore.");
162  }
163  return(StatusCode::SUCCESS);
164 }
165 
166 //__________________________________________________________________________
168  ATH_MSG_DEBUG("MetaDataSvc::stop()");
169  // Fire metaDataStopIncident
170  Incident metaDataStopIncident(name(), "MetaDataStop");
171  m_incSvc->fireIncident(metaDataStopIncident);
172  return(StatusCode::SUCCESS);
173 }
174 
175 //________________________________________________________________________________
177  if (storeID != StoreID::METADATA_STORE) { // should this (also) run in the INPUT_METADATA_STORE?
178  return(StatusCode::SUCCESS);
179  }
180  // Put Additional MetaData objects into Input MetaData Store using VersionedKey
181  std::list<SG::ObjectWithVersion<DataHeader> > allVersions;
182  StatusCode sc = m_inputDataStore->retrieveAllVersions(allVersions, name());
183  if (!sc.isSuccess()) {
184  ATH_MSG_WARNING("Could not retrieve all versions for DataHeader, will not read Metadata");
185  } else {
186  int verNumber = -1;
187  for (SG::ObjectWithVersion<DataHeader>& obj : allVersions) {
188  ++verNumber;
189  const DataHeader* dataHeader = obj.dataObject.cptr();
190  if (dataHeader == nullptr) {
191  ATH_MSG_ERROR("Could not get DataHeader, will not read Metadata");
192  return(StatusCode::FAILURE);
193  }
194  for (const DataHeaderElement& dhe : *dataHeader) {
195  const CLID clid = dhe.getPrimaryClassID();
196  if (clid != ClassID_traits<DataHeader>::ID()) {
197  SG::VersionedKey myVersObjKey(dhe.getKey(), verNumber);
198  std::string key = dhe.getKey();
199  if (verNumber != 0) {
200  key = myVersObjKey;
201  }
202  tads.push_back(dhe.getAddress(key));
203  }
204  }
205  }
206  }
207  return(StatusCode::SUCCESS);
208 }
209 //________________________________________________________________________________
211 {
212  const FileIncident* fileInc = dynamic_cast<const FileIncident*>(&inc);
213  if (fileInc == nullptr) {
214  ATH_MSG_ERROR("Unable to get FileName from EndInputFile incident");
215  return StatusCode::FAILURE;
216  }
217  const std::string guid = fileInc->fileGuid();
218  const std::string fileName = fileInc->fileName();
219  m_allowMetaDataStop = false;
220  if (!fileName.starts_with( "BSF:")) {
221  // the input file is _not_ bytestream
223  if (!m_inputDataStore->clearStore().isSuccess()) {
224  ATH_MSG_WARNING("Unable to clear input MetaData Proxies");
225  }
227  }
229  }
230  StatusCode rc{StatusCode::SUCCESS};
231  for (auto& tool : m_metaDataTools) {
232  ATH_MSG_DEBUG(" calling beginInputFile on " << tool->name() << " for GUID \"" << guid << "\"");
233  if (tool->beginInputFile(guid).isFailure()) {
234  ATH_MSG_ERROR("Unable to call beginInputFile for " << tool->name());
235  rc = StatusCode::FAILURE;
236  }
237  }
238  return rc;
239 }
240 
242 {
243  const FileIncident* fileInc = dynamic_cast<const FileIncident*>(&inc);
244  if (fileInc == nullptr) {
245  ATH_MSG_ERROR("Unable to get FileName from EndInputFile incident");
246  return StatusCode::FAILURE;
247  }
248  const std::string guid = fileInc->fileGuid();
249  ATH_MSG_DEBUG("retireMetadataSource: " << fileInc->fileName());
250  for (auto& tool : m_metaDataTools) {
251  ATH_MSG_DEBUG(" calling endInputFile on " << tool->name() << " for GUID \"" << guid << "\"");
252  ATH_CHECK(tool->endInputFile(guid));
253  }
254  m_allowMetaDataStop = true;
255  return StatusCode::SUCCESS;
256 }
257 
259 {
260  if (m_outputPrepared) {
261  return StatusCode::SUCCESS;
262  }
263 
264  StatusCode rc{StatusCode::SUCCESS};
265  for (auto& tool : m_metaDataTools) {
266  ATH_MSG_DEBUG(" calling metaDataStop for " << tool->name());
267  if (tool->metaDataStop().isFailure()) {
268  ATH_MSG_ERROR("Unable to call metaDataStop for " << tool->name());
269  rc = StatusCode::FAILURE;
270  }
271  }
272  if (!m_metaDataTools.release().isSuccess()) {
273  ATH_MSG_WARNING("Cannot release " << m_metaDataTools);
274  }
275 
276  m_outputPrepared = true;
277  return rc;
278 }
279 
280 // like prepareOutput() but for parallel streams
282 {
283  // default to the serial implementation if no output name given
284  if( outputName.empty() ) {
285  return prepareOutput();
286  }
287  ATH_MSG_DEBUG( "prepareOutput('" << outputName << "')" );
288 
289  StatusCode rc{StatusCode::SUCCESS};
290  for (auto& tool : m_metaDataTools) {
291  ATH_MSG_DEBUG(" calling metaDataStop for " << tool->name());
292  // planning to replace the call below with (*it)->prepareOutput(outputName)
293  if (tool->metaDataStop().isFailure()) {
294  ATH_MSG_ERROR("Unable to call metaDataStop for " << tool->name());
295  rc = StatusCode::FAILURE;
296  }
297  }
298  // MN: not releasing tools here - revisit when clear what happens on new file open
299  return rc;
300 }
301 
302 
304 {
306  ATH_CHECK(m_inputDataStore->clearStore(true));
308  }
310  ATH_CHECK(m_outputDataStore->clearStore(true));
312  }
314  return StatusCode::SUCCESS;
315 }
316 
317 //__________________________________________________________________________
318 void MetaDataSvc::handle(const Incident& inc) {
319  const FileIncident* fileInc = dynamic_cast<const FileIncident*>(&inc);
320  if (fileInc == nullptr) {
321  ATH_MSG_ERROR("Unable to get FileName from EndInputFile incident");
322  return;
323  }
324  const std::string fileName = fileInc->fileName();
325  ATH_MSG_DEBUG("handle() " << inc.type() << " for " << fileName);
326 
327  if (inc.type() == "FirstInputFile") {
328  // Register open/close callback actions
329  using namespace boost::placeholders;
330  Io::bfcn_action_t boa = boost::bind(&MetaDataSvc::rootOpenAction, this, _1,_2);
331  if (m_fileMgr->regAction(std::move(boa), Io::OPEN).isFailure()) {
332  ATH_MSG_FATAL("Cannot register ROOT file open action with FileMgr.");
333  }
334  if (!initInputMetaDataStore(fileName).isSuccess()) {
335  ATH_MSG_WARNING("Unable to initialize InputMetaDataStore");
336  }
337  } else if (inc.type() == "BeginInputFile") {
338  if(newMetadataSource(inc).isFailure()) {
339  ATH_MSG_ERROR("Could not process new metadata source " << fileName);
340  }
341  } else if (inc.type() == "EndInputFile") {
342  if(retireMetadataSource(inc).isFailure()) {
343  ATH_MSG_ERROR("Could not retire metadata source " << fileName);
344  }
345  }
346 }
347 
348 //__________________________________________________________________________
349 // This method is currently called only from OutputStreamSequencerSvc
350 StatusCode MetaDataSvc::transitionMetaDataFile(const std::string& outputConn, bool disconnect)
351 {
352  ATH_MSG_DEBUG("transitionMetaDataFile: " << outputConn );
353 
354  // this is normally called through EndInputFile inc, simulate it for EvSvc
355  FileIncident inc("transitionMetaDataFile", "EndInputFile", "dummyMetaInputFileName", "");
357 
358  // Reset flag to allow calling prepareOutput again at next transition
359  m_outputPrepared = false;
360 
361  Incident metaDataStopIncident(name(), "MetaDataStop");
362  m_incSvc->fireIncident(metaDataStopIncident);
363 
364  if( disconnect ) {
365  AthCnvSvc* cnvSvc = dynamic_cast<AthCnvSvc*>(m_addrCrtr.operator->());
366  if (cnvSvc) {
367  if (!cnvSvc->disconnectOutput(outputConn).isSuccess()) {
368  ATH_MSG_WARNING("Cannot get disconnect Output Files");
369  }
370  }
371  }
372 
373  return(StatusCode::SUCCESS);
374 }
375 
376 //__________________________________________________________________________
378  ATH_MSG_INFO("I/O reinitialization...");
379  ATH_MSG_DEBUG("Dumping InputMetaDataStore: " << m_inputDataStore->dump());
380  ATH_MSG_DEBUG("Dumping OutputMetaDataStore: " << m_outputDataStore->dump());
381  for (const auto& tool : m_metaDataTools) {
382  ATH_MSG_INFO("Attached MetaDataTool: " << tool->name());
383  }
384  m_outputPrepared = false;
385  return(StatusCode::SUCCESS);
386 }
387 //__________________________________________________________________________
388 StatusCode MetaDataSvc::rootOpenAction(FILEMGR_CALLBACK_ARGS) {
389  return(StatusCode::SUCCESS);
390 }
391 //__________________________________________________________________________
392 // check if the metadata object key contains Stream name (added by SharedWriter in MetaDataSvc)
393 // remove stream part from the key (i.e. modify the parameter) and return it
394 std::string MetaDataSvc::removeStreamFromKey(std::string& key) {
395  size_t pos = key.find(m_streamInKeyMark);
396  if( pos==std::string::npos ) return "";
397  size_t epos = key.find(']', pos);
398  size_t spos = pos + m_streamInKeyMark.size();
399  std::string stream = key.substr( spos, epos - spos );
400  //cppcheck-suppress uselessCallsSubstr
401  key = key.substr(0, pos) + key.substr(epos+1);
402  return stream;
403 }
404 
405 //__________________________________________________________________________
406 [[nodiscard]] std::set<std::string> MetaDataSvc::getPerStreamKeysFor(const std::string& key) const {
407  if (!m_streamKeys.contains(key)) {
408  return {key};
409  }
410  return m_streamKeys.at(key);
411 }
412 
413 //__________________________________________________________________________
415  std::string fileName = tokenStr.substr(tokenStr.find("[FILE=") + 6);
416  leftString(fileName, ']');
417  std::string className = tokenStr.substr(tokenStr.find("[PNAME=") + 7);
418  leftString(className, ']');
419  std::string contName = tokenStr.substr(tokenStr.find("[CONT=") + 6);
420  leftString(contName,']');
421  std::size_t pos1 = contName.find('(');
422  std::string keyName = contName.substr(pos1 + 1, contName.size() - pos1 - 2);
423  std::size_t pos2 = keyName.find('/');
424  if (pos2 != std::string::npos) keyName = keyName.substr(pos2 + 1);
425  std::string numName = tokenStr.substr(tokenStr.find("[NUM=") + 5);
426  leftString(numName,']');
427  unsigned long num = 0;
428  std::istringstream iss(numName);
429  iss >> num;
430  CLID clid = m_persToClid[className];
431  if (clid == 167728019) { // EventStreamInfo, will change tool to combine input metadata, clearing things before...
432  bool foundTool = std::ranges::any_of( m_metaDataTools, []( const auto& tool ) {
433  return tool->name() == "ToolSvc.CopyEventStreamInfo";
434  } );
435  if (!foundTool) {
436  if (serviceLocator()->existsService("CutFlowSvc")) {
437  ServiceHandle<IIncidentListener> cfSvc("CutFlowSvc", this->name()); // Disable CutFlowSvc by stopping its incidents.
438  if (cfSvc.retrieve().isSuccess()) {
439  ATH_MSG_INFO("Disabling incidents for: " << cfSvc.name());
440  m_incSvc->removeListener(cfSvc.get(), IncidentType::BeginInputFile);
441  m_incSvc->removeListener(cfSvc.get(), "MetaDataStop");
442  cfSvc.release().ignore();
443  }
444  }
445  if (serviceLocator()->existsService("xAODConfigSvc")) {
446  ServiceHandle<IIncidentListener> xcSvc("xAODConfigSvc", this->name()); // Disable xAODConfigSvc, fails for merging
447  if (xcSvc.retrieve().isSuccess()) {
448  ATH_MSG_INFO("Disabling incidents for: " << xcSvc.name());
449  m_incSvc->removeListener(xcSvc.get(), IncidentType::BeginInputFile);
450  m_incSvc->removeListener(xcSvc.get(), IncidentType::BeginEvent);
451  xcSvc.release().ignore();
452  }
453  }
454  }
455  }
456 
457  // make stream-unique keys for infile metadata objects
458  // AthenaOutputStream will use this to distribute objects to the right stream (and restore the original key)
459  if( clid == 178309087 ) { // FileMetaData
460  std::string newName = std::format("{}{}{}{}", keyName, m_streamInKeyMark, fileName, "]");
461  ATH_MSG_DEBUG("Recording " << keyName << " as " << newName);
462  m_streamKeys[keyName].insert(newName);
463  keyName = std::move(newName);
464  }
465  if( clid == 73252552 ) { // FileMetaDataAuxInfo
466  std::string newName = std::format("{}{}{}]{}",
467  keyName.substr(0, keyName.find(RootAuxDynIO::AUX_POSTFIX)),
469  fileName,
471  ATH_MSG_DEBUG("Recording " << keyName << " as " << newName);
472  m_streamKeys[keyName].insert(newName);
473  keyName = std::move(newName);
474  }
475  const std::string par[3] = { "SHM" , keyName , std::move(className) };
476  const unsigned long ipar[2] = { num , 0 };
477  IOpaqueAddress* opqAddr = nullptr;
478  SG::DataProxy* dp = m_inputDataStore->proxy(clid, keyName);
479  if (dp != nullptr) {
480  ATH_MSG_DEBUG("Resetting duplicate proxy for: " << clid << "#" << keyName << " from file: " << fileName);
481  dp->reset();
482  }
483  if (!m_addrCrtr->createAddress(m_storageType, clid, par, ipar, opqAddr).isSuccess()) {
484  ATH_MSG_FATAL("addProxyToInputMetaDataStore: Cannot create address for " << tokenStr);
485  return(StatusCode::FAILURE);
486  }
487  if (m_inputDataStore->recordAddress(keyName, opqAddr).isFailure()) {
488  delete opqAddr; opqAddr = nullptr;
489  ATH_MSG_FATAL("addProxyToInputMetaDataStore: Cannot create proxy for " << tokenStr);
490  return(StatusCode::FAILURE);
491  }
492  if (m_inputDataStore->accessData(clid, keyName) == nullptr) {
493  ATH_MSG_FATAL("addProxyToInputMetaDataStore: Cannot access data for " << tokenStr);
494  return(StatusCode::FAILURE);
495  }
496  if (keyName.find(RootAuxDynIO::AUX_POSTFIX) != std::string::npos
497  && m_inputDataStore->symLink(clid, keyName, 187169987).isFailure()) {
498  ATH_MSG_WARNING("addProxyToInputMetaDataStore: Cannot symlink to AuxStore for " << tokenStr);
499  }
500  return(StatusCode::SUCCESS);
501 }
502 //__________________________________________________________________________
504  ATH_MSG_DEBUG("initInputMetaDataStore: file name " << fileName);
505  m_clearedInputDataStore = false;
506  // Load proxies for InputMetaDataStore
507  if (m_metaDataCont.value().empty()) {
508  ATH_MSG_DEBUG("MetaDataSvc called without MetaDataContainer set.");
509  return(StatusCode::SUCCESS);
510  }
511  if (fileName.starts_with( "BSF:")) {
512  ATH_MSG_DEBUG("MetaDataSvc called for non ROOT file.");
513  } else if (fileName.compare(0, 3, "SHM")==0) {
514  ATH_MSG_DEBUG("MetaDataSvc called for shared memory.");
515  } else {
516  const std::string par[2] = {
517  fileName,
518  std::format("{}(DataHeader)", m_metaDataCont.value())
519  };
520  const std::string parOld[2] = {
521  fileName,
522  std::format("{}{}", m_metaDataCont.value(), "DataHeader")
523  };
524  for (int verNumber = 0; verNumber < 100; verNumber++) {
525  SG::VersionedKey myVersKey(name(), verNumber);
526  if (m_inputDataStore->contains<DataHeader>(myVersKey)) {
527  ATH_MSG_DEBUG("initInputMetaDataStore: MetaData Store already contains DataHeader, key = " << myVersKey);
528  } else {
529  const unsigned long ipar[2] = { (unsigned long)verNumber , 0 };
530  IOpaqueAddress* opqAddr = nullptr;
531  if (!m_addrCrtr->createAddress(m_storageType, ClassID_traits<DataHeader>::ID(), par, ipar, opqAddr).isSuccess()) {
532  if (!m_addrCrtr->createAddress(m_storageType, ClassID_traits<DataHeader>::ID(), parOld, ipar, opqAddr).isSuccess()) {
533  break;
534  }
535  }
536  if (m_inputDataStore->recordAddress(myVersKey, opqAddr).isFailure()) {
537  delete opqAddr; opqAddr = nullptr;
538  ATH_MSG_WARNING("initInputMetaDataStore: Cannot create proxy for DataHeader, key = " << myVersKey);
539  }
540  }
541  }
542  std::list<SG::TransientAddress*> tList;
544  for (SG::TransientAddress* tad : tList) {
545  CLID clid = tad->clID();
546  ATH_MSG_VERBOSE("initInputMetaDataStore: add proxy for clid = " << clid << ", key = " << tad->name());
547  if (m_inputDataStore->contains(tad->clID(), tad->name())) {
548  ATH_MSG_DEBUG("initInputMetaDataStore: MetaData Store already contains clid = " << clid << ", key = " << tad->name());
549  } else {
550  if (!m_inputDataStore->recordAddress(tad->name(), tad->address())) {
551  ATH_MSG_ERROR("initInputMetaDataStore: Cannot create proxy for clid = " << clid << ", key = " << tad->name());
552  return StatusCode::FAILURE;
553  }
554  }
555 
556  for (CLID tclid : tad->transientID()) {
557  if (tclid != clid) {
558  if (m_inputDataStore->symLink (clid, tad->name(), tclid).isFailure()) {
559  ATH_MSG_WARNING("Cannot make autosymlink from " <<
560  clid << "/" << tad->name() << " to " << tclid);
561  }
562  }
563  }
564  delete tad;
565  }
566  tList.clear();
567  }
568  ATH_MSG_DEBUG("Loaded input meta data store proxies");
569  return(StatusCode::SUCCESS);
570 }
571 
572 
573 const std::string MetaDataSvc::currentRangeID() const
574 {
575  return m_outSeqSvc.isValid()? m_outSeqSvc->currentRangeID() : "";
576 }
577 
578 
580 {
581  if (!m_handledClasses.contains(itemID)) {
582  ATH_MSG_DEBUG("Not translating metadata item ID #" << itemID);
583  return itemID;
584  }
585 
586  std::string itemName;
587  CLID contID = 0;
588  if (m_classIDSvc->getTypeNameOfID(itemID, itemName).isSuccess()) {
589  const std::string contName = std::format("MetaCont<{}>", itemName);
590  ATH_MSG_DEBUG("Transforming " << contName << " to " << itemName
591  << " for output");
592  if (m_classIDSvc->getIDOfTypeName(contName, contID).isSuccess())
593  return contID;
594  }
595 
596  return itemID;
597 }
598 
599 void MetaDataSvc::recordHook(const std::type_info& typeInfo) {
600  const std::string& typeName = System::typeinfoName(typeInfo);
601  ATH_MSG_VERBOSE("Handling record event of type " << typeName);
602 
603  CLID itemID = 0;
604  if (m_classIDSvc->getIDOfTypeInfoName(typeName, itemID).isSuccess()) {
605  auto result = m_handledClasses.insert(itemID);
606  if (result.second)
607  ATH_MSG_DEBUG("MetaDataSvc will handle " << typeName
608  << " ClassID: " << itemID);
609  }
610 }
611 
612 void MetaDataSvc::removeHook(const std::type_info& typeInfo) {
613  const std::string& typeName = System::typeinfoName(typeInfo);
614  ATH_MSG_VERBOSE("Handling removal event of type " << typeName);
615 
616  CLID itemID = 0;
617  if (m_classIDSvc->getIDOfTypeInfoName(typeName, itemID).isSuccess()) {
618  if (0 < m_handledClasses.erase(itemID))
619  ATH_MSG_DEBUG("MetaDataSvc will no longer handle " << typeName
620  << " ClassID: " << itemID);
621  }
622 }
623 
625  ATH_MSG_DEBUG("Locking metadata tools");
626  for(auto& tool : m_metaDataTools ) {
627  const ILockableTool *lockable = dynamic_cast<const ILockableTool*>( tool.get() );
628  if( lockable ) lockable->lock_shared();
629  }
630 }
631 
633  ATH_MSG_DEBUG("Unlocking metadata tools");
634  for(auto& tool : m_metaDataTools ) {
635  const ILockableTool *lockable = dynamic_cast<const ILockableTool*>( tool.get() );
636  if( lockable ) lockable->unlock_shared();
637  }
638 }
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
MetaDataSvc::stop
virtual StatusCode stop() override
stop the metadata service
Definition: MetaDataSvc.cxx:167
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
MetaDataSvc::initialize
virtual StatusCode initialize() override
initialize the metadata service at the beginning of the job
Definition: MetaDataSvc.cxx:90
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
MetaDataSvc::lockTools
void lockTools() const
Definition: MetaDataSvc.cxx:624
MetaDataSvc::m_clearedOutputDataStore
bool m_clearedOutputDataStore
Definition: MetaDataSvc.h:308
OutputStreamSequencerSvc.h
This file contains the class definition for the OutputStreamSequencerSvc class.
SGVersionedKey.h
SG::TransientAddress
Definition: TransientAddress.h:32
AthCnvSvc.h
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
MetaDataSvc::~MetaDataSvc
virtual ~MetaDataSvc()
Destructor.
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
MetaDataSvc::io_reinit
virtual StatusCode io_reinit() override
Implements IIoComponent interface sets m_outputPrepared to false and prints some information.
Definition: MetaDataSvc.cxx:377
DataHeaderElement
This class provides a persistent form for the TransientAddress.
Definition: DataHeader.h:37
MetaDataSvc::finalize
virtual StatusCode finalize() override
finalize the metadata service at the end of the job
Definition: MetaDataSvc.cxx:142
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
RootAuxDynDefs.h
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:210
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:503
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
MetaDataSvc::addProxyToInputMetaDataStore
StatusCode addProxyToInputMetaDataStore(const std::string &tokenStr)
Definition: MetaDataSvc.cxx:414
SG::VersionedKey
a StoreGateSvc key with a version number. Notice that StoreGate does not order multiple instances of ...
Definition: SGVersionedKey.h:31
MetaDataSvc::remapMetaContCLID
CLID remapMetaContCLID(const CLID &item_id) const
Definition: MetaDataSvc.cxx:579
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
MetaDataSvc::MetaDataSvc
MetaDataSvc(const std::string &name, ISvcLocator *pSvcLocator)
Standard Service Constructor.
Definition: MetaDataSvc.cxx:54
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:241
StoreID::METADATA_STORE
@ METADATA_STORE
Definition: StoreID.h:29
plotmaker.keyName
keyName
Definition: plotmaker.py:145
MetaDataSvc::prepareOutput
virtual StatusCode prepareOutput()
Makes the metadata store ready for output.
Definition: MetaDataSvc.cxx:258
DataHeader.h
This file contains the class definition for the DataHeader and DataHeaderElement classes.
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::transitionMetaDataFile
StatusCode transitionMetaDataFile(const std::string &outputConn, bool disconnect)
Transition output metadata file - fire MeteDataStop incident to transition OutputStream and disconnec...
Definition: MetaDataSvc.cxx:350
MetaDataSvc::m_persToClid
std::map< std::string_view, CLID > m_persToClid
Definition: MetaDataSvc.h:311
MetaDataSvc::unlockTools
void unlockTools() const
Definition: MetaDataSvc.cxx:632
MetaDataSvc::shmProxy
virtual StatusCode shmProxy(const std::string &filename) override
Loads file metadata from memory shared between streams in SharedWriter This function clears the input...
Definition: MetaDataSvc.cxx:303
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
MetaDataSvc::removeHook
void removeHook(const std::type_info &) override
Definition: MetaDataSvc.cxx:612
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:28
MetaDataSvc::currentRangeID
virtual const std::string currentRangeID() const override final
Definition: MetaDataSvc.cxx:573
MakeNewFileFromOldAndSubstitution.newName
dictionary newName
Definition: ICHEP2016/MakeNewFileFromOldAndSubstitution.py:95
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:452
MetaDataSvc::getPerStreamKeysFor
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-sp...
Definition: MetaDataSvc.cxx:406
lumiFormat.outputName
string outputName
Definition: lumiFormat.py:65
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
MetaDataSvc.h
This file contains the class definition for the MetaDataSvc class.
MetaDataSvc::handle
virtual void handle(const Incident &incident) override
react to file incidents.
Definition: MetaDataSvc.cxx:318
StoreID::type
type
Definition: StoreID.h:24
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:388
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:23
IAddressProvider::tadList
std::list< SG::TransientAddress * > tadList
Definition: IAddressProvider.h:32
python.SystemOfUnits.s
float s
Definition: SystemOfUnits.py:147
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
MetaDataSvc::removeStreamFromKey
std::string removeStreamFromKey(std::string &key)
check if the metadata object key contains Stream name (added by SharedWriter in MetaDataSvc) remove s...
Definition: MetaDataSvc.cxx:394
python.PyAthena.obj
obj
Definition: PyAthena.py:132
SG::DataProxy
Definition: DataProxy.h:45
StoreGateSvc.h
MetaDataSvc::recordHook
void recordHook(const std::type_info &) override
Definition: MetaDataSvc.cxx:599
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:176
MetaDataSvc::m_classIDSvc
ServiceHandle< IClassIDSvc > m_classIDSvc
Definition: MetaDataSvc.h:304
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