 |
DAS
3.0
Das Analysis System
|
Go to the documentation of this file.
25 #include <source_location>
38 using Slice = std::pair<int, int>;
44 return Stream << slice.second <<
'/' << slice.first;
85 std::vector<std::filesystem::path>
inputs;
87 std::unique_ptr<ChainSlice>
tIn;
88 std::shared_ptr<TFile>
fOut;
89 std::unique_ptr<TTree>
tOut;
95 template<
typename T> requires std::is_compound<T>::value
98 return std::any_cast<std::shared_ptr<T*>>(a);
100 catch (
const std::bad_any_cast& e) {
101 BOOST_THROW_EXCEPTION(e);
106 template<
typename T> requires std::is_fundamental<T>::value
109 return std::any_cast<std::shared_ptr<T>>(a);
111 catch (
const std::bad_any_cast& e) {
112 BOOST_THROW_EXCEPTION(e);
117 template<
typename T> requires std::is_compound<T>::value
125 template<
typename T> requires std::is_fundamental<T>::value
138 shared_ptr ptr = branch_cast<T>(a);
139 return GetBranchAddress<T>(ptr);
150 std::string what =
name +
" branch could not be found";
159 auto keys =
branches | std::views::keys;
160 return std::accumulate(keys.begin(), keys.end(), std::string(),
161 [](
const std::string& str,
const std::string& branch_name) {
162 return str +
' ' + branch_name;
171 const std::vector<std::filesystem::path>& = {}
184 const std::string& =
"events");
189 (
const std::string& =
"events");
196 template<
typename THX = TH1,
size_t N>
198 (
const std::array<std::string, N>& names = {}
202 namespace fs = filesystem;
205 BOOST_THROW_EXCEPTION( invalid_argument(
"Empty list of input files") );
207 array<unique_ptr<THX>, N> sums;
209 auto fIn = make_unique<TFile>(
input.c_str(),
"READ");
210 for (
size_t i = 0; i < N; ++i) {
211 const string&
name = names[i];
212 unique_ptr<THX> h(fIn->Get<THX>(
name.c_str()));
215 BOOST_THROW_EXCEPTION(
216 DE::BadInput(Form(
"`%s` cannot be found in (one of) the "
217 " file(s).",
name.c_str()), fIn));
220 sums[i]->Add(h.get());
222 sums[i] = std::move(h);
223 sums[i]->SetDirectory(
nullptr);
235 template<
typename THX = TH1,
typename... Args>
238 constexpr
const size_t N =
sizeof...(args);
239 std::array<std::string, N> names {{
args... }};
240 return GetInputHists<THX, N>(names);
247 template<
typename THX = TH1>
249 (
const std::string&
name)
251 auto hists = GetInputHists<THX,1>({
name});
252 THX * hist = hists.front().release();
253 return std::unique_ptr<THX>(hist);
270 const std::source_location = std::source_location::current());
275 const std::source_location = std::source_location::current());
287 std::pair<TFile *, TTree *>
GetOutput (
const std::filesystem::path&,
288 const std::source_location = std::source_location::current());
302 const std::string&
name,
308 BOOST_THROW_EXCEPTION( invalid_argument(
"`GetInputTree()` should "
309 "be called before declaring a read-only branch") );
314 if constexpr (is_compound<T>::value)
315 branch = make_shared<T*>();
317 branch = make_shared<T>();
320 cout <<
"Flow: loading read-only branch `" <<
name <<
"`" << endl;
322 if (
tIn->GetBranch(
name.c_str()) ==
nullptr)
323 return NoBranch<T>(
name, mode);
325 int err =
tIn->SetBranchAddress(
name.c_str(), branch_cast<T>(branch).get());
327 cout <<
"Flow: `TTree::SetBranchAddress()` returned " << to_string(err)
328 <<
" (check `TTree::ESetBranchAddressStatus` for the meaning)."
331 string what =
"`"s +
name +
"` branch could not be set. "s;
334 cout <<
orange <<
"Flow: " << what <<
def << endl;
344 return GetBranchAddress<T>(
name);
361 BOOST_THROW_EXCEPTION( invalid_argument(
"`GetOutputTree()` should "
362 "be called before") );
365 if constexpr (is_compound<T>::value)
372 shared_ptr ptr = branch_cast<T>(branch);
375 cout <<
"Flow: setting up a write-only branch for `" <<
name <<
"`" << endl;
377 if (
tOut->Branch(
name.c_str(), ptr.get()) ==
nullptr) {
379 string what =
name +
" branch could not be set up";
383 return GetBranchAddress<T>(ptr);
401 BOOST_THROW_EXCEPTION( invalid_argument(
"`GetInputTree()` should "
402 "be called before declaring a read-write branch") );
405 BOOST_THROW_EXCEPTION( invalid_argument(
"`GetOutputTree()` should "
406 "be called before declaring a read-write branch") );
409 if (GetBranchReadOnly<T>(
name, mode) ==
nullptr)
410 return NoBranch<T>(
name, mode);
412 GetBranchWriteOnly<T>(
name);
415 return GetBranchAddress<T>(
name);
424 template<Plugin P, std::ranges::range R> std::vector<P*>
GetPlugins (R&& plugin_paths)
427 namespace fs = filesystem;
429 for (fs::path file: plugin_paths)
441 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
PluginsVec * plugins()
Definition: IPlugin.h:77
Handling of exceptions.
Definition: darwin.h:37
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
PseudoJet join(const std::vector< PseudoJet > &pieces)
Definition: fjcore.hh:1245