DAS  3.0
Das Analysis System
UserInfo.cc File Reference
#include <boost/test/included/unit_test.hpp>
#include <boost/exception/all.hpp>
#include <boost/property_tree/info_parser.hpp>
#include "test.h"
#include "UserInfo.h"
+ Include dependency graph for UserInfo.cc:

Macros

#define BOOST_TEST_MODULE   testUserInfo
 

Functions

 BOOST_AUTO_TEST_CASE (arithmetic)
 
 BOOST_AUTO_TEST_CASE (literal)
 
 BOOST_AUTO_TEST_CASE (writing)
 
 BOOST_AUTO_TEST_CASE (loading)
 
 BOOST_AUTO_TEST_CASE (hashing)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   testUserInfo

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/5]

BOOST_AUTO_TEST_CASE ( arithmetic  )
19  {
20  DT::UserInfo userinfo;
21 
22  bool myBool = true;
23  int myInt = 2016;
24  float myFloat = 3.1415;
25  double myDouble = 3.141592404915836;
26  BOOST_REQUIRE_NO_THROW( userinfo.Set<bool >("closure", "arithmetic", "myBool" , myBool ) );
27  BOOST_REQUIRE_NO_THROW( userinfo.Set<int >("closure", "arithmetic", "myInt" , myInt ) );
28  BOOST_REQUIRE_NO_THROW( userinfo.Set<float >("closure", "arithmetic", "myFloat" , myFloat ) );
29  BOOST_REQUIRE_NO_THROW( userinfo.Set<double>("closure", "arithmetic", "myDouble", myDouble) );
30  BOOST_TEST( myBool == userinfo.Get<bool >("closure", "arithmetic", "myBool" ) );
31  BOOST_TEST( myInt == userinfo.Get<int >("closure", "arithmetic", "myInt" ) );
32  BOOST_TEST( myFloat == userinfo.Get<float >("closure", "arithmetic", "myFloat" ) );
33  BOOST_TEST( myDouble == userinfo.Get<double>("closure", "arithmetic", "myDouble") );
34  BOOST_REQUIRE_THROW( userinfo.Get<double>("closure", "arithmetic", "myBool" ), boost::wrapexcept<std::invalid_argument> );
35  BOOST_REQUIRE_THROW( userinfo.Set<double>("closure", "arithmetic", "myBool", myDouble), boost::wrapexcept<std::invalid_argument> );
36  BOOST_TEST( userinfo.Find("closure", "arithmetic", "myBool") );
37  BOOST_TEST( userinfo.Find("closure", "arithmetic", "sine") == false );
38  BOOST_TEST( userinfo.Find("closure", "trigonometry", "sine") == false );
39  }

◆ BOOST_AUTO_TEST_CASE() [2/5]

BOOST_AUTO_TEST_CASE ( hashing  )
95  {
96  DT::UserInfo userinfo1, userinfo2;
97  userinfo1.Set<int>("test", 1);
98  userinfo2.Set<int>("test", 1);
99 
100  hash<DT::UserInfo> Hash;
101  BOOST_TEST( Hash(userinfo1) == Hash(userinfo2) );
102  userinfo2.Set<int>("test", 2);
103  BOOST_TEST( Hash(userinfo1) != Hash(userinfo2) );
104  }

◆ BOOST_AUTO_TEST_CASE() [3/5]

BOOST_AUTO_TEST_CASE ( literal  )
42  {
43  DT::UserInfo userinfo;
44 
45  const char * myConstChar = "hello, world";
46  string myString = "Darwin";
47  fs::path myPath = "example.info";
48  BOOST_REQUIRE_NO_THROW( userinfo.Set<const char *>("closure", "literals", "myConstChar", myConstChar) );
49  BOOST_REQUIRE_NO_THROW( userinfo.Set<string >("closure", "literals", "myString" , myString ) );
50  BOOST_REQUIRE_NO_THROW( userinfo.Set<fs::path >("closure", "literals", "myPath" , myPath ) );
51  BOOST_TEST( strcmp(myConstChar, userinfo.Get<const char *>("closure", "literals", "myConstChar")) == 0 );
52  BOOST_TEST( myString == userinfo.Get<string >("closure", "literals", "myString" ) );
53  BOOST_TEST( myPath == userinfo.Get<fs::path >("closure", "literals", "myPath" ) );
54  BOOST_REQUIRE_THROW( userinfo.Get<const char *>("this", "does", "not", "exist"), boost::wrapexcept<std::invalid_argument> );
55  }

◆ BOOST_AUTO_TEST_CASE() [4/5]

BOOST_AUTO_TEST_CASE ( loading  )
74  {
75  DT::UserInfo userinfo;
76 
77  BOOST_REQUIRE_NO_THROW( userinfo.Set<const char *>("corrections", "JES", "nominal") );
78  BOOST_REQUIRE_NO_THROW( userinfo.Set<const char *>("corrections", "JES", "JESup" ) );
79  BOOST_REQUIRE_NO_THROW( userinfo.Set<const char *>("corrections", "JES", "JESdn" ) );
80  BOOST_REQUIRE_NO_THROW( userinfo.Set<int> ("answer", 42 ) );
81  BOOST_REQUIRE_NO_THROW( userinfo.Set<float>("pi" , 3.1415f) );
82 
83  stringstream ss;
84  auto pt = userinfo.Write(ss, DT::UserInfo::INFO);
85 
86  // Check round trip. We deserialize the ptree and serialize it again
87  DT::UserInfo reconstructed(pt);
88 
89  stringstream ss2;
90  BOOST_REQUIRE_NO_THROW( reconstructed.Write(ss2, DT::UserInfo::INFO) );
91  BOOST_REQUIRE( ss.str() == ss2.str() );
92  }

◆ BOOST_AUTO_TEST_CASE() [5/5]

BOOST_AUTO_TEST_CASE ( writing  )
58  {
59  DT::UserInfo userinfo;
60 
61  BOOST_REQUIRE_NO_THROW( userinfo.Set<const char *>("corrections", "JES", "nominal") );
62  BOOST_REQUIRE_NO_THROW( userinfo.Set<const char *>("corrections", "JES", "JESup" ) );
63  BOOST_REQUIRE_NO_THROW( userinfo.Set<const char *>("corrections", "JES", "JESdn" ) );
64 
65  BOOST_REQUIRE_NO_THROW( userinfo.Write("test.info") );
66  BOOST_REQUIRE_NO_THROW( userinfo.Write("test.json") );
67  BOOST_REQUIRE_NO_THROW( userinfo.Write("test.xml") );
68  fs::remove("test.info");
69  fs::remove("test.json");
70  fs::remove("test.xml");
71  }
jmarExample.pt
pt
Definition: jmarExample.py:19
BOOST_TEST
BOOST_TEST(gendijet.Rapidity()==1.3573785791881385)
Darwin::Tools::UserInfo::Get
T Get(TList *mother, const char *key) const
Definition: UserInfo.h:75
Darwin::Tools::UserInfo::Write
void Write() const
Write TList to TFile in ROOT format.
Definition: UserInfo.cc:149
Darwin::Tools::UserInfo::Find
bool Find(TList *mother, const char *key) const
Recursive finder.
Definition: UserInfo.h:107
Darwin::Tools::UserInfo::INFO
@ INFO
INFO format, proper to Boost Property Trees (default)
Definition: UserInfo.h:57
Darwin::Tools::UserInfo::Set
void Set(TList *mother, const char *key, T value) const
Definition: UserInfo.h:129
Darwin::Tools::UserInfo
Generic meta-information for n-tuple (can be used out of Darwin).
Definition: UserInfo.h:52