 |
Darwin
1.0
Event loop based prototype framework
|
#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"
|
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) |
|
◆ 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/14]
BOOST_AUTO_TEST_CASE |
( |
all_steps |
| ) |
|
189 BOOST_REQUIRE_NO_THROW( pt::read_info(
"example.info",
config) );
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) );
◆ BOOST_AUTO_TEST_CASE() [2/14]
BOOST_AUTO_TEST_CASE |
( |
closure |
| ) |
|
261 unique_ptr<TFile> f(TFile::Open(
"ntuple02.root"));
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"};
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"));
279 size_t Hash = getHash(
"ntuple02.root");
282 auto chain = [&
config,&getHash](
const fs::path& fOut,
bool isMC) {
283 fs::remove(
"ntuple02.root");
284 config.put<
bool>(
"flags.isMC", isMC);
287 DP::example01(
"ntuple01.root",
config, steering);
290 vector<fs::path> inputs = {
"hists03.root"};
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"));
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) );
306 pt::read_json(
"out1.json",
config);
307 BOOST_TEST( Hash == chain(
"out2.json",
true ) );
308 BOOST_TEST( Hash != chain(
"out2.json",
false) );
310 pt::read_xml(
"out1.xml",
config);
312 BOOST_TEST( Hash == chain(
"out2.xml",
true ) );
313 BOOST_TEST( Hash != chain(
"out2.xml",
false) );
315 vector<fs::path> inputs = {
"hists03_info_true.root" ,
"hists03_json_true.root" ,
"hists03_xml_true.root" };
317 inputs = {
"hists03_info_false.root",
"hists03_json_false.root",
"hists03_xml_false.root"};
319 inputs = {
"hists03_info_true.root" ,
"hists03_info_false.root"};
322 for (
string name: {
"true",
"false",
"failure"})
323 fs::remove(name +
".info");
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");
◆ BOOST_AUTO_TEST_CASE() [3/14]
BOOST_AUTO_TEST_CASE |
( |
exceptions |
| ) |
|
336 auto f = unique_ptr<TFile>(TFile::Open(
"ntuple02.root",
"READ"));
337 auto t = unique_ptr<TTree>(f->Get<TTree>(
"events"));
339 cout <<
DE::BadInput(
"Here is a bad input", metainfo).what() << endl;
341 cout <<
DE::AnomalousEvent(
"Here is an anomally (just for the example)", t).what() << endl;
345 BOOST_REQUIRE_NO_THROW( pt::read_info(DARWIN
"/test/example.info",
config) );
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 > );
352 fs::remove(
"inexistent.out");
353 fs::remove(
"ntuple01.root");
◆ BOOST_AUTO_TEST_CASE() [4/14]
BOOST_AUTO_TEST_CASE |
( |
forceMetaInfo |
| ) |
|
209 vector<fs::path> input = {
"ntuple02.root"};
212 input = {
"ntuple01.root"};
214 unique_ptr<TFile> f(TFile::Open(
"ntuple01.root",
"READ"));
215 auto events = unique_ptr<TTree>(f->Get<TTree>(
"events"));
217 BOOST_TEST( !metainfo.Find(
"history") );
218 BOOST_TEST( !metainfo.Get<
bool>(
"git",
"reproducible") );
◆ BOOST_AUTO_TEST_CASE() [5/14]
BOOST_AUTO_TEST_CASE |
( |
getBool |
| ) |
|
199 BOOST_TEST( !
DT::getBool(
"this will not work").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 );
◆ BOOST_AUTO_TEST_CASE() [6/14]
BOOST_AUTO_TEST_CASE |
( |
GetFirstTreeLocation |
| ) |
|
226 TFile::Open(
"GetFirstTreeLocation.root",
"RECREATE")->Close();
◆ BOOST_AUTO_TEST_CASE() [7/14]
BOOST_AUTO_TEST_CASE |
( |
getters |
| ) |
|
68 vector<fs::path> files;
69 BOOST_REQUIRE_THROW( DT::GetHist<TH1>(files,
"h"), boost::wrapexcept<fs::filesystem_error> );
70 BOOST_REQUIRE_THROW(
DT::GetChain (files,
"t"), boost::wrapexcept<fs::filesystem_error> );
72 for (
int i = 1; i < 4; ++i) {
73 fs::path name = Form(
"getters_%d.root", i);
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());
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> );
89 BOOST_REQUIRE_NO_THROW( DT::GetHist<TH1>(files,
"h") );
◆ BOOST_AUTO_TEST_CASE() [8/14]
BOOST_AUTO_TEST_CASE |
( |
ntuple_modifier |
| ) |
|
117 fs::path input, output;
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");
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()) );
132 const auto&
config = options(args.size(), args.data());
133 const auto& slice = options.slice();
134 const int steering = options.steering();
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"});
143 vector<DP::RecJet> * 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() );
149 for (
long long i = 0; i < tIn_f->GetEntries(); ++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() );
157 fs::remove(
"ntuple02_f.root");
158 fs::remove(
"ntuple01.root");
◆ BOOST_AUTO_TEST_CASE() [9/14]
BOOST_AUTO_TEST_CASE |
( |
ntuple_producer |
| ) |
|
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)" );
106 auto const args =
tokenize(
"example01 ntuple01.root -c example.info -f");
107 BOOST_REQUIRE_NO_THROW( options(args.size(), args.data()) );
109 const auto&
config = options(args.size(), args.data());
110 const int steering = options.steering();
112 BOOST_REQUIRE_NO_THROW( DP::example01(output,
config, steering) );
◆ BOOST_AUTO_TEST_CASE() [10/14]
BOOST_AUTO_TEST_CASE |
( |
output |
| ) |
|
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") );
◆ BOOST_AUTO_TEST_CASE() [11/14]
BOOST_AUTO_TEST_CASE |
( |
printBranches |
| ) |
|
246 vector<fs::path> inputs {
"ntuple01.root"};
◆ BOOST_AUTO_TEST_CASE() [12/14]
BOOST_AUTO_TEST_CASE |
( |
printEntries |
| ) |
|
232 auto f = TFile::Open(
"printEntries.root",
"RECREATE");
234 auto d = f->mkdir(
"dir2"); d->cd();
235 auto dd = d->mkdir(
"subdir"); dd->cd();
236 auto t =
new TTree(
"one_tree",
"");
241 fs::remove(
"printEntries.root");
◆ BOOST_AUTO_TEST_CASE() [13/14]
BOOST_AUTO_TEST_CASE |
( |
printMetaInfo |
| ) |
|
252 vector<fs::path> inputs {
"ntuple01.root"};
254 tree.put<
string>(
"path",
"preseed");
◆ BOOST_AUTO_TEST_CASE() [14/14]
BOOST_AUTO_TEST_CASE |
( |
projection |
| ) |
|
163 fs::path input, output;
166 options.input (
"input" , &input ,
"input ROOT file" )
167 .output(
"output", &output,
"output ROOT file");
169 auto const args =
tokenize(
"example03 ntuple02_F.root hists03.root");
170 BOOST_REQUIRE_NO_THROW( options(args.size(), args.data()) );
172 const auto&
config = options(args.size(), args.data());
173 const auto& slice = options.slice();
174 const int steering = options.steering();
178 fs::remove(
"ntuple02_F.root");
179 fs::remove(
"hists03.root");
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
Hash from TTree obtained by combination of different elements.
Definition: UserInfo.h:286
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
#define DT_GetOutput(output)
Definition: FileUtils.h:96
Generic exception for problematic event (during event loop).
Definition: exceptions.h:48