Jpp  18.2.1-ARCA-DF-PATCH
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JRootClass.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "JROOT/JRootClass.hh"
6 
8 #include "JAAnet/JHead.hh"
9 
10 #include "Jeep/JPrint.hh"
11 #include "Jeep/JParser.hh"
12 #include "Jeep/JMessage.hh"
13 
14 namespace {
15 
16  using namespace JPP;
17 
18  /**
19  * Print data member.
20  *
21  * \param OUT output stream
22  * \param T data member
23  */
24 #define PRINT(OUT, T) \
25  do { OUT \
26  << std::setw(24) << left << #T << " --> " \
27  << std::setw(16) << left << (getDataMember(T) != NULL ? getDataMember(T)->GetName() : "?") << std::endl; } while (0)
28 
29 
30  /**
31  * Test data member.
32  *
33  * \param T data member
34  */
35 #define TEST(T) \
36  (getClassname(#T) == (getDataMember(T) != NULL ? getDataMember(T)->GetName() : "?"))
37 }
38 
39 /**
40  * \file
41  *
42  * Program to test JROOT::JRootClass.
43  * \author mdejong
44  */
45 int main(int argc, char **argv)
46 {
47  using namespace std;
48  using namespace JPP;
49 
50  int debug;
51 
52  try {
53 
54  JParser<> zap("Program to test JRootClass.");
55 
56  zap['d'] = make_field(debug) = 3;
57 
58  zap(argc, argv);
59  }
60  catch(const exception& error) {
61  FATAL(error.what() << endl);
62  }
63 
64  if (debug >= debug_t) {
65  PRINT(cout, &JHead::start_run);
66  PRINT(cout, &JHead::detector);
67  PRINT(cout, &JHead::physics);
68  PRINT(cout, &JHead::simul);
69  PRINT(cout, &JHead::cut_primary);
70  PRINT(cout, &JHead::cut_seamuon);
71  PRINT(cout, &JHead::spectrum);
72  PRINT(cout, &JHead::can);
73  PRINT(cout, &JHead::genvol);
74  PRINT(cout, &JHead::coord_origin);
75  PRINT(cout, &JHead::livetime);
76  PRINT(cout, &JHead::seabottom);
77  }
78 
79  ASSERT( TEST(&JHead::start_run) );
81  ASSERT( TEST(&JHead::physics) );
82  ASSERT( TEST(&JHead::simul) );
83  ASSERT( TEST(&JHead::cut_primary) );
84  ASSERT( TEST(&JHead::cut_seamuon) );
85  ASSERT( TEST(&JHead::spectrum) );
86  ASSERT( TEST(&JHead::can) );
87  ASSERT( TEST(&JHead::genvol) );
88  ASSERT( TEST(&JHead::coord_origin) );
89  ASSERT( TEST(&JHead::livetime) );
90  ASSERT( TEST(&JHead::seabottom) );
91 
92  {
93  const JType<JHead> type;
94 
95  const JRootClass cls(type);
96 
97  for (const string key : { "start_run", "detector", "physics", "simul", "cut_primary", "cut_seamuon", "spectrum", "can", "genvol", "coord_origin", "livetime", "seabottom" }) {
98  ASSERT( cls.find(key.c_str()).is_valid(), "check validity of " << key);
99  ASSERT(!cls.find(to_upper(key).c_str(), true) .is_valid(), "check invalidity of " << to_upper(key));
100  ASSERT( cls.find(to_upper(key).c_str(), false).is_valid(), "check validity of " << to_upper(key));
101  }
102  }
103 
104  return 0;
105 }
Utility class to parse command line options.
Definition: JParser.hh:1514
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
JRootClass find(const char *const name, const bool option=true) const
Find base class or data member with given name within current class.
Definition: JRootClass.hh:237
bool is_valid(const json &js)
Check validity of JSon data.
Auxiliary class for a type holder.
Definition: JType.hh:19
#define TEST(T)
Test data member.
Definition: JRootClass.cc:35
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
bool is_valid() const
Check validity of this class.
Definition: JRootClass.hh:210
std::string to_upper(const std::string &value)
Convert all character to upper case.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
do set_variable DETECTOR_TXT $WORKDIR detector
#define PRINT(OUT, T)
Print data member.
Definition: JRootClass.cc:24
Auxiliary class to manage access to base classes and data members of ROOT class.
Definition: JRootClass.hh:41
int debug
debug level