ATLAS Offline Software
AthenaOutputStream.h
Go to the documentation of this file.
1 // Dear emacs, this is -*- C++ -*-
2 
3 /*
4  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 #ifndef ATHENASERVICES_ATHENAOUTPUTSTREAM_H
8 #define ATHENASERVICES_ATHENAOUTPUTSTREAM_H
9 
10 // STL include files
11 #include <memory>
12 #include <map>
13 #include <set>
14 #include <vector>
15 #include <string>
16 #include <mutex>
17 
18 // Required for inheritance
19 #include "GaudiKernel/IDataSelector.h"
20 #include "Gaudi/Property.h"
21 #include "GaudiKernel/ServiceHandle.h"
22 #include "GaudiKernel/ToolHandle.h"
23 
24 #include "GaudiKernel/IIncidentListener.h"
27 #include "GaudiKernel/IIoComponent.h"
28 
29 #include "SelectionVetoes.h"
30 #include "CompressionInfo.h"
31 
32 // forward declarations
33 class IClassIDSvc;
35 class StoreGateSvc;
37 class IAthenaOutputTool;
38 class IItemListSvc;
39 class IDictLoaderSvc;
40 class ITPCnvSvc;
41 class MetaDataSvc;
42 
43 namespace SG {
44  class DataProxy;
45  class IFolder;
46  class IAuxStoreIO;
47  class FolderItem;
48 }
49 
54 class AthenaOutputStream : public extends<FilteredAlgorithm,
55  IIncidentListener, IIoComponent> {
56 
57 public:
58  typedef std::vector<SG::DataProxy*> Items;
59 
60 protected:
66 
69 
72 
74 
76  std::string m_persName;
78  StringProperty m_writingTool;
80  std::string m_outputName;
81  std::string m_outputAttributes;
82 
86 
88  StringProperty m_streamName{this, "StreamName", "", "name of the output stream"};
90  StringArrayProperty m_itemList{this,"ItemList",{},"List of items to write","OutputStreamItemList"};
92  StringArrayProperty m_metadataItemList{this,"MetadataItemList",{},"List of metadata items to write","OutputStreamItemList"};
94  StringArrayProperty m_excludeList{this,"ExcludeList",{},"List of metadata items to write","OrderedSet<std::string>"};
96  StringArrayProperty m_compressionListHigh;
98  StringArrayProperty m_compressionListLow;
100  unsigned int m_compressionBitsHigh;
102  unsigned int m_compressionBitsLow;
105  StringArrayProperty m_transientItems;
107  ToolHandle<SG::IFolder> m_p2BWritten;
109  ToolHandle<SG::IFolder> m_decoder;
111  ToolHandle<SG::IFolder> m_compressionDecoderHigh;
113  ToolHandle<SG::IFolder> m_compressionDecoderLow;
115  ToolHandle<SG::IFolder> m_transient;
117  std::multimap<CLID,std::string> m_CLIDKeyPairs;
119  IDataSelector m_objects;
121  IDataSelector m_altObjects;
125  std::vector<std::unique_ptr<DataObject> > m_ownedObjects;
127  std::atomic<int> m_events;
142  typedef std::map<std::string, unsigned int> CounterMapType;
144 
146  ToolHandle<IAthenaOutputStreamTool> m_streamer;
148  ToolHandleArray<IAthenaOutputTool> m_helperTools;
149 
150  // flag set by MetaDataStop if OutputSequencer is used with EndEvent
152 
153  // ------- Event Ranges handling in MT -------
155  std::map< unsigned, std::string > m_slotRangeMap;
156 
158  std::map< std::string, std::string > m_rangeIDforRangeFN;
159 
161  std::map< std::string, std::unique_ptr<IAthenaOutputStreamTool> > m_streamerMap;
163  typedef std::recursive_mutex mutex_t;
165 
166 private:
170  { this, "SelVetoesKey", "" };
171 
175  { this, "CompInfoKey", "" };
176 
177 protected:
179  void itemListHandler(Gaudi::Details::PropertyBase& /* theProp */);
181  void excludeListHandler(Gaudi::Details::PropertyBase& /* theProp */);
183  void compressionListHandlerHigh(Gaudi::Details::PropertyBase& /* theProp */);
185  void compressionListHandlerLow(Gaudi::Details::PropertyBase& /* theProp */);
186 
187 public:
188  typedef std::vector<std::pair<std::string, std::string> > TypeKeyPairs;
189 
191  AthenaOutputStream(const std::string& name, ISvcLocator* pSvcLocator);
193  virtual ~AthenaOutputStream();
194 
196 
197  virtual StatusCode initialize() override;
198  virtual StatusCode finalize() override;
199  virtual StatusCode execute() override;
200  virtual StatusCode stop() override;
202  virtual StatusCode write();
205  void clearSelection();
209  IDataSelector* selectedObjects() {
210  return &m_objects;
211  }
213  virtual void handle(const Incident& incident) override;
215  virtual StatusCode io_reinit() override;
216  virtual StatusCode io_finalize() override;
217 
218 private:
221 
222  void handleVariableSelection (const SG::IConstAuxStore& auxstore,
223  SG::DataProxy& itemProxy,
224  const std::string& tns,
225  const std::string& aux_attr,
226  SG::SelectionVetoes& vetoes) const;
227 
229  void tokenizeAtSep( std::vector<std::string>&, const std::string&, const std::string& ) const;
230 
232  bool matchKey(const std::vector<std::string>& key, const std::string& proxyName) const;
233 
235  void writeMetaData( const std::string& outputFN="" );
236 
238  std::set<std::string> buildCompressionSet (const ToolHandle<SG::IFolder>& handle,
239  const CLID& item_id,
240  const std::string& item_key) const;
241 
242  // close an EventService substream that was writing to 'rangeFN' output
243  void finalizeRange( const std::string & rangeFN );
244 
250  void loadDict (CLID clid);
251 };
252 
253 #endif // ATHENASERVICES_OUTPUTSTREAM_H
AthenaOutputStream::finalize
virtual StatusCode finalize() override
Definition: AthenaOutputStream.cxx:533
AthenaOutputStream::m_rangeIDforRangeFN
std::map< std::string, std::string > m_rangeIDforRangeFN
map of RangeIDs (as used by the Sequencer) for each Range filename generated
Definition: AthenaOutputStream.h:158
AthenaOutputStream::writeMetaData
void writeMetaData(const std::string &outputFN="")
Write MetaData for this stream (by default) or for a substream outputFN (in ES mode)
Definition: AthenaOutputStream.cxx:465
AthenaOutputStream::m_outputAttributes
std::string m_outputAttributes
Definition: AthenaOutputStream.h:81
FilteredAlgorithm.h
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
IDictLoaderSvc
Definition: IDictLoaderSvc.h:37
AthenaOutputStream::addItemObjects
StatusCode addItemObjects(const SG::FolderItem &, SG::SelectionVetoes &vetoes, SG::CompressionInfo &compInfo)
Add item data objects to output streamer list.
Definition: AthenaOutputStream.cxx:769
AthenaOutputStream::m_compressionBitsHigh
unsigned int m_compressionBitsHigh
Number of mantissa bits in the float compression.
Definition: AthenaOutputStream.h:100
AthenaOutputStream::m_CLIDKeyPairs
std::multimap< CLID, std::string > m_CLIDKeyPairs
map of (clid,key) pairs to be excluded (comes from m_excludeList)
Definition: AthenaOutputStream.h:117
AthenaOutputStream::tokenizeAtSep
void tokenizeAtSep(std::vector< std::string > &, const std::string &, const std::string &) const
tokenize a string based on a substring
Definition: AthenaOutputStream.cxx:1166
AthenaOutputStream::m_decoder
ToolHandle< SG::IFolder > m_decoder
the top-level folder with items to be written
Definition: AthenaOutputStream.h:109
AthenaOutputStream::m_itemList
StringArrayProperty m_itemList
Vector of item names.
Definition: AthenaOutputStream.h:90
AthenaOutputStream::buildCompressionSet
std::set< std::string > buildCompressionSet(const ToolHandle< SG::IFolder > &handle, const CLID &item_id, const std::string &item_key) const
Helper function for building the compression lists.
Definition: AthenaOutputStream.cxx:1034
AthenaOutputStream::m_dataStore
ServiceHandle< StoreGateSvc > m_dataStore
handle to the StoreGateSvc store where the data we want to write out resides
Definition: AthenaOutputStream.h:63
AthenaOutputStream::m_pCLIDSvc
IClassIDSvc_t m_pCLIDSvc
Definition: AthenaOutputStream.h:84
AthenaOutputStream::m_compressionListLow
StringArrayProperty m_compressionListLow
Vector of item names.
Definition: AthenaOutputStream.h:98
AthenaOutputStream::m_writingTool
StringProperty m_writingTool
Name of the OutputStreamTool used for writing.
Definition: AthenaOutputStream.h:78
AthenaOutputStream::mutex_t
std::recursive_mutex mutex_t
mutex for this Stream write() and handle() methods
Definition: AthenaOutputStream.h:163
AthenaOutputStream::IClassIDSvc_t
ServiceHandle< IClassIDSvc > IClassIDSvc_t
Definition: AthenaOutputStream.h:83
SG::SelectionVetoes
std::unordered_map< std::string, SG::auxid_set_t > SelectionVetoes
Map of vetoed variables.
Definition: SelectionVetoes.h:50
AthenaOutputStream::m_persName
std::string m_persName
Name of the persistency service capable to write data from the store.
Definition: AthenaOutputStream.h:76
IAthenaOutputStreamTool
This is a tool that allows streaming out of DataObjects. This has been factorized out from AthenaOutp...
Definition: IAthenaOutputStreamTool.h:69
AthenaOutputStream::matchKey
bool matchKey(const std::vector< std::string > &key, const std::string &proxyName) const
Try to match a DataProxy name to a vector of strings.
Definition: AthenaOutputStream.cxx:1188
AthenaOutputStream::initialize
virtual StatusCode initialize() override
Definition: AthenaOutputStream.cxx:211
AthenaOutputStream::Items
std::vector< SG::DataProxy * > Items
Definition: AthenaOutputStream.h:58
AthenaOutputStream::selectedObjects
IDataSelector * selectedObjects()
Return the list of selected objects.
Definition: AthenaOutputStream.h:209
AthenaOutputStream::loadDict
void loadDict(CLID clid)
Helper function to load dictionaries (both transient and persistent) for a given type.
Definition: AthenaOutputStream.cxx:1270
AthenaOutputStream::m_transientItems
StringArrayProperty m_transientItems
List of items that are known to be present in the transient store (and hence we can make input depend...
Definition: AthenaOutputStream.h:105
AthenaOutputStream::m_objects
IDataSelector m_objects
Collection of objects being selected.
Definition: AthenaOutputStream.h:119
AthenaOutputStream::m_metadataItemList
StringArrayProperty m_metadataItemList
Vector of item names.
Definition: AthenaOutputStream.h:92
AthenaOutputStream::m_currentStore
ServiceHandle< StoreGateSvc > * m_currentStore
Definition: AthenaOutputStream.h:65
AthenaOutputStream::collectAllObjects
StatusCode collectAllObjects()
Collect data objects for output streamer list.
Definition: AthenaOutputStream.cxx:707
IItemListSvc
This class defines a protocol to register boolean decisions and.
Definition: IItemListSvc.h:33
AthenaOutputStream::m_checkNumberOfWrites
bool m_checkNumberOfWrites
set to true to check for number of times each object is written
Definition: AthenaOutputStream.h:140
AthenaOutputStream::m_compressionListHigh
StringArrayProperty m_compressionListHigh
Vector of item names.
Definition: AthenaOutputStream.h:96
AthenaOutputStream::m_forceRead
bool m_forceRead
set to true to force read of data objects in item list
Definition: AthenaOutputStream.h:129
AthenaOutputStream::m_writeOnExecute
bool m_writeOnExecute
set to true to trigger streaming of data on execute()
Definition: AthenaOutputStream.h:134
AthenaOutputStream::m_streamer
ToolHandle< IAthenaOutputStreamTool > m_streamer
pointer to AthenaOutputStreamTool
Definition: AthenaOutputStream.h:146
AthenaOutputStream::m_outSeqSvc
ServiceHandle< OutputStreamSequencerSvc > m_outSeqSvc
Definition: AthenaOutputStream.h:85
AthenaOutputStream::m_compressionBitsLow
unsigned int m_compressionBitsLow
Number of mantissa bits in the float compression.
Definition: AthenaOutputStream.h:102
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:125
AthenaOutputStream::m_extendProvenanceRecord
bool m_extendProvenanceRecord
set to false to omit adding the current DataHeader into the DataHeader history this will cause the in...
Definition: AthenaOutputStream.h:132
SG::WriteHandleKey< SG::SelectionVetoes >
AthenaOutputStream::AthenaOutputStream
AthenaOutputStream(const std::string &name, ISvcLocator *pSvcLocator)
Standard algorithm Constructor.
Definition: AthenaOutputStream.cxx:156
AthenaOutputStream::m_itemSvc
ServiceHandle< IItemListSvc > m_itemSvc
Definition: AthenaOutputStream.h:67
AthenaOutputStream::m_slotRangeMap
std::map< unsigned, std::string > m_slotRangeMap
map of filenames assigned to active slots
Definition: AthenaOutputStream.h:155
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthenaOutputStream::compressionListHandlerLow
void compressionListHandlerLow(Gaudi::Details::PropertyBase &)
Handler for ItemNames Property.
Definition: AthenaOutputStream.cxx:1157
DataProxy
DataProxy provides the registry services for StoreGate.
Definition: DataProxy.h:31
MetaDataSvc
Manages the content of the metadata stores.
Definition: MetaDataSvc.h:89
AthenaOutputStream::m_itemListFromTool
bool m_itemListFromTool
set to write out everything in input DataHeader
Definition: AthenaOutputStream.h:138
AthenaOutputStream::m_helperTools
ToolHandleArray< IAthenaOutputTool > m_helperTools
vector of AlgTools that that are executed by this stream
Definition: AthenaOutputStream.h:148
AthenaOutputStream::m_ownedObjects
std::vector< std::unique_ptr< DataObject > > m_ownedObjects
Collection of DataObject instances owned by this service.
Definition: AthenaOutputStream.h:125
AthenaOutputStream::excludeListHandler
void excludeListHandler(Gaudi::Details::PropertyBase &)
Handler for ItemNames Property.
Definition: AthenaOutputStream.cxx:1139
AthenaOutputStream::compressionListHandlerHigh
void compressionListHandlerHigh(Gaudi::Details::PropertyBase &)
Handler for ItemNames Property.
Definition: AthenaOutputStream.cxx:1148
AthenaOutputStream::handleVariableSelection
void handleVariableSelection(const SG::IConstAuxStore &auxstore, SG::DataProxy &itemProxy, const std::string &tns, const std::string &aux_attr, SG::SelectionVetoes &vetoes) const
Definition: AthenaOutputStream.cxx:1077
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
AthenaOutputStream::io_finalize
virtual StatusCode io_finalize() override
Definition: AthenaOutputStream.cxx:1248
AthenaOutputStream::m_writeMetadataAndDisconnect
bool m_writeMetadataAndDisconnect
Definition: AthenaOutputStream.h:151
AthenaOutputStream::m_transient
ToolHandle< SG::IFolder > m_transient
Decoded list of transient ids.
Definition: AthenaOutputStream.h:115
AthenaOutputStream::finalizeRange
void finalizeRange(const std::string &rangeFN)
Definition: AthenaOutputStream.cxx:444
AthenaOutputStream::m_incidentSvc
ServiceHandle< IIncidentSvc > m_incidentSvc
Definition: AthenaOutputStream.h:73
SG::CompressionInfo
std::unordered_map< std::string, SG::ThinningInfo::compression_map_t > CompressionInfo
Map of compressed variables and their compression levels.
Definition: CompressionInfo.h:37
AthenaOutputStream::m_outputName
std::string m_outputName
Name of the output file.
Definition: AthenaOutputStream.h:80
AthenaOutputStream::itemListHandler
void itemListHandler(Gaudi::Details::PropertyBase &)
Handler for ItemNames Property.
Definition: AthenaOutputStream.cxx:1129
AthenaOutputStream::TypeKeyPairs
std::vector< std::pair< std::string, std::string > > TypeKeyPairs
Definition: AthenaOutputStream.h:188
AthenaOutputStream::stop
virtual StatusCode stop() override
Definition: AthenaOutputStream.cxx:361
WriteHandleKey.h
Property holding a SG store/key/clid from which a WriteHandle is made.
OutputStreamSequencerSvc
This class provides configuration properties to enable OutputStream file sequences.
Definition: OutputStreamSequencerSvc.h:30
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AthenaOutputStream::m_metadataStore
ServiceHandle< StoreGateSvc > m_metadataStore
Definition: AthenaOutputStream.h:64
AthenaOutputStream::io_reinit
virtual StatusCode io_reinit() override
Callback method to reinitialize the internal state of the component for I/O purposes (e....
Definition: AthenaOutputStream.cxx:1231
IAthenaOutputTool
This class provides the interface for AthenaOutputTool classes used by AthenaOutputStream.
Definition: IAthenaOutputTool.h:20
AthenaOutputStream::m_tpCnvSvc
ServiceHandle< ITPCnvSvc > m_tpCnvSvc
Definition: AthenaOutputStream.h:71
AthenaOutputStream::m_streamName
StringProperty m_streamName
Stream name (defaults to algorithm name)
Definition: AthenaOutputStream.h:88
AthenaOutputStream::m_altObjects
IDataSelector m_altObjects
Objects overridden by ‘exact’ handling.
Definition: AthenaOutputStream.h:121
AthenaOutputStream::m_dictLoader
ServiceHandle< IDictLoaderSvc > m_dictLoader
Definition: AthenaOutputStream.h:70
AthenaOutputStream::m_metaDataSvc
ServiceHandle< MetaDataSvc > m_metaDataSvc
Definition: AthenaOutputStream.h:68
AthenaOutputStream::m_events
std::atomic< int > m_events
Number of events written to this output stream.
Definition: AthenaOutputStream.h:127
AthenaOutputStream::m_compressionDecoderHigh
ToolHandle< SG::IFolder > m_compressionDecoderHigh
the top-level folder with items to be compressed high
Definition: AthenaOutputStream.h:111
AthenaOutputStream::m_mutex
mutex_t m_mutex
Definition: AthenaOutputStream.h:164
AthenaOutputStream
algorithm that marks for write data objects in SG
Definition: AthenaOutputStream.h:55
AthenaOutputStream::execute
virtual StatusCode execute() override
Definition: AthenaOutputStream.cxx:559
AthenaOutputStream::m_streamerMap
std::map< std::string, std::unique_ptr< IAthenaOutputStreamTool > > m_streamerMap
map of streamerTools handling event ranges in MT
Definition: AthenaOutputStream.h:161
AthenaOutputStream::m_objectWriteCounter
CounterMapType m_objectWriteCounter
Definition: AthenaOutputStream.h:143
ITPCnvSvc
Definition: ITPCnvSvc.h:29
SelectionVetoes.h
CompressionInfo.h
AthenaOutputStream::write
virtual StatusCode write()
Stream the data.
Definition: AthenaOutputStream.cxx:592
AthenaOutputStream::m_selVetoesKey
SG::WriteHandleKey< SG::SelectionVetoes > m_selVetoesKey
Key used for recording selected dynamic variable information to the event store.
Definition: AthenaOutputStream.h:170
SG::IConstAuxStore
Interface for const operations on an auxiliary store.
Definition: IConstAuxStore.h:64
AthenaOutputStream::m_writeOnFinalize
bool m_writeOnFinalize
set to true to trigger streaming of data on finalize()
Definition: AthenaOutputStream.h:136
GetLBsToIgnore.outputFN
outputFN
Definition: GetLBsToIgnore.py:225
SG::DataProxy
Definition: DataProxy.h:44
SG::FolderItem
a Folder item (data object) is identified by the clid/key pair
Definition: SGFolderItem.h:24
AthenaOutputStream::m_excludeList
StringArrayProperty m_excludeList
Vector of item names.
Definition: AthenaOutputStream.h:94
AthenaOutputStream::handle
virtual void handle(const Incident &incident) override
Incident service handle listening for MetaDataStop.
Definition: AthenaOutputStream.cxx:368
AthenaOutputStream::m_p2BWritten
ToolHandle< SG::IFolder > m_p2BWritten
the top-level folder with items to be written
Definition: AthenaOutputStream.h:107
AthenaOutputStream::CounterMapType
std::map< std::string, unsigned int > CounterMapType
map to record number of writes per object
Definition: AthenaOutputStream.h:142
AthenaOutputStream::clearSelection
void clearSelection()
Clear list of selected objects.
Definition: AthenaOutputStream.cxx:701
AthenaOutputStream::m_compressionDecoderLow
ToolHandle< SG::IFolder > m_compressionDecoderLow
the top-level folder with items to be compressed low
Definition: AthenaOutputStream.h:113
ServiceHandle< StoreGateSvc >
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
AthenaOutputStream::~AthenaOutputStream
virtual ~AthenaOutputStream()
Standard Destructor.
Definition: AthenaOutputStream.cxx:206
AthenaOutputStream::m_compInfoKey
SG::WriteHandleKey< SG::CompressionInfo > m_compInfoKey
Key used for recording lossy float compressed variable information to the event store.
Definition: AthenaOutputStream.h:175