 |
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;
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>& = {}
145 const std::string& =
"events");
150 (
const std::string& =
"events");
157 template<
typename THX = TH1,
size_t N>
159 (
const std::array<std::string, N>& names = {}
163 namespace fs = filesystem;
166 BOOST_THROW_EXCEPTION( runtime_error(
"Empty input list") );
168 array<unique_ptr<THX>, N> sums;
170 auto fIn = make_unique<TFile>(
input.c_str(),
"READ");
171 for (
size_t i = 0; i < N; ++i) {
172 const string&
name = names[i];
173 unique_ptr<THX> h(fIn->Get<THX>(
name.c_str()));
176 BOOST_THROW_EXCEPTION(
177 DE::BadInput(Form(
"`%s` cannot be found in (one of) the "
178 " file(s).",
name.c_str()), fIn));
181 sums[i]->Add(h.get());
183 sums[i] = std::move(h);
184 sums[i]->SetDirectory(
nullptr);
196 template<
typename THX = TH1,
typename... Args>
199 constexpr
const size_t N =
sizeof...(args);
200 std::array<std::string, N> names {{
args... }};
201 return GetInputHists<THX, N>(names);
208 template<
typename THX = TH1>
210 (
const std::string&
name)
212 auto hists = GetInputHists<THX,1>({
name});
213 THX * hist = hists.front().release();
214 return std::unique_ptr<THX>(hist);
231 const std::source_location = std::source_location::current());
236 const std::source_location = std::source_location::current());
248 std::pair<TFile *, TTree *>
GetOutput (
const std::filesystem::path&,
249 const std::source_location = std::source_location::current());
263 const std::string&
name,
269 BOOST_THROW_EXCEPTION( invalid_argument(
"`GetInputTree()` should "
270 "be called before declaring a read-only branch") );
277 t = GetBranch<T>(
name);
279 t = make_shared<T*>();
281 cout <<
"Flow: loading branch `" <<
name <<
"`" << endl;
283 if (
tIn->GetBranch(
name.c_str()) ==
nullptr)
284 return NoBranch<T>(
name, mode);
286 int err =
tIn->SetBranchAddress(
name.c_str(), t.get());
288 cout <<
"Flow: `TTree::SetBranchAddress()` returned " << to_string(err)
289 <<
" (check `TTree::ESetBranchAddressStatus` for the meaning)."
292 string what =
"`"s +
name +
"` branch could not be set. "s;
295 cout <<
orange <<
"Flow: " << what <<
def << endl;
319 BOOST_THROW_EXCEPTION( invalid_argument(
"`GetOutputTree()` should "
320 "be called before") );
325 t = GetBranch<T>(
name);
327 t = make_shared<T*>();
330 cout <<
"Flow: setting up new branch for `" <<
name <<
"`" << endl;
331 if (
tOut->Branch(
name.c_str(), t.get()) ==
nullptr) {
333 string what =
name +
" branch could not be set up";
357 BOOST_THROW_EXCEPTION( invalid_argument(
"`GetInputTree()` should "
358 "be called before declaring a read-write branch") );
361 BOOST_THROW_EXCEPTION( invalid_argument(
"`GetOutputTree()` should "
362 "be called before declaring a read-write branch") );
367 t = GetBranch<T>(
name);
369 if (GetBranchReadOnly<T>(
name, mode) ==
nullptr)
370 return NoBranch<T>(
name, mode);
372 GetBranchWriteOnly<T>(
name);
381 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