|
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) |
|
| 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/15]
BOOST_AUTO_TEST_CASE |
( |
all_steps |
| ) |
|
240 BOOST_REQUIRE_NO_THROW( pt::read_info(
"example.info",
config) );
243 BOOST_REQUIRE_NO_THROW( DP::example01(
"ntuple01.root",
config, steering) );
244 BOOST_REQUIRE_NO_THROW(
DP::example02(
"ntuple01.root",
"ntuple02.root",
config, steering) );
245 BOOST_REQUIRE_NO_THROW(
DP::example03(
"ntuple02.root",
"ntuple03.root",
config, steering) );
246 BOOST_REQUIRE_NO_THROW(
DP::example04(
"ntuple03.root",
"hists04.root",
config, steering) );
◆ BOOST_AUTO_TEST_CASE() [2/15]
BOOST_AUTO_TEST_CASE |
( |
closure |
| ) |
|
313 unique_ptr<TFile>
f(TFile::Open(
"ntuple02.root"));
317 vector<string> exts {
"info",
"xml",
"json"};
318 for (
string ext: exts) {
319 fs::path file =
"out1." + ext;
320 vector<fs::path>
inputs = {
"ntuple02.root"};
324 auto getHash = [](
const fs::path& ntuple) {
325 auto rootfile = unique_ptr<TFile>(TFile::Open(ntuple.c_str(),
"READ"));
326 auto events = unique_ptr<TTree>(rootfile->Get<TTree>(
"events"));
331 size_t Hash = getHash(
"ntuple02.root");
334 auto chain = [&
config,&getHash](
const fs::path& fOut,
bool isMC) {
335 fs::remove(
"ntuple02.root");
336 fs::remove(
"ntuple03.root");
340 DP::example01(
"ntuple01.root",
config, steering);
344 vector<fs::path>
inputs = {
"hists04.root"};
346 size_t Hash = getHash(
"ntuple02.root");
347 fs::remove(
"ntuple01.root");
348 fs::rename(
"hists04.root", Form(
"hists04_%s_%s.root", &(fOut.extension().c_str()[1]),
isMC ?
"true" :
"false"));
352 pt::read_info(
"out1.info",
config);
353 int oldseed =
config.get<
int>(
"preseed");
354 config.put<
int>(
"preseed", 2*oldseed);
355 BOOST_TEST( Hash != chain(
"out2.info",
true ) );
356 config.put<
int>(
"preseed", oldseed);
357 BOOST_TEST( Hash == chain(
"out2.info",
true ) );
358 BOOST_TEST( Hash != chain(
"out2.info",
false) );
360 pt::read_json(
"out1.json",
config);
361 BOOST_TEST( Hash == chain(
"out2.json",
true ) );
362 BOOST_TEST( Hash != chain(
"out2.json",
false) );
364 pt::read_xml(
"out1.xml",
config);
366 BOOST_TEST( Hash == chain(
"out2.xml",
true ) );
367 BOOST_TEST( Hash != chain(
"out2.xml",
false) );
369 vector<fs::path>
inputs = {
"hists04_info_true.root" ,
"hists04_json_true.root" ,
"hists04_xml_true.root" };
371 inputs = {
"hists04_info_false.root",
"hists04_json_false.root",
"hists04_xml_false.root"};
373 inputs = {
"hists04_info_true.root" ,
"hists04_info_false.root"};
376 for (
string name: {
"true",
"false",
"failure"})
377 fs::remove(
name +
".info");
379 for (
string ext: exts) {
380 fs::remove(
"out1." + ext);
381 fs::remove(
"out2." + ext);
382 for (
string b: {
"true",
"false"})
383 fs::remove(
"hists04_" + ext +
"_" + b +
".root");
◆ BOOST_AUTO_TEST_CASE() [3/15]
BOOST_AUTO_TEST_CASE |
( |
exceptions |
| ) |
|
390 auto f = unique_ptr<TFile>(TFile::Open(
"ntuple02.root",
"READ"));
391 auto t = unique_ptr<TTree>(
f->Get<TTree>(
"events"));
393 cout <<
DE::BadInput(
"Here is a bad input", metainfo).what() << endl;
395 cout <<
DE::AnomalousEvent(
"Here is an anomally (just for the example)", t).what() << endl;
399 BOOST_REQUIRE_NO_THROW( pt::read_info(DARWIN
"/test/example.info",
config) );
402 DP::example01(
"ntuple01.root",
config, steering);
403 BOOST_REQUIRE_THROW( DP::example02<true>(
"ntuple01.root",
"ntuple02.root",
config, steering), boost::wrapexcept<DE::AnomalousEvent> );
404 BOOST_REQUIRE_THROW( DP::example01<true>(
"ntuple01.root",
config, steering), boost::wrapexcept<DE::BadInput > );
406 fs::remove(
"inexistent.out");
407 fs::remove(
"ntuple01.root");
◆ BOOST_AUTO_TEST_CASE() [4/15]
BOOST_AUTO_TEST_CASE |
( |
forceMetaInfo |
| ) |
|
261 vector<fs::path>
input = {
"ntuple02.root"};
264 input = {
"ntuple01.root"};
266 unique_ptr<TFile>
f(TFile::Open(
"ntuple01.root",
"READ"));
267 auto events = unique_ptr<TTree>(
f->Get<TTree>(
"events"));
270 BOOST_TEST( !metainfo.Get<
bool>(
"git",
"reproducible") );
◆ BOOST_AUTO_TEST_CASE() [5/15]
BOOST_AUTO_TEST_CASE |
( |
getBool |
| ) |
|
◆ BOOST_AUTO_TEST_CASE() [6/15]
BOOST_AUTO_TEST_CASE |
( |
GetFirstTreeLocation |
| ) |
|
278 TFile::Open(
"GetFirstTreeLocation.root",
"RECREATE")->Close();
◆ BOOST_AUTO_TEST_CASE() [7/15]
BOOST_AUTO_TEST_CASE |
( |
getters |
| ) |
|
77 vector<fs::path>
files;
78 BOOST_REQUIRE_THROW( DT::GetHist<TH1>(
files,
"h"), boost::wrapexcept<fs::filesystem_error> );
79 BOOST_REQUIRE_THROW(
DT::GetChain (
files, {0, 1},
"t"), boost::wrapexcept<fs::filesystem_error> );
81 for (
int i = 1; i < 4; ++i) {
82 fs::path
name = Form(
"getters_%d.root", i);
85 unique_ptr<TFile>
f(TFile::Open(
name.c_str(),
"RECREATE"));
86 auto h = make_unique<TH1F>(
"h",
"h", 1, 0., 1.);
87 auto t = make_unique<TTree>(
"t",
"t");
88 h->SetDirectory(
f.get());
89 t->SetDirectory(
f.get());
94 BOOST_REQUIRE_THROW(
DT::GetChain (
files, {0, 1},
"t" ), boost::wrapexcept<invalid_argument> );
95 BOOST_REQUIRE_THROW( DT::GetHist<TH1>(
files,
"thisHistDoesNotExist"), boost::wrapexcept<DE::BadInput> );
96 BOOST_REQUIRE_THROW(
DT::GetChain (
files, {0, 1},
"thisTreeDoesNotExist"), boost::wrapexcept<DE::BadInput> );
98 BOOST_REQUIRE_NO_THROW( DT::GetHist<TH1>(
files,
"h") );
◆ BOOST_AUTO_TEST_CASE() [8/15]
BOOST_AUTO_TEST_CASE |
( |
ntuple_JEC_modifier |
| ) |
|
168 fs::path
input, output;
173 .output(
"output", &output,
"output ROOT file");
175 for (
string mode: {
"f",
"F"}) {
176 string cmd =
"example03 ntuple02_" + mode +
".root ntuple03_" + mode +
".root -j 3 -k 1 -" + mode +
" -s";
182 const auto& slice =
options.slice();
183 const int steering =
options.steering();
189 unique_ptr<TChain> tIn_f =
DT::GetChain(vector<fs::path>{
"ntuple03_f.root"}),
190 tIn_F =
DT::GetChain(vector<fs::path>{
"ntuple03_F.root"});
192 vector<DP::RecJet> * recs_f =
nullptr,
196 BOOST_TEST( tIn_f->GetEntries() == tIn_F->GetEntries() );
198 for (
long long i = 0; i < tIn_f->GetEntries(); ++i) {
201 BOOST_TEST( recs_f->size() == recs_F->size() );
202 for (
size_t j = 0; j < recs_f->size(); ++j)
203 BOOST_TEST( recs_f->at(j).CorrPt() == recs_F->at(j).CorrPt() );
206 fs::remove(
"ntuple02_f.root");
207 fs::remove(
"ntuple03_f.root");
◆ BOOST_AUTO_TEST_CASE() [9/15]
BOOST_AUTO_TEST_CASE |
( |
ntuple_producer |
| ) |
|
110 options.output(
"output" , &output,
"output ROOT file")
111 .arg<
bool> (
"isMC" ,
"flags.isMC" ,
"flag" )
112 .arg<float> (
"R" ,
"flags.R" ,
"R parameter in jet clustering algorithm")
113 .arg<
int > (
"year" ,
"flags.year" ,
"year (20xx)" );
115 auto const args =
tokenize(
"example01 ntuple01.root -c example.info -f");
119 const int steering =
options.steering();
121 BOOST_REQUIRE_NO_THROW( DP::example01(output,
config, steering) );
◆ BOOST_AUTO_TEST_CASE() [10/15]
BOOST_AUTO_TEST_CASE |
( |
ntuple_weight_modifier |
| ) |
|
126 fs::path
input, output;
131 .output(
"output", &output,
"output ROOT file")
132 .arg<fs::path>(
"filters",
"corrections.filters",
"location of list of MET filters to apply");
134 for (
string mode: {
"f",
"F"}) {
135 string cmd =
"example02 ntuple01.root ntuple02_" + mode +
".root -c example.info -j 2 -k 1 -" + mode;
141 const auto& slice =
options.slice();
142 const int steering =
options.steering();
148 unique_ptr<DT::ChainSlice> tIn_f =
DT::GetChain(vector<fs::path>{
"ntuple02_f.root"}),
149 tIn_F =
DT::GetChain(vector<fs::path>{
"ntuple02_F.root"});
159 for (
long long i = 0; i < tIn_f->
GetEntries(); ++i) {
162 BOOST_TEST( event_f->weights.front() == event_F->weights.front() );
◆ BOOST_AUTO_TEST_CASE() [11/15]
BOOST_AUTO_TEST_CASE |
( |
output |
| ) |
|
71 BOOST_REQUIRE_THROW(
DT_GetOutput(
"/this/file/does/not/exists.root"), boost::wrapexcept<fs::filesystem_error> );
72 BOOST_REQUIRE_NO_THROW(
DT_GetOutput(
"this_file_is_allowed.root") );
◆ BOOST_AUTO_TEST_CASE() [12/15]
BOOST_AUTO_TEST_CASE |
( |
printBranches |
| ) |
|
298 vector<fs::path>
inputs {
"ntuple01.root"};
◆ BOOST_AUTO_TEST_CASE() [13/15]
BOOST_AUTO_TEST_CASE |
( |
printEntries |
| ) |
|
284 auto f = TFile::Open(
"printEntries.root",
"RECREATE");
286 auto d =
f->mkdir(
"dir2"); d->cd();
287 auto dd = d->mkdir(
"subdir"); dd->cd();
288 auto t =
new TTree(
"one_tree",
"");
293 fs::remove(
"printEntries.root");
◆ BOOST_AUTO_TEST_CASE() [14/15]
BOOST_AUTO_TEST_CASE |
( |
printMetaInfo |
| ) |
|
304 vector<fs::path>
inputs {
"ntuple01.root"};
306 tree.put<
string>(
"path",
"preseed");
◆ BOOST_AUTO_TEST_CASE() [15/15]
BOOST_AUTO_TEST_CASE |
( |
projection |
| ) |
|
212 fs::path
input, output;
216 .output(
"output", &output,
"output ROOT file");
218 auto const args =
tokenize(
"example04 ntuple02_F.root hists04.root");
222 const auto& slice =
options.slice();
223 const int steering =
options.steering();
227 fs::remove(
"ntuple01.root");
228 fs::remove(
"ntuple02_F.root");
229 fs::remove(
"ntuple03_F.root");
230 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:49
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:286
f
Definition: Ntupliser_cfg.py:252
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:41
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:56
files
Definition: compareFiles.py:125
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
Generic detector-level event.
Definition: Event.h:64
string isMC
Definition: Ntupliser_cfg.py:59
def inputs
Definition: jercExample.py:118
Generic exception for problematic event (during event loop).
Definition: exceptions.h:48
#define DT_GetOutput(output)
Definition: FileUtils.h:222