|
DAS
3.0
Das Analysis System
|
|
typedef std::pair< unsigned, unsigned > | Slice |
|
|
enum | BranchMode { mandatory,
facultative,
mandatory,
facultative
} |
|
enum | Mode {
none = 0b000000,
config = 0b000001,
split = 0b000010,
fill = 0b000100,
Friend = 0b001000,
syst = 0b010000,
verbose = 0b100000,
none = 0b000000,
config = 0b000001,
split = 0b000010,
fill = 0b000100,
Friend = 0b001000,
syst = 0b010000,
verbose = 0b100000
} |
|
enum | BranchMode { mandatory,
facultative,
mandatory,
facultative
} |
|
enum | Mode {
none = 0b000000,
config = 0b000001,
split = 0b000010,
fill = 0b000100,
Friend = 0b001000,
syst = 0b010000,
verbose = 0b100000,
none = 0b000000,
config = 0b000001,
split = 0b000010,
fill = 0b000100,
Friend = 0b001000,
syst = 0b010000,
verbose = 0b100000
} |
|
|
optional< bool > | getBool (string s) |
|
template<typename ... Args> |
void | FromPT2MetaInfo (const pt::ptree &elements, const MetaInfo &metainfo, ostream &cout, Args... args) |
|
void | forceMetaInfo (const fs::path &input, const fs::path &output, const int steering) |
|
int | getMetaInfo (vector< fs::path > inputs, const fs::path &output) |
|
int | initMetaInfo (const pt::ptree &config) |
|
template<int thousand = 1024> |
const char * | GetHumanReadableSize (long double size) |
|
Long64_t | GetSize (TBranch *br) |
|
Long64_t | loopBranches (TObjArray *branches, size_t factor, int nIndent=0) |
|
void | printBranches (vector< fs::path > inputs, const int steering) |
|
void | printDarwinSoftwareVersion () |
|
void | printEntries (vector< fs::path > inputs, const int steering) |
|
void | CollectFriends (const TTree *tree, set< string > &printed, const int steering, string indent="") |
|
void | CollectChainFriends (const TChain *chain, set< string > &printed, const int steering, string indent="") |
|
void | printFriends (vector< fs::path > inputs, const int steering) |
|
void | printHist (vector< fs::path > inputs, const pt::ptree &config) |
|
int | printMetaInfo (vector< fs::path > inputs, const pt::ptree &config) |
|
std::unique_ptr< TFile > | GetOutput (std::filesystem::path output, const std::string &name) |
|
void | StandardInit () |
|
std::vector< std::filesystem::path > | GetROOTfiles (std::vector< std::filesystem::path > inputs) |
|
std::unique_ptr< TChain > | GetChain (std::vector< std::filesystem::path > inputs, const char *name="events") |
|
template<typename THX = TH1> |
std::unique_ptr< THX > | GetHist (std::vector< std::filesystem::path > inputs, const std::string &name="h") |
|
std::string | GetFirstTreeLocation (const std::filesystem::path &input) |
|
std::shared_ptr< TFile > | GetOutputFile (const std::filesystem::path &, const std::source_location=std::source_location::current()) |
|
std::unique_ptr< TTree > | NewTree (const std::unique_ptr< TChain > &chain, const std::string &thisFunc) |
|
std::ostream & | operator<< (std::ostream &Stream, const Darwin::Tools::Slice &slice) |
|
static std::ostream | dev_null (nullptr) |
|
std::unique_ptr< TTree > | NewTree (const std::unique_ptr< ChainSlice > &chain, const std::string &thisFunc) |
|
std::vector< const char * > | tokenize (const char *str) |
|
static std::ostream | dev_null (nullptr) |
|
Classes and functions related to the framework.
Utilities enabling better support for friend chains in a TTree
.
SPDX-License-Idendifier: GPL-3.0-or-later SPDX-FileCopyrightText: Louis Moureaux louis.nosp@m..mou.nosp@m.reaux.nosp@m.@cer.nosp@m.n.ch
◆ Slice
typedef std::pair< unsigned, unsigned > Slice |
current slice (>=0) / total number of slices (>0)
◆ BranchMode [1/2]
Enumerator |
---|
mandatory | mounting branch is mandatory
|
facultative | mounting branch is facultative
|
mandatory | mounting branch is mandatory
|
facultative | mounting branch is facultative
|
◆ BranchMode [2/2]
Enumerator |
---|
mandatory | mounting branch is mandatory
|
facultative | mounting branch is facultative
|
mandatory | mounting branch is mandatory
|
facultative | mounting branch is facultative
|
◆ Mode [1/2]
Enumerator |
---|
none | default (for simple executables)
|
config | activate -c option to provide config file
|
split | activate -k and -j to define slice
|
fill | activate -f to fill the tree
|
Friend | activate -F to only fill the new branches
|
syst | activate -s to systematic uncertainties
|
verbose | bit for debug mode (-v is always available)
|
none | default (for simple executables)
|
config | activate -c option to provide config file
|
split | activate -k and -j to define slice
|
fill | activate -f to fill the tree
|
Friend | activate -F to only fill the new branches
|
syst | activate -s to systematic uncertainties
|
verbose | bit for debug mode (-v is always available)
|
◆ Mode [2/2]
Enumerator |
---|
none | default (for simple executables)
|
config | activate -c option to provide config file
|
split | activate -k and -j to define slice
|
fill | activate -f to fill the tree
|
Friend | activate -F to only fill the new branches
|
syst | activate -s to systematic uncertainties
|
verbose | bit for debug mode (-v is always available)
|
none | default (for simple executables)
|
config | activate -c option to provide config file
|
split | activate -k and -j to define slice
|
fill | activate -f to fill the tree
|
Friend | activate -F to only fill the new branches
|
syst | activate -s to systematic uncertainties
|
verbose | bit for debug mode (-v is always available)
|
◆ CollectChainFriends()
void Darwin::Tools::CollectChainFriends |
( |
const TChain * |
chain, |
|
|
set< string > & |
printed, |
|
|
const int |
steering, |
|
|
string |
indent = "" |
|
) |
| |
Retrieve and prints the elements in the chain and their friends recursively.
- Parameters
-
chain | chain to collect friends from |
printed | files already printed |
steering | bitfield from `Options::steering()` |
indent | spaces to show the distance from the original tree |
34 for (
const auto &obj : *chain->GetListOfFiles()) {
35 auto element =
dynamic_cast<TChainElement*
>(obj);
38 auto full_name = element->GetTitle() + string(
"?#") + element->GetName();
41 cout <<
indent <<
"[chain] " << full_name;
45 TTree *tree =
nullptr;
46 unique_ptr<TFile> file(TFile::Open(element->GetTitle()));
47 if (file && !file->IsZombie()) {
48 tree = file->Get<TTree>(element->GetName());
50 BOOST_THROW_EXCEPTION(Exceptions::BadInput(
51 Form(
"Tree %s not found", element->GetName()), file));
53 BOOST_THROW_EXCEPTION(Exceptions::BadInput(
"File not found", file));
57 if (printed.count(full_name) == 0) {
58 printed.insert(full_name);
61 cout <<
indent <<
" [see above]" << endl;
◆ CollectFriends()
void CollectFriends |
( |
const TTree * |
tree, |
|
|
set< string > & |
printed, |
|
|
const int |
steering, |
|
|
string |
indent |
|
) |
| |
Retrieve and prints the name and the friends.
When called on a long chain of friends, the output can include a very large number of files. To avoid printing too many lines, each file is printed only once. The printed
argument keeps track of files already printed.
- Parameters
-
tree | tree (or chain) to collect friends from |
printed | files already printed |
steering | bitflied from `Options::steering()` |
indent | spaces to show the distance from the original tree |
83 if (
const auto chain =
dynamic_cast<const TChain*
>(tree); chain)
86 auto friends = tree->GetListOfFriends();
89 if (friends ==
nullptr)
return;
91 if (steering &
verbose) friends->Print();
94 for (TObject * obj: *friends) {
95 auto buddy =
dynamic_cast<TFriendElement*
>(obj);
97 cout <<
indent <<
"[friend] ";
98 if (
auto sliced =
dynamic_cast<SlicedFriendElement*
>(obj); sliced)
100 cout << buddy->GetName()
101 <<
"[" << sliced->GetBegin() <<
":" << sliced->GetEnd() <<
"]";
104 cout << buddy->GetTitle() <<
" " << buddy->GetName();
◆ dev_null() [1/2]
static std::ostream Darwin::Tools::dev_null |
( |
nullptr |
| ) |
|
|
static |
to redirect output stream to nowhere
◆ dev_null() [2/2]
static std::ostream Darwin::Tools::dev_null |
( |
nullptr |
| ) |
|
|
static |
to redirect output stream to nowhere
◆ forceMetaInfo()
void Darwin::Tools::forceMetaInfo |
( |
const fs::path & |
input, |
|
|
const fs::path & |
output, |
|
|
const int |
steering |
|
) |
| |
Force content of all TTree::UserInfo()
and TList
found in the topmost directory of the root file. This method is to be used as a last resort, and certainly not in the context of reproducible results.
- Parameters
-
input | input config file (INFO, JSON, XML) |
output | ROOT file |
steering | parameters obtained from explicit options |
98 if (
input.extension() ==
".json")
100 else if (
input.extension() ==
".xml")
106 unique_ptr<TFile> fOut(TFile::Open(output.c_str(),
"UPDATE"));
107 auto t = unique_ptr<TTree>(fOut->Get<TTree>(location.c_str()));
109 BOOST_THROW_EXCEPTION(
DE::BadInput(
"The tree can't be found in this file.", fOut));
111 t->GetUserInfo()->Clear();
114 MetaInfo metainfo(t,
false);
116 metainfo.Set<
bool>(
"git",
"reproducible",
false);
117 if (metainfo.Find(
"history")) {
118 TList * history = metainfo.List(
"history");
119 metainfo.List()->Remove(history);
◆ FromPT2MetaInfo()
void Darwin::Tools::FromPT2MetaInfo |
( |
const pt::ptree & |
elements, |
|
|
const MetaInfo & |
metainfo, |
|
|
ostream & |
cout, |
|
|
Args... |
args |
|
) |
| |
Sets whatever is in the input config file into the metainfo of a TTree
.
- Parameters
-
elements | from config file |
metainfo | target metainfo (will be modified) |
cout | overrides standard output |
args | key chain |
56 if constexpr (
sizeof...(Args) < 10)
57 for (const auto& element: elements) {
58 const char *
key = element.first.c_str();
59 const auto& value = element.second.get_value<
string>();
62 if constexpr (
sizeof...(Args) > 0)
63 (cout << ... <<
args) <<
' ';
64 cout <<
def <<
key <<
" \"" << value <<
'"' << endl;
68 auto match = [&value](
const string& reg) {
69 return regex_match( value, regex(reg) );
71 if (
auto isBool =
getBool(value); isBool)
72 metainfo.Set<
bool>(
args...,
key, *isBool);
73 else if (
match(
"-?[0-9]+"))
74 metainfo.Set<
int>(
args...,
key, stoi(value));
75 else if (
match(
"-?[0-9]+([\\.][0-9]+)?"))
76 metainfo.Set<
float>(
args...,
key, stof(value));
77 else if (element.second.size() == 0) {
79 if constexpr (
sizeof...(Args) > 0)
80 metainfo.Set<
string>(
args...,
string(
key));
83 metainfo.Set<
string>(
args...,
key, value);
◆ getBool()
optional<bool> Darwin::Tools::getBool |
( |
string |
s | ) |
|
Translates a string into a boolean if possible.
36 static const array<string,4> trueStr {
"true",
"on",
"ktrue",
"yes"},
37 falseStr {
"false",
"off",
"kfalse",
"no"};
38 if (
auto it = find(trueStr.begin(), trueStr.end(), s);
40 return make_optional<bool>(
true);
41 if (
auto it = find(falseStr.begin(), falseStr.end(), s);
43 return make_optional<bool>(
false);
◆ GetChain()
std::unique_ptr< TChain > GetChain |
( |
std::vector< std::filesystem::path > |
inputs, |
|
|
const char * |
name = "events" |
|
) |
| |
internal path to TTree
Load chain from a list of files.
Only for backward compatibility.
- Parameters
-
inputs | ROOT files or directories |
name | internal path to `TTree` |
71 auto chain = make_unique<TChain>(
name);
74 int code = chain->Add(
input.c_str(), 0);
77 if (code == 1)
continue;
78 auto fIn = make_unique<TFile>(
input.c_str(),
"READ");
80 "found in (one of) the input file(s).", fIn));
82 if (chain->GetEntries() == 0)
83 BOOST_THROW_EXCEPTION(std::invalid_argument(
"Empty trees in input!"));
◆ GetFirstTreeLocation()
std::string GetFirstTreeLocation |
( |
const std::filesystem::path & |
input | ) |
|
one input ROOT file
Look for a tree in the input file (stop at the first found one).
- Note
- in principle, we take the risk of not looking at the same
TTree
as all other executables, but this is unlikely in practice
- Parameters
-
91 unique_ptr<TFile> fIn(TFile::Open(
input.c_str(),
"READ"));
92 if (!fIn || !fIn->IsOpen() || fIn->IsZombie() || !fs::exists(
input))
93 BOOST_THROW_EXCEPTION( fs::filesystem_error(
"Failed to open input file",
94 input, make_error_code(std::errc::io_error)) );
96 function<string(TDirectory *)> loop;
97 loop = [&loop](TDirectory * d) ->
string {
100 for (
const auto&& obj: *(d->GetListOfKeys())) {
101 auto const key =
dynamic_cast<TKey*
>(obj);
102 if (
dynamic_cast<TTree *
>(
key->ReadObj()) ==
nullptr)
continue;
103 return obj->GetName();
107 for (
const auto&& obj: *(d->GetListOfKeys())) {
108 auto const key =
dynamic_cast<TKey*
>(obj);
109 auto dd =
dynamic_cast<TDirectory *
>(
key->ReadObj());
110 if (dd ==
nullptr)
continue;
111 if (
auto location = loop(dd); !location.empty())
112 return Form(
"%s/%s", dd->GetName(), location.c_str());
118 string location = loop(fIn.get());
119 if (location.empty())
120 BOOST_THROW_EXCEPTION(
DE::BadInput(
"No `TTree` could be found in the input file.", fIn) );
◆ GetHist()
std::unique_ptr< THX > GetHist |
( |
std::vector< std::filesystem::path > |
inputs, |
|
|
const std::string & |
name = "h" |
|
) |
| |
|
inline |
Load a histogram from a list of files.
- Todo:
- what if the file had already been opened?? will it be closed prematurely?
- Todo:
- what if the file had already been opened?? will it be closed prematurely?
- Todo:
- what if the file had already been opened?? will it be closed prematurely?
- Parameters
-
inputs | ROOT files or directories |
name | internal path to ROOT histogram |
60 namespace fs = filesystem;
65 auto fIn = make_unique<TFile>(
input.c_str(),
"READ");
67 unique_ptr<THX> h(fIn->Get<THX>(
name.c_str()));
70 BOOST_THROW_EXCEPTION(
DE::BadInput(Form(
"`%s` cannot be found in (one of) the "
71 " file(s).",
name.c_str()), fIn));
77 sum->SetDirectory(
nullptr);
◆ GetHumanReadableSize()
const char* Darwin::Tools::GetHumanReadableSize |
( |
long double |
size | ) |
|
From an absolute number of bytes to human readable size in KB, MB, GB, etc.
< https://en.wikipedia.org/wiki/Byte
- Parameters
-
31 static const array levels = {
'\0',
'K',
'M',
'G',
'T',
'P',
'E',
'Z',
'Y'};
32 auto level = levels.begin();
33 while (level != prev(levels.end())
34 && size >
static_cast<long double>(thousand)) {
38 return Form(
"%.0Lf%c", size, *level);
◆ getMetaInfo()
int Darwin::Tools::getMetaInfo |
( |
vector< fs::path > |
inputs, |
|
|
const fs::path & |
output |
|
) |
| |
Print content of the first TTree::UserInfo()
found in the root file.
- Parameters
-
inputs | input ROOT files |
output | output config file (INFO, JSON, XML) |
31 const size_t N =
inputs.size();
33 vector<size_t> hashes(N,0);
38 for (
size_t i = 0; i < N; ++i) {
41 unique_ptr<TFile> fIn(TFile::Open(
inputs[i].c_str(),
"READ"));
43 BOOST_THROW_EXCEPTION(
DE::BadInput(
"Can't open the file.", fIn));
46 auto t = unique_ptr<TTree>(
dynamic_cast<TTree*
>(fIn->Get<TTree>(location.c_str())));
48 BOOST_THROW_EXCEPTION(
DE::BadInput(
"The tree can't be found in this file.", fIn));
51 MetaInfo mi(t,
false);
62 bool identical =
true;
64 for (
size_t i = 0; i < N; ++i) {
65 ss <<
inputs[i] <<
'\t' << hex << hashes[i] <<
'\n';
67 identical &= hashes[i-1] == hashes[i];
70 if (identical)
return EXIT_SUCCESS;
◆ GetOutput()
std::unique_ptr< TFile > GetOutput |
( |
std::filesystem::path |
output, |
|
|
const std::string & |
name |
|
) |
| |
Shortcut to create a reproducible output file
- See also
- The ROOT documentation for
TFile::kReproducible
20 const auto fname = output;
21 output +=
"?reproducible="; output +=
name;
22 std::unique_ptr<TFile>
f(TFile::Open(output.c_str(),
"RECREATE"));
23 if (!
f || !
f->IsOpen() ||
f->IsZombie() || !fs::exists(
fname))
24 BOOST_THROW_EXCEPTION( fs::filesystem_error(
"Failed to open output file",
25 output, make_error_code(std::errc::io_error)) );
◆ GetOutputFile()
std::shared_ptr< TFile > GetOutputFile |
( |
const std::filesystem::path & |
, |
|
|
const std::source_location |
= std::source_location::current() |
|
) |
| |
Shortcut to create a reproducible output file (see ROOT Doxygen for details)
upstream function
- Parameters
-
127 string title = fs::path(location.file_name()).stem();
128 auto output_rep = output.string() +
"?reproducible="s + title;
129 auto fOut = make_shared<TFile>(output_rep.c_str(),
"RECREATE");
130 if (!fOut->IsOpen() || fOut->IsZombie() || !fs::exists(output)) {
132 BOOST_THROW_EXCEPTION( fs::filesystem_error(
"Failed to open output file",
133 output, make_error_code(errc::io_error)) );
135 fOut->SetTitle(title.c_str());
◆ GetROOTfiles()
std::vector< std::filesystem::path > GetROOTfiles |
( |
std::vector< std::filesystem::path > |
inputs | ) |
|
ROOT files or directories.
In case directories are given as inputs, instead of files, this function looks for all ROOT files in those directories (and subdirectories, iteratively).
- Parameters
-
inputs | ROOT files or directories |
40 BOOST_THROW_EXCEPTION(fs::filesystem_error(
"No input was found!",
41 make_error_code(errc::no_such_file_or_directory)));
43 vector<fs::path> root_inputs;
44 root_inputs.reserve(
inputs.size());
48 if (fs::is_directory(
input)) {
49 for (
const auto &entry : fs::recursive_directory_iterator(
50 input, fs::directory_options::follow_directory_symlink)) {
51 if (fs::is_regular_file(entry) && entry.path().extension() ==
".root") {
52 root_inputs.push_back(entry);
56 else if (
input.extension() ==
".root")
57 root_inputs.push_back(
input);
60 sort(root_inputs.begin(), root_inputs.end(),
61 [](
const fs::path& a,
const fs::path& b) {
62 return strnatcmp(a.c_str(), b.c_str()) < 0;
◆ GetSize()
Long64_t Darwin::Tools::GetSize |
( |
TBranch * |
br | ) |
|
Adapted from ROOT example
45 TMemFile
f(
"buffer",
"CREATE");
46 auto fcurrent = br->GetTree()->GetCurrentFile();
48 auto settings = fcurrent->GetCompressionSettings();
49 f.SetCompressionSettings(settings);
51 f.WriteObject(br,
"thisbranch");
52 TKey *
key =
f.GetKey(
"thisbranch");
53 Long64_t size =
key->GetNbytes();
55 Long64_t basket = br->GetZipBytes();
56 if (basket == 0) basket = br->GetTotBytes();
◆ initMetaInfo()
int Darwin::Tools::initMetaInfo |
( |
const pt::ptree & |
config | ) |
|
Writes a minimal MetaInfo to standard output.
- Parameters
-
config | config, with `flags` and `corrections` at least |
24 auto formatStr =
config.get<
string>(
"format");
25 MetaInfo::Format format;
26 if (formatStr ==
"info")
27 format = MetaInfo::INFO;
28 else if (formatStr ==
"json")
29 format = MetaInfo::JSON;
30 else if (formatStr ==
"xml")
31 format = MetaInfo::XML;
33 BOOST_THROW_EXCEPTION( std::invalid_argument(
34 "Unknown MetaInfo format \"" + formatStr +
"\"") );
36 MetaInfo(MetaInfo::IKnowWhatIAmDoing{}).Write(cout, format);
◆ loopBranches()
Long64_t Darwin::Tools::loopBranches |
( |
TObjArray * |
branches, |
|
|
size_t |
factor, |
|
|
int |
nIndent = 0 |
|
) |
| |
Adapted from ROOT example
- Parameters
-
branches | list of (sub)branches |
factor | correction factor for #files in `TChain` |
nIndent | level of indentation |
67 size_t n = branches->GetEntries();
69 for (
size_t i = 0; i < n; ++i) {
70 auto br =
dynamic_cast<TBranch*
>(branches->At(i));
73 string branchname(nIndent,
' ');
74 branchname += br->GetName();
75 cout << left << setw(40) << branchname
78 TObjArray * subbranches = br->GetListOfBranches();
◆ NewTree() [1/2]
std::unique_ptr<TTree> Darwin::Tools::NewTree |
( |
const std::unique_ptr< ChainSlice > & |
chain, |
|
|
const std::string & |
thisFunc |
|
) |
| |
- Parameters
-
chain | input |
thisFunc | name of present exec |
142 auto tOut = unique_ptr<TTree>(chain->CloneTree(0));
143 tOut->SetTitle(thisFunc.c_str());
◆ NewTree() [2/2]
std::unique_ptr< TTree > NewTree |
( |
const std::unique_ptr< TChain > & |
chain, |
|
|
const std::string & |
thisFunc |
|
) |
| |
name of present exec
Either clone the input TChain
or define the input TChain
as a friend of the new TTree
.
Only for backward compatibility.
- Parameters
-
◆ operator<<()
Prints the current slice and the total number of slices.
26 Stream << slice.second <<
'/' << slice.first;
◆ printBranches()
void Darwin::Tools::printBranches |
( |
vector< fs::path > |
inputs, |
|
|
const int |
steering |
|
) |
| |
Adapted from ROOT example
- Parameters
-
inputs | input ROOT files |
steering | bitfield from `Options::steering()` |
91 size_t factor =
inputs.size();
94 auto tIn = flow.GetInputTree(
inputs, {1, 0});
95 TObjArray * branches = tIn->GetListOfBranches();
◆ printDarwinSoftwareVersion()
void Darwin::Tools::printDarwinSoftwareVersion |
( |
| ) |
|
Print the versions of the various pieces of software. Each software appears on a new line. Tought for exception handling in Python code and for Doxygen.
18 for (
auto const& v: MetaInfo::versions)
19 cout << v.first <<
' ' << v.second <<
'\n';
◆ printEntries()
void Darwin::Tools::printEntries |
( |
vector< fs::path > |
inputs, |
|
|
const int |
steering |
|
) |
| |
Get total number of entries in input ROOT file(s) or directory, and prints it directly to the terminal.
- Parameters
-
inputs | input ROOT files |
steering | bitfield from `Options::steering()` |
28 auto tIn = flow.GetInputTree(
inputs, {1, 0}, location);
29 cout << tIn->GetEntries() << endl;
31 catch (boost::wrapexcept<std::invalid_argument>& e) {
◆ printFriends()
void Darwin::Tools::printFriends |
( |
vector< fs::path > |
inputs, |
|
|
const int |
steering |
|
) |
| |
Prints the recursive list of friends to the input n-tuple.
- Parameters
-
inputs | input ROOT files |
steering | bitfield from `Options::steering()` |
122 auto chain = flow.GetInputTree(
inputs, {1, 0}, location);
◆ printHist()
void Darwin::Tools::printHist |
( |
vector< fs::path > |
inputs, |
|
|
const pt::ptree & |
config |
|
) |
| |
Print the content of a 1D histogram in columns.
Convention: index lowEdge upEdge content error
- Parameters
-
inputs | input ROOT files |
config | config handled with `Darwin::Tools::options` |
30 auto h = GetHist<TH1>({
inputs},
config.get<
string>(
"hist"));
31 if (h->GetDimension() > 1)
32 BOOST_THROW_EXCEPTION(
DE::BadInput(
"The desired histogram is not 1D",
33 TFile(
inputs.front().c_str()) ));
34 int N = h->GetNbinsX();
35 for (
int i = 0; i <= N+1; ++i) {
36 double low = h->GetBinLowEdge(i),
37 up = h->GetBinLowEdge(i+1),
38 content = h->GetBinContent(i),
39 error = h->GetBinError(i);
40 if (error == 0 && content == 0)
continue;
44 if (i == 0) cout <<
"underflow";
45 else if (i == N+1) cout <<
"overflow";
50 if (i == 0) cout <<
"-inf";
55 if (i > N) cout <<
"+inf";
59 cout << setw(15) << content
◆ printMetaInfo()
int Darwin::Tools::printMetaInfo |
( |
vector< fs::path > |
inputs, |
|
|
const pt::ptree & |
config |
|
) |
| |
Print the value(s) corresponding to a given key in the first given input ROOT file.
If no value / subtree is found, the command fails and exits. If multiple entries are found, they are all printed. Only the first subtree is displayed.
The INFO format allows a key to have a value and a child. Since the JSON format does not allow that, we assume here that this case does not happen.
- Parameters
-
inputs | input ROOT files |
config | config, with `flags` and `corrections` at least |
41 unique_ptr<TFile> fIn(TFile::Open(
inputs.front().c_str(),
"READ"));
43 BOOST_THROW_EXCEPTION(
DE::BadInput(
"Can't open the file.", fIn));
46 auto t = unique_ptr<TTree>(
dynamic_cast<TTree*
>(fIn->Get<TTree>(location.c_str())));
48 BOOST_THROW_EXCEPTION(
DE::BadInput(
"The tree can't be found in this file.", fIn));
51 MetaInfo metainfo(t,
false);
52 auto ptree = metainfo.MkPtree();
55 auto value = ptree.get<
string>(
key);
57 cout << value << endl;
61 auto child = ptree.get_child_optional(
key);
63 for (
auto& el: *child) {
64 string key = el.first,
65 val = el.second.get_value<
string>();
66 if (!
key.empty()) cout <<
key <<
' ';
67 if (!val.empty()) cout << val;
◆ StandardInit()
Standard initialisation for ROOT.
"Now you own all histogram objects and you will need to delete them, for in- stance through the use of std::unique_ptr
. You can still set the directory of a histogram by calling SetDirectory()
once it has been created."
32 TH1::SetDefaultSumw2();
33 TH1::AddDirectory(kFALSE);
◆ tokenize()
std::vector<const char *> Darwin::Tools::tokenize |
( |
const char * |
str | ) |
|
|
inline |
Tokenize a C-style string into a vector of C-style string with space as delimiter. It is especially useful in tests where the command is hard-coded.
17 std::cout <<
"\e[1m" << str <<
"\e[0m" << std::endl;
20 char *
cmd =
new char[strlen(str)+1];
24 std::vector<const char *>
args;
25 for (
char * arg = strtok(
cmd,
" ");
27 arg = strtok(NULL,
" "))
28 args.push_back(std::move(arg));
name
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:48
cerr
Definition: Ntupliser_cfg.py:93
fname
Definition: jercExample.py:88
static bool verbose
Definition: Step.h:40
static const char * def
Definition: Step.h:36
args
Definition: Ntupliser_cfg.py:11
f
Definition: Ntupliser_cfg.py:252
string key
Definition: jercExample.py:109
Handling of exceptions.
Definition: darwin.h:36
static const char * red
Definition: Step.h:34
cmd
Definition: Core-cfgcmd.txt:1
config
Definition: Ntupliser_cfg.py:260
input
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:35
indent
Definition: Ntupliser_cfg.py:252
def inputs
Definition: jercExample.py:118
DAS::FourVector match(const DAS::FourVector &jet, const std::vector< DAS::FourVector > *hltJets)
Definition: match.h:7
static const char * bold
Definition: Step.h:35