Project
Loading...
Searching...
No Matches
TreeStream.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15
16#ifndef ALICEO2_TREESTREAM_H
17#define ALICEO2_TREESTREAM_H
18
19#include <TString.h>
20#include <TTree.h>
21#include <vector>
22#include "GPUCommonDef.h"
23
24class TBranch;
25class TClass;
26class TDataType;
27
28namespace o2
29{
30namespace utils
31{
43{
44 public:
46 char type = 0;
47 const TClass* cls = nullptr;
48 const void* ptr = nullptr;
49 std::string name;
50 };
51
52 TreeStream(const char* treename);
53 TreeStream() = default;
54 virtual ~TreeStream() = default;
55 void Close() { mTree.Write(); }
56 Int_t CheckIn(Char_t type, const void* pointer);
57 void BuildTree();
58 void Fill();
59 Double_t getSize() { return mTree.GetZipBytes(); }
61
62 TTree& getTree() { return mTree; }
63 const char* getName() const { return mTree.GetName(); }
64 void setID(int id) { mID = id; }
65 int getID() const { return mID; }
66
67 TreeStream& operator<<(const Bool_t& b)
68 {
69 CheckIn('B', &b);
70 return *this;
71 }
72
73 TreeStream& operator<<(const Char_t& c)
74 {
75 CheckIn('B', &c);
76 return *this;
77 }
78
79 TreeStream& operator<<(const int8_t& i)
80 {
81 CheckIn('B', &i);
82 return *this;
83 }
84
85 TreeStream& operator<<(const UChar_t& c)
86 {
87 CheckIn('b', &c);
88 return *this;
89 }
90
91 TreeStream& operator<<(const Short_t& h)
92 {
93 CheckIn('S', &h);
94 return *this;
95 }
96
97 TreeStream& operator<<(const UShort_t& h)
98 {
99 CheckIn('s', &h);
100 return *this;
101 }
102
103 TreeStream& operator<<(const Int_t& i)
104 {
105 CheckIn('I', &i);
106 return *this;
107 }
108
109 TreeStream& operator<<(const UInt_t& i)
110 {
111 CheckIn('i', &i);
112 return *this;
113 }
114
115 TreeStream& operator<<(const Long_t& l)
116 {
117 CheckIn('L', &l);
118 return *this;
119 }
120
121 TreeStream& operator<<(const ULong_t& l)
122 {
123 CheckIn('l', &l);
124 return *this;
125 }
126
127 TreeStream& operator<<(const Long64_t& l)
128 {
129 CheckIn('L', &l);
130 return *this;
131 }
132
133 TreeStream& operator<<(const ULong64_t& l)
134 {
135 CheckIn('l', &l);
136 return *this;
137 }
138
140 {
141 CheckIn('F', &f);
142 return *this;
143 }
144
145 TreeStream& operator<<(const Double_t& d)
146 {
147 CheckIn('D', &d);
148 return *this;
149 }
150
151 TreeStream& operator<<(const Char_t* name);
152
153 template <class T>
154 TreeStream& operator<<(const T* obj)
155 {
156 CheckIn(obj);
157 return *this;
158 }
159
160 template <class T, typename std::enable_if<!std::is_pointer<GPUgeneric() T>::value, bool>::type* = nullptr>
161 TreeStream& operator<<(const T& obj)
162 {
163 CheckIn(&obj);
164 return *this;
165 }
166
167 template <class T>
168 Int_t CheckIn(const T* obj);
169
170 private:
171 //
172 std::vector<TreeDataElement> mElements;
173 std::vector<TBranch*> mBranches;
174 TTree mTree;
175 int mCurrentIndex = 0;
176 int mID = -1;
177 int mNextNameCounter = 0;
178 int mStatus = 0;
179 TString mNextName;
180
181 ClassDefNV(TreeStream, 0);
182};
183
184template <class T>
185Int_t TreeStream::CheckIn(const T* obj)
186{
187 // check in arbitrary class having dictionary
188 TClass* pClass = nullptr;
189 if (obj) {
190 pClass = TClass::GetClass(typeid(*obj));
191 }
192
193 if (mCurrentIndex >= static_cast<int>(mElements.size())) {
194 mElements.emplace_back();
195 auto& element = mElements.back();
196 element.cls = pClass;
197 TString name = mNextName;
198 if (name.Length()) {
199 if (mNextNameCounter > 0) {
200 name += mNextNameCounter;
201 }
202 } else {
203 name = TString::Format("B%d", static_cast<int>(mElements.size()));
204 }
205 element.name = name.Data();
206 element.ptr = obj;
207 } else {
208 auto& element = mElements[mCurrentIndex];
209 if (!element.cls) {
210 element.cls = pClass;
211 } else {
212 if (element.cls != pClass && pClass) {
213 mStatus++;
214 return 1; // mismatched data element
215 }
216 }
217 element.ptr = obj;
218 }
219 mCurrentIndex++;
220 return 0;
221}
222
223} // namespace utils
224} // namespace o2
225
226#endif
int32_t i
uint32_t c
Definition RawData.h:2
Class for time synchronization of RawReader instances.
TreeStream & operator<<(const T *obj)
Definition TreeStream.h:154
TreeStream & Endl()
Int_t CheckIn(Char_t type, const void *pointer)
const char * getName() const
Definition TreeStream.h:63
TreeStream & operator<<(const ULong64_t &l)
Definition TreeStream.h:133
TreeStream & operator<<(const Char_t &c)
Definition TreeStream.h:73
TreeStream & operator<<(const Short_t &h)
Definition TreeStream.h:91
TreeStream & operator<<(const Double_t &d)
Definition TreeStream.h:145
TreeStream & operator<<(const UInt_t &i)
Definition TreeStream.h:109
TreeStream & operator<<(const UChar_t &c)
Definition TreeStream.h:85
TreeStream & operator<<(const Long64_t &l)
Definition TreeStream.h:127
TreeStream & operator<<(const int8_t &i)
Definition TreeStream.h:79
TreeStream & operator<<(const Int_t &i)
Definition TreeStream.h:103
virtual ~TreeStream()=default
TreeStream & operator<<(const Bool_t &b)
Definition TreeStream.h:67
TreeStream & operator<<(const UShort_t &h)
Definition TreeStream.h:97
void setID(int id)
Definition TreeStream.h:64
TreeStream & operator<<(const ULong_t &l)
Definition TreeStream.h:121
TreeStream & operator<<(const Long_t &l)
Definition TreeStream.h:115
TreeStream & operator<<(const Float_t &f)
Definition TreeStream.h:139
TreeStream & operator<<(const T &obj)
Definition TreeStream.h:161
GLenum void ** pointer
Definition glcorearb.h:805
GLuint const GLchar * name
Definition glcorearb.h:781
GLdouble f
Definition glcorearb.h:310
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLuint id
Definition glcorearb.h:650
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Common utility functions.
std::string name
name of the element
Definition TreeStream.h:49
const void * ptr
pointer to element
Definition TreeStream.h:48
const TClass * cls
data type pointer
Definition TreeStream.h:47