g4tools  5.4.0
branch_element
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_wroot_branch_element
5 #define tools_wroot_branch_element
6 
7 #include "branch"
8 
9 namespace tools {
10 namespace wroot {
11 
12 inline const std::string& branch_element_store_class() {
13  static const std::string s_v("TBranchElement");
14  return s_v;
15 }
16 
17 class branch_element : public branch {
18  typedef branch parent;
19 #ifdef TOOLS_MEM
20  static const std::string& s_class() {
21  static const std::string s_v("tools::wroot::branch_element");
22  return s_v;
23  }
24 #endif
25 public: //ibo
26  virtual const std::string& store_cls() const {return branch_element_store_class();}
27  virtual bool stream(buffer& a_buffer) const {
28  unsigned int c;
29  if(!a_buffer.write_version(1,c)) return false;
30  if(!parent::stream(a_buffer)) return false;
31 
32  if(!a_buffer.write(fClassName)) return false;
33  if(!a_buffer.write(fClassVersion)) return false;
34  if(!a_buffer.write(fID)) return false;
35  if(!a_buffer.write(fType)) return false;
36  if(!a_buffer.write(fStreamerType)) return false;
37 
38  if(!a_buffer.set_byte_count(c)) return false;
39  return true;
40  }
41 
42 public:
43  branch_element(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
44  seek a_seek_directory,const std::string& a_name,const std::string& a_title,bool a_verbose)
45  :parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,a_verbose)
46  ,fClassVersion(0)
47  ,fID(0)
48  ,fType(0)
49  ,fStreamerType(-1)
50  {
51 #ifdef TOOLS_MEM
52  mem::increment(s_class().c_str());
53 #endif
54  }
55  virtual ~branch_element(){
56 #ifdef TOOLS_MEM
57  mem::decrement(s_class().c_str());
58 #endif
59  }
60 protected:
61  branch_element(const branch_element& a_from):ibo(a_from),parent(a_from) {}
62  branch_element& operator=(const branch_element& a_from){parent::operator=(a_from);return *this;}
63 public:
64  leaf_element* create_leaf_element(const std::string& a_name){
65  leaf_element* lf = new leaf_element(m_out,a_name,fID,fType);
66  m_leaves.push_back(lf);
67  return lf;
68  }
69 protected:
70  virtual bool fill_leaves(buffer&) {return false;} //must be derived.
71 protected:
72  std::string fClassName; //Class name of referenced object
73  int fClassVersion; //Version number of class
74  int fID; //element serial number in fInfo
75  int fType; //branch type
76  int fStreamerType; //branch streamer type
77 };
78 
79 template <class T>
81  typedef branch_element parent;
82 #ifdef TOOLS_MEM
83  static const std::string& s_class() {
84  static const std::string s_v("tools::wroot::std_vector_be_ref");
85  return s_v;
86  }
87 #endif
88 public:
89  std_vector_be_ref(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
90  seek a_seek_directory,
91  const std::string& a_name,const std::string& a_title,const std::vector<T>& a_ref,bool a_verbose)
92  :parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,a_verbose)
93  ,m_ref(a_ref)
94  {
95 #ifdef TOOLS_MEM
96  mem::increment(s_class().c_str());
97 #endif
98  fClassName = "vector<"+stype(T())+">";
99  fClassVersion = 0;
100  fID = -1;
101  fType = 0;
102  fStreamerType = -1; // TStreamerInfo::kSTLp;
103  }
105 #ifdef TOOLS_MEM
106  mem::decrement(s_class().c_str());
107 #endif
108  }
109 protected:
111  :ibo(a_from)
112  ,parent(a_from)
113  ,m_ref(a_from.m_ref)
114  {}
116  parent::operator=(a_from);
117  return *this;
118  }
119 protected:
120  virtual bool fill_leaves(buffer& a_buffer) {
121  unsigned int c;
122  if(!a_buffer.write_version(4,c)) return false;
123  if(!a_buffer.write((int)m_ref.size())) return false;
124  if(m_ref.size()) {
125  // The awfull below is to pass T=bool :
126  const T& vr = m_ref[0];
127  if(!a_buffer.write_fast_array(&vr,(int)m_ref.size())) return false;
128  }
129  if(!a_buffer.set_byte_count(c)) return false;
130  return true;
131  }
132 public:
133  const std::vector<T>& variable() const {return m_ref;}
134  std::vector<T>& variable() {return const_cast< std::vector<T>& >(m_ref);}
135 protected:
136  const std::vector<T>& m_ref;
137 };
138 
139 template <class T>
140 class std_vector_be : public std_vector_be_ref<T> {
142 #ifdef TOOLS_MEM
143  static const std::string& s_class() {
144  static const std::string s_v("tools::wroot::std_vector_be");
145  return s_v;
146  }
147 #endif
148 public:
149  std_vector_be(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
150  seek a_seek_directory,
151  const std::string& a_name,const std::string& a_title,const std::vector<T>& a_def,bool a_verbose)
152  :parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,m_value,a_verbose)
153  ,m_def(a_def),m_value(a_def)
154  {
155 #ifdef TOOLS_MEM
156  mem::increment(s_class().c_str());
157 #endif
158  }
159  virtual ~std_vector_be(){
160 #ifdef TOOLS_MEM
161  mem::decrement(s_class().c_str());
162 #endif
163  }
164 protected:
166  :ibo(a_from)
167  ,parent(a_from)
168  ,m_def(a_from.m_def)
169  ,m_value(a_from.m_value)
170  {}
172  parent::operator=(a_from);
173  m_def = a_from.m_def;
174  m_value = a_from.m_value;
175  return *this;
176  }
177 protected:
178  std::vector<T> m_def;
179  std::vector<T> m_value;
180 };
181 
182 template <class T>
184  typedef branch_element parent;
185 #ifdef TOOLS_MEM
186  static const std::string& s_class() {
187  static const std::string s_v("tools::wroot::std_vector_be_pointer");
188  return s_v;
189  }
190 #endif
191 public:
192  std_vector_be_pointer(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
193  seek a_seek_directory,
194  const std::string& a_name,const std::string& a_title,std::vector<T>* a_pointer,bool a_verbose)
195  :parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,a_verbose)
196  ,m_pointer(a_pointer)
197  {
198 #ifdef TOOLS_MEM
199  mem::increment(s_class().c_str());
200 #endif
201  fClassName = "vector<"+stype(T())+">";
202  fClassVersion = 0;
203  fID = -1;
204  fType = 0;
205  fStreamerType = -1; // TStreamerInfo::kSTLp;
206  }
208 #ifdef TOOLS_MEM
209  mem::decrement(s_class().c_str());
210 #endif
211  }
212 protected:
214  :ibo(a_from)
215  ,parent(a_from)
216  ,m_pointer(a_from.m_pointer)
217  {}
219  parent::operator=(a_from);
220  return *this;
221  }
222 protected:
223  virtual bool fill_leaves(buffer& a_buffer) {
224  if(!m_pointer) return false;
225  unsigned int c;
226  if(!a_buffer.write_version(4,c)) return false;
227  if(!a_buffer.write((int)m_pointer->size())) return false;
228  if(m_pointer->size()) {
229  // The awfull below is to pass T=bool :
230  T& vr = (*m_pointer)[0];
231  if(!a_buffer.write_fast_array(&vr,(int)m_pointer->size())) return false;
232  }
233  if(!a_buffer.set_byte_count(c)) return false;
234  return true;
235  }
236 public:
237  void set_pointer(std::vector<T>* a_pointer) {m_pointer = a_pointer;}
238  const std::vector<T>* get_pointer() const {return m_pointer;}
239  std::vector<T>* get_pointer() {return m_pointer;}
240 protected:
241  std::vector<T>* m_pointer;
242 };
243 
244 }}
245 
246 #endif
tools::wroot::std_vector_be::std_vector_be
std_vector_be(const std_vector_be &a_from)
Definition: branch_element:165
tools::wroot::branch_element::fClassVersion
int fClassVersion
Definition: branch_element:73
tools::wroot::seek
int64 seek
Definition: seek:16
tools::wroot::std_vector_be_pointer::get_pointer
std::vector< T > * get_pointer()
Definition: branch_element:239
tools::wroot::branch_element_store_class
const std::string & branch_element_store_class()
Definition: branch_element:12
tools::wroot::std_vector_be_ref::fill_leaves
virtual bool fill_leaves(buffer &a_buffer)
Definition: branch_element:120
tools::wroot::branch
Definition: branch:16
tools::wroot::std_vector_be_pointer::fill_leaves
virtual bool fill_leaves(buffer &a_buffer)
Definition: branch_element:223
tools::wroot::std_vector_be_pointer::~std_vector_be_pointer
virtual ~std_vector_be_pointer()
Definition: branch_element:207
tools::wroot::std_vector_be_ref::variable
const std::vector< T > & variable() const
Definition: branch_element:133
tools::wroot::ibo
Definition: ibo:17
tools::wroot::branch_element::~branch_element
virtual ~branch_element()
Definition: branch_element:55
tools::wroot::std_vector_be::~std_vector_be
virtual ~std_vector_be()
Definition: branch_element:159
tools::wroot::std_vector_be_ref::std_vector_be_ref
std_vector_be_ref(const std_vector_be_ref &a_from)
Definition: branch_element:110
tools::wroot::buffer::set_byte_count
bool set_byte_count(uint32 a_pos)
Definition: buffer:199
tools::wroot::branch_element::fStreamerType
int fStreamerType
Definition: branch_element:76
tools::wroot::branch::operator=
branch & operator=(const branch &)
Definition: branch:180
tools::wroot::branch_element::store_cls
virtual const std::string & store_cls() const
Definition: branch_element:26
tools::wroot::std_vector_be::operator=
std_vector_be & operator=(const std_vector_be &a_from)
Definition: branch_element:171
tools::wroot::std_vector_be_pointer::get_pointer
const std::vector< T > * get_pointer() const
Definition: branch_element:238
tools::wroot::std_vector_be_ref
Definition: branch_element:80
tools::wroot::std_vector_be::m_def
std::vector< T > m_def
Definition: branch_element:178
tools::wroot::branch::m_out
std::ostream & m_out
Definition: branch:561
tools::wroot::std_vector_be_ref::variable
std::vector< T > & variable()
Definition: branch_element:134
tools::wroot::std_vector_be_ref::m_ref
const std::vector< T > & m_ref
Definition: branch_element:136
tools::wroot::branch_element::fID
int fID
Definition: branch_element:74
tools::wroot::branch_element::create_leaf_element
leaf_element * create_leaf_element(const std::string &a_name)
Definition: branch_element:64
tools::wroot::branch_element::stream
virtual bool stream(buffer &a_buffer) const
Definition: branch_element:27
tools::wroot::std_vector_be_pointer::std_vector_be_pointer
std_vector_be_pointer(std::ostream &a_out, bool a_byte_swap, uint32 a_compression, seek a_seek_directory, const std::string &a_name, const std::string &a_title, std::vector< T > *a_pointer, bool a_verbose)
Definition: branch_element:192
tools::wroot::branch_element
Definition: branch_element:17
branch
tools::wroot::std_vector_be::std_vector_be
std_vector_be(std::ostream &a_out, bool a_byte_swap, uint32 a_compression, seek a_seek_directory, const std::string &a_name, const std::string &a_title, const std::vector< T > &a_def, bool a_verbose)
Definition: branch_element:149
tools::wroot::buffer::write_version
bool write_version(short a_version)
Definition: buffer:169
tools::wroot::std_vector_be_ref::~std_vector_be_ref
virtual ~std_vector_be_ref()
Definition: branch_element:104
tools::wroot::std_vector_be_pointer
Definition: branch_element:183
tools::wroot::buffer::write
bool write(T x)
Definition: buffer:97
tools::wroot::branch_element::operator=
branch_element & operator=(const branch_element &a_from)
Definition: branch_element:62
tools::wroot::buffer::write_fast_array
bool write_fast_array(const char *a_a, uint32 a_n)
Definition: buffer:114
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::wroot::std_vector_be
Definition: branch_element:140
tools::wroot::buffer
Definition: buffer:28
tools::wroot::std_vector_be_ref::std_vector_be_ref
std_vector_be_ref(std::ostream &a_out, bool a_byte_swap, uint32 a_compression, seek a_seek_directory, const std::string &a_name, const std::string &a_title, const std::vector< T > &a_ref, bool a_verbose)
Definition: branch_element:89
tools::wroot::std_vector_be_pointer::std_vector_be_pointer
std_vector_be_pointer(const std_vector_be_pointer &a_from)
Definition: branch_element:213
tools::wroot::branch_element::branch_element
branch_element(std::ostream &a_out, bool a_byte_swap, uint32 a_compression, seek a_seek_directory, const std::string &a_name, const std::string &a_title, bool a_verbose)
Definition: branch_element:43
tools::wroot::branch_element::fClassName
std::string fClassName
Definition: branch_element:72
tools::wroot::leaf_element
Definition: leaf:266
tools::wroot::std_vector_be::m_value
std::vector< T > m_value
Definition: branch_element:179
tools::wroot::std_vector_be_ref::operator=
std_vector_be_ref & operator=(const std_vector_be_ref &a_from)
Definition: branch_element:115
tools::wroot::std_vector_be_pointer::set_pointer
void set_pointer(std::vector< T > *a_pointer)
Definition: branch_element:237
tools::wroot::branch::m_leaves
obj_array< base_leaf > m_leaves
Definition: branch:580
tools::wroot::branch::stream
virtual bool stream(buffer &a_buffer) const
Definition: branch:29
tools::stype
const std::string & stype(const mat4f &)
Definition: mat4f:73
tools::wroot::std_vector_be_pointer::operator=
std_vector_be_pointer & operator=(const std_vector_be_pointer &a_from)
Definition: branch_element:218
tools::wroot::branch_element::branch_element
branch_element(const branch_element &a_from)
Definition: branch_element:61
tools::uint32
unsigned int uint32
Definition: typedefs:71
tools::wroot::branch_element::fType
int fType
Definition: branch_element:75
tools::wroot::std_vector_be_pointer::m_pointer
std::vector< T > * m_pointer
Definition: branch_element:241
tools::wroot::branch_element::fill_leaves
virtual bool fill_leaves(buffer &)
Definition: branch_element:70