DAS  3.0
Das Analysis System
main.cc File Reference
#include <boost/test/included/unit_test.hpp>
#include <boost/exception/all.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/info_parser.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include "test.h"
#include "exceptions.h"
#include "Options.h"
#include "UserInfo.h"
#include "MetaInfo.h"
#include "example01.cc"
#include "example02.cc"
#include "example03.cc"
#include "../bin/getMetaInfo.cc"
#include "../bin/printMetaInfo.cc"
#include "../bin/printEntries.cc"
#include "../bin/printBranches.cc"
#include "../bin/forceMetaInfo.cc"
+ Include dependency graph for main.cc:

Namespaces

 Darwin
 
 Darwin::Physics
 

Macros

#define DOXYGEN_SHOULD_SKIP_THIS
 
#define BOOST_TEST_MODULE   test
 
#define DARWIN_GIT_REPO   DARWIN
 

Functions

template<bool DARWIN_TEST_EXCEPTIONS = false>
void example02 (const fs::path &input, const fs::path &output, const pt::ptree &config, const int steering, const DT::Slice slice={1, 0})
 
void example03 (const fs::path &input, const fs::path &output, const pt::ptree &config, const int steering, const DT::Slice slice={1, 0})
 
 BOOST_AUTO_TEST_CASE (output)
 
 BOOST_AUTO_TEST_CASE (getters)
 
 BOOST_AUTO_TEST_CASE (ntuple_producer)
 
 BOOST_AUTO_TEST_CASE (ntuple_modifier)
 
 BOOST_AUTO_TEST_CASE (projection)
 
 BOOST_AUTO_TEST_CASE (all_steps)
 
 BOOST_AUTO_TEST_CASE (getBool)
 
 BOOST_AUTO_TEST_CASE (forceMetaInfo)
 
 BOOST_AUTO_TEST_CASE (GetFirstTreeLocation)
 
 BOOST_AUTO_TEST_CASE (printEntries)
 
 BOOST_AUTO_TEST_CASE (printBranches)
 
 BOOST_AUTO_TEST_CASE (printMetaInfo)
 
 BOOST_AUTO_TEST_CASE (closure)
 
 BOOST_AUTO_TEST_CASE (exceptions)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   test

◆ DARWIN_GIT_REPO

#define DARWIN_GIT_REPO   DARWIN

◆ DOXYGEN_SHOULD_SKIP_THIS

#define DOXYGEN_SHOULD_SKIP_THIS

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/14]

BOOST_AUTO_TEST_CASE ( all_steps  )
187  {
188  pt::ptree config;
189  BOOST_REQUIRE_NO_THROW( pt::read_info("example.info", config) );
190  BOOST_REQUIRE_NO_THROW( DT::Options::parse_config(config) );
191  const int steering = DT::fill | DT::syst;
192  BOOST_REQUIRE_NO_THROW( DP::example01("ntuple01.root", config, steering) );
193  BOOST_REQUIRE_NO_THROW( DP::example02("ntuple01.root", "ntuple02.root", config, steering) );
194  BOOST_REQUIRE_NO_THROW( DP::example03("ntuple02.root", "hists03.root", config, steering) );
195  }

◆ BOOST_AUTO_TEST_CASE() [2/14]

