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"
33 #include "boost/bind/bind.hpp"
44 bool leftString(std::string&
s,
char sc) {
45 if (
const auto pos =
s.find(
sc);
pos != std::string::npos) {
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 } } {}
117 m_incSvc->addListener(
this,
"FirstInputFile", 80,
true);
118 m_incSvc->addListener(
this,
"BeginInputFile", 80,
true);
119 m_incSvc->addListener(
this,
"EndInputFile", 10,
true);
127 if (!joSvc.retrieve().isSuccess()) {
130 if (joSvc->has(
"EventSelector.InputCollections")) {
133 if (!evtsel.retrieve().isSuccess()) {
141 return(StatusCode::SUCCESS);
146 if (!
m_incSvc.release().isSuccess()) {
165 return(StatusCode::SUCCESS);
172 Incident metaDataStopIncident(
name(),
"MetaDataStop");
173 m_incSvc->fireIncident(metaDataStopIncident);
174 return(StatusCode::SUCCESS);
180 return(StatusCode::SUCCESS);
183 std::list<SG::ObjectWithVersion<DataHeader> > allVersions;
185 if (!
sc.isSuccess()) {
186 ATH_MSG_WARNING(
"Could not retrieve all versions for DataHeader, will not read Metadata");
192 if (dataHeader ==
nullptr) {
193 ATH_MSG_ERROR(
"Could not get DataHeader, will not read Metadata");
194 return(StatusCode::FAILURE);
197 const CLID clid = dhe.getPrimaryClassID();
200 std::string
key = dhe.getKey();
201 if (verNumber != 0) {
204 tads.push_back(dhe.getAddress(
key));
209 return(StatusCode::SUCCESS);
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;
219 const std::string
guid = fileInc->fileGuid();
220 const std::string
fileName = fileInc->fileName();
222 if (!
fileName.starts_with(
"BSF:")) {
235 if (
tool->beginInputFile(
guid).isFailure()) {
237 rc = StatusCode::FAILURE;
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;
250 const std::string
guid = fileInc->fileGuid();
251 ATH_MSG_DEBUG(
"retireMetadataSource: " << fileInc->fileName());
257 return StatusCode::SUCCESS;
263 return StatusCode::SUCCESS;
269 if (
tool->metaDataStop().isFailure()) {
271 rc = StatusCode::FAILURE;
295 if (
tool->metaDataStop().isFailure()) {
297 rc = StatusCode::FAILURE;
316 return StatusCode::SUCCESS;
321 const FileIncident* fileInc =
dynamic_cast<const FileIncident*
>(&inc);
322 if (fileInc ==
nullptr) {
323 ATH_MSG_ERROR(
"Unable to get FileName from EndInputFile incident");
326 const std::string
fileName = fileInc->fileName();
329 if (inc.type() ==
"FirstInputFile") {
331 using namespace boost::placeholders;
333 if (
m_fileMgr->regAction(std::move(boa), Io::OPEN).isFailure()) {
334 ATH_MSG_FATAL(
"Cannot register ROOT file open action with FileMgr.");
339 }
else if (inc.type() ==
"BeginInputFile") {
343 }
else if (inc.type() ==
"EndInputFile") {
357 FileIncident inc(
"transitionMetaDataFile",
"EndInputFile",
"dummyMetaInputFileName",
"");
363 Incident metaDataStopIncident(
name(),
"MetaDataStop");
364 m_incSvc->fireIncident(metaDataStopIncident);
375 return(StatusCode::SUCCESS);
387 return(StatusCode::SUCCESS);
391 return(StatusCode::SUCCESS);
398 if(
pos==std::string::npos )
return "";
417 std::string
fileName = tokenStr.substr(tokenStr.find(
"[FILE=") + 6);
419 std::string
className = tokenStr.substr(tokenStr.find(
"[PNAME=") + 7);
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);
433 if (clid == 167728019) {
435 return tool->name() ==
"ToolSvc.CopyEventStreamInfo";
438 if (serviceLocator()->existsService(
"CutFlowSvc")) {
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();
447 if (serviceLocator()->existsService(
"xAODConfigSvc")) {
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();
461 if( clid == 178309087 ) {
467 if( clid == 73252552 ) {
478 const unsigned long ipar[2] = {
num , 0 };
479 IOpaqueAddress* opqAddr =
nullptr;
486 ATH_MSG_FATAL(
"addProxyToInputMetaDataStore: Cannot create address for " << tokenStr);
487 return(StatusCode::FAILURE);
490 delete opqAddr; opqAddr =
nullptr;
491 ATH_MSG_FATAL(
"addProxyToInputMetaDataStore: Cannot create proxy for " << tokenStr);
492 return(StatusCode::FAILURE);
495 ATH_MSG_FATAL(
"addProxyToInputMetaDataStore: Cannot access data for " << tokenStr);
496 return(StatusCode::FAILURE);
500 ATH_MSG_WARNING(
"addProxyToInputMetaDataStore: Cannot symlink to AuxStore for " << tokenStr);
502 return(StatusCode::SUCCESS);
510 ATH_MSG_DEBUG(
"MetaDataSvc called without MetaDataContainer set.");
511 return(StatusCode::SUCCESS);
513 if (
fileName.starts_with(
"BSF:")) {
515 }
else if (
fileName.compare(0, 3,
"SHM")==0) {
518 const std::string
par[2] = {
522 const std::string parOld[2] = {
526 for (
int verNumber = 0; verNumber < 100; verNumber++) {
529 ATH_MSG_DEBUG(
"initInputMetaDataStore: MetaData Store already contains DataHeader, key = " << myVersKey);
531 const unsigned long ipar[2] = { (
unsigned long)verNumber , 0 };
532 IOpaqueAddress* opqAddr =
nullptr;
539 delete opqAddr; opqAddr =
nullptr;
540 ATH_MSG_WARNING(
"initInputMetaDataStore: Cannot create proxy for DataHeader, key = " << myVersKey);
544 std::list<SG::TransientAddress*> tList;
547 CLID clid = tad->clID();
548 ATH_MSG_VERBOSE(
"initInputMetaDataStore: add proxy for clid = " << clid <<
", key = " << tad->name());
550 ATH_MSG_DEBUG(
"initInputMetaDataStore: MetaData Store already contains clid = " << clid <<
", key = " << tad->name());
553 ATH_MSG_ERROR(
"initInputMetaDataStore: Cannot create proxy for clid = " << clid <<
", key = " << tad->name());
554 return StatusCode::FAILURE;
558 for (
CLID tclid : tad->transientID()) {
562 clid <<
"/" << tad->name() <<
" to " << tclid);
571 return(StatusCode::SUCCESS);
584 ATH_MSG_DEBUG(
"Not translating metadata item ID #" << itemID);
588 std::string itemName;
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
594 if (
m_classIDSvc->getIDOfTypeName(contName, contID).isSuccess())
610 <<
" ClassID: " << itemID);
622 <<
" ClassID: " << itemID);