|
DAS
3.0
Das Analysis System
|
Go to the documentation of this file.
23 #include <source_location>
36 using Slice = std::pair<int, int>;
42 return Stream << slice.second <<
'/' << slice.first;
82 std::vector<std::filesystem::path>
inputs;
84 std::unique_ptr<ChainSlice>
tIn;
85 std::shared_ptr<TFile>
fOut;
86 std::unique_ptr<TTree>
tOut;
88 std::map<std::string, std::any>
branches;
97 cout <<
"Flow: retrieving an existing branch" << endl;
99 return any_cast<shared_ptr<T*>>(branch);
101 catch (
const std::bad_any_cast& e) {
102 BOOST_THROW_EXCEPTION(e);
111 std::string what =
name +
" branch could not be found";
120 auto keys =
branches | std::views::keys;
121 return std::accumulate(keys.begin(), keys.end(), std::string(),
122 [](
const std::string& str,
const std::string& branch_name) {
123 return str +
' ' + branch_name;
132 const std::vector<std::filesystem::path>& = {}
144 (
const Slice = {1, 0},
145 const std::string& =
"events");
152 template<
typename THX = TH1,
size_t N>
154 (
const std::array<std::string, N>& names = {}
158 namespace fs = filesystem;
161 BOOST_THROW_EXCEPTION( runtime_error(
"Empty input list") );
163 array<unique_ptr<THX>, N> sums;
165 auto fIn = make_unique<TFile>(
input.c_str(),
"READ");
166 for (
size_t i = 0; i < N; ++i) {
167 const string&
name = names[i];
168 unique_ptr<THX> h(fIn->Get<THX>(
name.c_str()));
171 BOOST_THROW_EXCEPTION(
172 DE::BadInput(Form(
"`%s` cannot be found in (one of) the "
173 " file(s).",
name.c_str()), fIn));
176 sums[i]->Add(h.get());
178 sums[i] = std::move(h);
179 sums[i]->SetDirectory(
nullptr);
191 template<
typename THX = TH1,
typename... Args>
194 constexpr
const size_t N =
sizeof...(args);
195 std::array<std::string, N> names {{
args... }};
196 return GetInputHists<THX, N>(names);
203 template<
typename THX = TH1>
205 (
const std::string&
name)
207 auto hists = GetInputHists<THX,1>({
name});
208 THX * hist = hists.front().release();
209 return std::unique_ptr<THX>(hist);
226 const std::source_location = std::source_location::current());
231 const std::source_location = std::source_location::current());
243 std::pair<TFile *, TTree *>
GetOutput (
const std::filesystem::path&,
244 const std::source_location = std::source_location::current());
258 const std::string&
name,
264 BOOST_THROW_EXCEPTION( invalid_argument(
"`GetInputTree()` should "
265 "be called before declaring a read-only branch") );
272 t = GetBranch<T>(
name);
274 t = make_shared<T*>();
276 cout <<
"Flow: loading branch `" <<
name <<
"`" << endl;
278 if (
tIn->GetBranch(
name.c_str()) ==
nullptr)
279 return NoBranch<T>(
name, mode);
281 int err =
tIn->SetBranchAddress(
name.c_str(), t.get());
283 cout <<
"Flow: `TTree::SetBranchAddress()` returned " << to_string(err)
284 <<
" (check `TTree::ESetBranchAddressStatus` for the meaning)."
287 string what =
"`"s +
name +
"` branch could not be set. "s;
290 cout <<
orange <<
"Flow: " << what <<
def << endl;
314 BOOST_THROW_EXCEPTION( invalid_argument(
"`GetOutputTree()` should "
315 "be called before") );
320 t = GetBranch<T>(
name);
322 t = make_shared<T*>();
325 cout <<
"Flow: setting up new branch for `" <<
name <<
"`" << endl;
326 if (
tOut->Branch(
name.c_str(), t.get()) ==
nullptr) {
328 string what =
name +
" branch could not be set up";
352 BOOST_THROW_EXCEPTION( invalid_argument(
"`GetInputTree()` should "
353 "be called before declaring a read-write branch") );
356 BOOST_THROW_EXCEPTION( invalid_argument(
"`GetOutputTree()` should "
357 "be called before declaring a read-write branch") );
362 t = GetBranch<T>(
name);
364 if (GetBranchReadOnly<T>(
name, mode) ==
nullptr)
365 return NoBranch<T>(
name, mode);
367 GetBranchWriteOnly<T>(
name);
376 using Darwin::Tools::operator<<;
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