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"
38 leftString(std::string &
s,
char sc){
39 bool truncated{
false};
41 if (
n!=std::string::npos){
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),
60 m_clearedInputDataStore(true),
61 m_clearedOutputDataStore(false),
62 m_allowMetaDataStop(false),
63 m_outputPrepared(false),
70 m_persToClid.insert(std::pair<std::string, CLID>(
"DataHeader_p5", 222376821));
71 m_persToClid.insert(std::pair<std::string, CLID>(
"EventStreamInfo_p3", 167728019));
72 m_persToClid.insert(std::pair<std::string, CLID>(
"ByteStreamMetadataContainer_p1", 1076128893));
73 m_persToClid.insert(std::pair<std::string, CLID>(
"IOVMetaDataContainer_p1", 1316383046));
74 m_persToClid.insert(std::pair<std::string, CLID>(
"xAOD::EventFormat_v1", 243004407));
75 m_persToClid.insert(std::pair<std::string, CLID>(
"xAOD::CutBookkeeperContainer_v1", 1234982351));
76 m_persToClid.insert(std::pair<std::string, CLID>(
"xAOD::CutBookkeeperAuxContainer_v1", 1147935274));
77 m_persToClid.insert(std::pair<std::string, CLID>(
"xAOD::TriggerMenuContainer_v1", 1107011239));
78 m_persToClid.insert(std::pair<std::string, CLID>(
"DataVector<xAOD::TriggerMenu_v1>", 1107011239));
79 m_persToClid.insert(std::pair<std::string, CLID>(
"xAOD::TriggerMenuAuxContainer_v1", 1212409402));
80 m_persToClid.insert(std::pair<std::string, CLID>(
"xAOD::TriggerMenuJsonContainer_v1", 1221262614));
81 m_persToClid.insert(std::pair<std::string, CLID>(
"DataVector<xAOD::TriggerMenuJson_v1>", 1221262614));
82 m_persToClid.insert(std::pair<std::string, CLID>(
"xAOD::TriggerMenuJsonAuxContainer_v1", 373045213));
83 m_persToClid.insert(std::pair<std::string, CLID>(
"xAOD::LumiBlockRangeContainer_v1", 1115934851));
84 m_persToClid.insert(std::pair<std::string, CLID>(
"DataVector<xAOD::LumiBlockRange_v1>", 1115934851));
85 m_persToClid.insert(std::pair<std::string, CLID>(
"xAOD::LumiBlockRangeAuxContainer_v1", 1251061086));
86 m_persToClid.insert(std::pair<std::string, CLID>(
"xAOD::FileMetaData_v1", 178309087));
87 m_persToClid.insert(std::pair<std::string, CLID>(
"xAOD::FileMetaDataAuxInfo_v1", 73252552));
88 m_persToClid.insert(std::pair<std::string, CLID>(
"xAOD::RingSetConfContainer_v1", 1157997427));
89 m_persToClid.insert(std::pair<std::string, CLID>(
"DataVector<xAOD::RingSetConf_v1>", 1157997427));
90 m_persToClid.insert(std::pair<std::string, CLID>(
"xAOD::RingSetConfAuxContainer_v1", 1307745126));
91 m_persToClid.insert(std::pair<std::string, CLID>(
"xAOD::TruthMetaDataContainer_v1", 1188015687));
92 m_persToClid.insert(std::pair<std::string, CLID>(
"DataVector<xAOD::TruthMetaData_v1>", 1188015687));
93 m_persToClid.insert(std::pair<std::string, CLID>(
"xAOD::TruthMetaDataAuxContainer_v1", 1094306618));
124 m_incSvc->addListener(
this,
"FirstInputFile", 80,
true);
125 m_incSvc->addListener(
this,
"BeginInputFile", 80,
true);
126 m_incSvc->addListener(
this,
"EndInputFile", 10,
true);
134 if (!joSvc.retrieve().isSuccess()) {
137 if (joSvc->has(
"EventSelector.InputCollections")) {
140 if (!evtsel.retrieve().isSuccess()) {
148 return(StatusCode::SUCCESS);
153 if (!
m_incSvc.release().isSuccess()) {
172 return(StatusCode::SUCCESS);
179 Incident metaDataStopIncident(
name(),
"MetaDataStop");
180 m_incSvc->fireIncident(metaDataStopIncident);
181 return(StatusCode::SUCCESS);
187 return(StatusCode::SUCCESS);
190 std::list<SG::ObjectWithVersion<DataHeader> > allVersions;
192 if (!
sc.isSuccess()) {
193 ATH_MSG_WARNING(
"Could not retrieve all versions for DataHeader, will not read Metadata");
199 if (dataHeader ==
nullptr) {
200 ATH_MSG_ERROR(
"Could not get DataHeader, will not read Metadata");
201 return(StatusCode::FAILURE);
204 const CLID clid = dhe.getPrimaryClassID();
207 std::string
key = dhe.getKey();
208 if (verNumber != 0)
key = myVersObjKey;
209 tads.push_back(dhe.getAddress(
key));
214 return(StatusCode::SUCCESS);
219 const FileIncident* fileInc =
dynamic_cast<const FileIncident*
>(&inc);
220 if (fileInc ==
nullptr) {
221 ATH_MSG_ERROR(
"Unable to get FileName from EndInputFile incident");
222 return StatusCode::FAILURE;
224 const std::string
guid = fileInc->fileGuid();
225 const std::string
fileName = fileInc->fileName();
227 if (!
fileName.starts_with(
"BSF:")) {
237 return StatusCode::FAILURE;
242 ATH_MSG_DEBUG(
" calling beginInputFile on " << (*it)->name() <<
" for GUID \"" <<
guid <<
"\"");
243 if ( (*it)->beginInputFile(
guid).isFailure() ) {
244 ATH_MSG_ERROR(
"Unable to call beginInputFile for " << (*it)->name());
245 rc = StatusCode::FAILURE;
253 const FileIncident* fileInc =
dynamic_cast<const FileIncident*
>(&inc);
254 if (fileInc ==
nullptr) {
255 ATH_MSG_ERROR(
"Unable to get FileName from EndInputFile incident");
256 return StatusCode::FAILURE;
258 const std::string
guid = fileInc->fileGuid();
259 ATH_MSG_DEBUG(
"retireMetadataSource: " << fileInc->fileName());
261 ATH_MSG_DEBUG(
" calling endInputFile on " << (*it)->name() <<
" for GUID \"" <<
guid <<
"\"");
262 if ( (*it)->endInputFile(
guid).isFailure() ) {
263 ATH_MSG_ERROR(
"Unable to call endInputFile for " << (*it)->name());
264 return StatusCode::FAILURE;
268 return StatusCode::SUCCESS;
277 ATH_MSG_DEBUG(
" calling metaDataStop for " << (*it)->name());
278 if ( (*it)->metaDataStop().isFailure() ) {
279 ATH_MSG_ERROR(
"Unable to call metaDataStop for " << (*it)->name());
280 rc = StatusCode::FAILURE;
300 ATH_MSG_DEBUG(
" calling metaDataStop for " << (*it)->name());
302 if ( (*it)->metaDataStop().isFailure() ) {
303 ATH_MSG_ERROR(
"Unable to call metaDataStop for " << (*it)->name());
304 rc = StatusCode::FAILURE;
317 return StatusCode::FAILURE;
324 return StatusCode::FAILURE;
330 return StatusCode::FAILURE;
332 return StatusCode::SUCCESS;
337 const FileIncident* fileInc =
dynamic_cast<const FileIncident*
>(&inc);
338 if (fileInc ==
nullptr) {
339 ATH_MSG_ERROR(
"Unable to get FileName from EndInputFile incident");
342 const std::string
fileName = fileInc->fileName();
345 if (inc.type() ==
"FirstInputFile") {
347 using namespace boost::placeholders;
349 if (
m_fileMgr->regAction(boa, Io::OPEN).isFailure()) {
350 ATH_MSG_FATAL(
"Cannot register ROOT file open action with FileMgr.");
355 }
else if (inc.type() ==
"BeginInputFile") {
359 }
else if (inc.type() ==
"EndInputFile") {
373 FileIncident inc(
"transitionMetaDataFile",
"EndInputFile",
"dummyMetaInputFileName",
"");
379 Incident metaDataStopIncident(
name(),
"MetaDataStop");
380 m_incSvc->fireIncident(metaDataStopIncident);
391 return(StatusCode::SUCCESS);
401 ATH_MSG_INFO(
"Attached MetaDataTool: " << (*iter)->name());
404 return(StatusCode::SUCCESS);
408 return(StatusCode::SUCCESS);
415 if(
pos==std::string::npos )
return "";
427 return std::set<std::string>( {
key} );
433 std::string
fileName = tokenStr.substr(tokenStr.find(
"[FILE=") + 6);
435 std::string
className = tokenStr.substr(tokenStr.find(
"[PNAME=") + 7);
437 std::string contName = tokenStr.substr(tokenStr.find(
"[CONT=") + 6);
438 leftString(contName,
']');
439 std::size_t pos1 = contName.find(
'(');
440 std::string
keyName = contName.substr(pos1 + 1, contName.size() - pos1 - 2);
441 std::size_t pos2 =
keyName.find(
'/');
442 if (pos2 != std::string::npos)
keyName =
keyName.substr(pos2 + 1);
443 std::string numName = tokenStr.substr(tokenStr.find(
"[NUM=") + 5);
444 leftString(numName,
']');
445 unsigned long num = 0;
446 std::istringstream iss(numName);
449 if (clid == 167728019) {
450 bool foundTool =
false;
452 if ((*iter)->name() ==
"ToolSvc.CopyEventStreamInfo") foundTool =
true;
455 if (serviceLocator()->existsService(
"CutFlowSvc")) {
457 if (cfSvc.retrieve().isSuccess()) {
458 ATH_MSG_INFO(
"Disabling incidents for: " << cfSvc.name());
459 m_incSvc->removeListener(cfSvc.get(), IncidentType::BeginInputFile);
460 m_incSvc->removeListener(cfSvc.get(),
"MetaDataStop");
461 cfSvc.release().ignore();
464 if (serviceLocator()->existsService(
"xAODConfigSvc")) {
466 if (xcSvc.retrieve().isSuccess()) {
467 ATH_MSG_INFO(
"Disabling incidents for: " << xcSvc.name());
468 m_incSvc->removeListener(xcSvc.get(), IncidentType::BeginInputFile);
469 m_incSvc->removeListener(xcSvc.get(), IncidentType::BeginEvent);
470 xcSvc.release().ignore();
478 if( clid == 178309087 ) {
484 if( clid == 73252552 ) {
492 const unsigned long ipar[2] = {
num , 0 };
493 IOpaqueAddress* opqAddr =
nullptr;
500 ATH_MSG_FATAL(
"addProxyToInputMetaDataStore: Cannot create address for " << tokenStr);
501 return(StatusCode::FAILURE);
504 delete opqAddr; opqAddr =
nullptr;
505 ATH_MSG_FATAL(
"addProxyToInputMetaDataStore: Cannot create proxy for " << tokenStr);
506 return(StatusCode::FAILURE);
509 ATH_MSG_FATAL(
"addProxyToInputMetaDataStore: Cannot access data for " << tokenStr);
510 return(StatusCode::FAILURE);
514 ATH_MSG_WARNING(
"addProxyToInputMetaDataStore: Cannot symlink to AuxStore for " << tokenStr);
516 return(StatusCode::SUCCESS);
524 ATH_MSG_DEBUG(
"MetaDataSvc called without MetaDataContainer set.");
525 return(StatusCode::SUCCESS);
527 if (
fileName.starts_with(
"BSF:")) {
529 }
else if (
fileName.compare(0, 3,
"SHM")==0) {
534 for (
int verNumber = 0; verNumber < 100; verNumber++) {
537 ATH_MSG_DEBUG(
"initInputMetaDataStore: MetaData Store already contains DataHeader, key = " << myVersKey);
539 const unsigned long ipar[2] = { (
unsigned long)verNumber , 0 };
540 IOpaqueAddress* opqAddr =
nullptr;
547 delete opqAddr; opqAddr =
nullptr;
548 ATH_MSG_WARNING(
"initInputMetaDataStore: Cannot create proxy for DataHeader, key = " << myVersKey);
552 std::list<SG::TransientAddress*> tList;
555 return StatusCode::FAILURE;
558 CLID clid = tad->clID();
559 ATH_MSG_VERBOSE(
"initInputMetaDataStore: add proxy for clid = " << clid <<
", key = " << tad->name());
561 ATH_MSG_DEBUG(
"initInputMetaDataStore: MetaData Store already contains clid = " << clid <<
", key = " << tad->name());
564 ATH_MSG_ERROR(
"initInputMetaDataStore: Cannot create proxy for clid = " << clid <<
", key = " << tad->name());
565 return StatusCode::FAILURE;
569 for (
CLID tclid : tad->transientID()) {
573 clid <<
"/" << tad->name() <<
" to " << tclid);
582 return(StatusCode::SUCCESS);
596 ATH_MSG_DEBUG(
"Not translating metadata item ID #" << itemID);
600 std::string itemName;
602 if (
m_classIDSvc->getTypeNameOfID(itemID, itemName).isSuccess()) {
603 const std::string contName =
"MetaCont<" + itemName +
">";
604 ATH_MSG_DEBUG(
"Transforming " << contName <<
" to " << itemName
606 if (
m_classIDSvc->getIDOfTypeName(contName, contID).isSuccess())
622 <<
" ClassID: " << itemID);
634 <<
" ClassID: " << itemID);