BOOST_AUTO_TEST_CASE ( closure  )
259  {
260  {
261  unique_ptr<TFile> f(TFile::Open("ntuple02.root"));
262  f->ls();
263  }
264 
265  vector<string> exts {"info", "xml", "json"};
266  for (string ext: exts) {
267  fs::path file = "out1." + ext;
268  vector<fs::path> inputs = {"ntuple02.root"};
269  BOOST_REQUIRE_NO_THROW( DT::getMetaInfo(inputs, file) );
270  }
271 
272  auto getHash = [](const fs::path& ntuple) {
273  auto rootfile = unique_ptr<TFile>(TFile::Open(ntuple.c_str(), "READ"));
274  auto events = unique_ptr<TTree>(rootfile->Get<TTree>("events"));
275  size_t Hash = hash<TTree*>{}(events.get());
276  return Hash;
277  };
278 
279  size_t Hash = getHash("ntuple02.root");
280 
281  pt::ptree config;
282  auto chain = [&config,&getHash](const fs::path& fOut, bool isMC) {
283  fs::remove("ntuple02.root");
284  config.put<bool>("flags.isMC", isMC);
285  const int steering = DT::fill | DT::syst;
286  BOOST_REQUIRE_NO_THROW( DT::Options::parse_config(config) );
287  DP::example01("ntuple01.root", config, steering);
288  DP::example02("ntuple01.root", "ntuple02.root", config, steering);
289  DP::example03("ntuple02.root", "hists03.root", config, steering);
290  vector<fs::path> inputs = {"hists03.root"};
291  DT::getMetaInfo(inputs, fOut);
292  size_t Hash = getHash("ntuple02.root");
293  fs::remove("ntuple01.root");
294  fs::rename("hists03.root", Form("hists03_%s_%s.root", &(fOut.extension().c_str()[1]), isMC ? "true" : "false"));
295  return Hash;
296  };
297 
298  pt::read_info("out1.info", config);
299  int oldseed = config.get<int>("preseed");
300  config.put<int>("preseed", 2*oldseed);
301  BOOST_TEST( Hash != chain("out2.info", true ) );
302  config.put<int>("preseed", oldseed);
303  BOOST_TEST( Hash == chain("out2.info", true ) );
304  BOOST_TEST( Hash != chain("out2.info", false) );
305 
306  pt::read_json("out1.json", config);
307  BOOST_TEST( Hash == chain("out2.json", true ) );
308  BOOST_TEST( Hash != chain("out2.json", false) );
309 
310  pt::read_xml("out1.xml", config);
311  config = config.get_child("userinfo");
312  BOOST_TEST( Hash == chain("out2.xml", true ) );
313  BOOST_TEST( Hash != chain("out2.xml", false) );
314 
315  vector<fs::path> inputs = {"hists03_info_true.root" , "hists03_json_true.root" , "hists03_xml_true.root" };
316  BOOST_TEST( DT::getMetaInfo(inputs, "true.info" ) == EXIT_SUCCESS );
317  inputs = {"hists03_info_false.root", "hists03_json_false.root", "hists03_xml_false.root"};
318  BOOST_TEST( DT::getMetaInfo(inputs, "false.info" ) == EXIT_SUCCESS );
319  inputs = {"hists03_info_true.root" , "hists03_info_false.root"};
320  BOOST_TEST( DT::getMetaInfo(inputs, "failure.info") == EXIT_FAILURE );
321 
322  for (string name: {"true", "false", "failure"})
323  fs::remove(name + ".info");
324 
325  for (string ext: exts) {
326  fs::remove("out1." + ext);
327  fs::remove("out2." + ext);
328  for (string b: {"true", "false"})
329  fs::remove("hists03_" + ext + "_" + b + ".root");
330  }
331  }

◆ BOOST_AUTO_TEST_CASE() [3/14]

BOOST_AUTO_TEST_CASE ( exceptions  )
334  {
335  // testing raw exception object
336  auto f = unique_ptr<TFile>(TFile::Open("ntuple02.root", "READ"));
337  auto t = unique_ptr<TTree>(f->Get<TTree>("events"));
338  DT::MetaInfo metainfo(t);
339  cout << DE::BadInput("Here is a bad input", metainfo).what() << endl;
340  t->GetEntry(5);
341  cout << DE::AnomalousEvent("Here is an anomally (just for the example)", t).what() << endl;
342 
343  // testing in real context
344  pt::ptree config;
345  BOOST_REQUIRE_NO_THROW( pt::read_info(DARWIN "/test/example.info", config) );
346  BOOST_REQUIRE_NO_THROW( DT::Options::parse_config(config) );
347  const int steering = DT::fill | DT::syst;
348  DP::example01("ntuple01.root", config, steering);
349  BOOST_REQUIRE_THROW( DP::example02<true>("ntuple01.root", "ntuple02.root", config, steering), boost::wrapexcept<DE::AnomalousEvent> );
350  BOOST_REQUIRE_THROW( DP::example01<true>("ntuple01.root", config, steering), boost::wrapexcept<DE::BadInput > );
351 
352  fs::remove("inexistent.out");
353  fs::remove("ntuple01.root");
354  }

◆ BOOST_AUTO_TEST_CASE() [4/14]

