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"
41 bool leftString(std::string& s,
char sc) {
42 if (
const auto pos =
s.find(
sc); pos != std::string::npos) {
53 : base_class( name, pSvcLocator )
60 {
"EventStreamInfo_p3", 167728019 },
61 {
"ByteStreamMetadataContainer_p1", 1076128893 },
62 {
"IOVMetaDataContainer_p1", 1316383046 },
63 {
"xAOD::EventFormat_v1", 243004407 },
64 {
"xAOD::CutBookkeeperContainer_v1", 1234982351 },
65 {
"xAOD::CutBookkeeperAuxContainer_v1", 1147935274 },
66 {
"xAOD::TriggerMenuContainer_v1", 1107011239 },
67 {
"DataVector<xAOD::TriggerMenu_v1>", 1107011239 },
68 {
"xAOD::TriggerMenuAuxContainer_v1", 1212409402 },
69 {
"xAOD::TriggerMenuJsonContainer_v1", 1221262614 },
70 {
"DataVector<xAOD::TriggerMenuJson_v1>", 1221262614 },
71 {
"xAOD::TriggerMenuJsonAuxContainer_v1", 373045213 },
72 {
"xAOD::LumiBlockRangeContainer_v1", 1115934851 },
73 {
"DataVector<xAOD::LumiBlockRange_v1>", 1115934851 },
74 {
"xAOD::LumiBlockRangeAuxContainer_v1", 1251061086 },
75 {
"xAOD::FileMetaData_v1", 178309087 },
76 {
"xAOD::FileMetaDataAuxInfo_v1", 73252552 },
77 {
"xAOD::RingSetConfContainer_v1", 1157997427 },
78 {
"DataVector<xAOD::RingSetConf_v1>", 1157997427 },
79 {
"xAOD::RingSetConfAuxContainer_v1", 1307745126 },
80 {
"xAOD::TruthMetaDataContainer_v1", 1188015687 },
81 {
"DataVector<xAOD::TruthMetaData_v1>", 1188015687 },
82 {
"xAOD::TruthMetaDataAuxContainer_v1", 1094306618 } } {}
113 m_incSvc->addListener(
this,
"FirstInputFile", 80,
true);
114 m_incSvc->addListener(
this,
"BeginInputFile", 80,
true);
115 m_incSvc->addListener(
this,
"EndInputFile", 10,
true);
116 m_incSvc->addListener(
this,
"BeginInputMemFile", 80,
true);
117 m_incSvc->addListener(
this,
"EndInputMemFile", 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()) {
166 return(StatusCode::SUCCESS);
173 Incident metaDataStopIncident(name(),
"MetaDataStop");
174 m_incSvc->fireIncident(metaDataStopIncident);
175 return(StatusCode::SUCCESS);
181 return(StatusCode::SUCCESS);
184 std::list<SG::ObjectWithVersion<DataHeader> > allVersions;
186 if (!
sc.isSuccess()) {
187 ATH_MSG_WARNING(
"Could not retrieve all versions for DataHeader, will not read Metadata");
192 const DataHeader* dataHeader = obj.dataObject.cptr();
193 if (dataHeader ==
nullptr) {
194 ATH_MSG_ERROR(
"Could not get DataHeader, will not read Metadata");
195 return(StatusCode::FAILURE);
198 const CLID clid = dhe.getPrimaryClassID();
201 std::string key = dhe.getKey();
202 if (verNumber != 0) {
210 return(StatusCode::SUCCESS);
215 const FileIncident* fileInc =
dynamic_cast<const FileIncident*
>(&inc);
216 if (fileInc ==
nullptr) {
217 ATH_MSG_ERROR(
"Unable to get FileName from EndInputFile incident");
218 return StatusCode::FAILURE;
220 const std::string guid = fileInc->fileGuid();
221 const std::string fileName = fileInc->fileName();
224 if (!fileName.starts_with(
"BSF:")) {
234 StatusCode
rc{StatusCode::SUCCESS};
236 ATH_MSG_DEBUG(
" calling beginInputFile on " << tool->name() <<
" for GUID \"" << guid <<
"\"");
237 if (tool->beginInputFile(guid).isFailure()) {
238 ATH_MSG_ERROR(
"Unable to call beginInputFile for " << tool->name());
239 rc = StatusCode::FAILURE;
247 const FileIncident* fileInc =
dynamic_cast<const FileIncident*
>(&inc);
248 if (fileInc ==
nullptr) {
249 ATH_MSG_ERROR(
"Unable to get FileName from EndInputFile incident");
250 return StatusCode::FAILURE;
252 const std::string guid = fileInc->fileGuid();
253 ATH_MSG_DEBUG(
"retireMetadataSource: " << fileInc->fileName());
255 ATH_MSG_DEBUG(
" calling endInputFile on " << tool->name() <<
" for GUID \"" << guid <<
"\"");
259 return StatusCode::SUCCESS;
265 return StatusCode::SUCCESS;
268 StatusCode
rc{StatusCode::SUCCESS};
271 if (tool->metaDataStop().isFailure()) {
272 ATH_MSG_ERROR(
"Unable to call metaDataStop for " << tool->name());
273 rc = StatusCode::FAILURE;
288 if( outputName.empty() ) {
293 StatusCode
rc{StatusCode::SUCCESS};
297 if (tool->metaDataStop().isFailure()) {
298 ATH_MSG_ERROR(
"Unable to call metaDataStop for " << tool->name());
299 rc = StatusCode::FAILURE;
318 return StatusCode::SUCCESS;
323 const FileIncident* fileInc =
dynamic_cast<const FileIncident*
>(&inc);
324 if (fileInc ==
nullptr) {
325 ATH_MSG_ERROR(
"Unable to get FileName from EndInputFile incident");
328 const std::string fileName = fileInc->fileName();
329 ATH_MSG_DEBUG(
"handle() " << inc.type() <<
" for " << fileName);
331 if (inc.type() ==
"FirstInputFile") {
333 using namespace std::placeholders;
335 if (
m_fileMgr->regAction(std::move(boa), Io::OPEN).isFailure()) {
336 ATH_MSG_FATAL(
"Cannot register ROOT file open action with FileMgr.");
341 }
else if (inc.type() ==
"BeginInputFile" || inc.type() ==
"BeginInputMemFile") {
343 ATH_MSG_ERROR(
"Could not process new metadata source " << fileName);
345 }
else if (inc.type() ==
"EndInputFile" || inc.type() ==
"EndInputMemFile") {
347 ATH_MSG_ERROR(
"Could not retire metadata source " << fileName);
359 FileIncident inc(
"transitionMetaDataFile",
"EndInputFile",
"dummyMetaInputFileName",
"");
365 Incident metaDataStopIncident(name(),
"MetaDataStop");
366 m_incSvc->fireIncident(metaDataStopIncident);
377 return(StatusCode::SUCCESS);
386 ATH_MSG_INFO(
"Attached MetaDataTool: " << tool->name());
389 return(StatusCode::SUCCESS);
393 return(StatusCode::SUCCESS);
400 if( pos==std::string::npos )
return "";
401 size_t epos = key.find(
']', pos);
403 std::string stream = key.substr( spos, epos - spos );
405 key = key.substr(0, pos) + key.substr(epos+1);
419 std::string fileName = tokenStr.substr(tokenStr.find(
"[FILE=") + 6);
420 leftString(fileName,
']');
421 std::string className = tokenStr.substr(tokenStr.find(
"[PNAME=") + 7);
422 leftString(className,
']');
423 std::string contName = tokenStr.substr(tokenStr.find(
"[CONT=") + 6);
424 leftString(contName,
']');
425 std::size_t pos1 = contName.find(
'(');
426 std::string keyName = contName.substr(pos1 + 1, contName.size() - pos1 - 2);
427 std::size_t pos2 = keyName.find(
'/');
428 if (pos2 != std::string::npos) keyName = keyName.substr(pos2 + 1);
429 std::string numName = tokenStr.substr(tokenStr.find(
"[NUM=") + 5);
430 leftString(numName,
']');
431 unsigned long num = 0;
432 std::istringstream iss(numName);
438 if( clid == 178309087 ) {
439 std::string newName = std::format(
"{}{}{}{}", keyName,
m_streamInKeyMark, fileName,
"]");
442 keyName = std::move(newName);
444 if( clid == 73252552 ) {
445 std::string newName = std::format(
"{}{}{}]{}",
452 keyName = std::move(newName);
454 const std::string par[3] = {
"SHM" , keyName , std::move(className) };
455 const unsigned long ipar[2] = { num , 0 };
456 IOpaqueAddress* opqAddr =
nullptr;
459 ATH_MSG_DEBUG(
"Resetting duplicate proxy for: " << clid <<
"#" << keyName <<
" from file: " << fileName);
463 ATH_MSG_FATAL(
"addProxyToInputMetaDataStore: Cannot create address for " << tokenStr);
464 return(StatusCode::FAILURE);
467 ATH_MSG_FATAL(
"addProxyToInputMetaDataStore: Cannot create proxy for " << tokenStr);
468 return(StatusCode::FAILURE);
471 ATH_MSG_FATAL(
"addProxyToInputMetaDataStore: Cannot access data for " << tokenStr);
472 return(StatusCode::FAILURE);
476 ATH_MSG_WARNING(
"addProxyToInputMetaDataStore: Cannot symlink to AuxStore for " << tokenStr);
478 return(StatusCode::SUCCESS);
482 ATH_MSG_DEBUG(
"initInputMetaDataStore: file name " << fileName);
486 ATH_MSG_DEBUG(
"MetaDataSvc called without MetaDataContainer set.");
487 return(StatusCode::SUCCESS);
489 if (fileName.starts_with(
"BSF:")) {
491 }
else if (fileName.compare(0, 3,
"SHM")==0) {
494 const std::string par[2] = {
498 const std::string parOld[2] = {
502 for (
int verNumber = 0; verNumber < 100; verNumber++) {
505 ATH_MSG_DEBUG(
"initInputMetaDataStore: MetaData Store already contains DataHeader, key = " << myVersKey);
507 const unsigned long ipar[2] = { (
unsigned long)verNumber , 0 };
508 IOpaqueAddress* opqAddr =
nullptr;
515 ATH_MSG_WARNING(
"initInputMetaDataStore: Cannot create proxy for DataHeader, key = " << myVersKey);
519 std::list<SG::TransientAddress*> tList;
522 CLID clid = tad->clID();
523 ATH_MSG_VERBOSE(
"initInputMetaDataStore: add proxy for clid = " << clid <<
", key = " << tad->name());
525 ATH_MSG_DEBUG(
"initInputMetaDataStore: MetaData Store already contains clid = " << clid <<
", key = " << tad->name());
528 ATH_MSG_ERROR(
"initInputMetaDataStore: Cannot create proxy for clid = " << clid <<
", key = " << tad->name());
529 return StatusCode::FAILURE;
533 for (
CLID tclid : tad->transientID()) {
537 clid <<
"/" << tad->name() <<
" to " << tclid);
546 return(StatusCode::SUCCESS);
552 const EventContext& ctx = Gaudi::Hive::currentContext();
560 ATH_MSG_DEBUG(
"Not translating metadata item ID #" << itemID);
564 std::string itemName;
566 if (
m_classIDSvc->getTypeNameOfID(itemID, itemName).isSuccess()) {
567 const std::string contName = std::format(
"MetaCont<{}>", itemName);
568 ATH_MSG_DEBUG(
"Transforming " << contName <<
" to " << itemName
570 if (
m_classIDSvc->getIDOfTypeName(contName, contID).isSuccess())
578 const std::string& typeName = System::typeinfoName(typeInfo);
582 if (
m_classIDSvc->getIDOfTypeInfoName(typeName, itemID).isSuccess()) {
586 <<
" ClassID: " << itemID);
591 const std::string& typeName = System::typeinfoName(typeInfo);
595 if (
m_classIDSvc->getIDOfTypeInfoName(typeName, itemID).isSuccess()) {
597 ATH_MSG_DEBUG(
"MetaDataSvc will no longer handle " << typeName
598 <<
" ClassID: " << itemID);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
uint32_t CLID
The Class ID type.
This file contains the class definition for the OutputStreamSequencerSvc class.
defines a StoreGateSvc key with a version number
Base class for all conversion services.
virtual long repSvcType() const override
Retrieve the class type of the data store the converter uses.
virtual StatusCode disconnectOutput(const std::string &output)
Disconnect output files from the service.
std::list< SG::TransientAddress * > tadList
associate a data object with its VersionedKey The object is held by a ReadHandle to delay its retriev...
a StoreGateSvc key with a version number.
virtual StatusCode shmProxy(const std::string &filename) override
Loads file metadata from memory shared between streams in SharedWriter This function clears the input...
constexpr char AUX_POSTFIX[]
Common post-fix for the names of auxiliary containers in StoreGate.
static constexpr CLID ID()