g4tools  5.4.0
base_leaf
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_base_leaf
5 #define tools_rroot_base_leaf
6 
7 #ifdef TOOLS_MEM
8 #include "../mem"
9 #endif
10 
11 #include "named"
12 
13 namespace tools {
14 namespace rroot {
15 
16 class base_leaf : public virtual iro {
17 public:
18  static const std::string& s_class() {
19  static const std::string s_v("tools::rroot::base_leaf");
20  return s_v;
21  }
22 public: //iro
23  virtual void* cast(const std::string& a_class) const {
24  if(void* p = cmp_cast<base_leaf>(this,a_class)) return p;
25  return 0;
26  }
27  virtual const std::string& s_cls() const {return s_class();}
28 public:
29  static cid id_class() {return base_leaf_cid();}
30  virtual void* cast(cid a_class) const {
31  if(void* p = cmp_cast<base_leaf>(this,a_class)) {return p;}
32  else return 0;
33  }
34 public:
35  virtual bool stream(buffer& a_buffer) {
36  if(m_own_leaf_count) {
37  if(a_buffer.map_objs()) a_buffer.remove_in_map(m_leaf_count);
38  delete m_leaf_count;
39  }
40  m_leaf_count = 0;
41  m_own_leaf_count = false;
42 
43  int fOffset;
44  bool fIsUnsigned;
45 
46  short v;
47  unsigned int s,c;
48  if(!a_buffer.read_version(v,s,c)) return false;
49  //FIXME if (v > 1) {
50  //TLeaf::Class()->ReadBuffer(b, this, R__v, R__s, R__c);
51  //FIXME } else {
52  //====process old versions before automatic schema evolution
53  if(!Named_stream(a_buffer,m_name,m_title)) return false;
54 
55  // Ok with v 1 & 2
56  if(!a_buffer.read(m_length)) return false;
57  if(!a_buffer.read(m_length_type)) return false;
58  if(!a_buffer.read(fOffset)) return false;
59  if(!a_buffer.read(m_is_range)) return false;
60  if(!a_buffer.read(fIsUnsigned)) return false;
61 
63  iro* obj;
64  bool created;
65  if(!a_buffer.read_object(m_fac,args,obj,created)) {
66  m_out << "tools::rroot::base_leaf::stream :"
67  << " can't read object."
68  << std::endl;
69  return false;
70  }
71  if(!obj) {
72  //m_out << "tools::rroot::base_leaf::stream :"
73  // << " null leaf count object."
74  // << std::endl;
75  } else {
76  m_leaf_count = safe_cast<iro,base_leaf>(*obj);
77  if(!m_leaf_count) {
78  m_out << "tools::rroot::base_leaf::stream :"
79  << " can't cast base_leaf."
80  << std::endl;
81  m_leaf_count = 0;
82  if(created) {
83  if(a_buffer.map_objs()) a_buffer.remove_in_map(obj);
84  delete obj;
85  }
86  return false;
87  }
88  if(created) m_own_leaf_count = true;
89  }}
90 
91  if(!a_buffer.check_byte_count(s,c,"TLeaf")) return false;
92 
93  if(!m_length) m_length = 1;
94 /*
95  fNewValue = false;
96  if(!setAddress(0)) return false;
97 */
98  return true;
99  }
100 public:
101  virtual bool read_buffer(buffer&) = 0;
102  virtual bool print_value(std::ostream&,uint32) const = 0;
103  virtual uint32 num_elem() const = 0;
104 public:
105  base_leaf(std::ostream& a_out,ifac& a_fac)
106  :m_out(a_out)
107  ,m_fac(a_fac)
108  ,m_name("")
109  ,m_title("")
110 
111  //,fIndirectAddress(false)
112  //,fNewValue(false)
113  //,m_ndata(0)
114  ,m_length(0)
115  ,m_length_type(0)
116 //,fOffset(0)
117  ,m_is_range(false)
118 //,fIsUnsigned(false)
119  ,m_leaf_count(0)
120  ,m_own_leaf_count(false)
121  {
122 #ifdef TOOLS_MEM
123  mem::increment(s_class().c_str());
124 #endif
125  }
126  virtual ~base_leaf(){
127  if(m_own_leaf_count) delete m_leaf_count;
128 #ifdef TOOLS_MEM
129  mem::decrement(s_class().c_str());
130 #endif
131  }
132 protected:
133  base_leaf(const base_leaf& a_from)
134  :iro(a_from)
135  ,m_out(a_from.m_out)
136  ,m_fac(a_from.m_fac)
137  //,m_ndata(0)
138  ,m_length(0)
139  ,m_length_type(0)
140  ,m_is_range(false)
141  ,m_leaf_count(0)
142  ,m_own_leaf_count(false)
143  {}
144  base_leaf& operator=(const base_leaf&){return *this;}
145 public:
146  const std::string& name() const {return m_name;}
147  const std::string& title() const {return m_title;}
148  const base_leaf* leaf_count() const {return m_leaf_count;}
149 /*
150  uint32 length() const {
151  // Return the number of effective elements of this leaf.
152  if(m_leaf_count) {
153  m_out << "tools::rroot::base_leaf::length :"
154  << " m_leaf_count not null. Case not yet handled."
155  << std::endl;
156  return m_length;
157 
158  //uint32 len = m_leaf_count->number();
159  //if (len > fLeafCount->maximum()) {
160  // m_out << "tools::rroot::base_leaf::length :"
161  // << fName << ", len=" << len << " and max="
162  // << fLeafCount->maximum()
163  // << std::endl;
164  // len = fLeafCount->maximum();
165  //}
166  //return len * fLength;
167 
168  } else {
169  return m_length;
170  }
171  }
172 */
173 protected:
174  std::ostream& m_out;
176 protected: //Named
177  std::string m_name;
178  std::string m_title;
179  //bool fIndirectAddress;
180  //bool fNewValue;
181 //uint32 m_ndata; //! Number of elements in fAddress data buffer
182  uint32 m_length; // Number of fixed length elements
183  uint32 m_length_type; // Number of bytes for this data type
184 //int fOffset; // Offset in ClonesArray object (if one)
185  bool m_is_range; // (=true if leaf has a range, false otherwise)
186 //bool fIsUnsigned; // (=kTRUE if unsigned, kFALSE otherwise)
187  base_leaf* m_leaf_count; // Pointer to Leaf count if variable length
189 };
190 
191 }}
192 
193 #endif
tools::rroot::base_leaf::s_class
static const std::string & s_class()
Definition: base_leaf:18
tools::rroot::base_leaf::leaf_count
const base_leaf * leaf_count() const
Definition: base_leaf:148
tools::rroot::base_leaf::s_cls
virtual const std::string & s_cls() const
Definition: base_leaf:27
tools::rroot::base_leaf::m_out
std::ostream & m_out
Definition: base_leaf:174
tools::rroot::base_leaf::~base_leaf
virtual ~base_leaf()
Definition: base_leaf:126
tools::rroot::base_leaf::read_buffer
virtual bool read_buffer(buffer &)=0
tools::rroot::buffer::read_object
bool read_object(ifac &a_fac, const ifac::args &a_args, iro *&a_obj, bool &a_created)
Definition: buffer:283
tools::rroot::base_leaf::print_value
virtual bool print_value(std::ostream &, uint32) const =0
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::base_leaf::base_leaf
base_leaf(const base_leaf &a_from)
Definition: base_leaf:133
tools::rroot::base_leaf::name
const std::string & name() const
Definition: base_leaf:146
tools::rroot::Named_stream
bool Named_stream(buffer &a_buffer, std::string &a_name, std::string &a_title)
Definition: named:15
named
tools::rroot::base_leaf::m_is_range
bool m_is_range
Definition: base_leaf:185
tools::rroot::base_leaf::num_elem
virtual uint32 num_elem() const =0
tools::rroot::base_leaf::m_name
std::string m_name
Definition: base_leaf:177
tools::rroot::base_leaf::m_title
std::string m_title
Definition: base_leaf:178
tools::rroot::buffer::read_version
bool read_version(short &a_version)
Definition: buffer:503
tools::args
Definition: args:24
tools::rroot::base_leaf
Definition: base_leaf:16
tools::rroot::base_leaf::id_class
static cid id_class()
Definition: base_leaf:29
tools::rroot::base_leaf_cid
cid base_leaf_cid()
Definition: cids:45
tools::rroot::base_leaf::title
const std::string & title() const
Definition: base_leaf:147
tools::rroot::base_leaf::m_leaf_count
base_leaf * m_leaf_count
Definition: base_leaf:187
tools::rroot::base_leaf::m_length
uint32 m_length
Definition: base_leaf:182
tools::rroot::buffer::map_objs
bool map_objs() const
Definition: buffer:124
tools::rroot::base_leaf::stream
virtual bool stream(buffer &a_buffer)
Definition: base_leaf:35
tools::rroot::ifac
Definition: ifac:19
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::rroot::base_leaf::m_fac
ifac & m_fac
Definition: base_leaf:175
tools::rroot::base_leaf::operator=
base_leaf & operator=(const base_leaf &)
Definition: base_leaf:144
tools::rroot::base_leaf::m_length_type
uint32 m_length_type
Definition: base_leaf:183
tools::rroot::buffer
Definition: buffer:43
tools::rroot::base_leaf::cast
virtual void * cast(const std::string &a_class) const
Definition: base_leaf:23
tools::rroot::rbuf::read
bool read(unsigned char &a_x)
Definition: rbuf:146
tools::rroot::iro
Definition: iro:19
tools::rroot::ifac::args
std::map< char, void * > args
Definition: ifac:21
tools::rroot::base_leaf::m_own_leaf_count
bool m_own_leaf_count
Definition: base_leaf:188
tools::uint32
unsigned int uint32
Definition: typedefs:71
tools::rroot::base_leaf::base_leaf
base_leaf(std::ostream &a_out, ifac &a_fac)
Definition: base_leaf:105
tools::rroot::base_leaf::cast
virtual void * cast(cid a_class) const
Definition: base_leaf:30
tools::rroot::buffer::remove_in_map
void remove_in_map(iro *a_obj)
Definition: buffer:276
tools::cid
unsigned short cid
Definition: cid:9