ATLAS Offline Software
MetaDataSvc.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 {
37  bool
38  leftString(std::string & s, char sc){
39  bool truncated{false};
40  auto n = s.find(sc);
41  if (n!=std::string::npos){
42  s.resize(n);
43  truncated=true;
44  }
45  return truncated;
46  }
47 
48 }
49 
50 
51 //________________________________________________________________________________
52 MetaDataSvc::MetaDataSvc(const std::string& name, ISvcLocator* pSvcLocator) : base_class(name, pSvcLocator),
53  m_inputDataStore("StoreGateSvc/InputMetaDataStore", name),
54  m_outputDataStore("StoreGateSvc/MetaDataStore", name),
55  m_addrCrtr("AthenaPoolCnvSvc", name),
56  m_fileMgr("FileMgr", name),
57  m_incSvc("IncidentSvc", name),
58  m_outSeqSvc("OutputStreamSequencerSvc", name),
59  m_storageType(0L),
60  m_clearedInputDataStore(true),
61  m_clearedOutputDataStore(false),
62  m_allowMetaDataStop(false),
63  m_outputPrepared(false),
64  m_persToClid(),
65  m_toolForClid() {
66  // declare properties
67  declareProperty("MetaDataContainer", m_metaDataCont = "");
68  declareProperty("MetaDataTools", m_metaDataTools);
69  declareProperty("CnvSvc", m_addrCrtr = ServiceHandle<IAddressCreator>("AthenaPoolCnvSvc", name));
70  // persistent class name to transient CLID map
71  m_persToClid.insert(std::pair<std::string, CLID>("DataHeader_p5", 222376821));
72  m_persToClid.insert(std::pair<std::string, CLID>("EventStreamInfo_p3", 167728019));
73  m_persToClid.insert(std::pair<std::string, CLID>("ByteStreamMetadataContainer_p1", 1076128893));
74  m_persToClid.insert(std::pair<std::string, CLID>("IOVMetaDataContainer_p1", 1316383046));
75  m_persToClid.insert(std::pair<std::string, CLID>("xAOD::EventFormat_v1", 243004407));
76  m_persToClid.insert(std::pair<std::string, CLID>("xAOD::CutBookkeeperContainer_v1", 1234982351));
77  m_persToClid.insert(std::pair<std::string, CLID>("xAOD::CutBookkeeperAuxContainer_v1", 1147935274));
78  m_persToClid.insert(std::pair<std::string, CLID>("xAOD::TriggerMenuContainer_v1", 1107011239));
79  m_persToClid.insert(std::pair<std::string, CLID>("DataVector<xAOD::TriggerMenu_v1>", 1107011239));
80  m_persToClid.insert(std::pair<std::string, CLID>("xAOD::TriggerMenuAuxContainer_v1", 1212409402));
81  m_persToClid.insert(std::pair<std::string, CLID>("xAOD::TriggerMenuJsonContainer_v1", 1221262614));
82  m_persToClid.insert(std::pair<std::string, CLID>("DataVector<xAOD::TriggerMenuJson_v1>", 1221262614));
83  m_persToClid.insert(std::pair<std::string, CLID>("xAOD::TriggerMenuJsonAuxContainer_v1", 373045213));
84  m_persToClid.insert(std::pair<std::string, CLID>("xAOD::LumiBlockRangeContainer_v1", 1115934851));
85  m_persToClid.insert(std::pair<std::string, CLID>("DataVector<xAOD::LumiBlockRange_v1>", 1115934851));
86  m_persToClid.insert(std::pair<std::string, CLID>("xAOD::LumiBlockRangeAuxContainer_v1", 1251061086));
87  m_persToClid.insert(std::pair<std::string, CLID>("xAOD::FileMetaData_v1", 178309087));
88  m_persToClid.insert(std::pair<std::string, CLID>("xAOD::FileMetaDataAuxInfo_v1", 73252552));
89  m_persToClid.insert(std::pair<std::string, CLID>("xAOD::RingSetConfContainer_v1", 1157997427));
90  m_persToClid.insert(std::pair<std::string, CLID>("DataVector<xAOD::RingSetConf_v1>", 1157997427));
91  m_persToClid.insert(std::pair<std::string, CLID>("xAOD::RingSetConfAuxContainer_v1", 1307745126));
92  m_persToClid.insert(std::pair<std::string, CLID>("xAOD::TruthMetaDataContainer_v1", 1188015687));
93  m_persToClid.insert(std::pair<std::string, CLID>("DataVector<xAOD::TruthMetaData_v1>", 1188015687));
94  m_persToClid.insert(std::pair<std::string, CLID>("xAOD::TruthMetaDataAuxContainer_v1", 1094306618));
95  // some classes need to have new/different tools added for metadata propagation
96  m_toolForClid.insert(std::pair<CLID, std::string>(167728019, "CopyEventStreamInfo"));
97  m_toolForClid.insert(std::pair<CLID, std::string>(243004407, "xAODMaker::EventFormatMetaDataTool"));
98  m_toolForClid.insert(std::pair<CLID, std::string>(1234982351, "BookkeeperTool"));
99  m_toolForClid.insert(std::pair<CLID, std::string>(1107011239, "xAODMaker::TriggerMenuMetaDataTool"));
100  m_toolForClid.insert(std::pair<CLID, std::string>(1221262614, "xAODMaker::TriggerMenuMetaDataTool"));
101  m_toolForClid.insert(std::pair<CLID, std::string>(1115934851, "LumiBlockMetaDataTool"));
102  m_toolForClid.insert(std::pair<CLID, std::string>(178309087, "xAODMaker::FileMetaDataTool"));
103  m_toolForClid.insert(std::pair<CLID, std::string>(1188015687, "xAODMaker::TruthMetaDataTool"));
104 }
105 //__________________________________________________________________________
107 }
108 //__________________________________________________________________________
110  ATH_MSG_INFO("Initializing " << name());
111 
112  // Retrieve InputMetaDataStore
113  ATH_CHECK( m_inputDataStore.retrieve() );
114  // Retrieve OutputMetaDataStore
115  ATH_CHECK( m_outputDataStore.retrieve() );
116  // Retrieve AddressCreator
117  ATH_CHECK( m_addrCrtr.retrieve() );
118 
119  AthCnvSvc* cnvSvc = dynamic_cast<AthCnvSvc*>(m_addrCrtr.operator->());
120  if (cnvSvc) {
121  m_storageType = cnvSvc->repSvcType();
122  } else {
123  ATH_MSG_WARNING("Cannot get ConversionSvc Interface.");
124  }
125  // Get FileMgr
126  ATH_CHECK( m_fileMgr.retrieve() );
127 
128  // Set to be listener for end of event
129  ATH_CHECK( m_incSvc.retrieve() );
130 
131  ATH_CHECK( m_metaDataTools.retrieve() );
132  ATH_MSG_INFO("Found " << m_metaDataTools);
133 
134  m_incSvc->addListener(this, "FirstInputFile", 80, true);
135  m_incSvc->addListener(this, "BeginInputFile", 80, true);
136  m_incSvc->addListener(this, "EndInputFile", 10, true);
137 
138  // Register this service for 'I/O' events
139  ServiceHandle<IIoComponentMgr> iomgr("IoComponentMgr", this->name());
140  ATH_CHECK( iomgr.retrieve() );
141  ATH_CHECK( iomgr->io_register(this) );
142 
143  ServiceHandle<Gaudi::Interfaces::IOptionsSvc> joSvc("JobOptionsSvc", name());
144  if (!joSvc.retrieve().isSuccess()) {
145  ATH_MSG_WARNING("Cannot get JobOptionsSvc.");
146  } else {
147  if (joSvc->has("EventSelector.InputCollections")) {
148  // Get EventSelector to force in-time initialization and FirstInputFile incident
149  ServiceHandle<IEvtSelector> evtsel("EventSelector", this->name());
150  if (!evtsel.retrieve().isSuccess()) {
151  ATH_MSG_WARNING("Cannot get EventSelector.");
152  }
153  }
154  }
155  // retrieve the output sequences service (EventService) if available
156  m_outSeqSvc.retrieve().ignore();
157 
158  return(StatusCode::SUCCESS);
159 }
160 //__________________________________________________________________________
162  // Release IncidentService
163  if (!m_incSvc.release().isSuccess()) {
164  ATH_MSG_WARNING("Cannot release IncidentService.");
165  }
166  // Release FileMgr
167  if (!m_fileMgr.release().isSuccess()) {
168  ATH_MSG_WARNING("Cannot release FileMgr.");
169  }
170  // Release AddressCreator
171  if (!m_addrCrtr.release().isSuccess()) {
172  ATH_MSG_WARNING("Cannot release AddressCreator.");
173  }
174  // Release OutputMetaDataStore
175  if (!m_outputDataStore.release().isSuccess()) {
176  ATH_MSG_WARNING("Cannot release OutputMetaDataStore.");
177  }
178  // Release InputMetaDataStore
179  if (!m_inputDataStore.release().isSuccess()) {
180  ATH_MSG_WARNING("Cannot release InputMetaDataStore.");
181  }
182  return(StatusCode::SUCCESS);
183 }
184 
185 //__________________________________________________________________________
187  ATH_MSG_DEBUG("MetaDataSvc::stop()");
188  // Fire metaDataStopIncident
189  Incident metaDataStopIncident(name(), "MetaDataStop");
190  m_incSvc->fireIncident(metaDataStopIncident);
191  return(StatusCode::SUCCESS);
192 }
193 
194 //_______________________________________________________________________
195 StatusCode MetaDataSvc::queryInterface(const InterfaceID& riid, void** ppvInterface) {
196  if (riid == this->interfaceID()) {
197  *ppvInterface = this;
198  } else {
199  // Interface is not directly available: try out a base class
200  return(base_class::queryInterface(riid, ppvInterface));
201  }
202  addRef();
203  return(StatusCode::SUCCESS);
204 }
205 //________________________________________________________________________________
207  if (storeID != StoreID::METADATA_STORE) { // should this (also) run in the INPUT_METADATA_STORE?
208  return(StatusCode::SUCCESS);
209  }
210  // Put Additional MetaData objects into Input MetaData Store using VersionedKey
211  std::list<SG::ObjectWithVersion<DataHeader> > allVersions;
212  StatusCode sc = m_inputDataStore->retrieveAllVersions(allVersions, name());
213  if (!sc.isSuccess()) {
214  ATH_MSG_WARNING("Could not retrieve all versions for DataHeader, will not read Metadata");
215  } else {
216  int verNumber = -1;
217  for (SG::ObjectWithVersion<DataHeader>& obj : allVersions) {
218  ++verNumber;
219  const DataHeader* dataHeader = obj.dataObject.cptr();
220  if (dataHeader == nullptr) {
221  ATH_MSG_ERROR("Could not get DataHeader, will not read Metadata");
222  return(StatusCode::FAILURE);
223  }
224  for (const DataHeaderElement& dhe : *dataHeader) {
225  const CLID clid = dhe.getPrimaryClassID();
226  if (clid != ClassID_traits<DataHeader>::ID()) {
227  SG::VersionedKey myVersObjKey(dhe.getKey(), verNumber);
228  std::string key = dhe.getKey();
229  if (verNumber != 0) key = myVersObjKey;
230  tads.push_back(dhe.getAddress(key));
231  }
232  }
233  }
234  }
235  return(StatusCode::SUCCESS);
236 }
237 //________________________________________________________________________________
239 {
240  const FileIncident* fileInc = dynamic_cast<const FileIncident*>(&inc);
241  if (fileInc == nullptr) {
242  ATH_MSG_ERROR("Unable to get FileName from EndInputFile incident");
243  return StatusCode::FAILURE;
244  }
245  const std::string guid = fileInc->fileGuid();
246  const std::string fileName = fileInc->fileName();
247  m_allowMetaDataStop = false;
248  if (!fileName.starts_with( "BSF:")) {
249  // the input file is _not_ bytestream
251  if (!m_inputDataStore->clearStore().isSuccess()) {
252  ATH_MSG_WARNING("Unable to clear input MetaData Proxies");
253  }
255  }
256  if (!initInputMetaDataStore(fileName).isSuccess()) {
257  ATH_MSG_ERROR("Unable to initialize InputMetaDataStore");
258  return StatusCode::FAILURE;
259  }
260  }
261  StatusCode rc(StatusCode::SUCCESS);
262  for (auto it = m_metaDataTools.begin(); it != m_metaDataTools.end(); ++it) {
263  ATH_MSG_DEBUG(" calling beginInputFile on " << (*it)->name() << " for GUID \"" << guid << "\"");
264  if ( (*it)->beginInputFile(guid).isFailure() ) {
265  ATH_MSG_ERROR("Unable to call beginInputFile for " << (*it)->name());
266  rc = StatusCode::FAILURE;
267  }
268  }
269  return rc;
270 }
271 
273 {
274  const FileIncident* fileInc = dynamic_cast<const FileIncident*>(&inc);
275  if (fileInc == nullptr) {
276  ATH_MSG_ERROR("Unable to get FileName from EndInputFile incident");
277  return StatusCode::FAILURE;
278  }
279  const std::string guid = fileInc->fileGuid();
280  ATH_MSG_DEBUG("retireMetadataSource: " << fileInc->fileName());
281  for (auto it = m_metaDataTools.begin(); it != m_metaDataTools.end(); ++it) {
282  ATH_MSG_DEBUG(" calling endInputFile on " << (*it)->name() << " for GUID \"" << guid << "\"");
283  if ( (*it)->endInputFile(guid).isFailure() ) {
284  ATH_MSG_ERROR("Unable to call endInputFile for " << (*it)->name());
285  return StatusCode::FAILURE;
286  }
287  }
288  m_allowMetaDataStop = true;
289  return StatusCode::SUCCESS;
290 }
291 
293 {
294  StatusCode rc(StatusCode::SUCCESS);
295  // Check if already called
296  if (!m_outputPrepared) {
297  for (auto it = m_metaDataTools.begin(); it != m_metaDataTools.end(); ++it) {
298  ATH_MSG_DEBUG(" calling metaDataStop for " << (*it)->name());
299  if ( (*it)->metaDataStop().isFailure() ) {
300  ATH_MSG_ERROR("Unable to call metaDataStop for " << (*it)->name());
301  rc = StatusCode::FAILURE;
302  }
303  }
304  if (!m_metaDataTools.release().isSuccess()) {
305  ATH_MSG_WARNING("Cannot release " << m_metaDataTools);
306  }
307  }
308  m_outputPrepared=true;
309  return rc;
310 }
311 
312 // like prepareOutput() but for parallel streams
314 {
315  // default to the serial implementation if no output name given
316  if( outputName.empty() ) return prepareOutput();
317  ATH_MSG_DEBUG( "prepareOutput('" << outputName << "')" );
318 
319  StatusCode rc = StatusCode::SUCCESS;
320  for (auto it = m_metaDataTools.begin(); it != m_metaDataTools.end(); ++it) {
321  ATH_MSG_DEBUG(" calling metaDataStop for " << (*it)->name());
322  // planning to replace the call below with (*it)->prepareOutput(outputName)
323  if ( (*it)->metaDataStop().isFailure() ) {
324  ATH_MSG_ERROR("Unable to call metaDataStop for " << (*it)->name());
325  rc = StatusCode::FAILURE;
326  }
327  }
328  // MN: not releasing tools here - revisit when clear what happens on new file open
329  return rc;
330 }
331 
332 
334 {
336  if (!m_inputDataStore->clearStore(true).isSuccess()) {
337  ATH_MSG_ERROR("Unable to clear input MetaData Proxies");
338  return StatusCode::FAILURE;
339  }
341  }
343  if (!m_outputDataStore->clearStore(true).isSuccess()) {
344  ATH_MSG_ERROR("Unable to clear output MetaData Proxies");
345  return StatusCode::FAILURE;
346  }
348  }
349  if (!addProxyToInputMetaDataStore(filename).isSuccess()) {
350  ATH_MSG_ERROR("Unable to add proxy to InputMetaDataStore");
351  return StatusCode::FAILURE;
352  }
353  return StatusCode::SUCCESS;
354 }
355 
356 //__________________________________________________________________________
357 void MetaDataSvc::handle(const Incident& inc) {
358  const FileIncident* fileInc = dynamic_cast<const FileIncident*>(&inc);
359  if (fileInc == nullptr) {
360  ATH_MSG_ERROR("Unable to get FileName from EndInputFile incident");
361  return;
362  }
363  const std::string fileName = fileInc->fileName();
364  ATH_MSG_DEBUG("handle() " << inc.type() << " for " << fileName);
365 
366  if (inc.type() == "FirstInputFile") {
367  // Register open/close callback actions
368  using namespace boost::placeholders;
369  Io::bfcn_action_t boa = boost::bind(&MetaDataSvc::rootOpenAction, this, _1,_2);
370  if (m_fileMgr->regAction(boa, Io::OPEN).isFailure()) {
371  ATH_MSG_FATAL("Cannot register ROOT file open action with FileMgr.");
372  }
373  if (!initInputMetaDataStore(fileName).isSuccess()) {
374  ATH_MSG_WARNING("Unable to initialize InputMetaDataStore");
375  }
376  } else if (inc.type() == "BeginInputFile") {
377  if(newMetadataSource(inc).isFailure()) {
378  ATH_MSG_ERROR("Could not process new metadata source " << fileName);
379  }
380  } else if (inc.type() == "EndInputFile") {
381  if(retireMetadataSource(inc).isFailure()) {
382  ATH_MSG_ERROR("Could not retire metadata source " << fileName);
383  }
384  }
385 }
386 
387 //__________________________________________________________________________
388 // This method is currently called only from OutputStreamSequencerSvc
389 StatusCode MetaDataSvc::transitionMetaDataFile(const std::string& outputConn, bool disconnect)
390 {
391  ATH_MSG_DEBUG("transitionMetaDataFile: " << outputConn );
392 
393  // this is normally called through EndInputFile inc, simulate it for EvSvc
394  FileIncident inc("transitionMetaDataFile", "EndInputFile", "dummyMetaInputFileName", "");
396 
397  // Reset flag to allow calling prepareOutput again at next transition
398  m_outputPrepared = false;
399 
400  Incident metaDataStopIncident(name(), "MetaDataStop");
401  m_incSvc->fireIncident(metaDataStopIncident);
402 
403  if( disconnect ) {
404  AthCnvSvc* cnvSvc = dynamic_cast<AthCnvSvc*>(m_addrCrtr.operator->());
405  if (cnvSvc) {
406  if (!cnvSvc->disconnectOutput(outputConn).isSuccess()) {
407  ATH_MSG_WARNING("Cannot get disconnect Output Files");
408  }
409  }
410  }
411 
412  return(StatusCode::SUCCESS);
413 }
414 
415 //__________________________________________________________________________
417  ATH_MSG_INFO("I/O reinitialization...");
418  ATH_MSG_INFO("Dumping InputMetaDataStore: " << m_inputDataStore->dump());
419  ATH_MSG_INFO("Dumping OutputMetaDataStore: " << m_outputDataStore->dump());
420  for (auto iter = m_metaDataTools.begin(),
421  last = m_metaDataTools.end(); iter != last; iter++) {
422  ATH_MSG_INFO("Attached MetaDataTool: " << (*iter)->name());
423  }
424  m_outputPrepared = false;
425  return(StatusCode::SUCCESS);
426 }
427 //__________________________________________________________________________
428 StatusCode MetaDataSvc::rootOpenAction(FILEMGR_CALLBACK_ARGS) {
429  return(StatusCode::SUCCESS);
430 }
431 //__________________________________________________________________________
432 // check if the metadata object key contains Stream name (added by SharedWriter in MetaDataSvc)
433 // remove stream part from the key (i.e. modify the parameter) and return it
434 std::string MetaDataSvc::removeStreamFromKey(std::string& key) {
435  size_t pos = key.find(m_streamInKeyMark);
436  if( pos==std::string::npos ) return "";
437  size_t epos = key.find(']', pos);
438  size_t spos = pos + m_streamInKeyMark.size();
439  std::string stream = key.substr( spos, epos - spos );
440  //cppcheck-suppress uselessCallsSubstr
441  key = key.substr(0, pos) + key.substr(epos+1);
442  return stream;
443 }
444 //__________________________________________________________________________
445 std::set<std::string> MetaDataSvc::getPerStreamKeysFor(const std::string& key ) const {
446  auto iter = m_streamKeys.find( key );
447  if( iter == m_streamKeys.end() ) {
448  return std::set<std::string>( {key} );
449  }
450  return iter->second;
451 }
452 //__________________________________________________________________________
454  std::string fileName = tokenStr.substr(tokenStr.find("[FILE=") + 6);
455  leftString(fileName, ']');
456  std::string className = tokenStr.substr(tokenStr.find("[PNAME=") + 7);
457  leftString(className, ']');
458  std::string contName = tokenStr.substr(tokenStr.find("[CONT=") + 6);
459  leftString(contName,']');
460  std::size_t pos1 = contName.find('(');
461  std::string keyName = contName.substr(pos1 + 1, contName.size() - pos1 - 2);
462  std::size_t pos2 = keyName.find('/');
463  if (pos2 != std::string::npos) keyName = keyName.substr(pos2 + 1);
464  std::string numName = tokenStr.substr(tokenStr.find("[NUM=") + 5);
465  leftString(numName,']');
466  unsigned long num = 0;
467  std::istringstream iss(numName);
468  iss >> num;
469  CLID clid = m_persToClid[className];
470  if (clid == 167728019) { // EventStreamInfo, will change tool to combine input metadata, clearing things before...
471  bool foundTool = false;
472  for (auto iter = m_metaDataTools.begin(), iterEnd = m_metaDataTools.end(); iter != iterEnd; iter++) {
473  if ((*iter)->name() == "ToolSvc.CopyEventStreamInfo") foundTool = true;
474  }
475  if (!foundTool) {
476  if (serviceLocator()->existsService("CutFlowSvc")) {
477  ServiceHandle<IIncidentListener> cfSvc("CutFlowSvc", this->name()); // Disable CutFlowSvc by stopping its incidents.
478  if (cfSvc.retrieve().isSuccess()) {
479  ATH_MSG_INFO("Disabling incidents for: " << cfSvc.name());
480  m_incSvc->removeListener(cfSvc.get(), IncidentType::BeginInputFile);
481  m_incSvc->removeListener(cfSvc.get(), "MetaDataStop");
482  cfSvc.release().ignore();
483  }
484  }
485  if (serviceLocator()->existsService("xAODConfigSvc")) {
486  ServiceHandle<IIncidentListener> xcSvc("xAODConfigSvc", this->name()); // Disable xAODConfigSvc, fails for merging
487  if (xcSvc.retrieve().isSuccess()) {
488  ATH_MSG_INFO("Disabling incidents for: " << xcSvc.name());
489  m_incSvc->removeListener(xcSvc.get(), IncidentType::BeginInputFile);
490  m_incSvc->removeListener(xcSvc.get(), IncidentType::BeginEvent);
491  xcSvc.release().ignore();
492  }
493  }
494  }
495  }
496  const std::string toolName = m_toolForClid[clid];
497  if (!toolName.empty()) {
498  std::string toolInstName;
499  std::size_t pos = toolName.find("::");
500  if (pos != std::string::npos) {
501  toolInstName = toolName.substr(pos + 2);
502  } else {
503  toolInstName = toolName;
504  }
505  bool foundTool = false;
506  for (auto iter = m_metaDataTools.begin(), iterEnd = m_metaDataTools.end(); iter != iterEnd; iter++) {
507  if ((*iter)->name() == "ToolSvc." + toolInstName) foundTool = true;
508  }
509  if (!foundTool) {
510  if (toolInstName != toolName) {
511  toolInstName = toolName + "/" + toolInstName;
512  }
513  ToolHandle<IMetaDataTool> metadataTool(toolInstName);
514  m_metaDataTools.push_back(metadataTool);
515  ATH_MSG_DEBUG("Added new MetaDataTool: " << metadataTool->name());
516  if (!metadataTool.retrieve().isSuccess()) {
517  ATH_MSG_FATAL("Cannot get " << toolInstName);
518  return(StatusCode::FAILURE);
519  }
520  }
521  }
522  // make stream-unique keys for infile metadata objects
523  // AthenaOutputStream will use this to distribute objects to the right stream (and restore the original key)
524  if( clid == 178309087 ) { // FileMetaData
525  std::string newName = keyName + m_streamInKeyMark + fileName + "]";
526  ATH_MSG_DEBUG("Recording " << keyName << " as " << newName);
527  m_streamKeys[keyName].insert(newName);
528  keyName = std::move(newName);
529  }
530  if( clid == 73252552 ) { // FileMetaDataAuxInfo
531  std::string newName = keyName.substr(0, keyName.find(RootAuxDynIO::AUX_POSTFIX)) + m_streamInKeyMark
533  ATH_MSG_DEBUG("Recording " << keyName << " as " << newName);
534  m_streamKeys[keyName].insert(newName);
535  keyName = std::move(newName);
536  }
537  const std::string par[3] = { "SHM" , keyName , className };
538  const unsigned long ipar[2] = { num , 0 };
539  IOpaqueAddress* opqAddr = nullptr;
540  SG::DataProxy* dp = m_inputDataStore->proxy(clid, keyName);
541  if (dp != nullptr) {
542  ATH_MSG_DEBUG("Resetting duplicate proxy for: " << clid << "#" << keyName << " from file: " << fileName);
543  dp->reset();
544  }
545  if (!m_addrCrtr->createAddress(m_storageType, clid, par, ipar, opqAddr).isSuccess()) {
546  ATH_MSG_FATAL("addProxyToInputMetaDataStore: Cannot create address for " << tokenStr);
547  return(StatusCode::FAILURE);
548  }
549  if (m_inputDataStore->recordAddress(keyName, opqAddr).isFailure()) {
550  delete opqAddr; opqAddr = nullptr;
551  ATH_MSG_FATAL("addProxyToInputMetaDataStore: Cannot create proxy for " << tokenStr);
552  return(StatusCode::FAILURE);
553  }
554  if (m_inputDataStore->accessData(clid, keyName) == nullptr) {
555  ATH_MSG_FATAL("addProxyToInputMetaDataStore: Cannot access data for " << tokenStr);
556  return(StatusCode::FAILURE);
557  }
558  if (keyName.find(RootAuxDynIO::AUX_POSTFIX) != std::string::npos
559  && m_inputDataStore->symLink(clid, keyName, 187169987).isFailure()) {
560  ATH_MSG_WARNING("addProxyToInputMetaDataStore: Cannot symlink to AuxStore for " << tokenStr);
561  }
562  return(StatusCode::SUCCESS);
563 }
564 //__________________________________________________________________________
566  ATH_MSG_DEBUG("initInputMetaDataStore: file name " << fileName);
567  m_clearedInputDataStore = false;
568  // Load proxies for InputMetaDataStore
569  if (m_metaDataCont.value().empty()) {
570  ATH_MSG_DEBUG("MetaDataSvc called without MetaDataContainer set.");
571  return(StatusCode::SUCCESS);
572  }
573  if (fileName.starts_with( "BSF:")) {
574  ATH_MSG_DEBUG("MetaDataSvc called for non ROOT file.");
575  } else if (fileName.compare(0, 3, "SHM")==0) {
576  ATH_MSG_DEBUG("MetaDataSvc called for shared memory.");
577  } else {
578  const std::string par[2] = { fileName, m_metaDataCont.value() + "(DataHeader)" };
579  const std::string parOld[2] = { fileName, m_metaDataCont.value() + "DataHeader" };
580  for (int verNumber = 0; verNumber < 100; verNumber++) {
581  SG::VersionedKey myVersKey(name(), verNumber);
582  if (m_inputDataStore->contains<DataHeader>(myVersKey)) {
583  ATH_MSG_DEBUG("initInputMetaDataStore: MetaData Store already contains DataHeader, key = " << myVersKey);
584  } else {
585  const unsigned long ipar[2] = { (unsigned long)verNumber , 0 };
586  IOpaqueAddress* opqAddr = nullptr;
587  if (!m_addrCrtr->createAddress(m_storageType, ClassID_traits<DataHeader>::ID(), par, ipar, opqAddr).isSuccess()) {
588  if (!m_addrCrtr->createAddress(m_storageType, ClassID_traits<DataHeader>::ID(), parOld, ipar, opqAddr).isSuccess()) {
589  break;
590  }
591  }
592  if (m_inputDataStore->recordAddress(myVersKey, opqAddr).isFailure()) {
593  delete opqAddr; opqAddr = nullptr;
594  ATH_MSG_WARNING("initInputMetaDataStore: Cannot create proxy for DataHeader, key = " << myVersKey);
595  }
596  }
597  }
598  std::list<SG::TransientAddress*> tList;
599  if (!loadAddresses(StoreID::METADATA_STORE, tList).isSuccess()) {
600  ATH_MSG_ERROR("Unable to load MetaData Proxies");
601  return StatusCode::FAILURE;
602  }
603  for (SG::TransientAddress* tad : tList) {
604  CLID clid = tad->clID();
605  ATH_MSG_VERBOSE("initInputMetaDataStore: add proxy for clid = " << clid << ", key = " << tad->name());
606  if (m_inputDataStore->contains(tad->clID(), tad->name())) {
607  ATH_MSG_DEBUG("initInputMetaDataStore: MetaData Store already contains clid = " << clid << ", key = " << tad->name());
608  } else {
609  if (!m_inputDataStore->recordAddress(tad->name(), tad->address())) {
610  ATH_MSG_ERROR("initInputMetaDataStore: Cannot create proxy for clid = " << clid << ", key = " << tad->name());
611  return StatusCode::FAILURE;
612  }
613  }
614 
615  for (CLID tclid : tad->transientID()) {
616  if (tclid != clid) {
617  if (m_inputDataStore->symLink (clid, tad->name(), tclid).isFailure()) {
618  ATH_MSG_WARNING("Cannot make autosymlink from " <<
619  clid << "/" << tad->name() << " to " << tclid);
620  }
621  }
622  }
623  delete tad;
624  }
625  tList.clear();
626  }
627  ATH_MSG_DEBUG("Loaded input meta data store proxies");
628  return(StatusCode::SUCCESS);
629 }
630 
631 
632 const std::string MetaDataSvc::currentRangeID() const
633 {
634  return m_outSeqSvc.isValid()? m_outSeqSvc->currentRangeID() : "";
635 }
636 
637 
639 {
640  auto it = m_handledClasses.find(itemID);
641  if (it == m_handledClasses.end()) {
642  ATH_MSG_DEBUG("Not translating metadata item ID #" << itemID);
643  return itemID;
644  }
645 
646  std::string itemName;
647  CLID contID = 0;
648  if (m_classIDSvc->getTypeNameOfID(itemID, itemName).isSuccess()) {
649  const std::string contName = "MetaCont<" + itemName + ">";
650  ATH_MSG_DEBUG("Transforming " << contName << " to " << itemName
651  << " for output");
652  if (m_classIDSvc->getIDOfTypeName(contName, contID).isSuccess())
653  return contID;
654  }
655 
656  return itemID;
657 }
658 
659 void MetaDataSvc::recordHook(const std::type_info& typeInfo) {
660  const std::string& typeName = System::typeinfoName(typeInfo);
661  ATH_MSG_VERBOSE("Handling record event of type " << typeName);
662 
663  CLID itemID = 0;
664  if (m_classIDSvc->getIDOfTypeInfoName(typeName, itemID).isSuccess()) {
665  auto result = m_handledClasses.insert(itemID);
666  if (result.second)
667  ATH_MSG_DEBUG("MetaDataSvc will handle " << typeName
668  << " ClassID: " << itemID);
669  }
670 }
671 
672 void MetaDataSvc::removeHook(const std::type_info& typeInfo) {
673  const std::string& typeName = System::typeinfoName(typeInfo);
674  ATH_MSG_VERBOSE("Handling removal event of type " << typeName);
675 
676  CLID itemID = 0;
677  if (m_classIDSvc->getIDOfTypeInfoName(typeName, itemID).isSuccess()) {
678  if (0 < m_handledClasses.erase(itemID))
679  ATH_MSG_DEBUG("MetaDataSvc will no longer handle " << typeName
680  << " ClassID: " << itemID);
681  }
682 }
683 
684 
686 {
687  ATH_MSG_DEBUG("Locking metadata tools");
688  for(auto tool : m_metaDataTools ) {
689  ILockableTool *lockable = dynamic_cast<ILockableTool*>( tool.get() );
690  if( lockable ) lockable->lock_shared();
691  }
692 }
693 
694 
696 {
697  ATH_MSG_DEBUG("Unlocking metadata tools");
698  for(auto tool : m_metaDataTools ) {
699  ILockableTool *lockable = dynamic_cast<ILockableTool*>( tool.get() );
700  if( lockable ) lockable->unlock_shared();
701  }
702 }
703 
704 
TileDCSDataPlotter.dp
dp
Definition: TileDCSDataPlotter.py:840
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
MetaDataSvc::interfaceID
static const InterfaceID & interfaceID()
Retrieve interface ID.
Definition: MetaDataSvc.h:106
get_generator_info.result
result
Definition: get_generator_info.py:21
MetaDataSvc::stop
virtual StatusCode stop() override
stop the metadata service
Definition: MetaDataSvc.cxx:186
RootAuxDynIO::AUX_POSTFIX
constexpr char AUX_POSTFIX[]
Common post-fix for the names of auxiliary containers in StoreGate.
Definition: RootAuxDynDefs.h:10
MetaDataSvc::m_storageType
long m_storageType
Definition: MetaDataSvc.h:320
MetaDataSvc::initialize
virtual StatusCode initialize() override
initialize the metadata service at the beginning of the job
Definition: MetaDataSvc.cxx:109
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
MetaDataSvc::m_metaDataTools
ToolHandleArray< IMetaDataTool > m_metaDataTools
MetaDataTools, vector with the MetaData tools.
Definition: MetaDataSvc.h:338
MetaDataSvc::m_clearedInputDataStore
bool m_clearedInputDataStore
Definition: MetaDataSvc.h:321
MetaDataSvc::lockTools
void lockTools() const
Definition: MetaDataSvc.cxx:685
MetaDataSvc::m_clearedOutputDataStore
bool m_clearedOutputDataStore
Definition: MetaDataSvc.h:322
OutputStreamSequencerSvc.h
This file contains the class definition for the OutputStreamSequencerSvc class.
SGVersionedKey.h
skel.it
it
Definition: skel.GENtoEVGEN.py:423
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:312
MetaDataSvc::m_metaDataCont
StringProperty m_metaDataCont
MetaDataContainer, POOL container name for MetaData.
Definition: MetaDataSvc.h:336
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MetaDataSvc::~MetaDataSvc
virtual ~MetaDataSvc()
Destructor.
Definition: MetaDataSvc.cxx:106
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:416
JetTagCalibConfig.className
string className
Definition: JetTagCalibConfig.py:31
DataHeaderElement
This class provides a persistent form for the TransientAddress.
Definition: DataHeader.h:36
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
MetaDataSvc::finalize
virtual StatusCode finalize() override
finalize the metadata service at the end of the job
Definition: MetaDataSvc.cxx:161
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MetaDataSvc::m_outputPrepared
bool m_outputPrepared
Definition: MetaDataSvc.h:324
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:238
DataHeader
This class provides the layout for summary information stored for data written to POOL.
Definition: DataHeader.h:124
MetaDataSvc::m_addrCrtr
ServiceHandle< IAddressCreator > m_addrCrtr
Definition: MetaDataSvc.h:314
beamspotman.n
n
Definition: beamspotman.py:731
MetaDataSvc::initInputMetaDataStore
StatusCode initInputMetaDataStore(const std::string &fileName)
Initialize input metadata store - can be called directly or via BeginInputFile incident.
Definition: MetaDataSvc.cxx:565
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:313
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MetaDataSvc::addProxyToInputMetaDataStore
StatusCode addProxyToInputMetaDataStore(const std::string &tokenStr)
Definition: MetaDataSvc.cxx:453
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:638
MetaDataSvc::m_allowMetaDataStop
bool m_allowMetaDataStop
Definition: MetaDataSvc.h:323
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
MetaDataSvc::m_streamKeys
std::map< std::string, std::set< std::string > > m_streamKeys
Definition: MetaDataSvc.h:332
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:52
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MetaDataSvc::m_fileMgr
ServiceHandle< IFileMgr > m_fileMgr
Definition: MetaDataSvc.h:315
MetaDataSvc::retireMetadataSource
virtual StatusCode retireMetadataSource(const Incident &)
Allows metadata tools to act before an input file is closed.
Definition: MetaDataSvc.cxx:272
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:292
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:316
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:389
MetaDataSvc::unlockTools
void unlockTools() const
Definition: MetaDataSvc.cxx:695
MetaDataSvc::queryInterface
StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface) override
Provide access to the interfaces implemented by this service.
Definition: MetaDataSvc.cxx:195
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:333
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
MetaDataSvc::removeHook
void removeHook(const std::type_info &) override
Definition: MetaDataSvc.cxx:672
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:29
MetaDataSvc::currentRangeID
virtual const std::string currentRangeID() const override final
Definition: MetaDataSvc.cxx:632
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:445
lumiFormat.outputName
string outputName
Definition: lumiFormat.py:71
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
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:357
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:428
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
MetaDataSvc::m_persToClid
std::map< std::string, CLID > m_persToClid
Definition: MetaDataSvc.h:325
IAddressProvider::tadList
std::list< SG::TransientAddress * > tadList
Definition: IAddressProvider.h:32
ReadCalibFromCool.typeName
typeName
Definition: ReadCalibFromCool.py:477
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
AthCnvSvc::disconnectOutput
virtual StatusCode disconnectOutput(const std::string &output)
Disconnect output files from the service.
Definition: AthCnvSvc.cxx:437
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:434
MetaDataSvc::m_streamInKeyMark
const std::string m_streamInKeyMark
marker string for embedding stream name in MetaData object keys for SharedWriter server
Definition: MetaDataSvc.h:330
python.PyAthena.obj
obj
Definition: PyAthena.py:135
SG::DataProxy
Definition: DataProxy.h:44
MetaDataSvc::m_toolForClid
std::map< CLID, std::string > m_toolForClid
Definition: MetaDataSvc.h:326
AthCnvSvc::repSvcType
virtual long repSvcType() const
Retrieve the class type of the data store the converter uses.
Definition: AthCnvSvc.cxx:172
StoreGateSvc.h
MetaDataSvc::recordHook
void recordHook(const std::type_info &) override
Definition: MetaDataSvc.cxx:659
AthCnvSvc
Definition: AthCnvSvc.h:67
MetaDataSvc::loadAddresses
StatusCode loadAddresses(StoreID::type storeID, IAddressProvider::tadList &tads) override
loads addresses of versioned metadata object.
Definition: MetaDataSvc.cxx:206
MetaDataSvc::m_classIDSvc
ServiceHandle< IClassIDSvc > m_classIDSvc
Definition: MetaDataSvc.h:318
ServiceHandle< IAddressCreator >
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
MetaDataSvc::m_handledClasses
std::set< CLID > m_handledClasses
Definition: MetaDataSvc.h:328
MetaDataSvc::m_outSeqSvc
ServiceHandle< OutputStreamSequencerSvc > m_outSeqSvc
Definition: MetaDataSvc.h:317