 |
DAS
3.0
Das Analysis System
|
#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 "example04.cc"
#include "../bin/getMetaInfo.cc"
#include "../bin/printMetaInfo.cc"
#include "../bin/printEntries.cc"
#include "../bin/printBranches.cc"
#include "../bin/forceMetaInfo.cc"
|
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}) |
|
template<bool DARWIN_TEST_EXCEPTIONS = false> |
void | example03 (const fs::path &input, const fs::path &output, const pt::ptree &config, const int steering, const DT::Slice slice={1, 0}) |
|
void | example04 (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_empty_input) |
|
| BOOST_AUTO_TEST_CASE (getters_broken_input) |
|
| BOOST_AUTO_TEST_CASE (getters_wrong_objects) |
|
| BOOST_AUTO_TEST_CASE (ntuple_producer) |
|
| BOOST_AUTO_TEST_CASE (ntuple_weight_modifier) |
|
| BOOST_AUTO_TEST_CASE (ntuple_JEC_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) |
|
◆ 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 |
◆ BOOST_AUTO_TEST_CASE() [1/17]
BOOST_AUTO_TEST_CASE |
( |
all_steps |
| ) |
|
277 BOOST_REQUIRE_NO_THROW( pt::read_info(
"example.info",
config) );
280 BOOST_REQUIRE_NO_THROW( DP::example01(
"ntuple01.root",
config, steering) );
281 BOOST_REQUIRE_NO_THROW(
DP::example02(
"ntuple01.root",
"ntuple02.root",
config, steering) );
282 BOOST_REQUIRE_NO_THROW(
DP::example03(
"ntuple02.root",
"ntuple03.root",
config, steering) );
283 BOOST_REQUIRE_NO_THROW(
DP::example04(
"ntuple03.root",
"hists04.root",
config, steering) );
◆ BOOST_AUTO_TEST_CASE() [2/17]
BOOST_AUTO_TEST_CASE |
( |
closure |
| ) |
|
350 unique_ptr<TFile>
f(TFile::Open(
"ntuple02.root"));
354 vector<string> exts {
"info",
"xml",
"json"};
355 for (
string ext: exts) {
356 fs::path file =
"out1." + ext;
357 vector<fs::path>
inputs = {
"ntuple02.root"};
361 auto getHash = [](
const fs::path& ntuple) {
362 auto rootfile = unique_ptr<TFile>(TFile::Open(ntuple.c_str(),
"READ"));
363 auto events = unique_ptr<TTree>(rootfile->Get<TTree>(
"events"));
368 size_t Hash = getHash(
"ntuple02.root");
371 auto chain = [&
config,&getHash](
const fs::path& fOut,
bool isMC) {
372 fs::remove(
"ntuple02.root");
373 fs::remove(
"ntuple03.root");
377 DP::example01(
"ntuple01.root",
config, steering);
381 vector<fs::path>
inputs = {
"hists04.root"};
383 size_t Hash = getHash(
"ntuple02.root");
384 fs::remove(
"ntuple01.root");
385 fs::rename(
"hists04.root", Form(
"hists04_%s_%s.root", &(fOut.extension().c_str()[1]),
isMC ?
"true" :
"false"));
389 BOOST_TEST_MESSAGE(
"Reading config in INFO format" );
390 pt::read_info(
"out1.info",
config);
391 int oldseed =
config.get<
int>(
"preseed");
392 config.put<
int>(
"preseed", 2*oldseed);
393 BOOST_TEST( Hash != chain(
"out2.info",
true ) );
394 config.put<
int>(
"preseed", oldseed);
395 BOOST_TEST( Hash == chain(
"out2.info",
true ) );
396 BOOST_TEST( Hash != chain(
"out2.info",
false) );
398 BOOST_TEST_MESSAGE(
"Reading config in JSON format" );
399 pt::read_json(
"out1.json",
config);
400 BOOST_TEST( Hash == chain(
"out2.json",
true ) );
401 BOOST_TEST( Hash != chain(
"out2.json",
false) );
403 BOOST_TEST_MESSAGE(
"Reading config in XML format" );
404 pt::read_xml(
"out1.xml",
config);
406 BOOST_TEST( Hash == chain(
"out2.xml",
true ) );
407 BOOST_TEST( Hash != chain(
"out2.xml",
false) );
409 vector<fs::path>
inputs = {
"hists04_info_true.root" ,
"hists04_json_true.root" ,
"hists04_xml_true.root" };
411 inputs = {
"hists04_info_false.root",
"hists04_json_false.root",
"hists04_xml_false.root"};
413 inputs = {
"hists04_info_true.root" ,
"hists04_info_false.root"};
416 for (
string name: {
"true",
"false",
"failure"})
417 fs::remove(
name +
".info");
419 for (
string ext: exts) {
420 fs::remove(
"out1." + ext);
421 fs::remove(
"out2." + ext);
422 for (
string b: {
"true",
"false"})
423 fs::remove(
"hists04_" + ext +
"_" + b +
".root");
◆ BOOST_AUTO_TEST_CASE() [3/17]
BOOST_AUTO_TEST_CASE |
( |
exceptions |
| ) |
|
430 auto f = unique_ptr<TFile>(TFile::Open(
"ntuple02.root",
"READ"));
431 auto t = unique_ptr<TTree>(
f->Get<TTree>(
"events"));
433 cout <<
DE::BadInput(
"Here is a bad input", metainfo).what() << endl;
435 cout <<
DE::AnomalousEvent(
"Here is an anomally (just for the example)", t).what() << endl;
439 BOOST_REQUIRE_NO_THROW( pt::read_info(DARWIN
"/test/example.info",
config) );
442 DP::example01(
"ntuple01.root",
config, steering);
443 BOOST_REQUIRE_THROW( DP::example02<true>(
"ntuple01.root",
"ntuple02.root",
config, steering), wrapexcept<DE::AnomalousEvent> );
444 BOOST_REQUIRE_THROW( DP::example01<true>(
"ntuple01.root",
config, steering), wrapexcept<DE::BadInput > );
446 fs::remove(
"inexistent.out");
447 fs::remove(
"ntuple01.root");
◆ BOOST_AUTO_TEST_CASE() [4/17]
BOOST_AUTO_TEST_CASE |
( |
forceMetaInfo |
| ) |
|
298 vector<fs::path>
input = {
"ntuple02.root"};
301 input = {
"ntuple01.root"};
303 unique_ptr<TFile>
f(TFile::Open(
"ntuple01.root",
"READ"));
304 auto events = unique_ptr<TTree>(
f->Get<TTree>(
"events"));
307 BOOST_TEST( !metainfo.Get<
bool>(
"git",
"reproducible") );
◆ BOOST_AUTO_TEST_CASE() [5/17]
BOOST_AUTO_TEST_CASE |
( |
getBool |
| ) |
|
◆ BOOST_AUTO_TEST_CASE() [6/17]
BOOST_AUTO_TEST_CASE |
( |
GetFirstTreeLocation |
| ) |
|
315 TFile::Open(
"GetFirstTreeLocation.root",
"RECREATE")->Close();
◆ BOOST_AUTO_TEST_CASE() [7/17]
BOOST_AUTO_TEST_CASE |
( |
getters_broken_input |
| ) |
|
89 vector<fs::path>
files{
"/this/dir/does/not/exist"};
◆ BOOST_AUTO_TEST_CASE() [8/17]
BOOST_AUTO_TEST_CASE |
( |
getters_empty_input |
| ) |
|
80 vector<fs::path>
files;
82 BOOST_TEST_MESSAGE(
"Testing exceptions for empty list of input files" );
83 BOOST_REQUIRE_THROW( flow.GetInputHist(
"h") , wrapexcept<invalid_argument> );
84 BOOST_REQUIRE_THROW( flow.GetInputTree({1, 0},
"t"), wrapexcept<invalid_argument> );
◆ BOOST_AUTO_TEST_CASE() [9/17]
BOOST_AUTO_TEST_CASE |
( |
getters_wrong_objects |
| ) |
|
95 vector<fs::path>
files;
96 for (
int i = 1; i < 4; ++i) {
97 fs::path
name = Form(
"getters_%d.root", i);
100 unique_ptr<TFile>
f(TFile::Open(
name.c_str(),
"RECREATE"));
101 auto h = make_unique<TH1F>(
"h",
"h", 1, 0., 1.);
102 auto t = make_unique<TTree>(
"t",
"t");
103 h->SetDirectory(
f.get());
104 t->SetDirectory(
f.get());
110 BOOST_TEST_MESSAGE(
"Testing exceptions for inexisting histogram" );
111 BOOST_REQUIRE_THROW( flow.GetInputHist(
"thisHistDoesNotExist"), wrapexcept<DE::BadInput> );
112 BOOST_TEST_MESSAGE(
"Testing exceptions for empty tree" );
113 BOOST_REQUIRE_THROW( flow.GetInputTree({1, 0},
"t" ), wrapexcept<invalid_argument> );
114 BOOST_TEST_MESSAGE(
"Testing exceptions for inexisting tree" );
115 BOOST_REQUIRE_THROW( flow.GetInputTree({1, 0},
"thisTreeDoesNotExist"), wrapexcept<DE::BadInput> );
117 BOOST_REQUIRE_NO_THROW( flow.GetInputHist(
"h") );
◆ BOOST_AUTO_TEST_CASE() [10/17]
BOOST_AUTO_TEST_CASE |
( |
ntuple_JEC_modifier |
| ) |
|
194 fs::path
input, output;
199 .output(
"output", &output,
"output ROOT file");
201 for (
string mode: {
"fill",
"Friend"}) {
202 string cmd =
"example03 ntuple02_" + mode +
".root ntuple03_" + mode +
".root -j 3 -k 1 -" + mode.at(0) +
" -s";
209 const auto& slice =
options.slice();
210 const int steering =
options.steering();
215 vector<DP::RecJet> * recs_f =
nullptr,
220 flow_F.GetInputTree();
221 BOOST_REQUIRE_NO_THROW( recs_f = flow_f.GetBranchReadOnly<vector<DP::RecJet>>(
"recJets") );
222 BOOST_REQUIRE_NO_THROW( recs_F = flow_F.GetBranchReadOnly<vector<DP::RecJet>>(
"recJets") );
224 string active_branches_f = flow_f.DumpActiveBranches(),
225 active_branches_F = flow_F.DumpActiveBranches();
226 cout <<
"Without friends: " << active_branches_f << endl;
227 cout <<
"With friends: " << active_branches_F << endl;
228 BOOST_TEST( active_branches_f == active_branches_F );
230 auto tIn_f = flow_f.GetInputTree(),
231 tIn_F = flow_F.GetInputTree();
232 BOOST_TEST( tIn_f->GetEntries() == tIn_F->GetEntries() );
234 for (
long long i = 0; i < tIn_f->GetEntries(); ++i) {
237 BOOST_TEST( recs_f->size() == recs_F->size() );
238 for (
size_t j = 0; j < recs_f->size(); ++j)
239 BOOST_TEST( recs_f->at(j).CorrPt() == recs_F->at(j).CorrPt() );
242 fs::remove(
"ntuple02_fill.root");
243 fs::remove(
"ntuple03_fill.root");
◆ BOOST_AUTO_TEST_CASE() [11/17]
BOOST_AUTO_TEST_CASE |
( |
ntuple_producer |
| ) |
|
129 options.output(
"output" , &output,
"output ROOT file")
130 .arg<
bool> (
"isMC" ,
"flags.isMC" ,
"flag" )
131 .arg<float> (
"R" ,
"flags.R" ,
"R parameter in jet clustering algorithm")
132 .arg<
int > (
"year" ,
"flags.year" ,
"year (20xx)" );
134 auto const args =
tokenize(
"example01 ntuple01.root -c example.info -f");
138 const int steering =
options.steering();
140 DP::example01(output,
config, steering);
141 BOOST_REQUIRE_NO_THROW( DP::example01(output,
config, steering) );
◆ BOOST_AUTO_TEST_CASE() [12/17]
BOOST_AUTO_TEST_CASE |
( |
ntuple_weight_modifier |
| ) |
|
146 fs::path
input, output;
151 .output(
"output", &output,
"output ROOT file")
152 .arg<fs::path>(
"filters",
"corrections.filters",
"location of list of event filters to apply");
154 for (
string mode: {
"fill",
"Friend"}) {
155 string cmd =
"example02 ntuple01.root ntuple02_" + mode +
".root -c example.info -v -j 2 -k 1 -" + mode.at(0);
161 const auto& slice =
options.slice();
162 const int steering =
options.steering();
174 tIn_F = flow_F.GetInputTree();
175 BOOST_TEST( tIn_f->GetEntries() == tIn_F->GetEntries() );
177 BOOST_TEST_MESSAGE(
"Trying to load an inexistant branch" );
181 BOOST_TEST_MESSAGE(
"Loading the analog branch in the friend and no-friend n-tuples." );
182 BOOST_REQUIRE_NO_THROW( event_f = flow_f.GetBranchReadOnly<
DP::RecEvent>(
"recEvent") );
183 BOOST_REQUIRE_NO_THROW( event_F = flow_F.GetBranchReadOnly<
DP::RecEvent>(
"recEvent") );
185 for (
long long i = 0; i < tIn_f->GetEntries(); ++i) {
◆ BOOST_AUTO_TEST_CASE() [13/17]
BOOST_AUTO_TEST_CASE |
( |
output |
| ) |
|
74 BOOST_REQUIRE_THROW(
DT::GetOutputFile(
"/this/file/does/not/exists.root"), wrapexcept<fs::filesystem_error> );
◆ BOOST_AUTO_TEST_CASE() [14/17]
BOOST_AUTO_TEST_CASE |
( |
printBranches |
| ) |
|
335 vector<fs::path>
inputs {
"ntuple01.root"};
◆ BOOST_AUTO_TEST_CASE() [15/17]
BOOST_AUTO_TEST_CASE |
( |
printEntries |
| ) |
|
321 auto f = TFile::Open(
"printEntries.root",
"RECREATE");
323 auto d =
f->mkdir(
"dir2"); d->cd();
324 auto dd = d->mkdir(
"subdir"); dd->cd();
325 auto t =
new TTree(
"one_tree",
"");
330 fs::remove(
"printEntries.root");
◆ BOOST_AUTO_TEST_CASE() [16/17]
BOOST_AUTO_TEST_CASE |
( |
printMetaInfo |
| ) |
|
341 vector<fs::path>
inputs {
"ntuple01.root"};
343 tree.put<
string>(
"path",
"preseed");
◆ BOOST_AUTO_TEST_CASE() [17/17]
BOOST_AUTO_TEST_CASE |
( |
projection |
| ) |
|
248 fs::path
input, output;
252 .output(
"output", &output,
"output ROOT file");
254 BOOST_TEST( fs::exists(
"ntuple03_Friend.root") );
255 auto const args =
tokenize(
"example04 ntuple03_Friend.root hists04.root -v");
259 const auto& slice =
options.slice();
260 const int steering =
options.steering();
264 fs::remove(
"ntuple01.root");
265 fs::remove(
"ntuple02_Friend.root");
266 fs::remove(
"ntuple03_Friend.root");
267 fs::remove(
"hists04.root");
name
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:48
options
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:41
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:51
static bool verbose
Definition: Step.h:40
args
Definition: Ntupliser_cfg.py:11
BOOST_TEST(gendijet.Rapidity()==1.3573785791881385)
Hash from TTree obtained by combination of different elements.
Definition: UserInfo.h:313
f
Definition: Ntupliser_cfg.py:318
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:43
void example04(const fs::path &input, const fs::path &output, const pt::ptree &config, const int steering, const DT::Slice slice={1, 0})
Definition: main.cc:58
files
Definition: compareFiles.py:125
cmd
Definition: Core-cfgcmd.txt:1
config
Definition: Ntupliser_cfg.py:326
input
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:35
Weights weights
e.g. cross section normalisation
Definition: GenericObject.h:45
Generic detector-level event.
Definition: Event.h:32
dictionary isMC
Definition: Ntupliser_cfg.py:61
def inputs
Definition: jercExample.py:118
Generic exception for problematic event (during event loop).
Definition: exceptions.h:63