DAS  3.0
Das Analysis System
MetaInfo.cc File Reference
#include <boost/test/included/unit_test.hpp>
#include <boost/exception/all.hpp>
#include "test.h"
#include "MetaInfo.h"
#include <TFile.h>
#include <TTree.h>
#include <memory>
#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 dependency graph for MetaInfo.cc:

Macros

#define BOOST_TEST_MODULE   testMetaInfo
 

Functions

 BOOST_AUTO_TEST_CASE (flags_and_corrections)
 
 BOOST_AUTO_TEST_CASE (git)
 
 BOOST_AUTO_TEST_CASE (software_version)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   testMetaInfo

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/3]

BOOST_AUTO_TEST_CASE ( flags_and_corrections  )
30  {
31  pt::ptree config;
32  BOOST_REQUIRE_NO_THROW( pt::read_info(DARWIN "/test/example.info", config) );
33 
34  auto events = make_unique<TTree>("events", "events");
35 
36  MetaInfo metainfo1(events, config);
37  BOOST_TEST( metainfo1.Get<bool>("flags", "isMC") == true );
38  BOOST_TEST_MESSAGE( "Checking reproducibility" );
39  BOOST_TEST_WARN( metainfo1.Get<bool>("git", "reproducible") == true );
40  events->GetUserInfo()->ls();
41 
42  hash<UserInfo> HashM;
43  MetaInfo metainfo2(events, config);
44  BOOST_TEST( HashM(metainfo1) == HashM(metainfo2) );
45 
46  BOOST_TEST_MESSAGE( "Checking inconsistent preseeds" );
47  config.put<int>("preseed", 42);
48  BOOST_REQUIRE_NO_THROW( MetaInfo(events, config) );
49 
50  BOOST_TEST_MESSAGE( "Checking exception in case of inconsistent flags" );
51  config.put<bool>("flags.isMC", false);
52  config.put<bool>("flags.label", "aNewLabel");
53  BOOST_REQUIRE_THROW( MetaInfo(events, config), wrapexcept<invalid_argument> );
54 
55  auto events2 = make_unique<TTree>("events2", "events");
56  MetaInfo metainfo3(events2, config);
57  BOOST_TEST( HashM(metainfo1) != HashM(metainfo3) );
58  hash<TTree*> HashT;
59  BOOST_TEST( HashT(events.get()) != HashT(events2.get()));
60 
61  BOOST_TEST_MESSAGE( "Testing incomplete metainfo" );
62  auto events3 = make_unique<TTree>("events3", "events");
63  UserInfo ui(events3.get());
64  ui.Set<int>("flags", "R", 4);
65  BOOST_REQUIRE_THROW( MetaInfo(events3, config), wrapexcept<invalid_argument> );
66  }

◆ BOOST_AUTO_TEST_CASE() [2/3]

BOOST_AUTO_TEST_CASE ( git  )
Todo:
Test MetaInfo::PrintStatus
69  {
70  BOOST_TEST_MESSAGE( "Testing empty git path" );
71  BOOST_REQUIRE_THROW( MetaInfo(MetaInfo::IKnowWhatIAmDoing{}, ""), wrapexcept<fs::filesystem_error> );
72 
73  BOOST_TEST_MESSAGE( "Testing wrong git path" );
74  BOOST_REQUIRE_THROW( MetaInfo(MetaInfo::IKnowWhatIAmDoing{}, "/this/path/does/not/exist"), wrapexcept<fs::filesystem_error> );
75 
77 
78  auto events = make_unique<TTree>("events", "events");
79 
80  pt::ptree config;
81  pt::read_info(DARWIN "/test/example.info", config);
82  BOOST_REQUIRE_NO_THROW( MetaInfo(events, config) );
83  UserInfo ui(events.get());
84  auto repo = ui.Get<string>("git", "repo"),
85  commit = ui.Get<string>("git", "commit");
86 
87  BOOST_TEST_MESSAGE( "Testing incomplete git block (missing commit)" );
88  config.put<bool>("git.complete", true);
89  config.put<bool>("git.reproducible", true);
90  BOOST_REQUIRE_THROW( MetaInfo(events, config), wrapexcept<pt::ptree_error> );
91  config.put<string>("git.repo", repo);
92  config.put<string>("git.commit", commit);
93 
94  BOOST_TEST_MESSAGE( "Testing inconsistent git repos" );
95  config.put<fs::path>("git.repo", "/another/repo");
96  BOOST_REQUIRE_NO_THROW( MetaInfo(events, config) );
97  config.put<string>("git.repo", repo);
98 
99  BOOST_TEST_MESSAGE( "Testing inconsistent git commits" );
100  config.put<string>("git.commit", "42abcd");
101  BOOST_WARN_NO_THROW( MetaInfo(events, config) );
102  config.put<string>("git.commit", commit);
103 
104  BOOST_TEST_MESSAGE( "Testing complete flag" );
105  config.put<bool>("git.complete", false);
106  BOOST_REQUIRE_NO_THROW( MetaInfo(events, config) );
107  config.put<bool>("git.complete", true);
108 
109  BOOST_TEST_MESSAGE( "Testing reproducible flag" );
110  config.put<bool>("git.reproducible", false);
111  BOOST_REQUIRE_NO_THROW( MetaInfo(events, config) );
112  config.put<bool>("git.reproducible", true);
113 
114  BOOST_TEST_MESSAGE( "Testing multiple git repos" );
115  config.erase("git.repo");
116  config.add<fs::path>("git.repo.one", "");
117  config.add<fs::path>("git.repo.two", "");
118  BOOST_REQUIRE_NO_THROW( MetaInfo(events, config) );
119  config.get_child("git.repo").erase("one");
120  config.get_child("git.repo").erase("two");
121  config.get_child("git").erase("repo");
122  config.add<fs::path>("git.repo", "/one/repo");
123 
124  BOOST_TEST_MESSAGE( "Testing multiple git commits" );
125  config.erase("git.commit");
126  config.add<fs::path>("git.commit.one", "123456");
127  config.add<fs::path>("git.commit.two", "abcdef");
128  BOOST_REQUIRE_NO_THROW( MetaInfo(events, config) );
129  }

◆ BOOST_AUTO_TEST_CASE() [3/3]

BOOST_AUTO_TEST_CASE ( software_version  )
132  {
133  pt::ptree config;
134  pt::read_info(DARWIN "/test/example.info", config);
135  auto events = make_shared<TTree>("events", "events");
136  MetaInfo metainfo(events, config);
137  cout << "Forcing inconsistent version (42 everywhere)" << endl;
138  metainfo.Set<const char *>("software", "gpp" , "42");
139  metainfo.Set<const char *>("software", "Cpp" , "42");
140  metainfo.Set<const char *>("software", "ROOT" , "42");
141  metainfo.Set<const char *>("software", "Boost", "42");
142  BOOST_REQUIRE_NO_THROW( MetaInfo{events} );
143  }
BOOST_TEST
BOOST_TEST(gendijet.Rapidity()==1.3573785791881385)
std::hash< TTree * >
Hash from TTree obtained by combination of different elements.
Definition: UserInfo.h:313
Darwin::Tools::MetaInfo
Generic meta-information for n-tuple (including speficities to Darwin).
Definition: MetaInfo.h:68
Ntupliser_cfg.config
config
Definition: Ntupliser_cfg.py:326
Darwin::Tools::MetaInfo::IKnowWhatIAmDoing
If you use this, you're supposed to know what you are doing.
Definition: MetaInfo.h:142
Darwin::Tools::UserInfo
Generic meta-information for n-tuple (can be used out of Darwin).
Definition: UserInfo.h:54