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()) {
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");
191 const DataHeader* dataHeader = obj.dataObject.cptr();
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) {
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:")) {
232 StatusCode
rc{StatusCode::SUCCESS};
234 ATH_MSG_DEBUG(
" calling beginInputFile on " << tool->name() <<
" for GUID \"" << guid <<
"\"");
235 if (tool->beginInputFile(guid).isFailure()) {
236 ATH_MSG_ERROR(
"Unable to call beginInputFile for " << tool->name());
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());
253 ATH_MSG_DEBUG(
" calling endInputFile on " << tool->name() <<
" for GUID \"" << guid <<
"\"");
257 return StatusCode::SUCCESS;
263 return StatusCode::SUCCESS;
266 StatusCode
rc{StatusCode::SUCCESS};
269 if (tool->metaDataStop().isFailure()) {
270 ATH_MSG_ERROR(
"Unable to call metaDataStop for " << tool->name());
271 rc = StatusCode::FAILURE;
286 if( outputName.empty() ) {
291 StatusCode
rc{StatusCode::SUCCESS};
295 if (tool->metaDataStop().isFailure()) {
296 ATH_MSG_ERROR(
"Unable to call metaDataStop for " << tool->name());
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();
327 ATH_MSG_DEBUG(
"handle() " << inc.type() <<
" for " << 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" || inc.type() ==
"BeginInputMemFile") {
341 ATH_MSG_ERROR(
"Could not process new metadata source " << fileName);
343 }
else if (inc.type() ==
"EndInputFile" || inc.type() ==
"EndInputMemFile") {
345 ATH_MSG_ERROR(
"Could not retire metadata source " << fileName);
357 FileIncident inc(
"transitionMetaDataFile",
"EndInputFile",
"dummyMetaInputFileName",
"");
363 Incident metaDataStopIncident(name(),
"MetaDataStop");
364 m_incSvc->fireIncident(metaDataStopIncident);
375 return(StatusCode::SUCCESS);
384 ATH_MSG_INFO(
"Attached MetaDataTool: " << tool->name());
387 return(StatusCode::SUCCESS);
391 return(StatusCode::SUCCESS);
398 if( pos==std::string::npos )
return "";
399 size_t epos = key.find(
']', pos);
401 std::string stream = key.substr( spos, epos - spos );
403 key = key.substr(0, pos) + key.substr(epos+1);
417 std::string fileName = tokenStr.substr(tokenStr.find(
"[FILE=") + 6);
418 leftString(fileName,
']');
419 std::string className = tokenStr.substr(tokenStr.find(
"[PNAME=") + 7);
420 leftString(className,
']');
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);
436 if( clid == 178309087 ) {
437 std::string newName = std::format(
"{}{}{}{}", keyName,
m_streamInKeyMark, fileName,
"]");
440 keyName = std::move(newName);
442 if( clid == 73252552 ) {
443 std::string newName = std::format(
"{}{}{}]{}",
450 keyName = std::move(newName);
452 const std::string par[3] = {
"SHM" , keyName , std::move(className) };
453 const unsigned long ipar[2] = { num , 0 };
454 IOpaqueAddress* opqAddr =
nullptr;
457 ATH_MSG_DEBUG(
"Resetting duplicate proxy for: " << clid <<
"#" << keyName <<
" from file: " << fileName);
461 ATH_MSG_FATAL(
"addProxyToInputMetaDataStore: Cannot create address for " << tokenStr);
462 return(StatusCode::FAILURE);
465 ATH_MSG_FATAL(
"addProxyToInputMetaDataStore: Cannot create proxy for " << tokenStr);
466 return(StatusCode::FAILURE);
469 ATH_MSG_FATAL(
"addProxyToInputMetaDataStore: Cannot access data for " << tokenStr);
470 return(StatusCode::FAILURE);
474 ATH_MSG_WARNING(
"addProxyToInputMetaDataStore: Cannot symlink to AuxStore for " << tokenStr);
476 return(StatusCode::SUCCESS);
480 ATH_MSG_DEBUG(
"initInputMetaDataStore: file name " << fileName);
484 ATH_MSG_DEBUG(
"MetaDataSvc called without MetaDataContainer set.");
485 return(StatusCode::SUCCESS);
487 if (fileName.starts_with(
"BSF:")) {
489 }
else if (fileName.compare(0, 3,
"SHM")==0) {
492 const std::string par[2] = {
496 const std::string parOld[2] = {
500 for (
int verNumber = 0; verNumber < 100; verNumber++) {
503 ATH_MSG_DEBUG(
"initInputMetaDataStore: MetaData Store already contains DataHeader, key = " << myVersKey);
505 const unsigned long ipar[2] = { (
unsigned long)verNumber , 0 };
506 IOpaqueAddress* opqAddr =
nullptr;
513 ATH_MSG_WARNING(
"initInputMetaDataStore: Cannot create proxy for DataHeader, key = " << myVersKey);
517 std::list<SG::TransientAddress*> tList;
520 CLID clid = tad->clID();
521 ATH_MSG_VERBOSE(
"initInputMetaDataStore: add proxy for clid = " << clid <<
", key = " << tad->name());
523 ATH_MSG_DEBUG(
"initInputMetaDataStore: MetaData Store already contains clid = " << clid <<
", key = " << tad->name());
526 ATH_MSG_ERROR(
"initInputMetaDataStore: Cannot create proxy for clid = " << clid <<
", key = " << tad->name());
527 return StatusCode::FAILURE;
531 for (
CLID tclid : tad->transientID()) {
535 clid <<
"/" << tad->name() <<
" to " << tclid);
544 return(StatusCode::SUCCESS);
557 ATH_MSG_DEBUG(
"Not translating metadata item ID #" << itemID);
561 std::string itemName;
563 if (
m_classIDSvc->getTypeNameOfID(itemID, itemName).isSuccess()) {
564 const std::string contName = std::format(
"MetaCont<{}>", itemName);
565 ATH_MSG_DEBUG(
"Transforming " << contName <<
" to " << itemName
567 if (
m_classIDSvc->getIDOfTypeName(contName, contID).isSuccess())
575 const std::string& typeName = System::typeinfoName(typeInfo);
579 if (
m_classIDSvc->getIDOfTypeInfoName(typeName, itemID).isSuccess()) {
583 <<
" ClassID: " << itemID);
588 const std::string& typeName = System::typeinfoName(typeInfo);
592 if (
m_classIDSvc->getIDOfTypeInfoName(typeName, itemID).isSuccess()) {
594 ATH_MSG_DEBUG(
"MetaDataSvc will no longer handle " << typeName
595 <<
" 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.