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 
71  public:
72  TFile *file () const noexcept;
73 
74 
81  public:
82  void saveOutput ();
83 
84 
90  public:
91  void close ();
92 
93 
99  public:
100  std::string finalFileName () const;
101 
102 
113  public:
114  void addOutput (std::unique_ptr<TObject> outputObject);
115 
116 
124  public:
125  void addClone (const TObject& prototypeObject);
126 
127 
137  public:
138  TDirectory *makeDirectoryFor (std::string& name);
139 
140 
146  public:
147  TObject *getOutputHist (const std::string& name) const noexcept;
148 
149 
155  public:
156  TTree *getOutputTree (const std::string& name) const noexcept;
157 
158 
159 
160  //
161  // private interface
162  //
163 
165  private:
166  std::unique_ptr<SH::DiskWriter> m_writer;
167 
169  private:
170  std::vector<std::unique_ptr<TObject> > m_output;
171 
173  private:
174  std::unordered_map<std::string,TObject*> m_outputHistMap;
175 
177  private:
178  std::unordered_map<std::string,TTree*> m_outputTreeMap;
179  };
180  }
181 }
182 
183 #endif
EL::Detail::OutputStreamData::addOutput
void addOutput(std::unique_ptr< TObject > outputObject)
add the given output object to this stream
Definition: OutputStreamData.cxx:204
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:142
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:170
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:293
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:304
EL::Detail::OutputStreamData::addClone
void addClone(const TObject &prototypeObject)
add a clone of the given object to the output
Definition: OutputStreamData.cxx:241
EL::Detail::ManagerStep::final
@ final
EL::Detail::OutputStreamData::close
void close()
close this file
Definition: OutputStreamData.cxx:153
EL::Detail::OutputStreamData::m_writer
std::unique_ptr< SH::DiskWriter > m_writer
the writer we use
Definition: OutputStreamData.h:166
EL::Detail::OutputStreamData::m_outputTreeMap
std::unordered_map< std::string, TTree * > m_outputTreeMap
the output tree map
Definition: OutputStreamData.h:178
EL::Detail::OutputStreamData::finalFileName
std::string finalFileName() const
the final path of the file created
Definition: OutputStreamData.cxx:163
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: AlgorithmWorkerData.h:24
Preparation.mode
mode
Definition: Preparation.py:95
EL::Detail::OutputStreamData::testInvariant
void testInvariant() const
test the invariant of this object
Definition: OutputStreamData.cxx:106
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
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:264
TH1
Definition: rootspy.cxx:268
EL::Detail::OutputStreamData::m_outputHistMap
std::unordered_map< std::string, TObject * > m_outputHistMap
the output histogram map
Definition: OutputStreamData.h:174
EL::Detail::OutputStreamData::saveOutput
void saveOutput()
write the list of output objects to disk and clear it
Definition: OutputStreamData.cxx:172
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