ATLAS Offline Software
AthenaOutputStreamTool.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef ATHENAOUTPUTSTREAMTOOL_H
6 #define ATHENAOUTPUTSTREAMTOOL_H
7 
12 #include "GaudiKernel/IConversionSvc.h"
13 #include "GaudiKernel/ServiceHandle.h"
14 
17 
18 #include <string>
19 #include <map>
20 #include <regex>
21 
22 class IClassIDSvc;
23 class IDecisionSvc;
24 class StoreGateSvc;
25 class DataHeader;
26 namespace SG {
27  class IFolder;
28 }
29 
33 class AthenaOutputStreamTool : public extends<::AthAlgTool, IAthenaOutputStreamTool> {
34 public:
36  AthenaOutputStreamTool(const std::string& type,
37  const std::string& name,
38  const IInterface* parent);
39 
41  virtual StatusCode initialize() override;
42 
46  StatusCode connectServices(const std::string& dataStore,
47  const std::string& cnvSvc,
48  bool extendProvenenceRecord) override;
49 
53  StatusCode connectOutput(const std::string& outputName = "") override;
54 
57  StatusCode commitOutput(bool doCommit = false) override;
58 
61  StatusCode finalizeOutput() override;
62 
66  typedef std::pair<std::string, std::string> TypeKeyPair;
67  typedef std::vector<TypeKeyPair> TypeKeyPairs;
68  virtual StatusCode streamObjects(const TypeKeyPairs& typeKeys, const std::string& outputName = "") override;
69 
75  typedef std::vector<DataObject*> DataObjectVec;
76  virtual StatusCode streamObjects(const DataObjectVec& dataObjects, const std::string& outputName = "") override;
77 
78  virtual StatusCode getInputItemList(SG::IFolder* m_p2BWrittenFromTool) override;
79 
80 private:
84  void propagateProvenance( const DataHeader& src_dh );
85 
86 private:
87  StringProperty m_outputName{ this, "OutputFile", "", "name of the output db name"};
88  StringProperty m_dataHeaderKey{ this, "DataHeaderKey", "", "name of the data header key: defaults to tool name"};
89  StringProperty m_processTag{ this, "ProcessingTag", "", "tag of processing stage: defaults to SG key of DataHeader (Stream name)"};
90  StringProperty m_outputCollection{ this, "OutputCollection", "", "custom container name prefix for DataHeader: default = "" (will result in \"POOLContainer_\")"};
91  StringProperty m_containerPrefix{ this, "PoolContainerPrefix", "", "prefix for top level POOL container: default = \"CollectionTree\""};
92  StringProperty m_containerNameHint{ this, "TopLevelContainerName", "0", "naming hint policy for top level POOL container: default = \"0\""};
93  StringProperty m_metaDataOutputCollection{ this, "MetaDataOutputCollection", "", "custom container name prefix for MetaDataHeader: default = "" (will result in \"MetaDataHdr\")"};
94  StringProperty m_metaDataContainerPrefix{ this, "MetaDataPoolContainerPrefix", "", "prefix for top level MetaData container: default = "" (will result in \"MetaData\")"};
95  StringProperty m_branchNameHint{ this, "SubLevelBranchName", "0", "naming hint policy for POOL branching: default = \"0\"" };
96  BooleanProperty m_extend{ this, "SaveDecisions", false, "Set to true to add streaming decisions to an attributeList"};
97 
98  std::string m_outputAttributes;
100  SG::ReadHandleKey<AthenaAttributeList> m_attrListKey{this, "AttributeListKey", "", "optional key for AttributeList to be written as part of the DataHeader: default = \"\""};
101  //SG::WriteHandleKey<AthenaAttributeList> m_attrListWrite{this, "AttributeListWrite", "", "optional key for AttributeList to be written as part of the DataHeader: default = <AttributeListKey>+\"Decisions\""};
102  std::string m_attrListWrite{""};
103 
104  ServiceHandle<StoreGateSvc> m_store{ this, "Store", "StoreGateSvc/DetectorStore", "Pointer to the data store"};
106  ServiceHandle<IConversionSvc> m_conversionSvc{ this, "ConversionService", "AthenaPoolCnvSvc" };
114  bool m_connectionOpen{false};
115 
119  std::string m_keepProvenancesStr;
123  std::map<std::string, bool> m_keepProvenanceMatch;
124 
126  std::set<std::string> m_skippedItems;
127 };
128 
129 #endif
AthenaOutputStreamTool::commitOutput
StatusCode commitOutput(bool doCommit=false) override
Commit the output stream after having streamed out objects Must commitOutput AFTER streaming.
Definition: AthenaOutputStreamTool.cxx:338
AthenaOutputStreamTool::propagateProvenance
void propagateProvenance(const DataHeader &src_dh)
copy provenance records when creating new DataHeaders
Definition: AthenaOutputStreamTool.cxx:283
AthenaOutputStreamTool::finalizeOutput
StatusCode finalizeOutput() override
Finalize the output stream after the last commit, e.g.
Definition: AthenaOutputStreamTool.cxx:350
AthenaOutputStreamTool::getInputItemList
virtual StatusCode getInputItemList(SG::IFolder *m_p2BWrittenFromTool) override
Definition: AthenaOutputStreamTool.cxx:533
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
AthenaOutputStreamTool::m_extend
BooleanProperty m_extend
Definition: AthenaOutputStreamTool.h:96
AthenaOutputStreamTool::m_dataHeader
DataHeader * m_dataHeader
Current DataHeader for streamed objects.
Definition: AthenaOutputStreamTool.h:112
AthenaOutputStreamTool::m_skippedItems
std::set< std::string > m_skippedItems
set of skipped item keys, because of missing CLID
Definition: AthenaOutputStreamTool.h:126
AthenaOutputStreamTool::m_metaDataContainerPrefix
StringProperty m_metaDataContainerPrefix
Definition: AthenaOutputStreamTool.h:94
AthenaOutputStreamTool::m_keepProvenancesStr
std::string m_keepProvenancesStr
RegEx string to match provenance tags to keep in the output DataHeader. Retrieved from an OutputStrea...
Definition: AthenaOutputStreamTool.h:119
AthenaOutputStreamTool::m_processTag
StringProperty m_processTag
Definition: AthenaOutputStreamTool.h:89
AthenaOutputStreamTool::m_keepProvenancesRE
std::regex m_keepProvenancesRE
RegEx pattern created from m_keepProvenancesStr.
Definition: AthenaOutputStreamTool.h:121
SG::ReadHandleKey< AthenaAttributeList >
AthenaOutputStreamTool::connectServices
StatusCode connectServices()
Do the real connection to services.
Definition: AthenaOutputStreamTool.cxx:150
SG::IFolder
a run-time configurable list of data objects
Definition: SGIFolder.h:21
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
AthenaOutputStreamTool::connectOutput
StatusCode connectOutput(const std::string &outputName="") override
Connect to the output stream Must connectOutput BEFORE streaming Only specify "outputName" if one wan...
Definition: AthenaOutputStreamTool.cxx:159
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
IAthenaOutputStreamTool.h
Interface to an output stream tool.
AthenaOutputStreamTool::m_containerNameHint
StringProperty m_containerNameHint
Definition: AthenaOutputStreamTool.h:92
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:120
IDecisionSvc
This class defines a protocol to register boolean decisions and.
Definition: IDecisionSvc.h:32
DataHeader
This class provides the layout for summary information stored for data written to POOL.
Definition: DataHeader.h:126
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthenaOutputStreamTool::m_dataHeaderKey
StringProperty m_dataHeaderKey
Definition: AthenaOutputStreamTool.h:88
AthAlgTool.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
AthenaOutputStreamTool::AthenaOutputStreamTool
AthenaOutputStreamTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard AlgTool Constructor.
Definition: AthenaOutputStreamTool.cxx:43
AthenaOutputStreamTool::m_containerPrefix
StringProperty m_containerPrefix
Definition: AthenaOutputStreamTool.h:91
AthenaOutputStreamTool::TypeKeyPairs
std::vector< TypeKeyPair > TypeKeyPairs
Definition: AthenaOutputStreamTool.h:67
AthenaOutputStreamTool::m_branchNameHint
StringProperty m_branchNameHint
Definition: AthenaOutputStreamTool.h:95
AthenaOutputStreamTool::m_outputCollection
StringProperty m_outputCollection
Definition: AthenaOutputStreamTool.h:90
AthenaOutputStreamTool::m_conversionSvc
ServiceHandle< IConversionSvc > m_conversionSvc
Keep reference to the data conversion service.
Definition: AthenaOutputStreamTool.h:106
AthenaOutputStreamTool::DataObjectVec
std::vector< DataObject * > DataObjectVec
Stream out a vector of objects Must convert to DataObject, e.g.
Definition: AthenaOutputStreamTool.h:75
AthenaOutputStreamTool::m_metaDataOutputCollection
StringProperty m_metaDataOutputCollection
Definition: AthenaOutputStreamTool.h:93
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
AthenaOutputStreamTool::m_metaDataOutputAttributes
std::string m_metaDataOutputAttributes
Definition: AthenaOutputStreamTool.h:99
lumiFormat.outputName
string outputName
Definition: lumiFormat.py:65
AthenaOutputStreamTool::m_outputAttributes
std::string m_outputAttributes
Definition: AthenaOutputStreamTool.h:98
AthenaOutputStreamTool::m_attrListKey
SG::ReadHandleKey< AthenaAttributeList > m_attrListKey
Definition: AthenaOutputStreamTool.h:100
AthenaOutputStreamTool::m_extendProvenanceRecord
bool m_extendProvenanceRecord
Flag as to whether to extend provenance via the DataHeader.
Definition: AthenaOutputStreamTool.h:117
AthenaOutputStreamTool::TypeKeyPair
std::pair< std::string, std::string > TypeKeyPair
Stream out objects.
Definition: AthenaOutputStreamTool.h:66
AthenaOutputStreamTool::m_store
ServiceHandle< StoreGateSvc > m_store
Definition: AthenaOutputStreamTool.h:104
AthenaOutputStreamTool::m_connectionOpen
bool m_connectionOpen
Flag to tell whether connectOutput has been called.
Definition: AthenaOutputStreamTool.h:114
AthenaOutputStreamTool::m_clidSvc
ServiceHandle< IClassIDSvc > m_clidSvc
Ref to ClassIDSvc to convert type name to clid.
Definition: AthenaOutputStreamTool.h:108
AthenaOutputStreamTool::m_decSvc
ServiceHandle< IDecisionSvc > m_decSvc
Ref to DecisionSvc.
Definition: AthenaOutputStreamTool.h:110
AthenaOutputStreamTool::m_keepProvenanceMatch
std::map< std::string, bool > m_keepProvenanceMatch
Cache provenance RegEx matching result in a map.
Definition: AthenaOutputStreamTool.h:123
AthenaOutputStreamTool
This is the implementation of IAthenaOutputStreamTool.
Definition: AthenaOutputStreamTool.h:33
AthenaOutputStreamTool::m_attrListWrite
std::string m_attrListWrite
Definition: AthenaOutputStreamTool.h:102
AthenaOutputStreamTool::streamObjects
virtual StatusCode streamObjects(const TypeKeyPairs &typeKeys, const std::string &outputName="") override
Definition: AthenaOutputStreamTool.cxx:361
ServiceHandle< StoreGateSvc >
AthenaOutputStreamTool::initialize
virtual StatusCode initialize() override
AthAlgTool Interface method implementations:
Definition: AthenaOutputStreamTool.cxx:50
AthenaOutputStreamTool::m_outputName
StringProperty m_outputName
Definition: AthenaOutputStreamTool.h:87