 |
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;
92 template<
typename T> requires std::is_compound<T>::value
95 return std::any_cast<std::shared_ptr<T*>>(a);
97 catch (
const std::bad_any_cast& e) {
98 BOOST_THROW_EXCEPTION(e);
103 template<
typename T> requires std::is_fundamental<T>::value
106 return std::any_cast<std::shared_ptr<T>>(a);
108 catch (
const std::bad_any_cast& e) {
109 BOOST_THROW_EXCEPTION(e);
114 template<
typename T> requires std::is_compound<T>::value
122 template<
typename T> requires std::is_fundamental<T>::value
135 shared_ptr ptr = branch_cast<T>(a);
136 return GetBranchAddress<T>(ptr);
147 std::string what =
name +
" branch could not be found";
156 auto keys =
branches | std::views::keys;
157 return std::accumulate(keys.begin(), keys.end(), std::string(),
158 [](
const std::string& str,
const std::string& branch_name) {
159 return str +
' ' + branch_name;
168 const std::vector<std::filesystem::path>& = {}
181 const std::string& =
"events");
186 (
const std::string& =
"events");
193 template<
typename THX = TH1,
size_t N>
195 (
const std::array<std::string, N>& names = {}
199 namespace fs = filesystem;
202 BOOST_THROW_EXCEPTION( invalid_argument(
"Empty list of input files") );
204 array<unique_ptr<THX>, N> sums;
206 auto fIn = make_unique<TFile>(
input.c_str(),
"READ");
207 for (
size_t i = 0; i < N; ++i) {
208 const string&
name = names[i];
209 unique_ptr<THX> h(fIn->Get<THX>(
name.c_str()));
212 BOOST_THROW_EXCEPTION(
213 DE::BadInput(Form(
"`%s` cannot be found in (one of) the "
214 " file(s).",
name.c_str()), fIn));
217 sums[i]->Add(h.get());
219 sums[i] = std::move(h);
220 sums[i]->SetDirectory(
nullptr);
232 template<
typename THX = TH1,
typename... Args>
235 constexpr
const size_t N =
sizeof...(args);
236 std::array<std::string, N> names {{
args... }};
237 return GetInputHists<THX, N>(names);
244 template<
typename THX = TH1>
246 (
const std::string&
name)
248 auto hists = GetInputHists<THX,1>({
name});
249 THX * hist = hists.front().release();
250 return std::unique_ptr<THX>(hist);
267 const std::source_location = std::source_location::current());
272 const std::source_location = std::source_location::current());
284 std::pair<TFile *, TTree *>
GetOutput (
const std::filesystem::path&,
285 const std::source_location = std::source_location::current());
299 const std::string&
name,
305 BOOST_THROW_EXCEPTION( invalid_argument(
"`GetInputTree()` should "
306 "be called before declaring a read-only branch") );
311 if constexpr (is_compound<T>::value)
312 branch = make_shared<T*>();
314 branch = make_shared<T>();
317 cout <<
"Flow: loading read-only branch `" <<
name <<
"`" << endl;
319 if (
tIn->GetBranch(
name.c_str()) ==
nullptr)
320 return NoBranch<T>(
name, mode);
322 int err =
tIn->SetBranchAddress(
name.c_str(), branch_cast<T>(branch).get());
324 cout <<
"Flow: `TTree::SetBranchAddress()` returned " << to_string(err)
325 <<
" (check `TTree::ESetBranchAddressStatus` for the meaning)."
328 string what =
"`"s +
name +
"` branch could not be set. "s;
331 cout <<
orange <<
"Flow: " << what <<
def << endl;
341 return GetBranchAddress<T>(
name);
358 BOOST_THROW_EXCEPTION( invalid_argument(
"`GetOutputTree()` should "
359 "be called before") );
362 if constexpr (is_compound<T>::value)
369 shared_ptr ptr = branch_cast<T>(branch);
372 cout <<
"Flow: setting up a write-only branch for `" <<
name <<
"`" << endl;
374 if (
tOut->Branch(
name.c_str(), ptr.get()) ==
nullptr) {
376 string what =
name +
" branch could not be set up";
380 return GetBranchAddress<T>(ptr);
398 BOOST_THROW_EXCEPTION( invalid_argument(
"`GetInputTree()` should "
399 "be called before declaring a read-write branch") );
402 BOOST_THROW_EXCEPTION( invalid_argument(
"`GetOutputTree()` should "
403 "be called before declaring a read-write branch") );
406 if (GetBranchReadOnly<T>(
name, mode) ==
nullptr)
407 return NoBranch<T>(
name, mode);
409 GetBranchWriteOnly<T>(
name);
412 return GetBranchAddress<T>(
name);
418 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