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