ATLAS Offline Software
OutputStreamData.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 
9 #ifndef EVENT_LOOP__OUTPUT_STREAM_DATA_H
10 #define EVENT_LOOP__OUTPUT_STREAM_DATA_H
11 
12 #include <EventLoop/Global.h>
13 
15 #include <TFile.h>
16 #include <memory>
17 #include <unordered_map>
18 
19 class TH1;
20 class StatusCode;
21 class TTree;
22 
23 namespace EL
24 {
25  namespace Detail
26  {
28 
30  {
31  //
32  // public interface
33  //
34 
36  public:
37  void testInvariant () const;
38 
39 
45  public:
46  explicit OutputStreamData (const std::string& val_fileName, const std::string& mode);
47 
48 
54  public:
55  explicit OutputStreamData (std::unique_ptr<TFile> val_file);
56 
57 
63  public:
64  explicit OutputStreamData (std::unique_ptr<SH::DiskWriter> val_writer);
65 
66 
72  public:
73  const std::string& mainStreamName () const noexcept;
74  void setMainStreamName (const std::string& val_mainStreamName);
75 
76 
81  public:
82  TFile *file () const noexcept;
83 
84 
91  public:
92  void saveOutput ();
93 
94 
100  public:
101  void close ();
102 
103 
109  public:
110  std::string finalFileName () const;
111 
112 
123  public:
124  void addOutput (std::unique_ptr<TObject> outputObject);
125 
126 
134  public:
135  void addClone (const TObject& prototypeObject);
136 
137 
147  public:
148  TDirectory *makeDirectoryFor (std::string& name);
149 
150 
156  public:
157  TObject *getOutputHist (const std::string& name) const noexcept;
158 
159 
165  public:
166  TTree *getOutputTree (const std::string& name) const noexcept;
167 
168 
169 
170  //
171  // private interface
172  //
173 
175  private:
176  std::string m_mainStreamName;
177 
179  private:
180  std::unique_ptr<SH::DiskWriter> m_writer;
181 
183  private:
184  std::vector<std::unique_ptr<TObject> > m_output;
185 
187  private:
188  std::unordered_map<std::string,TObject*> m_outputHistMap;
189 
191  private:
192  std::unordered_map<std::string,TTree*> m_outputTreeMap;
193  };
194  }
195 }
196 
197 #endif
EL::Detail::OutputStreamData::addOutput
void addOutput(std::unique_ptr< TObject > outputObject)
add the given output object to this stream
Definition: OutputStreamData.cxx:224
EL::Detail::OutputStreamData::m_mainStreamName
std::string m_mainStreamName
the name of the main stream
Definition: OutputStreamData.h:176
EL::Detail::OutputStreamData
all data needed to manage a given output stream
Definition: OutputStreamData.h:30
EL::Detail::OutputStreamData::file
TFile * file() const noexcept
the file we are writing to
Definition: OutputStreamData.cxx:162
EL::Detail::OutputStreamData::m_output
std::vector< std::unique_ptr< TObject > > m_output
the list of objects to write out at the end of job
Definition: OutputStreamData.h:184
EL::Detail::OutputStreamData::getOutputHist
TObject * getOutputHist(const std::string &name) const noexcept
get the output histogram with the given name, or nullptr if there is no histogam with such a name
Definition: OutputStreamData.cxx:313
EL::Detail::OutputStreamData::getOutputTree
TTree * getOutputTree(const std::string &name) const noexcept
get the output tree with the given name, or nullptr if there is no tree with such a name
Definition: OutputStreamData.cxx:324
EL::Detail::OutputStreamData::addClone
void addClone(const TObject &prototypeObject)
add a clone of the given object to the output
Definition: OutputStreamData.cxx:261
EL::Detail::OutputStreamData::mainStreamName
const std::string & mainStreamName() const noexcept
the name of the main stream
Definition: OutputStreamData.cxx:142
EL::Detail::OutputStreamData::close
void close()
close this file
Definition: OutputStreamData.cxx:173
EL::Detail::OutputStreamData::setMainStreamName
void setMainStreamName(const std::string &val_mainStreamName)
Definition: OutputStreamData.cxx:151
EL::Detail::OutputStreamData::m_writer
std::unique_ptr< SH::DiskWriter > m_writer
the writer we use
Definition: OutputStreamData.h:180
EL::Detail::OutputStreamData::m_outputTreeMap
std::unordered_map< std::string, TTree * > m_outputTreeMap
the output tree map
Definition: OutputStreamData.h:192
EL::Detail::OutputStreamData::finalFileName
std::string finalFileName() const
the final path of the file created
Definition: OutputStreamData.cxx:183
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DiskWriter.h
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AsgComponentFactories.h:16
Preparation.mode
mode
Definition: Preparation.py:107
EL::Detail::OutputStreamData::testInvariant
void testInvariant() const
test the invariant of this object
Definition: OutputStreamData.cxx:106
columnar::final
CM final
Definition: ColumnAccessor.h:106
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
xAOD::DiTauJetParameters::Detail
Detail
Definition: DiTauDefs.h:38
EL::Detail::OutputStreamData::makeDirectoryFor
TDirectory * makeDirectoryFor(std::string &name)
make the directory for the object of the given name
Definition: OutputStreamData.cxx:284
EL::Detail::OutputStreamData::m_outputHistMap
std::unordered_map< std::string, TObject * > m_outputHistMap
the output histogram map
Definition: OutputStreamData.h:188
EL::Detail::OutputStreamData::saveOutput
void saveOutput()
write the list of output objects to disk and clear it
Definition: OutputStreamData.cxx:192
Global.h
EL::Detail::OutputStreamData::OutputStreamData
OutputStreamData(const std::string &val_fileName, const std::string &mode)
open the given file and create an output stream for it
Definition: OutputStreamData.cxx:115