Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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/IAddressCreator.h"
14 #include "GaudiKernel/IAlgTool.h"
15 #include "GaudiKernel/IEvtSelector.h"
16 #include "GaudiKernel/IIncidentSvc.h"
17 #include "GaudiKernel/IIoComponentMgr.h"
18 #include "GaudiKernel/IOpaqueAddress.h"
19 #include "GaudiKernel/FileIncident.h"
20 #include "GaudiKernel/System.h"
21 
23 #include "StoreGate/StoreGateSvc.h"
24 #include "SGTools/SGVersionedKey.h"
27 
29 
30 #include <vector>
31 #include <sstream>
32 
33 #include "boost/bind/bind.hpp"
34 
35 
36 namespace {
44  bool leftString(std::string& s, char sc) {
45  if (const auto pos = s.find(sc); pos != std::string::npos) {
46  s.resize(pos);
47  return true;
48  }
49  return false;
50  }
51 }
52 
53 
54 //________________________________________________________________________________
55 MetaDataSvc::MetaDataSvc( const std::string& name, ISvcLocator* pSvcLocator )
56  : base_class( name, pSvcLocator )
57  , m_inputDataStore( "StoreGateSvc/InputMetaDataStore", name )
58  , m_outputDataStore( "StoreGateSvc/MetaDataStore", name )
59  , m_addrCrtr( "AthenaPoolCnvSvc", name )
60  , m_fileMgr( "FileMgr", name )
61  , m_incSvc( "IncidentSvc", name )
62  , m_outSeqSvc( "OutputStreamSequencerSvc", name )
63  , m_persToClid{ { "DataHeader_p5", 222376821 },
64  { "EventStreamInfo_p3", 167728019 },
65  { "ByteStreamMetadataContainer_p1", 1076128893 },
66  { "IOVMetaDataContainer_p1", 1316383046 },
67  { "xAOD::EventFormat_v1", 243004407 },
68  { "xAOD::CutBookkeeperContainer_v1", 1234982351 },
69  { "xAOD::CutBookkeeperAuxContainer_v1", 1147935274 },
70  { "xAOD::TriggerMenuContainer_v1", 1107011239 },
71  { "DataVector<xAOD::TriggerMenu_v1>", 1107011239 },
72  { "xAOD::TriggerMenuAuxContainer_v1", 1212409402 },
73  { "xAOD::TriggerMenuJsonContainer_v1", 1221262614 },
74  { "DataVector<xAOD::TriggerMenuJson_v1>", 1221262614 },
75  { "xAOD::TriggerMenuJsonAuxContainer_v1", 373045213 },
76  { "xAOD::LumiBlockRangeContainer_v1", 1115934851 },
77  { "DataVector<xAOD::LumiBlockRange_v1>", 1115934851 },
78  { "xAOD::LumiBlockRangeAuxContainer_v1", 1251061086 },
79  { "xAOD::FileMetaData_v1", 178309087 },
80  { "xAOD::FileMetaDataAuxInfo_v1", 73252552 },
81  { "xAOD::RingSetConfContainer_v1", 1157997427 },
82  { "DataVector<xAOD::RingSetConf_v1>", 1157997427 },
83  { "xAOD::RingSetConfAuxContainer_v1", 1307745126 },
84  { "xAOD::TruthMetaDataContainer_v1", 1188015687 },
85  { "DataVector<xAOD::TruthMetaData_v1>", 1188015687 },
86  { "xAOD::TruthMetaDataAuxContainer_v1", 1094306618 } } {}
87 
88 //________________________________________________________________________________
89 MetaDataSvc::~MetaDataSvc() = default;
90 
91 //__________________________________________________________________________
93  ATH_MSG_INFO("Initializing " << name());
94 
95  // Retrieve InputMetaDataStore
96  ATH_CHECK( m_inputDataStore.retrieve() );
97  // Retrieve OutputMetaDataStore
98  ATH_CHECK( m_outputDataStore.retrieve() );
99  // Retrieve AddressCreator
100  ATH_CHECK( m_addrCrtr.retrieve() );
101 
102  AthCnvSvc* cnvSvc = dynamic_cast<AthCnvSvc*>(m_addrCrtr.operator->());
103  if (cnvSvc) {
104  m_storageType = cnvSvc->repSvcType();
105  } else {
106  ATH_MSG_WARNING("Cannot get ConversionSvc Interface.");
107  }
108  // Get FileMgr
109  ATH_CHECK( m_fileMgr.retrieve() );
110 
111  // Set to be listener for end of event
112  ATH_CHECK( m_incSvc.retrieve() );
113 
114  ATH_CHECK( m_metaDataTools.retrieve() );
115  ATH_MSG_INFO("Found " << m_metaDataTools);
116 
117  m_incSvc->addListener(this, "FirstInputFile", 80, true);
118  m_incSvc->addListener(this, "BeginInputFile", 80, true);
119  m_incSvc->addListener(this, "EndInputFile", 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 }
143 //__________________________________________________________________________
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 }
167 
168 //__________________________________________________________________________
170  ATH_MSG_DEBUG("MetaDataSvc::stop()");
171  // Fire metaDataStopIncident
172  Incident metaDataStopIncident(name(), "MetaDataStop");
173  m_incSvc->fireIncident(metaDataStopIncident);
174  return(StatusCode::SUCCESS);
175 }
176 
177 //________________________________________________________________________________
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 }
211 //________________________________________________________________________________
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 }
242 
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 }
259 
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 }
281 
282 // like prepareOutput() but for parallel streams
284 {
285  // default to the serial implementation if no output name given
286  if( outputName.empty() ) {
287  return prepareOutput();
288  }
289  ATH_MSG_DEBUG( "prepareOutput('" << outputName << "')" );
290 
291  StatusCode rc{StatusCode::SUCCESS};
292  for (auto& tool : m_metaDataTools) {
293  ATH_MSG_DEBUG(" calling metaDataStop for " << tool->name());
294  // planning to replace the call below with (*it)->prepareOutput(outputName)
295  if (tool->metaDataStop().isFailure()) {
296  ATH_MSG_ERROR("Unable to call metaDataStop for " << tool->name());
297  rc = StatusCode::FAILURE;
298  }
299  }
300  // MN: not releasing tools here - revisit when clear what happens on new file open
301  return rc;
302 }
303 
304 
306 {
308  ATH_CHECK(m_inputDataStore->clearStore(true));
310  }
312  ATH_CHECK(m_outputDataStore->clearStore(true));
314  }
316  return StatusCode::SUCCESS;
317 }
318 
319 //__________________________________________________________________________
320 void MetaDataSvc::handle(const Incident& inc) {
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") {
340  if(newMetadataSource(inc).isFailure()) {
341  ATH_MSG_ERROR("Could not process new metadata source " << fileName);
342  }
343  } else if (inc.type() == "EndInputFile") {
344  if(retireMetadataSource(inc).isFailure()) {
345  ATH_MSG_ERROR("Could not retire metadata source " << fileName);
346  }
347  }
348 }
349 
350 //__________________________________________________________________________
351 // This method is currently called only from OutputStreamSequencerSvc
352 StatusCode MetaDataSvc::transitionMetaDataFile(const std::string& outputConn, bool disconnect)
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 }
377 
378 //__________________________________________________________________________
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 }
389 //__________________________________________________________________________
390 StatusCode MetaDataSvc::rootOpenAction(FILEMGR_CALLBACK_ARGS) {
391  return(StatusCode::SUCCESS);
392 }
393 //__________________________________________________________________________
394 // check if the metadata object key contains Stream name (added by SharedWriter in MetaDataSvc)
395 // remove stream part from the key (i.e. modify the parameter) and return it
396 std::string MetaDataSvc::removeStreamFromKey(std::string& key) {
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 }
406 
407 //__________________________________________________________________________
408 [[nodiscard]] std::set<std::string> MetaDataSvc::getPerStreamKeysFor(const std::string& key) const {
409  if (!m_streamKeys.contains(key)) {
410  return {key};
411  }
412  return m_streamKeys.at(key);
413 }
414 
415 //__________________________________________________________________________
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  if (clid == 167728019) { // EventStreamInfo, will change tool to combine input metadata, clearing things before...
434  bool foundTool = std::ranges::any_of( m_metaDataTools, []( const auto& tool ) {
435  return tool->name() == "ToolSvc.CopyEventStreamInfo";
436  } );
437  if (!foundTool) {
438  if (serviceLocator()->existsService("CutFlowSvc")) {
439  ServiceHandle<IIncidentListener> cfSvc("CutFlowSvc", this->name()); // Disable CutFlowSvc by stopping its incidents.
440  if (cfSvc.retrieve().isSuccess()) {
441  ATH_MSG_INFO("Disabling incidents for: " << cfSvc.name());
442  m_incSvc->removeListener(cfSvc.get(), IncidentType::BeginInputFile);
443  m_incSvc->removeListener(cfSvc.get(), "MetaDataStop");
444  cfSvc.release().ignore();
445  }
446  }
447  if (serviceLocator()->existsService("xAODConfigSvc")) {
448  ServiceHandle<IIncidentListener> xcSvc("xAODConfigSvc", this->name()); // Disable xAODConfigSvc, fails for merging
449  if (xcSvc.retrieve().isSuccess()) {
450  ATH_MSG_INFO("Disabling incidents for: " << xcSvc.name());
451  m_incSvc->removeListener(xcSvc.get(), IncidentType::BeginInputFile);
452  m_incSvc->removeListener(xcSvc.get(), IncidentType::BeginEvent);
453  xcSvc.release().ignore();
454  }
455  }
456  }
457  }
458 
459  // make stream-unique keys for infile metadata objects
460  // AthenaOutputStream will use this to distribute objects to the right stream (and restore the original key)
461  if( clid == 178309087 ) { // FileMetaData
462  std::string newName = std::format("{}{}{}{}", keyName, m_streamInKeyMark, fileName, "]");
463  ATH_MSG_DEBUG("Recording " << keyName << " as " << newName);
464  m_streamKeys[keyName].insert(newName);
465  keyName = std::move(newName);
466  }
467  if( clid == 73252552 ) { // FileMetaDataAuxInfo
468  std::string newName = std::format("{}{}{}]{}",
469  keyName.substr(0, keyName.find(RootAuxDynIO::AUX_POSTFIX)),
471  fileName,
473  ATH_MSG_DEBUG("Recording " << keyName << " as " << newName);
474  m_streamKeys[keyName].insert(newName);
475  keyName = std::move(newName);
476  }
477  const std::string par[3] = { "SHM" , keyName , std::move(className) };
478  const unsigned long ipar[2] = { num , 0 };
479  IOpaqueAddress* opqAddr = nullptr;
480  SG::DataProxy* dp = m_inputDataStore->proxy(clid, keyName);
481  if (dp != nullptr) {
482  ATH_MSG_DEBUG("Resetting duplicate proxy for: " << clid << "#" << keyName << " from file: " << fileName);
483  dp->reset();
484  }
485  if (!m_addrCrtr->createAddress(m_storageType, clid, par, ipar, opqAddr).isSuccess()) {
486  ATH_MSG_FATAL("addProxyToInputMetaDataStore: Cannot create address for " << tokenStr);
487  return(StatusCode::FAILURE);
488  }
489  if (m_inputDataStore->recordAddress(keyName, opqAddr).isFailure()) {
490  delete opqAddr; opqAddr = nullptr;
491  ATH_MSG_FATAL("addProxyToInputMetaDataStore: Cannot create proxy for " << tokenStr);
492  return(StatusCode::FAILURE);
493  }
494  if (m_inputDataStore->accessData(clid, keyName) == nullptr) {
495  ATH_MSG_FATAL("addProxyToInputMetaDataStore: Cannot access data for " << tokenStr);
496  return(StatusCode::FAILURE);
497  }
498  if (keyName.find(RootAuxDynIO::AUX_POSTFIX) != std::string::npos
499  && m_inputDataStore->symLink(clid, keyName, 187169987).isFailure()) {
500  ATH_MSG_WARNING("addProxyToInputMetaDataStore: Cannot symlink to AuxStore for " << tokenStr);
501  }
502  return(StatusCode::SUCCESS);
503 }
504 //__________________________________________________________________________
506  ATH_MSG_DEBUG("initInputMetaDataStore: file name " << fileName);
507  m_clearedInputDataStore = false;
508  // Load proxies for InputMetaDataStore
509  if (m_metaDataCont.value().empty()) {
510  ATH_MSG_DEBUG("MetaDataSvc called without MetaDataContainer set.");
511  return(StatusCode::SUCCESS);
512  }
513  if (fileName.starts_with( "BSF:")) {
514  ATH_MSG_DEBUG("MetaDataSvc called for non ROOT file.");
515  } else if (fileName.compare(0, 3, "SHM")==0) {
516  ATH_MSG_DEBUG("MetaDataSvc called for shared memory.");
517  } else {
518  const std::string par[2] = {
519  fileName,
520  std::format("{}(DataHeader)", m_metaDataCont.value())
521  };
522  const std::string parOld[2] = {
523  fileName,
524  std::format("{}{}", m_metaDataCont.value(), "DataHeader")
525  };
526  for (int verNumber = 0; verNumber < 100; verNumber++) {
527  SG::VersionedKey myVersKey(name(), verNumber);
528  if (m_inputDataStore->contains<DataHeader>(myVersKey)) {
529  ATH_MSG_DEBUG("initInputMetaDataStore: MetaData Store already contains DataHeader, key = " << myVersKey);
530  } else {
531  const unsigned long ipar[2] = { (unsigned long)verNumber , 0 };
532  IOpaqueAddress* opqAddr = nullptr;
533  if (!m_addrCrtr->createAddress(m_storageType, ClassID_traits<DataHeader>::ID(), par, ipar, opqAddr).isSuccess()) {
534  if (!m_addrCrtr->createAddress(m_storageType, ClassID_traits<DataHeader>::ID(), parOld, ipar, opqAddr).isSuccess()) {
535  break;
536  }
537  }
538  if (m_inputDataStore->recordAddress(myVersKey, opqAddr).isFailure()) {
539  delete opqAddr; opqAddr = nullptr;
540  ATH_MSG_WARNING("initInputMetaDataStore: Cannot create proxy for DataHeader, key = " << myVersKey);
541  }
542  }
543  }
544  std::list<SG::TransientAddress*> tList;
546  for (SG::TransientAddress* tad : tList) {
547  CLID clid = tad->clID();
548  ATH_MSG_VERBOSE("initInputMetaDataStore: add proxy for clid = " << clid << ", key = " << tad->name());
549  if (m_inputDataStore->contains(tad->clID(), tad->name())) {
550  ATH_MSG_DEBUG("initInputMetaDataStore: MetaData Store already contains clid = " << clid << ", key = " << tad->name());
551  } else {
552  if (!m_inputDataStore->recordAddress(tad->name(), tad->address())) {
553  ATH_MSG_ERROR("initInputMetaDataStore: Cannot create proxy for clid = " << clid << ", key = " << tad->name());
554  return StatusCode::FAILURE;
555  }
556  }
557 
558  for (CLID tclid : tad->transientID()) {
559  if (tclid != clid) {
560  if (m_inputDataStore->symLink (clid, tad->name(), tclid).isFailure()) {
561  ATH_MSG_WARNING("Cannot make autosymlink from " <<
562  clid << "/" << tad->name() << " to " << tclid);
563  }
564  }
565  }
566  delete tad;
567  }
568  tList.clear();
569  }
570  ATH_MSG_DEBUG("Loaded input meta data store proxies");
571  return(StatusCode::SUCCESS);
572 }
573 
574 
575 const std::string MetaDataSvc::currentRangeID() const
576 {
577  return m_outSeqSvc.isValid()? m_outSeqSvc->currentRangeID() : "";
578 }
579 
580 
582 {
583  if (!m_handledClasses.contains(itemID)) {
584  ATH_MSG_DEBUG("Not translating metadata item ID #" << itemID);
585  return itemID;
586  }
587 
588  std::string itemName;
589  CLID contID = 0;
590  if (m_classIDSvc->getTypeNameOfID(itemID, itemName).isSuccess()) {
591  const std::string contName = std::format("MetaCont<{}>", itemName);
592  ATH_MSG_DEBUG("Transforming " << contName << " to " << itemName
593  << " for output");
594  if (m_classIDSvc->getIDOfTypeName(contName, contID).isSuccess())
595  return contID;
596  }
597 
598  return itemID;
599 }
600 
601 void MetaDataSvc::recordHook(const std::type_info& typeInfo) {
602  const std::string& typeName = System::typeinfoName(typeInfo);
603  ATH_MSG_VERBOSE("Handling record event of type " << typeName);
604 
605  CLID itemID = 0;
606  if (m_classIDSvc->getIDOfTypeInfoName(typeName, itemID).isSuccess()) {
607  auto result = m_handledClasses.insert(itemID);
608  if (result.second)
609  ATH_MSG_DEBUG("MetaDataSvc will handle " << typeName
610  << " ClassID: " << itemID);
611  }
612 }
613 
614 void MetaDataSvc::removeHook(const std::type_info& typeInfo) {
615  const std::string& typeName = System::typeinfoName(typeInfo);
616  ATH_MSG_VERBOSE("Handling removal event of type " << typeName);
617 
618  CLID itemID = 0;
619  if (m_classIDSvc->getIDOfTypeInfoName(typeName, itemID).isSuccess()) {
620  if (0 < m_handledClasses.erase(itemID))
621  ATH_MSG_DEBUG("MetaDataSvc will no longer handle " << typeName
622  << " ClassID: " << itemID);
623  }
624 }
625 
627  ATH_MSG_DEBUG("Locking metadata tools");
628  for(auto& tool : m_metaDataTools ) {
629  const ILockableTool *lockable = dynamic_cast<const ILockableTool*>( tool.get() );
630  if( lockable ) lockable->lock_shared();
631  }
632 }
633 
635  ATH_MSG_DEBUG("Unlocking metadata tools");
636  for(auto& tool : m_metaDataTools ) {
637  const ILockableTool *lockable = dynamic_cast<const ILockableTool*>( tool.get() );
638  if( lockable ) lockable->unlock_shared();
639  }
640 }
TileDCSDataPlotter.dp
dp
Definition: TileDCSDataPlotter.py:840
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:169
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:92
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:626
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:379
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:144
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: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:505
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:416
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:581
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:55
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
MetaDataSvc::prepareOutput
virtual StatusCode prepareOutput()
Makes the metadata store ready for output.
Definition: MetaDataSvc.cxx:260
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:352
MetaDataSvc::m_persToClid
std::map< std::string_view, CLID > m_persToClid
Definition: MetaDataSvc.h:311
MetaDataSvc::unlockTools
void unlockTools() const
Definition: MetaDataSvc.cxx:634
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:305
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
MetaDataSvc::removeHook
void removeHook(const std::type_info &) override
Definition: MetaDataSvc.cxx:614
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:29
MetaDataSvc::currentRangeID
virtual const std::string currentRangeID() const override final
Definition: MetaDataSvc.cxx:575
MakeNewFileFromOldAndSubstitution.newName
dictionary newName
Definition: ICHEP2016/MakeNewFileFromOldAndSubstitution.py:95
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
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:408
lumiFormat.outputName
string outputName
Definition: lumiFormat.py:65
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
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:320
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:390
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
IAddressProvider::tadList
std::list< SG::TransientAddress * > tadList
Definition: IAddressProvider.h:32
python.SystemOfUnits.s
float s
Definition: SystemOfUnits.py:146
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:396
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:601
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
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