Jpp 21.0.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JRootSupportkit.hh
Go to the documentation of this file.
1#ifndef __JROOTSUPPORTKIT__
2#define __JROOTSUPPORTKIT__
3
4#include <type_traits>
5
6
7#include "TFile.h"
8
9#include "JLang/JTest.hh"
10
11#include "JROOT/JRootToolkit.hh"
12
13
14/**
15 * \file
16 *
17 * Data type dependent action methods for customised ROOT version management.
18 * \author mdejong
19 */
20namespace JROOT {}
21namespace JPP { using namespace JROOT; }
22
23namespace JROOT {
24
25 using JLANG::JTest;
26
27
28 /**
29 * Auxiliary class to handle version management of given class at opening of a ROOT file.
30 */
31 template <class T>
33 public JTest
34 {
35 using JTest::test;
36
37 template<class U> static JTrue test(JTypecheck<void (*)(int), &U::actionAtFileOpen>*);
38
39
40 /**
41 * Execute action.
42 *
43 * This implementation transfers the action to the given class.
44 *
45 * \param file pointer to file
46 * \param option true
47 */
48 static inline void execute(TFile* file, std::true_type option)
49 {
50 T::actionAtFileOpen(getStreamerVersion(file, T::Class_Name()));
51 }
52
53
54 /**
55 * Execute action.
56 *
57 * This implementation does nothing.
58 *
59 * \param file pointer to file
60 * \param option false
61 */
62 static inline void execute(TFile* file, std::false_type option)
63 {}
64
65 public:
66
67 static const bool has_method = JTEST(test<T>(NULL)); //!< true if class has policy method actionAtFileOpen; else false
68
69
70 /**
71 * Execute action.
72 *
73 * \param file pointer to file
74 */
75 static inline void execute(TFile* file)
76 {
77 execute(file, std::bool_constant<has_method>());
78 }
79 };
80
81
82 /**
83 * Auxiliary class to handle version management of given class at reading from a ROOT file.
84 */
85 template <class T>
87 public JTest
88 {
89 using JTest::test;
90
91 template<class U> static JTrue test(JTypecheck<void (U::*)(), &U::actionAtFileRead>*);
92
93
94 /**
95 * Execute action.
96 *
97 * This implementation transfers the action to the given object.
98 *
99 * \param object pointer to object (I/O)
100 * \param option true
101 */
102 static inline void execute(T* object, std::true_type option)
103 {
104 object->actionAtFileRead();
105 }
106
107
108 /**
109 * Execute action.
110 *
111 * This implementation does nothing.
112 *
113 * \param object pointer to object (I/O)
114 * \param option false
115 */
116 static inline void execute(T* object, std::false_type option)
117 {}
118
119 public:
120
121 static const bool has_method = JTEST(test<T>(NULL)); //!< true if class has policy method actionAtFileRead; else false
122
123
124 /**
125 * Execute action.
126 *
127 * \param object pointer to object (I/O)
128 */
129 static inline void execute(T* object)
130 {
131 execute(object, std::bool_constant<has_method>());
132 }
133 };
134
135
136 /**
137 * General action method at file open.
138 *
139 * The class T should provide the policy method:
140 * <pre>
141 * static void %actionAtFileOpen(int version);
142 * </pre>
143 * whenever an action specific to this data type has to be executed after opening a file.\n
144 * This method will then be called following each file open operation.
145 *
146 * \param file pointer to file
147 */
148 template<class T>
149 inline void actionAtFileOpen(TFile* file)
150 {
151 if (file != NULL) {
153 }
154 }
155
156
157 /**
158 * General action method at file read.
159 *
160 * The class T should provide the policy method:
161 * <pre>
162 * void %actionAtFileRead();
163 * </pre>
164 * whenever an action specific to this data type has to be executed after reading from a file.\n
165 * This method will then be called following each file read operation.
166 *
167 * \param object pointer to object (I/O)
168 */
169 template<class T>
170 inline void actionAtFileRead(T* object)
171 {
172 if (object != NULL) {
174 }
175 }
176}
177#endif
#define JTEST(__A__)
Test macro.
Definition JTest.hh:45
Auxiliary class to handle version management of given class at opening of a ROOT file.
static const bool has_method
true if class has policy method actionAtFileOpen; else false
static JTrue test(JTypecheck< void(*)(int), &U::actionAtFileOpen > *)
static void execute(TFile *file, std::true_type option)
Execute action.
static void execute(TFile *file, std::false_type option)
Execute action.
static void execute(TFile *file)
Execute action.
Auxiliary class to handle version management of given class at reading from a ROOT file.
static void execute(T *object)
Execute action.
static const bool has_method
true if class has policy method actionAtFileRead; else false
static void execute(T *object, std::false_type option)
Execute action.
static void execute(T *object, std::true_type option)
Execute action.
static JTrue test(JTypecheck< void(U::*)(), &U::actionAtFileRead > *)
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for ROOT I/O.
void actionAtFileRead(T *object)
General action method at file read.
int getStreamerVersion(TFile *file, const char *const name)
Get ROOT streamer version of class with given name.
void actionAtFileOpen(TFile *file)
General action method at file open.
definition of true
Definition JTest.hh:24
Auxiliary class for type checking.
Definition JTest.hh:36
Auxiliary base class for compile time evaluation of test.
Definition JTest.hh:21
static JFalse test(...)
default false