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