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 )
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);
118 m_incSvc->addListener(
this,
"BeginInputMemFile", 80,
true);
119 m_incSvc->addListener(
this,
"EndInputMemFile", 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()) {
168 return(StatusCode::SUCCESS);
175 Incident metaDataStopIncident(name(),
"MetaDataStop");
176 m_incSvc->fireIncident(metaDataStopIncident);
177 return(StatusCode::SUCCESS);
183 return(StatusCode::SUCCESS);
186 std::list<SG::ObjectWithVersion<DataHeader> > allVersions;
188 if (!
sc.isSuccess()) {
189 ATH_MSG_WARNING(
"Could not retrieve all versions for DataHeader, will not read Metadata");
194 const DataHeader* dataHeader = obj.dataObject.cptr();
195 if (dataHeader ==
nullptr) {
196 ATH_MSG_ERROR(
"Could not get DataHeader, will not read Metadata");
197 return(StatusCode::FAILURE);
200 const CLID clid = dhe.getPrimaryClassID();
203 std::string key = dhe.getKey();
204 if (verNumber != 0) {
212 return(StatusCode::SUCCESS);
217 const FileIncident* fileInc =
dynamic_cast<const FileIncident*
>(&inc);
218 if (fileInc ==
nullptr) {
219 ATH_MSG_ERROR(
"Unable to get FileName from EndInputFile incident");
220 return StatusCode::FAILURE;
222 const std::string guid = fileInc->fileGuid();
223 const std::string fileName = fileInc->fileName();
226 if (!fileName.starts_with(
"BSF:")) {
236 StatusCode
rc{StatusCode::SUCCESS};
238 ATH_MSG_DEBUG(
" calling beginInputFile on " << tool->name() <<
" for GUID \"" << guid <<
"\"");
239 if (tool->beginInputFile(guid).isFailure()) {
240 ATH_MSG_ERROR(
"Unable to call beginInputFile for " << tool->name());
241 rc = StatusCode::FAILURE;
249 const FileIncident* fileInc =
dynamic_cast<const FileIncident*
>(&inc);
250 if (fileInc ==
nullptr) {
251 ATH_MSG_ERROR(
"Unable to get FileName from EndInputFile incident");
252 return StatusCode::FAILURE;
254 const std::string guid = fileInc->fileGuid();
255 ATH_MSG_DEBUG(
"retireMetadataSource: " << fileInc->fileName());
257 ATH_MSG_DEBUG(
" calling endInputFile on " << tool->name() <<
" for GUID \"" << guid <<
"\"");
261 return StatusCode::SUCCESS;
267 return StatusCode::SUCCESS;
270 StatusCode
rc{StatusCode::SUCCESS};
273 if (tool->metaDataStop().isFailure()) {
274 ATH_MSG_ERROR(
"Unable to call metaDataStop for " << tool->name());
275 rc = StatusCode::FAILURE;
290 if( outputName.empty() ) {
295 StatusCode
rc{StatusCode::SUCCESS};
299 if (tool->metaDataStop().isFailure()) {
300 ATH_MSG_ERROR(
"Unable to call metaDataStop for " << tool->name());
301 rc = StatusCode::FAILURE;
320 return StatusCode::SUCCESS;
325 const FileIncident* fileInc =
dynamic_cast<const FileIncident*
>(&inc);
326 if (fileInc ==
nullptr) {
327 ATH_MSG_ERROR(
"Unable to get FileName from EndInputFile incident");
330 const std::string fileName = fileInc->fileName();
331 ATH_MSG_DEBUG(
"handle() " << inc.type() <<
" for " << fileName);
333 if (inc.type() ==
"FirstInputFile") {
335 using namespace boost::placeholders;
337 if (
m_fileMgr->regAction(std::move(boa), Io::OPEN).isFailure()) {
338 ATH_MSG_FATAL(
"Cannot register ROOT file open action with FileMgr.");
343 }
else if (inc.type() ==
"BeginInputFile" || inc.type() ==
"BeginInputMemFile") {
345 ATH_MSG_ERROR(
"Could not process new metadata source " << fileName);
347 }
else if (inc.type() ==
"EndInputFile" || inc.type() ==
"EndInputMemFile") {
349 ATH_MSG_ERROR(
"Could not retire metadata source " << fileName);
361 FileIncident inc(
"transitionMetaDataFile",
"EndInputFile",
"dummyMetaInputFileName",
"");
367 Incident metaDataStopIncident(name(),
"MetaDataStop");
368 m_incSvc->fireIncident(metaDataStopIncident);
379 return(StatusCode::SUCCESS);
388 ATH_MSG_INFO(
"Attached MetaDataTool: " << tool->name());
391 return(StatusCode::SUCCESS);
395 return(StatusCode::SUCCESS);
402 if( pos==std::string::npos )
return "";
403 size_t epos = key.find(
']', pos);
405 std::string stream = key.substr( spos, epos - spos );
407 key = key.substr(0, pos) + key.substr(epos+1);
421 std::string fileName = tokenStr.substr(tokenStr.find(
"[FILE=") + 6);
422 leftString(fileName,
']');
423 std::string className = tokenStr.substr(tokenStr.find(
"[PNAME=") + 7);
424 leftString(className,
']');
425 std::string contName = tokenStr.substr(tokenStr.find(
"[CONT=") + 6);
426 leftString(contName,
']');
427 std::size_t pos1 = contName.find(
'(');
428 std::string keyName = contName.substr(pos1 + 1, contName.size() - pos1 - 2);
429 std::size_t pos2 = keyName.find(
'/');
430 if (pos2 != std::string::npos) keyName = keyName.substr(pos2 + 1);
431 std::string numName = tokenStr.substr(tokenStr.find(
"[NUM=") + 5);
432 leftString(numName,
']');
433 unsigned long num = 0;
434 std::istringstream iss(numName);
440 if( clid == 178309087 ) {
441 std::string newName = std::format(
"{}{}{}{}", keyName,
m_streamInKeyMark, fileName,
"]");
444 keyName = std::move(newName);
446 if( clid == 73252552 ) {
447 std::string newName = std::format(
"{}{}{}]{}",
454 keyName = std::move(newName);
456 const std::string par[3] = {
"SHM" , keyName , std::move(className) };
457 const unsigned long ipar[2] = { num , 0 };
458 IOpaqueAddress* opqAddr =
nullptr;
461 ATH_MSG_DEBUG(
"Resetting duplicate proxy for: " << clid <<
"#" << keyName <<
" from file: " << fileName);
465 ATH_MSG_FATAL(
"addProxyToInputMetaDataStore: Cannot create address for " << tokenStr);
466 return(StatusCode::FAILURE);
469 ATH_MSG_FATAL(
"addProxyToInputMetaDataStore: Cannot create proxy for " << tokenStr);
470 return(StatusCode::FAILURE);
473 ATH_MSG_FATAL(
"addProxyToInputMetaDataStore: Cannot access data for " << tokenStr);
474 return(StatusCode::FAILURE);
478 ATH_MSG_WARNING(
"addProxyToInputMetaDataStore: Cannot symlink to AuxStore for " << tokenStr);
480 return(StatusCode::SUCCESS);
484 ATH_MSG_DEBUG(
"initInputMetaDataStore: file name " << fileName);
488 ATH_MSG_DEBUG(
"MetaDataSvc called without MetaDataContainer set.");
489 return(StatusCode::SUCCESS);
491 if (fileName.starts_with(
"BSF:")) {
493 }
else if (fileName.compare(0, 3,
"SHM")==0) {
496 const std::string par[2] = {
500 const std::string parOld[2] = {
504 for (
int verNumber = 0; verNumber < 100; verNumber++) {
507 ATH_MSG_DEBUG(
"initInputMetaDataStore: MetaData Store already contains DataHeader, key = " << myVersKey);
509 const unsigned long ipar[2] = { (
unsigned long)verNumber , 0 };
510 IOpaqueAddress* opqAddr =
nullptr;
517 ATH_MSG_WARNING(
"initInputMetaDataStore: Cannot create proxy for DataHeader, key = " << myVersKey);
521 std::list<SG::TransientAddress*> tList;
524 CLID clid = tad->clID();
525 ATH_MSG_VERBOSE(
"initInputMetaDataStore: add proxy for clid = " << clid <<
", key = " << tad->name());
527 ATH_MSG_DEBUG(
"initInputMetaDataStore: MetaData Store already contains clid = " << clid <<
", key = " << tad->name());
530 ATH_MSG_ERROR(
"initInputMetaDataStore: Cannot create proxy for clid = " << clid <<
", key = " << tad->name());
531 return StatusCode::FAILURE;
535 for (
CLID tclid : tad->transientID()) {
539 clid <<
"/" << tad->name() <<
" to " << tclid);
548 return(StatusCode::SUCCESS);
561 ATH_MSG_DEBUG(
"Not translating metadata item ID #" << itemID);
565 std::string itemName;
567 if (
m_classIDSvc->getTypeNameOfID(itemID, itemName).isSuccess()) {
568 const std::string contName = std::format(
"MetaCont<{}>", itemName);
569 ATH_MSG_DEBUG(
"Transforming " << contName <<
" to " << itemName
571 if (
m_classIDSvc->getIDOfTypeName(contName, contID).isSuccess())
579 const std::string& typeName = System::typeinfoName(typeInfo);
583 if (
m_classIDSvc->getIDOfTypeInfoName(typeName, itemID).isSuccess()) {
587 <<
" ClassID: " << itemID);
592 const std::string& typeName = System::typeinfoName(typeInfo);
596 if (
m_classIDSvc->getIDOfTypeInfoName(typeName, itemID).isSuccess()) {
598 ATH_MSG_DEBUG(
"MetaDataSvc will no longer handle " << typeName
599 <<
" 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()