DAS  3.0
Das Analysis System
FileUtils.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPLv3-or-later
2 //
3 // SPDX-FileCopyrightText: Patrick L.S. Connor <patrick.connor@desy.de>
4 // SPDX-FileCopyrightText: Louis Moureaux <louis.moureaux@cern.ch>
5 
6 #pragma once
7 
8 #include "exceptions.h"
9 
10 #include <TChain.h>
11 #include <TFile.h>
12 #include <TH1.h>
13 #include <TTree.h>
14 
15 #include <filesystem>
16 #include <string>
17 #include <memory>
18 #include <vector>
19 
20 namespace Darwin::Tools {
21 
28 void StandardInit ();
29 
33 std::vector<std::filesystem::path> GetROOTfiles
34  (std::vector<std::filesystem::path> inputs);
35 
38 template<typename THX = TH1>
39 [[deprecated("Use Darwin::Tools::Flow::GetInputHist[s]()")]]
40 inline std::unique_ptr<THX> GetHist
41  (std::vector<std::filesystem::path> inputs,
42  const std::string& name = "h")
43 {
44  using namespace std;
45  namespace fs = filesystem;
46 
47  unique_ptr<THX> sum;
49  for (auto const& input: inputs) {
50  auto fIn = make_unique<TFile>(input.c_str(), "READ");
52  unique_ptr<THX> h(fIn->Get<THX>(name.c_str()));
53  if (!h) {
54  namespace DE = Darwin::Exceptions;
55  BOOST_THROW_EXCEPTION(DE::BadInput(Form("`%s` cannot be found in (one of) the "
56  " file(s).", name.c_str()), fIn));
57  }
58  if (sum)
59  sum->Add(h.get());
60  else {
61  sum = std::move(h);
62  sum->SetDirectory(nullptr);
63  }
64  }
65  return sum;
66 }
67 
73 std::string GetFirstTreeLocation
74  (const std::filesystem::path& input);
75 
78 std::shared_ptr<TFile> GetOutputFile (const std::filesystem::path&,
79  const std::source_location = std::source_location::current());
80 
81 } // namespace Darwin::Tools
Darwin::Tools::GetFirstTreeLocation
std::string GetFirstTreeLocation(const std::filesystem::path &input)
one input ROOT file
Definition: FileUtils.cc:64
DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.name
name
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:48
exceptions.h
Darwin::Tools::GetOutputFile
std::shared_ptr< TFile > GetOutputFile(const std::filesystem::path &, const std::source_location=std::source_location::current())
Shortcut to create a reproducible output file (see ROOT Doxygen for details)
Definition: FileUtils.cc:99
Darwin::Tools::StandardInit
void StandardInit()
Definition: FileUtils.cc:29
Darwin::Exceptions
Handling of exceptions.
Definition: darwin.h:36
DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.input
input
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:35
Darwin::Tools
Classes and functions related to the framework.
Definition: Dict_rdict.cxx:990
Darwin::Tools::GetHist
std::unique_ptr< THX > GetHist(std::vector< std::filesystem::path > inputs, const std::string &name="h")
Load a histogram from a list of files.
Definition: FileUtils.h:41
Darwin::Tools::GetROOTfiles
std::vector< std::filesystem::path > GetROOTfiles(std::vector< std::filesystem::path > inputs)
ROOT files or directories.
Definition: FileUtils.cc:37
jercExample.inputs
def inputs
Definition: jercExample.py:118
Darwin::Exceptions::BadInput
Generic exception for ill-defined input (before the event loop).
Definition: exceptions.h:83