BOOST_AUTO_TEST_CASE ( forceMetaInfo  )
208  {
209  vector<fs::path> input = {"ntuple02.root"};
210  DT::getMetaInfo(input, "force02.info");
211  DT::forceMetaInfo("force02.info", "ntuple01.root", DT::verbose);
212  input = {"ntuple01.root"};
213  DT::getMetaInfo(input, "force01.info");
214  unique_ptr<TFile> f(TFile::Open("ntuple01.root", "READ"));
215  auto events = unique_ptr<TTree>(f->Get<TTree>("events"));
216  DT::MetaInfo metainfo(events);
217  BOOST_TEST( !metainfo.Find("history") );
218  BOOST_TEST( !metainfo.Get<bool>("git", "reproducible") );
219  }

◆ BOOST_AUTO_TEST_CASE() [5/14]

BOOST_AUTO_TEST_CASE ( getBool  )
198  {
199  BOOST_TEST( !DT::getBool("this will not work").has_value());
200  BOOST_TEST( DT::getBool("yes").has_value());
201  BOOST_TEST( DT::getBool("true" ).value() == true );
202  BOOST_TEST( DT::getBool("kTRUE").value() == true );
203  BOOST_TEST( DT::getBool("off" ).value() == false );
204  BOOST_TEST( DT::getBool("NO" ).value() == false );
205  }

◆ BOOST_AUTO_TEST_CASE() [6/14]

BOOST_AUTO_TEST_CASE ( GetFirstTreeLocation  )
222  {
223  BOOST_TEST( DT::GetFirstTreeLocation("ntuple01.root") == "events" );
224  BOOST_REQUIRE_NO_THROW( DT::GetFirstTreeLocation("ntuple01.root") );
225 
226  TFile::Open("GetFirstTreeLocation.root", "RECREATE")->Close();
227  BOOST_REQUIRE_THROW( DT::GetFirstTreeLocation("GetFirstTreeLocation.root"), boost::wrapexcept<DE::BadInput> );
228  }

◆ BOOST_AUTO_TEST_CASE() [7/14]

BOOST_AUTO_TEST_CASE ( getters  )
67  {
68  vector<fs::path> files;
69  BOOST_REQUIRE_THROW( DT::GetHist<TH1>(files, "h"), boost::wrapexcept<fs::filesystem_error> ); // bc empty
70  BOOST_REQUIRE_THROW( DT::GetChain (files, "t"), boost::wrapexcept<fs::filesystem_error> ); // bc empty
71 
72  for (int i = 1; i < 4; ++i) {
73  fs::path name = Form("getters_%d.root", i);
74  cout << name << endl;
75  files.push_back(name);
76  unique_ptr<TFile> f(TFile::Open(name.c_str(), "RECREATE"));
77  auto h = make_unique<TH1F>("h", "h", 1, 0., 1.);
78  auto t = make_unique<TTree>("t", "t");
79  h->SetDirectory(f.get());
80  t->SetDirectory(f.get());
81  h->Write();
82  t->Write();
83  }
84 
85  BOOST_REQUIRE_THROW( DT::GetChain (files, "t" ), boost::wrapexcept<invalid_argument> );
86  BOOST_REQUIRE_THROW( DT::GetHist<TH1>(files, "thisHistDoesNotExist"), boost::wrapexcept<DE::BadInput> );
87  BOOST_REQUIRE_THROW( DT::GetChain (files, "thisTreeDoesNotExist"), boost::wrapexcept<DE::BadInput> );
88 
89  BOOST_REQUIRE_NO_THROW( DT::GetHist<TH1>(files, "h") );
90  }

◆ BOOST_AUTO_TEST_CASE() [8/14]

