g4tools  5.4.0
info
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_rroot_info
5 #define tools_rroot_info
6 
7 //#include "buffer"
8 //#include "element"
9 #include "named"
10 #include "obj_array"
11 #include "../forit"
12 
13 namespace tools {
14 namespace rroot {
15 
16 class streamer_element : public virtual iro {
17  static const std::string& s_store_class() {
18  static const std::string s_v("TStreamerElement");
19  return s_v;
20  }
21 public:
22  static const std::string& s_class() {
23  static const std::string s_v("tools::rroot::streamer_element");
24  return s_v;
25  }
26  static cid id_class() {return streamer_element_cid();}
27 public: //iro
28  virtual void* cast(const std::string& a_class) const {
29  if(void* p = cmp_cast<streamer_element>(this,a_class)) return p;
30  return 0;
31  }
32  virtual void* cast(cid a_class) const {
33  if(void* p = cmp_cast<streamer_element>(this,a_class)) {return p;}
34  else return 0;
35  }
36  virtual const std::string& s_cls() const {return s_class();}
37  virtual iro* copy() const {return new streamer_element(*this);}
38 
39  virtual bool stream(buffer& a_buffer) {
40  short v;
41  unsigned int s, c;
42  if(!a_buffer.read_version(v,s,c)) return false;
43  if(!Named_stream(a_buffer,fName,fTitle)) return false;
44  if(!a_buffer.read(fType)) return false;
45  if(!a_buffer.read(fSize)) return false;
46  if(!a_buffer.read(fArrayLength)) return false;
47  if(!a_buffer.read(fArrayDim)) return false;
48  if(!a_buffer.read_fast_array<int>(fMaxIndex,5)) return false;
49  if(!a_buffer.read(fTypeName)) return false;
50  return a_buffer.check_byte_count(s,c,s_store_class());
51  }
52 public:
53  virtual void out(std::ostream& aOut) const {
54  std::string _fname;
55  fullName(_fname);
56  char s[128];
57  snpf(s,sizeof(s)," %-14s%-15s offset=%3d type=%2d %-20s",
58  fTypeName.c_str(),_fname.c_str(),fOffset,fType,fTitle.c_str());
59  aOut << s << std::endl;
60  }
61 public:
63  :fName(),fTitle(),fType(-1)
64  ,fSize(0),fArrayLength(0),fArrayDim(0),fOffset(0)
65  ,fTypeName(){
66 #ifdef TOOLS_MEM
67  mem::increment(s_class().c_str());
68 #endif
69  for(int i=0;i<5;i++) fMaxIndex[i] = 0;
70  }
71  virtual ~streamer_element(){
72 #ifdef TOOLS_MEM
73  mem::decrement(s_class().c_str());
74 #endif
75  }
76 protected:
78  :iro(a_from)
79  ,fName(a_from.fName),fTitle(a_from.fTitle)
80  ,fType(a_from.fType),fSize(a_from.fSize)
81  ,fArrayLength(a_from.fArrayLength)
82  ,fArrayDim(a_from.fArrayDim),fOffset(a_from.fOffset)
83  ,fTypeName(a_from.fTypeName){
84 #ifdef TOOLS_MEM
85  mem::increment(s_class().c_str());
86 #endif
87  for(int i=0;i<5;i++) fMaxIndex[i] = a_from.fMaxIndex[i];
88  }
90  fName = a_from.fName;
91  fTitle = a_from.fTitle;
92  fType = a_from.fType;
93  fSize = a_from.fSize;
94  fArrayLength = a_from.fArrayLength;
95  fArrayDim = a_from.fArrayDim;
96  fOffset = a_from.fOffset;
97  fTypeName = a_from.fTypeName;
98  for(int i=0;i<5;i++) fMaxIndex[i] = a_from.fMaxIndex[i];
99  return *this;
100  }
101 public:
102  virtual void fullName(std::string& a_s) const {
103  a_s = fName;
104  for (int i=0;i<fArrayDim;i++) {
105  char cdim[32];
106  snpf(cdim,sizeof(cdim),"[%d]",fMaxIndex[i]);
107  a_s += cdim;
108  }
109  }
110  const std::string& type_name() const {return fTypeName;}
111 protected: //Named
112  std::string fName;
113  std::string fTitle;
114 protected:
115  int fType; //element type
116  int fSize; //sizeof element
117  int fArrayLength; //cumulative size of all array dims
118  int fArrayDim; //number of array dimensions
119  int fMaxIndex[5]; //Maximum array index for array dimension "dim"
120  int fOffset;
121  //FIXME Int_t fNewType; //!new element type when reading
122  std::string fTypeName; //Data type name of data member
123 };
124 
126  typedef streamer_element parent;
127 public: //iro
128  virtual iro* copy() const {return new dummy_streamer_element(*this);}
129  virtual bool stream(buffer& a_buffer) {
130  //the below code skips correctly the data in the file.
131  uint32 startpos = a_buffer.length();
132  short v;
133  unsigned int s,c;
134  if(!a_buffer.read_version(v,s,c)) return false;
135 
136  if(!parent::stream(a_buffer)) return false;
137 
138  a_buffer.set_offset(startpos+c+sizeof(unsigned int));
139  if(!a_buffer.check_byte_count(s,c,"dummy_streamer_element")) return false;
140  return true;
141  }
142 public:
145 protected:
146  dummy_streamer_element(const dummy_streamer_element& a_from):iro(a_from),parent(a_from){}
148  parent::operator=(a_from);
149  return *this;
150  }
151 };
152 
153 class streamer_info : public virtual iro {
154  static const std::string& s_store_class() {
155  static const std::string s_v("TStreamerInfo");
156  return s_v;
157  }
158 public:
159  static const std::string& s_class() {
160  static const std::string s_v("tools::rroot::streamer_info");
161  return s_v;
162  }
163  static cid id_class() {return streamer_info_cid();}
164 public: //iro
165  virtual void* cast(const std::string& a_class) const {
166  if(void* p = cmp_cast<streamer_info>(this,a_class)) return p;
167  return 0;
168  }
169  virtual void* cast(cid a_class) const {
170  if(void* p = cmp_cast<streamer_info>(this,a_class)) {return p;}
171  else return 0;
172  }
173  virtual const std::string& s_cls() const {return s_class();}
174  virtual iro* copy() const {return new streamer_info(*this);}
175 
176  virtual bool stream(buffer& a_buffer) {
177  short v;
178  unsigned int s, c;
179  if(!a_buffer.read_version(v,s,c)) return false;
180 
181  if(!Named_stream(a_buffer,m_name,m_title)) return false;
182  if(!a_buffer.read(m_check_sum)) return false;
183  if(!a_buffer.read(m_streamed_class_version)) return false;
184 
185  //TObjArray *fElements; //Array of TStreamerElements
189  bool obj_created;
190  if(!pointer_stream(a_buffer,m_fac,args,obj,obj_created)) {
191  a_buffer.out() << "tools::rroot::streamer_info::stream : "
192  << "can't read fElements."
193  << std::endl;
194  return false;
195  }
196  if(obj) m_elements.operator=(*obj);
197  if(obj_created) delete obj;}
198 
199  return a_buffer.check_byte_count(s,c,s_store_class());
200  }
201 public:
202  void out(std::ostream& a_out) const {
203  a_out << "streamer_info for class :"
204  << " " << m_name << ", version=" << m_streamed_class_version
205  << std::endl;
206  tools_vforcit(streamer_element*,m_elements,it) (*it)->out(a_out);
207  }
208 public:
210  :m_fac(a_fac)
211  ,m_name()
212  ,m_title()
213  ,m_check_sum(0)
215  ,m_elements(a_fac)
216  {
217 #ifdef TOOLS_MEM
218  mem::increment(s_class().c_str());
219 #endif
220  }
221  virtual ~streamer_info(){
222 #ifdef TOOLS_MEM
223  mem::decrement(s_class().c_str());
224 #endif
225  }
226 protected:
228  :iro(a_from)
229  ,m_fac(a_from.m_fac)
230  ,m_name(a_from.m_name)
231  ,m_title(a_from.m_name)
232  ,m_check_sum(a_from.m_check_sum)
234  ,m_elements(a_from.m_elements)
235  {
236 #ifdef TOOLS_MEM
237  mem::increment(s_class().c_str());
238 #endif
239  }
241  m_name = a_from.m_name;
242  m_title = a_from.m_name;
243  m_check_sum = a_from.m_check_sum;
245  m_elements = a_from.m_elements;
246  return *this;
247  }
248 public:
249  const std::string& name() const {return m_name;}
250  streamer_element* find_streamer_element(size_t a_index) const {
251  if(a_index>=m_elements.size()) return 0;
252  return m_elements[a_index];
253  }
254 protected:
256 protected: //Named
257  std::string m_name;
258  std::string m_title;
259 protected:
260  unsigned int m_check_sum; //checksum of original class
261  int m_streamed_class_version; //Class version identifier
262  //int fNumber; //!Unique identifier
263  obj_array<streamer_element> m_elements; //Array of TStreamerElements
264 };
265 
266 }}
267 
268 #endif
tools::rroot::streamer_info
Definition: info:153
tools::rroot::streamer_element::out
virtual void out(std::ostream &aOut) const
Definition: info:53
tools::rroot::streamer_element::streamer_element
streamer_element()
Definition: info:62
tools::rroot::dummy_streamer_element::dummy_streamer_element
dummy_streamer_element(const dummy_streamer_element &a_from)
Definition: info:146
tools::rroot::streamer_element::id_class
static cid id_class()
Definition: info:26
tools::rroot::streamer_info::cast
virtual void * cast(cid a_class) const
Definition: info:169
tools::rroot::streamer_element::fSize
int fSize
Definition: info:116
tools::rroot::rbuf::read_fast_array
bool read_fast_array(bool *b, uint32 n)
Definition: rbuf:261
tools::rroot::streamer_info::m_elements
obj_array< streamer_element > m_elements
Definition: info:263
tools::rroot::streamer_element::fTypeName
std::string fTypeName
element offset in class
Definition: info:122
tools::rroot::streamer_element::copy
virtual iro * copy() const
Definition: info:37
tools::rroot::buffer::check_byte_count
bool check_byte_count(uint32 a_start_pos, uint32 a_byte_count, const std::string &a_store_cls)
Definition: buffer:568
tools::rroot::streamer_info::name
const std::string & name() const
Definition: info:249
tools::rroot::streamer_info::s_cls
virtual const std::string & s_cls() const
Definition: info:173
tools::rroot::streamer_info::m_streamed_class_version
int m_streamed_class_version
Definition: info:261
tools::rroot::streamer_element::s_class
static const std::string & s_class()
Definition: info:22
tools::rroot::Named_stream
bool Named_stream(buffer &a_buffer, std::string &a_name, std::string &a_title)
Definition: named:15
named
tools::rroot::streamer_info::cast
virtual void * cast(const std::string &a_class) const
Definition: info:165
obj_array
tools::rroot::streamer_element::type_name
const std::string & type_name() const
Definition: info:110
tools::rroot::rbuf::out
std::ostream & out() const
Definition: rbuf:125
tools::rroot::buffer::read_version
bool read_version(short &a_version)
Definition: buffer:503
tools::rroot::streamer_info::m_check_sum
unsigned int m_check_sum
Definition: info:260
tools::rroot::streamer_info::s_class
static const std::string & s_class()
Definition: info:159
tools::args
Definition: args:24
tools::snpf
int snpf(char *a_s, size_t a_n, const char *a_fmt,...)
Definition: snpf:27
tools::rroot::streamer_element::stream
virtual bool stream(buffer &a_buffer)
Definition: info:39
tools::rroot::streamer_element::fName
std::string fName
Definition: info:112
tools::rroot::streamer_info::id_class
static cid id_class()
Definition: info:163
tools::rroot::pointer_stream
bool pointer_stream(buffer &a_buffer, ifac &a_fac, ifac::args &a_args, const std::string &a_T_class, T *&a_obj, bool &a_created)
Definition: buffer:646
tools::rroot::dummy_streamer_element
Definition: info:125
tools::rroot::dummy_streamer_element::~dummy_streamer_element
virtual ~dummy_streamer_element()
Definition: info:144
tools::rroot::buffer::length
uint32 length() const
Definition: buffer:120
tools::rroot::streamer_element::fullName
virtual void fullName(std::string &a_s) const
Definition: info:102
tools::rroot::dummy_streamer_element::stream
virtual bool stream(buffer &a_buffer)
Definition: info:129
tools::rroot::streamer_element::s_cls
virtual const std::string & s_cls() const
Definition: info:36
tools::rroot::streamer_element::fArrayDim
int fArrayDim
Definition: info:118
tools::rroot::dummy_streamer_element::dummy_streamer_element
dummy_streamer_element()
Definition: info:143
tools::rroot::streamer_element::fArrayLength
int fArrayLength
Definition: info:117
tools::rroot::streamer_info::out
void out(std::ostream &a_out) const
Definition: info:202
tools::rroot::streamer_element
Definition: info:16
tools::rroot::ifac
Definition: ifac:19
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::rroot::buffer::set_offset
void set_offset(unsigned int a_off)
Definition: buffer:117
tools::rroot::streamer_info::m_title
std::string m_title
Definition: info:258
tools::rroot::streamer_info::copy
virtual iro * copy() const
Definition: info:174
tools::rroot::streamer_element::operator=
streamer_element & operator=(const streamer_element &a_from)
Definition: info:89
tools::rroot::buffer
Definition: buffer:43
tools::rroot::streamer_info::stream
virtual bool stream(buffer &a_buffer)
Definition: info:176
tools::rroot::streamer_element::fType
int fType
Definition: info:115
tools::rroot::streamer_info::find_streamer_element
streamer_element * find_streamer_element(size_t a_index) const
Definition: info:250
tools::rroot::streamer_element::streamer_element
streamer_element(const streamer_element &a_from)
Definition: info:77
tools::rroot::streamer_element::fOffset
int fOffset
Definition: info:120
tools::rroot::streamer_info_cid
cid streamer_info_cid()
Definition: cids:34
tools::rroot::dummy_streamer_element::operator=
dummy_streamer_element & operator=(const dummy_streamer_element &a_from)
Definition: info:147
tools::rroot::streamer_info::operator=
streamer_info & operator=(const streamer_info &a_from)
Definition: info:240
tools::rroot::streamer_element::fTitle
std::string fTitle
Definition: info:113
tools::rroot::rbuf::read
bool read(unsigned char &a_x)
Definition: rbuf:146
tools::rroot::streamer_info::streamer_info
streamer_info(const streamer_info &a_from)
Definition: info:227
tools::rroot::streamer_info::m_name
std::string m_name
Definition: info:257
tools::rroot::ifac::arg_class
static char arg_class()
Definition: ifac:34
tools::rroot::iro
Definition: iro:19
tools::rroot::streamer_info::~streamer_info
virtual ~streamer_info()
Definition: info:221
tools::rroot::streamer_element::cast
virtual void * cast(cid a_class) const
Definition: info:32
tools::rroot::streamer_info::streamer_info
streamer_info(ifac &a_fac)
Definition: info:209
tools::rroot::streamer_info::m_fac
ifac & m_fac
Definition: info:255
tools::rroot::ifac::args
std::map< char, void * > args
Definition: ifac:21
tools_vforcit
#define tools_vforcit(a__T, a__v, a__it)
Definition: forit:7
tools::rroot::dummy_streamer_element::copy
virtual iro * copy() const
Definition: info:128
tools::uint32
unsigned int uint32
Definition: typedefs:71
tools::rroot::streamer_element::~streamer_element
virtual ~streamer_element()
Definition: info:71
tools::rroot::streamer_element::cast
virtual void * cast(const std::string &a_class) const
Definition: info:28
tools::rroot::streamer_element_cid
cid streamer_element_cid()
Definition: cids:35
tools::rroot::obj_array
Definition: obj_array:17
tools::cid
unsigned short cid
Definition: cid:9
tools::rroot::streamer_element::fMaxIndex
int fMaxIndex[5]
Definition: info:119