Jpp 21.0.0-rc.1-88-g0130508c4
the software that should make you happy
Loading...
Searching...
No Matches
JTreeParameters.hh
Go to the documentation of this file.
1#ifndef __JROOT__JTREEPARAMETERS__
2#define __JROOT__JTREEPARAMETERS__
3
4#include <istream>
5#include <ostream>
6#include <iomanip>
7#include <type_traits>
8
9#include "TString.h"
10
11#include "JLang/JType.hh"
12#include "JLang/JNullType.hh"
13
14
15/**
16 * \author mdejong
17 */
18
19namespace JROOT {}
20namespace JPP { using namespace JROOT; }
21
22namespace JROOT {
23
24 using JLANG::JType;
25 using JLANG::JNullType;
26
27
28 /**
29 * Data structure for TTree parameters.
30 */
32 public:
33 /**
34 * Constructor.
35 *
36 * \param treeName TTree name
37 * \param treeTitle TTree title
38 * \param branchName TBranch name
39 * \param compressionLevel TBranch compression level
40 * \param basketSize TBranch basket size
41 * \param splitLevel TBranch split level
42 * \param autoFlush TTree auto flush
43 */
44 JTreeParameters(const TString& treeName,
45 const TString& treeTitle,
46 const TString& branchName = "",
47 const int compressionLevel = 1,
48 const int basketSize = 65536,
49 const int splitLevel = 1,
50 const Long64_t autoFlush = 5000)
51
52 {
53 this->treeName = treeName;
54 this->treeTitle = treeTitle;
55 this->branchName = branchName;
57 this->basketSize = basketSize;
58 this->splitLevel = splitLevel;
59 this->autoFlush = autoFlush;
60 }
61
62
63 /**
64 * Get TTree parameters.
65 *
66 * \return TTree parameters
67 */
68 inline const JTreeParameters& getTreeParameters() const
69 {
70 return static_cast<const JTreeParameters&>(*this);
71 }
72
73
74 /**
75 * Get TTree name.
76 *
77 * \return TTree name
78 */
79 const TString& getTreeName() const
80 {
81 return treeName;
82 }
83
84
85 /**
86 * Get TTree title.
87 *
88 * \return TTree title
89 */
90 const TString& getTreeTitle() const
91 {
92 return treeTitle;
93 }
94
95
96 /**
97 * Get TBranch name.
98 *
99 * \return TBranch name
100 */
101 const TString& getBranchName() const
102 {
103 return (branchName != "" ? branchName : treeName);
104 }
105
106
107 /**
108 * Get compression level.
109 *
110 * \return compression level
111 */
113 {
114 return compressionLevel;
115 }
116
117
118 /**
119 * Set compression level.
120 *
121 * \param value compression level
122 */
123 void setCompressionLevel(const int value)
124 {
125 compressionLevel = value;
126 }
127
128
129 /**
130 * Get basket size.
131 *
132 * \return basket size
133 */
134 int getBasketSize() const
135 {
136 return basketSize;
137 }
138
139
140 /**
141 * Set basket size.
142 *
143 * \param value basket size
144 */
145 void setBasketSize(int value)
146 {
147 basketSize = value;
148 }
149
150
151 /**
152 * Get split level.
153 *
154 * \return split level
155 */
156 int getSplitLevel() const
157 {
158 return splitLevel;
159 }
160
161
162 /**
163 * Set split level.
164 *
165 * \param value split level
166 */
167 void setSplitLevel(int value)
168 {
169 splitLevel = value;
170 }
171
172
173 /**
174 * Get auto flush.
175 *
176 * \return auto flush
177 */
178 Long64_t getAutoFlush() const
179 {
180 return autoFlush;
181 }
182
183
184 /**
185 * Set auto flush.
186 *
187 * \param value auto flush
188 */
189 void setAutoFlush(Long64_t value)
190 {
191 autoFlush = value;
192 }
193
194
195 /**
196 * Read TTree parameters from input.
197 *
198 * \param in input stream
199 * \param object TTree parameters
200 * \return input stream
201 */
202 friend inline std::istream& operator>>(std::istream& in, JTreeParameters& object)
203 {
204 using namespace std;
205
206 object.treeName .ReadToken(in);
207 object.branchName.ReadToken(in);
208
209 return in >> object.compressionLevel
210 >> object.basketSize
211 >> object.splitLevel
212 >> object.autoFlush;
213 }
214
215 /**
216 * Write TTree parameters to output.
217 *
218 * \param out output stream
219 * \param object TTree parameters
220 * \return output stream
221 */
222 friend inline std::ostream& operator<<(std::ostream& out, const JTreeParameters& object)
223 {
224 using namespace std;
225
226 return out << setw(24) << left << object.getTreeName() << right << ' '
227 << setw(24) << left << object.getBranchName() << right << ' '
228 << setw(1) << object.getCompressionLevel() << ' '
229 << setw(10) << object.getBasketSize() << ' '
230 << setw(2) << object.getSplitLevel() << ' '
231 << setw(8) << object.getAutoFlush();
232 }
233
234
235 protected:
236 /**
237 * Default constructor.
238 */
241
242
243 TString treeName; //!< TTree name
244 TString treeTitle; //!< TTree title
245 TString branchName; //!< TBranch name
246 int compressionLevel; //!< TBranch compression level
247 int basketSize; //!< TBranch basket size
248 int splitLevel; //!< TBranch split level
249 Long64_t autoFlush; //!< TTree auto flush
250 };
251
252
253 /**
254 * Template definition for method returning TTree parameters.
255 * The template argument refers to the class for which ROOT TTree I/O is desired.
256 *
257 * \return TTree parameters
258 */
259 template<class T>
261 {
262 static JTreeParameters parameters = getTreeParameters(JType<T>());
263
264 return parameters;
265 }
266
267
268 /**
269 * Method with argument definition for obtaining TTree parameters.
270 * The method argument refers to the class for which ROOT TTree I/O is desired.
271 * This method should then be overloaded and the overloaded method should
272 * return a JTreeParameters object with the corresponding TTree parameters.
273 *
274 * \param type data type
275 * \return TTree parameters
276 */
277 template<class T>
279
280
281 /**
282 * Test availability of TTree parameters for given class.
283 *
284 * The parameter result evaluates to true if for this class TTree parameters are defined.
285 */
286 template<class T>
288 {
289 public:
290 static const bool result = std::is_same<JTreeParameters, decltype(getTreeParameters(JType<T>()))>::value; //!< true if TTree parameters available; else false
291 };
292
293
294 /**
295 * Auxiliary data structure for setting TTree parameters.
296 */
298 public JTreeParameters
299 {
300 /**
301 * Set TTree parameters.
302 *
303 * \param type data type
304 */
305 template<class T>
306 void operator()(const JType<T>& type) const
307 {
308 set(type, std::bool_constant<JTreeParametersAvailable<T>::result>());
309 }
310
311 private:
312 /**
313 * Set TTree parameters.
314 *
315 * \param type data type
316 * \param option option for availability of TTree parameters
317 */
318 template<class T>
319 void set(const JType<T>& type, std::true_type option) const
320 {
324 }
325 }
326
327
328 /**
329 * Set TTree parameters.
330 *
331 * \param type data type
332 * \param option option for unavailability of TTree parameters
333 */
334 template<class T>
335 void set(const JType<T>& type, std::false_type option) const
336 {}
337 };
338}
339
340#endif
Test availability of TTree parameters for given class.
static const bool result
true if TTree parameters available; else false
Data structure for TTree parameters.
int getBasketSize() const
Get basket size.
const JTreeParameters & getTreeParameters() const
Get TTree parameters.
Long64_t getAutoFlush() const
Get auto flush.
JTreeParameters()
Default constructor.
friend std::ostream & operator<<(std::ostream &out, const JTreeParameters &object)
Write TTree parameters to output.
int getCompressionLevel() const
Get compression level.
int basketSize
TBranch basket size.
int getSplitLevel() const
Get split level.
int splitLevel
TBranch split level.
void setCompressionLevel(const int value)
Set compression level.
TString branchName
TBranch name.
void setSplitLevel(int value)
Set split level.
const TString & getBranchName() const
Get TBranch name.
TString treeTitle
TTree title.
JTreeParameters(const TString &treeName, const TString &treeTitle, const TString &branchName="", const int compressionLevel=1, const int basketSize=65536, const int splitLevel=1, const Long64_t autoFlush=5000)
Constructor.
void setAutoFlush(Long64_t value)
Set auto flush.
const TString & getTreeTitle() const
Get TTree title.
void setBasketSize(int value)
Set basket size.
friend std::istream & operator>>(std::istream &in, JTreeParameters &object)
Read TTree parameters from input.
const TString & getTreeName() const
Get TTree name.
int compressionLevel
TBranch compression level.
Long64_t autoFlush
TTree auto flush.
TString treeName
TTree name.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for ROOT I/O.
JTreeParameters & getTreeParameters()
Template definition for method returning TTree parameters.
Auxiliary class for no type definition.
Definition JNullType.hh:19
Auxiliary class for a type holder.
Definition JType.hh:19
Auxiliary data structure for setting TTree parameters.
void set(const JType< T > &type, std::true_type option) const
Set TTree parameters.
void operator()(const JType< T > &type) const
Set TTree parameters.
void set(const JType< T > &type, std::false_type option) const
Set TTree parameters.