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"
32 #include "boost/bind/bind.hpp"
43 bool leftString(std::string&
s,
char sc) {
44 if (
const auto pos =
s.find(
sc);
pos != std::string::npos) {
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 } } {}
115 m_incSvc->addListener(
this,
"FirstInputFile", 80,
true);
116 m_incSvc->addListener(
this,
"BeginInputFile", 80,
true);
117 m_incSvc->addListener(
this,
"EndInputFile", 10,
true);
125 if (!joSvc.retrieve().isSuccess()) {
128 if (joSvc->has(
"EventSelector.InputCollections")) {
131 if (!evtsel.retrieve().isSuccess()) {
139 return(StatusCode::SUCCESS);
144 if (!
m_incSvc.release().isSuccess()) {
163 return(StatusCode::SUCCESS);
170 Incident metaDataStopIncident(
name(),
"MetaDataStop");
171 m_incSvc->fireIncident(metaDataStopIncident);
172 return(StatusCode::SUCCESS);
178 return(StatusCode::SUCCESS);
181 std::list<SG::ObjectWithVersion<DataHeader> > allVersions;
183 if (!
sc.isSuccess()) {
184 ATH_MSG_WARNING(
"Could not retrieve all versions for DataHeader, will not read Metadata");
190 if (dataHeader ==
nullptr) {
191 ATH_MSG_ERROR(
"Could not get DataHeader, will not read Metadata");
192 return(StatusCode::FAILURE);
195 const CLID clid = dhe.getPrimaryClassID();
198 std::string
key = dhe.getKey();
199 if (verNumber != 0) {
202 tads.push_back(dhe.getAddress(
key));
207 return(StatusCode::SUCCESS);
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;
217 const std::string
guid = fileInc->fileGuid();
218 const std::string
fileName = fileInc->fileName();
220 if (!
fileName.starts_with(
"BSF:")) {
233 if (
tool->beginInputFile(
guid).isFailure()) {
235 rc = StatusCode::FAILURE;
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;
248 const std::string
guid = fileInc->fileGuid();
249 ATH_MSG_DEBUG(
"retireMetadataSource: " << fileInc->fileName());
255 return StatusCode::SUCCESS;
261 return StatusCode::SUCCESS;
267 if (
tool->metaDataStop().isFailure()) {
269 rc = StatusCode::FAILURE;
293 if (
tool->metaDataStop().isFailure()) {
295 rc = StatusCode::FAILURE;
314 return StatusCode::SUCCESS;
319 const FileIncident* fileInc =
dynamic_cast<const FileIncident*
>(&inc);
320 if (fileInc ==
nullptr) {
321 ATH_MSG_ERROR(
"Unable to get FileName from EndInputFile incident");
324 const std::string
fileName = fileInc->fileName();
327 if (inc.type() ==
"FirstInputFile") {
329 using namespace boost::placeholders;
331 if (
m_fileMgr->regAction(std::move(boa), Io::OPEN).isFailure()) {
332 ATH_MSG_FATAL(
"Cannot register ROOT file open action with FileMgr.");
337 }
else if (inc.type() ==
"BeginInputFile") {
341 }
else if (inc.type() ==
"EndInputFile") {
355 FileIncident inc(
"transitionMetaDataFile",
"EndInputFile",
"dummyMetaInputFileName",
"");
361 Incident metaDataStopIncident(
name(),
"MetaDataStop");
362 m_incSvc->fireIncident(metaDataStopIncident);
373 return(StatusCode::SUCCESS);
385 return(StatusCode::SUCCESS);
389 return(StatusCode::SUCCESS);
396 if(
pos==std::string::npos )
return "";
415 std::string
fileName = tokenStr.substr(tokenStr.find(
"[FILE=") + 6);
417 std::string
className = tokenStr.substr(tokenStr.find(
"[PNAME=") + 7);
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);
431 if (clid == 167728019) {
433 return tool->name() ==
"ToolSvc.CopyEventStreamInfo";
436 if (serviceLocator()->existsService(
"CutFlowSvc")) {
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();
445 if (serviceLocator()->existsService(
"xAODConfigSvc")) {
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();
459 if( clid == 178309087 ) {
465 if( clid == 73252552 ) {
476 const unsigned long ipar[2] = {
num , 0 };
477 IOpaqueAddress* opqAddr =
nullptr;
484 ATH_MSG_FATAL(
"addProxyToInputMetaDataStore: Cannot create address for " << tokenStr);
485 return(StatusCode::FAILURE);
488 delete opqAddr; opqAddr =
nullptr;
489 ATH_MSG_FATAL(
"addProxyToInputMetaDataStore: Cannot create proxy for " << tokenStr);
490 return(StatusCode::FAILURE);
493 ATH_MSG_FATAL(
"addProxyToInputMetaDataStore: Cannot access data for " << tokenStr);
494 return(StatusCode::FAILURE);
498 ATH_MSG_WARNING(
"addProxyToInputMetaDataStore: Cannot symlink to AuxStore for " << tokenStr);
500 return(StatusCode::SUCCESS);
508 ATH_MSG_DEBUG(
"MetaDataSvc called without MetaDataContainer set.");
509 return(StatusCode::SUCCESS);
511 if (
fileName.starts_with(
"BSF:")) {
513 }
else if (
fileName.compare(0, 3,
"SHM")==0) {
516 const std::string
par[2] = {
520 const std::string parOld[2] = {
524 for (
int verNumber = 0; verNumber < 100; verNumber++) {
527 ATH_MSG_DEBUG(
"initInputMetaDataStore: MetaData Store already contains DataHeader, key = " << myVersKey);
529 const unsigned long ipar[2] = { (
unsigned long)verNumber , 0 };
530 IOpaqueAddress* opqAddr =
nullptr;
537 delete opqAddr; opqAddr =
nullptr;
538 ATH_MSG_WARNING(
"initInputMetaDataStore: Cannot create proxy for DataHeader, key = " << myVersKey);
542 std::list<SG::TransientAddress*> tList;
545 CLID clid = tad->clID();
546 ATH_MSG_VERBOSE(
"initInputMetaDataStore: add proxy for clid = " << clid <<
", key = " << tad->name());
548 ATH_MSG_DEBUG(
"initInputMetaDataStore: MetaData Store already contains clid = " << clid <<
", key = " << tad->name());
551 ATH_MSG_ERROR(
"initInputMetaDataStore: Cannot create proxy for clid = " << clid <<
", key = " << tad->name());
552 return StatusCode::FAILURE;
556 for (
CLID tclid : tad->transientID()) {
560 clid <<
"/" << tad->name() <<
" to " << tclid);
569 return(StatusCode::SUCCESS);
582 ATH_MSG_DEBUG(
"Not translating metadata item ID #" << itemID);
586 std::string itemName;
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
592 if (
m_classIDSvc->getIDOfTypeName(contName, contID).isSuccess())
608 <<
" ClassID: " << itemID);
620 <<
" ClassID: " << itemID);