BOOST_AUTO_TEST_CASE ( ntuple_modifier  )
116  {
117  fs::path input, output;
118 
119  DT::Options options("This is just a toy to play with the options and with the exceptions.",
121  options.input ("input" , &input , "input ROOT file" )
122  .output("output", &output, "output ROOT file")
123  .arg<fs::path>("hotzones" , "corrections.hotzones" , "location of hot zones in the calorimeter")
124  .arg<fs::path>("METfilters", "corrections.METfilters", "location of list of MET filters to apply");
125 
126  for (string mode: {"f", "F"}) {
127  string cmd = "example02 ntuple01.root ntuple02_" + mode + ".root -c example.info -j 2 -k 1 -" + mode + " -s";
128  auto const args = tokenize(cmd.c_str());
129  options(args.size(), args.data());
130  BOOST_REQUIRE_NO_THROW( options(args.size(), args.data()) );
131 
132  const auto& config = options(args.size(), args.data());
133  const auto& slice = options.slice();
134  const int steering = options.steering();
135 
136  DP::example02(input, output, config, steering, slice);
137  BOOST_REQUIRE_NO_THROW( DP::example02(input, output, config, steering, slice) );
138  }
139 
140  unique_ptr<TChain> tIn_f = DT::GetChain(vector<fs::path>{"ntuple02_f.root"}),
141  tIn_F = DT::GetChain(vector<fs::path>{"ntuple02_F.root"});
142 
143  vector<DP::RecJet> * recs_f = nullptr,
144  * recs_F = nullptr;
145  tIn_f->SetBranchAddress("recs", &recs_f);
146  tIn_F->SetBranchAddress("recs", &recs_F);
147  BOOST_TEST( tIn_f->GetEntries() == tIn_F->GetEntries() );
148 
149  for (long long i = 0; i < tIn_f->GetEntries(); ++i) {
150  tIn_f->GetEntry(i);
151  tIn_F->GetEntry(i);
152  BOOST_TEST( recs_f->size() == recs_F->size() );
153  for (size_t j = 0; j < recs_f->size(); ++j)
154  BOOST_TEST( recs_f->at(j).CorrPt() == recs_F->at(j).CorrPt() );
155  }
156 
157  fs::remove("ntuple02_f.root");
158  fs::remove("ntuple01.root");
159  }

◆ BOOST_AUTO_TEST_CASE() [9/14]

BOOST_AUTO_TEST_CASE ( ntuple_producer  )
97  {
98  fs::path output;
99 
100  DT::Options options("This is just a toy example to generate a n-tuple.", DT::config | DT::fill);
101  options.output("output" , &output, "output ROOT file")
102  .arg<bool> ("isMC" , "flags.isMC" , "flag" )
103  .arg<float> ("R" , "flags.R" , "R parameter in jet clustering algorithm")
104  .arg<int > ("year" , "flags.year" , "year (20xx)" );
105 
106  auto const args = tokenize("example01 ntuple01.root -c example.info -f");
107  BOOST_REQUIRE_NO_THROW( options(args.size(), args.data()) );
108 
109  const auto& config = options(args.size(), args.data());
110  const int steering = options.steering();
111 
112  BOOST_REQUIRE_NO_THROW( DP::example01(output, config, steering) );
113  }

◆ BOOST_AUTO_TEST_CASE() [10/14]

BOOST_AUTO_TEST_CASE ( output  )
61  {
62  BOOST_REQUIRE_THROW( DT_GetOutput("/this/file/does/not/exists.root"), boost::wrapexcept<fs::filesystem_error> );
63  BOOST_REQUIRE_NO_THROW( DT_GetOutput("this_file_is_allowed.root") );
64  }

◆ BOOST_AUTO_TEST_CASE() [11/14]

BOOST_AUTO_TEST_CASE ( printBranches  )
245  {
246  vector<fs::path> inputs {"ntuple01.root"};
247  BOOST_REQUIRE_NO_THROW( DT::printBranches(inputs) );
248  }

◆ BOOST_AUTO_TEST_CASE() [12/14]

BOOST_AUTO_TEST_CASE ( printEntries  )
231  {
232  auto f = TFile::Open("printEntries.root", "RECREATE");
233  f->mkdir("dir1");
234  auto d = f->mkdir("dir2"); d->cd();
235  auto dd = d->mkdir("subdir"); dd->cd();
236  auto t = new TTree("one_tree", "");
237  t->SetDirectory(dd);
238  t->Write();
239  f->Close();
240  BOOST_REQUIRE_NO_THROW( DT::printEntries({"printEntries.root"}) );
241  fs::remove("printEntries.root");
242  }

◆ BOOST_AUTO_TEST_CASE() [13/14]

BOOST_AUTO_TEST_CASE ( printMetaInfo  )
251  {
252  vector<fs::path> inputs {"ntuple01.root"};
253  pt::ptree tree;
254  tree.put<string>("path", "preseed");
255  BOOST_REQUIRE_NO_THROW( DT::printMetaInfo(inputs, tree) );
256  }

◆ BOOST_AUTO_TEST_CASE() [14/14]

BOOST_AUTO_TEST_CASE ( projection  )
162  {
163  fs::path input, output;
164 
165  DT::Options options("Toy example to project a n-tuple.", DT::split);
166  options.input ("input" , &input , "input ROOT file" )
167  .output("output", &output, "output ROOT file");
168 
169  auto const args = tokenize("example03 ntuple02_F.root hists03.root");
170  BOOST_REQUIRE_NO_THROW( options(args.size(), args.data()) );
171 
172  const auto& config = options(args.size(), args.data());
173  const auto& slice = options.slice();
174  const int steering = options.steering();
175 
176  BOOST_REQUIRE_NO_THROW( DP::example03(input, output, config, steering, slice) );
177 
178  fs::remove("ntuple02_F.root");
179  fs::remove("hists03.root");
180  }
Darwin::Tools::GetFirstTreeLocation
std::string GetFirstTreeLocation(const std::filesystem::path &input)
one input ROOT file
Definition: FileUtils.cc:91
DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.name
name
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:48
Darwin::Tools::printEntries
void printEntries(vector< fs::path > inputs)
Definition: printEntries.cc:22
DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.options
options
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:41
Darwin::Tools::syst
@ syst
activate -s to systematic uncertainties
Definition: Options.h:30
Darwin::Physics::example03
void example03(const fs::path &input, const fs::path &output, const pt::ptree &config, const int steering, const DT::Slice slice={1, 0})
Definition: main.cc:47
Step::verbose
static bool verbose
Definition: Step.h:40
Ntupliser_cfg.args
args
Definition: Ntupliser_cfg.py:11
BOOST_TEST
BOOST_TEST(gendijet.Rapidity()==1.3573785791881385)
std::hash< TTree * >
Hash from TTree obtained by combination of different elements.
Definition: UserInfo.h:286
Darwin::Tools::GetChain
std::unique_ptr< TChain > GetChain(std::vector< std::filesystem::path > inputs, const char *name="events")
Load chain from a list of files.
Definition: FileUtils.cc:67
Ntupliser_cfg.f
f
Definition: Ntupliser_cfg.py:255
Darwin::Physics::example02
void example02(const fs::path &input, const fs::path &output, const pt::ptree &config, const int steering, const DT::Slice slice={1, 0})
Definition: main.cc:40
compareFiles.files
files
Definition: compareFiles.py:125
Darwin::Tools::Options::parse_config
static void parse_config(boost::property_tree::ptree &, std::string="")
Parse config if given. This method calls itself to parse the tree structure.
Darwin::Tools::MetaInfo
Generic meta-information for n-tuple (including speficities to Darwin).
Definition: MetaInfo.h:65
Darwin::Tools::fill
@ fill
activate -f to fill the tree
Definition: Options.h:28
Darwin::Tools::forceMetaInfo
void forceMetaInfo(const fs::path &input, const fs::path &output, const int steering)
Definition: forceMetaInfo.cc:92
cmd
cmd
Definition: Core-cfgcmd.txt:1
Darwin::Tools::split
@ split
activate -k and -j to define slice
Definition: Options.h:27
Ntupliser_cfg.config
config
Definition: Ntupliser_cfg.py:263
DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.input
input
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:35
Darwin::Tools::Options
Common class to interpret the command line, based on Boost Program Options.
Definition: Options.h:56
Ntupliser_cfg.isMC
string isMC
Definition: Ntupliser_cfg.py:59
Darwin::Tools::printMetaInfo
int printMetaInfo(vector< fs::path > inputs, const pt::ptree &config)
Definition: printMetaInfo.cc:33
jercExample.inputs
def inputs
Definition: jercExample.py:118
Darwin::Exceptions::AnomalousEvent
Generic exception for problematic event (during event loop).
Definition: exceptions.h:48
Darwin::Tools::Friend
@ Friend
activate -F to only fill the new branches
Definition: Options.h:29
Darwin::Tools::tokenize
std::vector< const char * > tokenize(const char *str)
Definition: test.h:15
DT_GetOutput
#define DT_GetOutput(output)
Definition: FileUtils.h:96
Darwin::Exceptions::BadInput
Generic exception for ill-defined input (before the event loop).
Definition: exceptions.h:68
Darwin::Tools::printBranches
void printBranches(vector< fs::path > inputs)
Adapted from ROOT example
Definition: printBranches.cc:88
Darwin::Tools::getBool
optional< bool > getBool(string s)
Translates a string into a boolean if possible.
Definition: forceMetaInfo.cc:32
Darwin::Tools::getMetaInfo
int getMetaInfo(vector< fs::path > inputs, const fs::path &output)
Print content of the first TTree::UserInfo() found in the root file.
Definition: getMetaInfo.cc:25