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 
57  virtual public IIncidentListener,
58  virtual public IIoComponent {
59 
60 public:
61  typedef std::vector<SG::DataProxy*> Items;
62 
63 protected:
69 
72 
75 
77  std::string m_persName;
79  StringProperty m_writingTool;
81  std::string m_outputName;
82  std::string m_outputAttributes;
83 
87 
89  StringProperty m_streamName{this, "StreamName", "", "name of the output stream"};
91  StringArrayProperty m_itemList{this,"ItemList",{},"List of items to write","OutputStreamItemList"};
93  StringArrayProperty m_metadataItemList{this,"MetadataItemList",{},"List of metadata items to write","OutputStreamItemList"};
95  StringArrayProperty m_excludeList{this,"ExcludeList",{},"List of metadata items to write","OrderedSet<std::string>"};
97  StringArrayProperty m_compressionListHigh;
99  StringArrayProperty m_compressionListLow;
101  unsigned int m_compressionBitsHigh;
103  unsigned int m_compressionBitsLow;
106  StringArrayProperty m_transientItems;
108  ToolHandle<SG::IFolder> m_p2BWritten;
110  ToolHandle<SG::IFolder> m_decoder;
112  ToolHandle<SG::IFolder> m_compressionDecoderHigh;
114  ToolHandle<SG::IFolder> m_compressionDecoderLow;
116  ToolHandle<SG::IFolder> m_transient;
118  std::multimap<CLID,std::string> m_CLIDKeyPairs;
120  IDataSelector m_objects;
122  IDataSelector m_altObjects;
126  std::vector<std::unique_ptr<DataObject> > m_ownedObjects;
128  std::atomic<int> m_events;
143  typedef std::map<std::string, unsigned int> CounterMapType;
145 
147  ToolHandle<IAthenaOutputStreamTool> m_streamer;
149  ToolHandleArray<IAthenaOutputTool> m_helperTools;
150 
151  // flag set by MetaDataStop if OutputSequencer is used with EndEvent
153 
154  // ------- Event Ranges handling in MT -------
156  std::map< unsigned, std::string > m_slotRangeMap;
157 
159  std::map< std::string, std::string > m_rangeIDforRangeFN;
160 
162  std::map< std::string, std::unique_ptr<IAthenaOutputStreamTool> > m_streamerMap;
164  typedef std::recursive_mutex mutex_t;
166 
167 private:
171  { this, "SelVetoesKey", "" };
172 
176  { this, "CompInfoKey", "" };
177 
178 protected:
180  void itemListHandler(Gaudi::Details::PropertyBase& /* theProp */);
182  void excludeListHandler(Gaudi::Details::PropertyBase& /* theProp */);
184  void compressionListHandlerHigh(Gaudi::Details::PropertyBase& /* theProp */);
186  void compressionListHandlerLow(Gaudi::Details::PropertyBase& /* theProp */);
187 
188 public:
189  typedef std::vector<std::pair<std::string, std::string> > TypeKeyPairs;
190 
192  AthenaOutputStream(const std::string& name, ISvcLocator* pSvcLocator);
194  virtual ~AthenaOutputStream();
195 
197 
198  virtual StatusCode initialize() override;
199  virtual StatusCode finalize() override;
200  virtual StatusCode execute() override;
201  virtual StatusCode stop() override;
203  virtual StatusCode write();
206  void clearSelection();
210  IDataSelector* selectedObjects() {
211  return &m_objects;
212  }
214  virtual void handle(const Incident& incident) override;
216  virtual StatusCode io_reinit() override;
217  virtual StatusCode io_finalize() override;
218 
219 private:
222 
223  void handleVariableSelection (const SG::IConstAuxStore& auxstore,
224  SG::DataProxy& itemProxy,
225  const std::string& tns,
226  const std::string& aux_attr,
227  SG::SelectionVetoes& vetoes) const;
228 
230  void tokenizeAtSep( std::vector<std::string>&, const std::string&, const std::string& ) const;
231 
233  bool matchKey(const std::vector<std::string>& key, const std::string& proxyName) const;
234 
236  void writeMetaData( const std::string& outputFN="" );
237 
239  std::set<std::string> buildCompressionSet (const ToolHandle<SG::IFolder>& handle,
240  const CLID& item_id,
241  const std::string& item_key) const;
242 
243  // close an EventService substream that was writing to 'rangeFN' output
244  void finalizeRange( const std::string & rangeFN );
245 
251  void loadDict (CLID clid);
252 };
253 
254 #endif // ATHENASERVICES_OUTPUTSTREAM_H
AthenaOutputStream::finalize
virtual StatusCode finalize() override
Definition: AthenaOutputStream.cxx:526
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:159
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:467
AthenaOutputStream::m_outputAttributes
std::string m_outputAttributes
Definition: AthenaOutputStream.h:82
FilteredAlgorithm
algorithm that marks for write data objects in SG
Definition: FilteredAlgorithm.h:33
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:765
AthenaOutputStream::m_compressionBitsHigh
unsigned int m_compressionBitsHigh
Number of mantissa bits in the float compression.
Definition: AthenaOutputStream.h:101
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:118
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:1162
AthenaOutputStream::m_decoder
ToolHandle< SG::IFolder > m_decoder
the top-level folder with items to be written
Definition: AthenaOutputStream.h:110
AthenaOutputStream::m_itemList
StringArrayProperty m_itemList
Vector of item names.
Definition: AthenaOutputStream.h:91
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:1030
AthenaOutputStream::m_dataStore
ServiceHandle< StoreGateSvc > m_dataStore
handle to the StoreGateSvc store where the data we want to write out resides
Definition: AthenaOutputStream.h:66
AthenaOutputStream::m_pCLIDSvc
IClassIDSvc_t m_pCLIDSvc
Definition: AthenaOutputStream.h:85
AthenaOutputStream::m_compressionListLow
StringArrayProperty m_compressionListLow
Vector of item names.
Definition: AthenaOutputStream.h:99
AthenaOutputStream::m_writingTool
StringProperty m_writingTool
Name of the OutputStreamTool used for writing.
Definition: AthenaOutputStream.h:79
AthenaOutputStream::mutex_t
std::recursive_mutex mutex_t
mutex for this Stream write() and handle() methods
Definition: AthenaOutputStream.h:164
AthenaOutputStream::IClassIDSvc_t
ServiceHandle< IClassIDSvc > IClassIDSvc_t
Definition: AthenaOutputStream.h:84
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:77
IAthenaOutputStreamTool
This is a tool that allows streaming out of DataObjects. This has been factorized out from AthenaOutp...
Definition: IAthenaOutputStreamTool.h:70
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:1184
AthenaOutputStream::initialize
virtual StatusCode initialize() override
Definition: AthenaOutputStream.cxx:209
AthenaOutputStream::Items
std::vector< SG::DataProxy * > Items
Definition: AthenaOutputStream.h:61
AthenaOutputStream::selectedObjects
IDataSelector * selectedObjects()
Return the list of selected objects.
Definition: AthenaOutputStream.h:210
AthenaOutputStream::loadDict
void loadDict(CLID clid)
Helper function to load dictionaries (both transient and persistent) for a given type.
Definition: AthenaOutputStream.cxx:1276
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:106
AthenaOutputStream::m_objects
IDataSelector m_objects
Collection of objects being selected.
Definition: AthenaOutputStream.h:120
AthenaOutputStream::m_metadataItemList
StringArrayProperty m_metadataItemList
Vector of item names.
Definition: AthenaOutputStream.h:93
AthenaOutputStream::m_currentStore
ServiceHandle< StoreGateSvc > * m_currentStore
Definition: AthenaOutputStream.h:68
AthenaOutputStream::collectAllObjects
StatusCode collectAllObjects()
Collect data objects for output streamer list.
Definition: AthenaOutputStream.cxx:703
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:141
AthenaOutputStream::m_compressionListHigh
StringArrayProperty m_compressionListHigh
Vector of item names.
Definition: AthenaOutputStream.h:97
AthenaOutputStream::m_forceRead
bool m_forceRead
set to true to force read of data objects in item list
Definition: AthenaOutputStream.h:130
AthenaOutputStream::m_writeOnExecute
bool m_writeOnExecute
set to true to trigger streaming of data on execute()
Definition: AthenaOutputStream.h:135
AthenaOutputStream::m_streamer
ToolHandle< IAthenaOutputStreamTool > m_streamer
pointer to AthenaOutputStreamTool
Definition: AthenaOutputStream.h:147
AthenaOutputStream::m_outSeqSvc
ServiceHandle< OutputStreamSequencerSvc > m_outSeqSvc
Definition: AthenaOutputStream.h:86
AthenaOutputStream::m_compressionBitsLow
unsigned int m_compressionBitsLow
Number of mantissa bits in the float compression.
Definition: AthenaOutputStream.h:103
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
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:133
SG::WriteHandleKey< SG::SelectionVetoes >
AthenaOutputStream::AthenaOutputStream
AthenaOutputStream(const std::string &name, ISvcLocator *pSvcLocator)
Standard algorithm Constructor.
Definition: AthenaOutputStream.cxx:155
AthenaOutputStream::m_itemSvc
ServiceHandle< IItemListSvc > m_itemSvc
Definition: AthenaOutputStream.h:70
AthenaOutputStream::m_slotRangeMap
std::map< unsigned, std::string > m_slotRangeMap
map of filenames assigned to active slots
Definition: AthenaOutputStream.h:156
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:1153
DataProxy
DataProxy provides the registry services for StoreGate.
Definition: DataProxy.h:31
MetaDataSvc
Manages the content of the metadata stores.
Definition: MetaDataSvc.h:95
AthenaOutputStream::m_itemListFromTool
bool m_itemListFromTool
set to write out everything in input DataHeader
Definition: AthenaOutputStream.h:139
AthenaOutputStream::m_helperTools
ToolHandleArray< IAthenaOutputTool > m_helperTools
vector of AlgTools that that are executed by this stream
Definition: AthenaOutputStream.h:149
AthenaOutputStream::m_ownedObjects
std::vector< std::unique_ptr< DataObject > > m_ownedObjects
Collection of DataObject instances owned by this service.
Definition: AthenaOutputStream.h:126
AthenaOutputStream::excludeListHandler
void excludeListHandler(Gaudi::Details::PropertyBase &)
Handler for ItemNames Property.
Definition: AthenaOutputStream.cxx:1135
AthenaOutputStream::compressionListHandlerHigh
void compressionListHandlerHigh(Gaudi::Details::PropertyBase &)
Handler for ItemNames Property.
Definition: AthenaOutputStream.cxx:1144
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:1073
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:1249
AthenaOutputStream::m_writeMetadataAndDisconnect
bool m_writeMetadataAndDisconnect
Definition: AthenaOutputStream.h:152
AthenaOutputStream::m_transient
ToolHandle< SG::IFolder > m_transient
Decoded list of transient ids.
Definition: AthenaOutputStream.h:116
AthenaOutputStream::finalizeRange
void finalizeRange(const std::string &rangeFN)
Definition: AthenaOutputStream.cxx:446
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:81
AthenaOutputStream::itemListHandler
void itemListHandler(Gaudi::Details::PropertyBase &)
Handler for ItemNames Property.
Definition: AthenaOutputStream.cxx:1125
AthenaOutputStream::TypeKeyPairs
std::vector< std::pair< std::string, std::string > > TypeKeyPairs
Definition: AthenaOutputStream.h:189
AthenaOutputStream::stop
virtual StatusCode stop() override
Definition: AthenaOutputStream.cxx:363
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:33
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
AthenaOutputStream::m_metadataStore
ServiceHandle< StoreGateSvc > m_metadataStore
Definition: AthenaOutputStream.h:67
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:1227
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:74
AthenaOutputStream::m_streamName
StringProperty m_streamName
Stream name (defaults to algorithm name)
Definition: AthenaOutputStream.h:89
AthenaOutputStream::m_altObjects
IDataSelector m_altObjects
Objects overridden by ‘exact’ handling.
Definition: AthenaOutputStream.h:122
AthenaOutputStream::m_dictLoader
ServiceHandle< IDictLoaderSvc > m_dictLoader
Definition: AthenaOutputStream.h:73
AthenaOutputStream::m_metaDataSvc
ServiceHandle< MetaDataSvc > m_metaDataSvc
Definition: AthenaOutputStream.h:71
AthenaOutputStream::m_events
std::atomic< int > m_events
Number of events written to this output stream.
Definition: AthenaOutputStream.h:128
AthenaOutputStream::m_compressionDecoderHigh
ToolHandle< SG::IFolder > m_compressionDecoderHigh
the top-level folder with items to be compressed high
Definition: AthenaOutputStream.h:112
AthenaOutputStream::m_mutex
mutex_t m_mutex
Definition: AthenaOutputStream.h:165
AthenaOutputStream
algorithm that marks for write data objects in SG
Definition: AthenaOutputStream.h:58
AthenaOutputStream::execute
virtual StatusCode execute() override
Definition: AthenaOutputStream.cxx:552
AthenaOutputStream::m_streamerMap
std::map< std::string, std::unique_ptr< IAthenaOutputStreamTool > > m_streamerMap
map of streamerTools handling event ranges in MT
Definition: AthenaOutputStream.h:162
AthenaOutputStream::m_objectWriteCounter
CounterMapType m_objectWriteCounter
Definition: AthenaOutputStream.h:144
ITPCnvSvc
Definition: ITPCnvSvc.h:29
SelectionVetoes.h
CompressionInfo.h
AthenaOutputStream::write
virtual StatusCode write()
Stream the data.
Definition: AthenaOutputStream.cxx:585
AthenaOutputStream::m_selVetoesKey
SG::WriteHandleKey< SG::SelectionVetoes > m_selVetoesKey
Key used for recording selected dynamic variable information to the event store.
Definition: AthenaOutputStream.h:171
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:137
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:95
AthenaOutputStream::handle
virtual void handle(const Incident &incident) override
Incident service handle listening for MetaDataStop.
Definition: AthenaOutputStream.cxx:370
AthenaOutputStream::m_p2BWritten
ToolHandle< SG::IFolder > m_p2BWritten
the top-level folder with items to be written
Definition: AthenaOutputStream.h:108
AthenaOutputStream::CounterMapType
std::map< std::string, unsigned int > CounterMapType
map to record number of writes per object
Definition: AthenaOutputStream.h:143
AthenaOutputStream::clearSelection
void clearSelection()
Clear list of selected objects.
Definition: AthenaOutputStream.cxx:697
AthenaOutputStream::m_compressionDecoderLow
ToolHandle< SG::IFolder > m_compressionDecoderLow
the top-level folder with items to be compressed low
Definition: AthenaOutputStream.h:114
ServiceHandle< StoreGateSvc >
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
AthenaOutputStream::~AthenaOutputStream
virtual ~AthenaOutputStream()
Standard Destructor.
Definition: AthenaOutputStream.cxx:204
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:176