Jpp test-rotations-new
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 <ostream>
5#include <iomanip>
6#include <type_traits>
7
8#include "TString.h"
9
10#include "JLang/JType.hh"
11#include "JLang/JNullType.hh"
12
13
14/**
15 * \author mdejong
16 */
17
18namespace JROOT {}
19namespace JPP { using namespace JROOT; }
20
21namespace JROOT {
22
23 using JLANG::JType;
24 using JLANG::JNullType;
25
26
27 /**
28 * Data structure for TTree parameters.
29 */
31 public:
32 /**
33 * Constructor.
34 *
35 * \param treeName TTree name
36 * \param treeTitle TTree title
37 * \param branchName TBranch name
38 * \param compressionLevel TBranch compression level
39 * \param basketSize TBranch basket size
40 * \param splitLevel TBranch split level
41 * \param autoFlush TTree auto flush
42 */
43 JTreeParameters(const TString& treeName,
44 const TString& treeTitle,
45 const TString& branchName = "",
46 const int compressionLevel = 1,
47 const int basketSize = 65536,
48 const int splitLevel = 1,
49 const Long64_t autoFlush = 5000)
50
51 {
52 this->treeName = treeName;
53 this->treeTitle = treeTitle;
54 this->branchName = branchName;
56 this->basketSize = basketSize;
57 this->splitLevel = splitLevel;
58 this->autoFlush = autoFlush;
59 }
60
61
62 /**
63 * Get TTree parameters.
64 *
65 * \return TTree parameters
66 */
67 inline const JTreeParameters& getTreeParameters() const
68 {
69 return static_cast<const JTreeParameters&>(*this);
70 }
71
72
73 /**
74 * Get TTree name.
75 *
76 * \return TTree name
77 */
78 const TString& getTreeName() const
79 {
80 return treeName;
81 }
82
83
84 /**
85 * Get TTree title.
86 *
87 * \return TTree title
88 */
89 const TString& getTreeTitle() const
90 {
91 return treeTitle;
92 }
93
94
95 /**
96 * Get TBranch name.
97 *
98 * \return TBranch name
99 */
100 const TString& getBranchName() const
101 {
102 return (branchName != "" ? branchName : treeName);
103 }
104
105
106 /**
107 * Get compression level.
108 *
109 * \return compression level
110 */
112 {
113 return compressionLevel;
114 }
115
116
117 /**
118 * Set compression level.
119 *
120 * \param value compression level
121 */
122 void setCompressionLevel(const int value)
123 {
124 compressionLevel = value;
125 }
126
127
128 /**
129 * Get basket size.
130 *
131 * \return basket size
132 */
133 int getBasketSize() const
134 {
135 return basketSize;
136 }
137
138
139 /**
140 * Set basket size.
141 *
142 * \param value basket size
143 */
144 void setBasketSize(int value)
145 {
146 basketSize = value;
147 }
148
149
150 /**
151 * Get split level.
152 *
153 * \return split level
154 */
155 int getSplitLevel() const
156 {
157 return splitLevel;
158 }
159
160
161 /**
162 * Set split level.
163 *
164 * \param value split level
165 */
166 void setSplitLevel(int value)
167 {
168 splitLevel = value;
169 }
170
171
172 /**
173 * Get auto flush.
174 *
175 * \return auto flush
176 */
177 Long64_t getAutoFlush() const
178 {
179 return autoFlush;
180 }
181
182
183 /**
184 * Set auto flush.
185 *
186 * \param value auto flush
187 */
188 void setAutoFlush(Long64_t value)
189 {
190 autoFlush = value;
191 }
192
193
194 /**
195 * Write TTree parameters to output.
196 *
197 * \param out output stream
198 * \param object TTree parameters
199 * \return output stream
200 */
201 friend inline std::ostream& operator<<(std::ostream& out, const JTreeParameters& object)
202 {
203 using namespace std;
204
205 return out << setw(24) << left << object.getTreeName() << right << ' '
206 << setw(24) << left << object.getBranchName() << right << ' '
207 << setw(1) << object.getCompressionLevel() << ' '
208 << setw(10) << object.getBasketSize() << ' '
209 << setw(2) << object.getSplitLevel() << ' '
210 << setw(8) << object.getAutoFlush();
211 }
212
213
214 protected:
215 TString treeName; //!< TTree name
216 TString treeTitle; //!< TTree title
217 TString branchName; //!< TBranch name
218 int compressionLevel; //!< TBranch compression level
219 int basketSize; //!< TBranch basket size
220 int splitLevel; //!< TBranch split level
221 Long64_t autoFlush; //!< TTree auto flush
222 };
223
224
225 /**
226 * Template definition for method returning TTree parameters.
227 * The template argument refers to the class for which ROOT TTree I/O is desired.
228 *
229 * \return TTree parameters
230 */
231 template<class T>
233 {
234 static JTreeParameters parameters = getTreeParameters(JType<T>());
235
236 return parameters;
237 }
238
239
240 /**
241 * Method with argument definition for obtaining TTree parameters.
242 * The method argument refers to the class for which ROOT TTree I/O is desired.
243 * This method should then be overloaded and the overloaded method should
244 * return a JTreeParameters object with the corresponding TTree parameters.
245 *
246 * \param type data type
247 * \return TTree parameters
248 */
249 template<class T>
251
252
253 /**
254 * Test availability of TTree parameters for given class.
255 *
256 * The parameter result evaluates to true if for this class TTree parameters are defined.
257 */
258 template<class T>
260 {
261 public:
262 static const bool result = std::is_same<JTreeParameters, decltype(getTreeParameters(JType<T>()))>::value; //!< true if TTree parameters available; else false
263 };
264}
265
266#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.
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.
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