33 class DirectoryReset {
38 ~DirectoryReset() { m_dir.cd(); }
46 struct MyWriter :
public SH::DiskWriter
52 std::unique_ptr<TFile> m_file;
54 explicit MyWriter (std::unique_ptr<TFile> val_file)
55 : m_file (std::move (val_file))
57 if (m_file ==
nullptr)
58 throw std::runtime_error (
"encountered null pointer for output file");
59 m_path = m_file->GetName();
68 std::string getPath ()
const
94 std::unique_ptr<TFile> checkedOpenFile (
const std::string& path,
const std::string& mode)
96 std::unique_ptr<TFile>
result (TFile::Open (
path.c_str(),
mode.c_str()));
97 if (result ==
nullptr)
98 throw std::runtime_error (
"failed to open file " + path +
" with mode " + mode);
105 void OutputStreamData ::
106 testInvariant ()
const
115 OutputStreamData (
const std::string& val_fileName,
const std::string& mode)
124 OutputStreamData (std::unique_ptr<TFile>
file)
133 OutputStreamData (std::unique_ptr<SH::DiskWriter> val_writer)
141 const std::string& OutputStreamData ::
142 mainStreamName ()
const noexcept
150 void OutputStreamData ::
151 setMainStreamName (
const std::string& val_mainStreamName)
155 throw std::runtime_error (
"main stream name already set");
161 TFile *OutputStreamData ::
162 file ()
const noexcept
172 void OutputStreamData ::
182 std::string OutputStreamData ::
183 finalFileName ()
const
191 void OutputStreamData ::
197 for (std::unique_ptr<TObject>&
object :
m_output)
199 std::string name =
object->GetName();
203 TNamed *named =
dynamic_cast<TNamed*
>(
object.get());
205 named->SetName (name.c_str());
210 dir->WriteObject (
object.
get(), name.c_str());
214 std::ignore =
object.release();
223 void OutputStreamData ::
224 addOutput (std::unique_ptr<TObject> outputObject)
228 TTree *
const tree =
dynamic_cast<TTree*
> (outputObject.get());
231 std::string name =
tree->GetName();
232 std::string treeName =
tree->GetName();
237 if (name != treeName)
238 tree->SetName (treeName.c_str());
241 tree->SetDirectory (dir);
242 outputObject.release();
249 TH1 *
const hist =
dynamic_cast<TH1*
> (outputObject.get());
252 m_output.emplace_back (std::move (outputObject));
254 hist->SetDirectory (
nullptr);
260 void OutputStreamData ::
261 addClone (
const TObject& prototypeObject)
267 DirectoryReset dirReset;
271 std::string name = prototypeObject.GetName();
275 std::unique_ptr<TObject> clone {prototypeObject.Clone()};
283 TDirectory *OutputStreamData ::
284 makeDirectoryFor (std::string& name)
289 std::string::size_type
split = name.rfind (
"/");
290 if (
split == std::string::npos)
296 name = name.substr (
split + 1);
297 TDirectory *subdir =
dynamic_cast<TDirectory*
>(
result->Get (
dirname.c_str()));
301 subdir =
dynamic_cast<TDirectory*
>(
result->Get (
dirname.c_str()));
312 TObject *OutputStreamData ::
313 getOutputHist (
const std::string& name)
const noexcept
323 TTree *OutputStreamData ::
324 getOutputTree (
const std::string& name)
const noexcept
#define RCU_CHANGE_INVARIANT(x)
#define RCU_REQUIRE2_SOFT(x, y)
#define RCU_NEW_INVARIANT(x)
#define RCU_READ_INVARIANT(x)
std::unordered_map< std::string, TObject * > m_outputHistMap
the output histogram map
TFile * file() const noexcept
the file we are writing to
TDirectory * makeDirectoryFor(std::string &name)
make the directory for the object of the given name
OutputStreamData(const std::string &val_fileName, const std::string &mode)
open the given file and create an output stream for it
void saveOutput()
write the list of output objects to disk and clear it
void addOutput(std::unique_ptr< TObject > outputObject)
add the given output object to this stream
std::vector< std::unique_ptr< TObject > > m_output
the list of objects to write out at the end of job
std::string m_mainStreamName
the name of the main stream
std::unique_ptr< SH::DiskWriter > m_writer
the writer we use
std::unordered_map< std::string, TTree * > m_outputTreeMap
the output tree map
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
std::vector< std::string > split(const std::string &s, const std::string &t=":")
This module defines the arguments passed from the BATCH driver to the BATCH worker.
bool SetDirectory(TObject *object, TDirectory *directory)
effects: set the directory this object is associated with returns: whether the object type actively k...
path
python interpreter configuration --------------------------------------—
std::string dirname(std::string name)