|
DAS
3.0
Das Analysis System
|
Go to the documentation of this file.
23 #include <source_location>
73 std::vector<std::filesystem::path>
inputs;
75 std::unique_ptr<ChainSlice>
tIn;
76 std::shared_ptr<TFile>
fOut;
77 std::unique_ptr<TTree>
tOut;
88 cout <<
"Flow: retrieving an existing branch" << endl;
90 return any_cast<shared_ptr<T*>>(branch);
92 catch (
const std::bad_any_cast& e) {
93 BOOST_THROW_EXCEPTION(e);
102 std::string what =
name +
" branch could not be found";
111 auto keys =
branches | std::views::keys;
112 return std::accumulate(keys.begin(), keys.end(), std::string(),
113 [](
const std::string& str,
const std::string& branch_name) {
114 return str +
' ' + branch_name;
123 const std::vector<std::filesystem::path>& = {}
134 [[deprecated(
"Give the input paths to the constructor")]]
136 (std::vector<std::filesystem::path>,
137 const Slice = {1, 0},
138 const std::string& =
"events");
143 (
const Slice = {1, 0},
144 const std::string& =
"events");
151 template<
typename THX = TH1,
size_t N>
153 (
const std::array<std::string, N>& names = {}
157 namespace fs = filesystem;
160 BOOST_THROW_EXCEPTION( runtime_error(
"Empty input list") );
162 array<unique_ptr<THX>, N> sums;
164 auto fIn = make_unique<TFile>(
input.c_str(),
"READ");
165 for (
size_t i = 0; i < N; ++i) {
166 const string&
name = names[i];
167 unique_ptr<THX> h(fIn->Get<THX>(
name.c_str()));
170 BOOST_THROW_EXCEPTION(
171 DE::BadInput(Form(
"`%s` cannot be found in (one of) the "
172 " file(s).",
name.c_str()), fIn));
175 sums[i]->Add(h.get());
177 sums[i] = std::move(h);
178 sums[i]->SetDirectory(
nullptr);
190 template<
typename THX = TH1,
typename... Args>
193 constexpr
const size_t N =
sizeof...(args);
194 std::array<std::string, N> names {{
args... }};
195 return GetInputHists<THX, N>(names);
202 template<
typename THX = TH1>
204 (
const std::string&
name)
206 auto hists = GetInputHists<THX,1>({
name});
207 THX * hist = hists.front().release();
208 return std::unique_ptr<THX>(hist);
225 const std::source_location = std::source_location::current());
230 const std::source_location = std::source_location::current());
242 std::pair<TFile *, TTree *>
GetOutput (
const std::filesystem::path&,
243 const std::source_location = std::source_location::current());
257 const std::string&
name,
263 BOOST_THROW_EXCEPTION( invalid_argument(
"`GetInputTree()` should "
264 "be called before declaring a read-only branch") );
271 t = GetBranch<T>(
name);
273 t = make_shared<T*>();
275 cout <<
"Flow: loading branch `" <<
name <<
"`" << endl;
277 if (
tIn->GetBranch(
name.c_str()) ==
nullptr)
278 return NoBranch<T>(
name, mode);
280 int err =
tIn->SetBranchAddress(
name.c_str(), t.get());
282 cout <<
"Flow: `TTree::SetBranchAddress()` returned " << to_string(err)
283 <<
" (check `TTree::ESetBranchAddressStatus` for the meaning)."
286 string what =
"`"s +
name +
"` branch could not be set. "s;
289 cout <<
orange <<
"Flow: " << what <<
def << endl;
313 BOOST_THROW_EXCEPTION( invalid_argument(
"`GetOutputTree()` should "
314 "be called before") );
319 t = GetBranch<T>(
name);
321 t = make_shared<T*>();
324 cout <<
"Flow: setting up new branch for `" <<
name <<
"`" << endl;
325 if (
tOut->Branch(
name.c_str(), t.get()) ==
nullptr) {
327 string what =
name +
" branch could not be set up";
351 BOOST_THROW_EXCEPTION( invalid_argument(
"`GetInputTree()` should "
352 "be called before declaring a read-write branch") );
355 BOOST_THROW_EXCEPTION( invalid_argument(
"`GetOutputTree()` should "
356 "be called before declaring a read-write branch") );
361 t = GetBranch<T>(
name);
363 if (GetBranchReadOnly<T>(
name, mode) ==
nullptr)
364 return NoBranch<T>(
name, mode);
366 GetBranchWriteOnly<T>(
name);
name
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:48
static const char * def
Definition: Step.h:36
args
Definition: Ntupliser_cfg.py:11
Handling of exceptions.
Definition: darwin.h:36
static const char * orange
Definition: colours.h:6
input
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:35