Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 2 // See the file tools.license for terms. 3 4 #ifndef tools_wroot_element 5 #define tools_wroot_element 6 7 #include "buffer" 8 #include "named" 9 #include "../snpf" 10 11 namespace tools { 12 namespace wroot { 13 14 namespace streamer__info { 15 16 enum Type { // sizeof : 17 BASE = 0, // x 18 ARRAY = 20, // ? 19 POINTER = 40, // 4 20 POINTER_INT = 43, // 4 21 POINTER_FLOAT = 45, // 4 22 POINTER_DOUBLE = 48, // 4 23 COUNTER = 6, // 4 24 CHAR = 1, // 1 25 SHORT = 2, // 2 26 INT = 3, // 4 27 FLOAT = 5, // 4 28 DOUBLE = 8, // 8 29 UNSIGNED_CHAR = 11, // 1 30 UNSIGNED_SHORT = 12, // 2 31 UNSIGNED_INT = 13, // 4 32 BOOL = 18, // 1 ? 33 OBJECT = 61, // ? 34 OBJECT_ANY = 62, // ? 35 OBJECT_ARROW = 63, // ? 36 OBJECT_POINTER = 64, // ? 37 _TSTRING = 65, // 8 //NOTE : TST 38 TOBJECT = 66, // 12 39 TNAMED = 67 // 28 40 }; 41 42 const int size_FLOAT = 4; 43 const int size_DOUBLE = 8; 44 const int size_INT = 4; 45 const int size_UINT = 4; 46 const int size_SHORT = 2; 47 const int size_BOOL = 4; //(Bool_t = 1 + 3 f 48 //uuu ? const int size_BOOL = 1; 49 50 const int size_TString = 8; 51 } 52 53 54 class streamer_element : public virtual ibo { 55 static const std::string& s_class() { 56 static const std::string s_v("tools::wroot 57 return s_v; 58 } 59 public: //ibo 60 virtual const std::string& store_cls() const 61 static const std::string s_v("TStreamerEle 62 return s_v; 63 } 64 virtual bool stream(buffer& aBuffer) const { 65 unsigned int c; 66 if(!aBuffer.write_version(2,c)) return fal 67 if(!Named_stream(aBuffer,fName,fTitle)) re 68 if(!aBuffer.write(fType)) return false; 69 if(!aBuffer.write(fSize)) return false; 70 if(!aBuffer.write(fArrayLength)) return fa 71 if(!aBuffer.write(fArrayDim)) return false 72 if(!aBuffer.write_fast_array<int>(fMaxInde 73 if(!aBuffer.write(fTypeName)) return false 74 if(!aBuffer.set_byte_count(c)) return fals 75 return true; 76 } 77 public: 78 virtual streamer_element* copy() const = 0; 79 public: 80 virtual void out(std::ostream& aOut) const { 81 std::string _fname; 82 fullName(_fname); 83 char _s[256]; 84 snpf(_s,sizeof(_s)," %-14s%-15s offset=%3 85 aOut << _s << std::endl; 86 } 87 public: 88 streamer_element(const std::string& aName,co 89 int aOffset,int aType,const 90 :fName(aName),fTitle(aTitle),fType(aType) 91 ,fSize(0),fArrayLength(0),fArrayDim(0),fOffs 92 ,fTypeName(aTypeName){ 93 #ifdef TOOLS_MEM 94 mem::increment(s_class().c_str()); 95 #endif 96 for(int i=0;i<5;i++) fMaxIndex[i] = 0; 97 } 98 virtual ~streamer_element(){ 99 #ifdef TOOLS_MEM 100 mem::decrement(s_class().c_str()); 101 #endif 102 } 103 protected: 104 streamer_element(const streamer_element& a_f 105 :ibo(a_from) 106 ,fName(a_from.fName),fTitle(a_from.fTitle) 107 ,fType(a_from.fType),fSize(a_from.fSize) 108 ,fArrayLength(a_from.fArrayLength) 109 ,fArrayDim(a_from.fArrayDim),fOffset(a_from. 110 ,fTypeName(a_from.fTypeName){ 111 #ifdef TOOLS_MEM 112 mem::increment(s_class().c_str()); 113 #endif 114 for(int i=0;i<5;i++) fMaxIndex[i] = a_from 115 } 116 streamer_element& operator=(const streamer_e 117 fName = a_from.fName; 118 fTitle = a_from.fTitle; 119 fType = a_from.fType; 120 fSize = a_from.fSize; 121 fArrayLength = a_from.fArrayLength; 122 fArrayDim = a_from.fArrayDim; 123 fOffset = a_from.fOffset; 124 fTypeName = a_from.fTypeName; 125 for(int i=0;i<5;i++) fMaxIndex[i] = a_from 126 return *this; 127 } 128 public: 129 virtual void setArrayDimension(int aDimensio 130 fArrayDim = aDimension; 131 if(aDimension) fType += streamer__info::AR 132 //fNewType = fType; 133 } 134 virtual void setMaxIndex(int aDimension,int 135 //set maximum index for array with dimensi 136 if (aDimension < 0 || aDimension > 4) retu 137 fMaxIndex[aDimension] = aMaximum; 138 if (fArrayLength == 0) fArrayLength = aM 139 else fArrayLength *= aM 140 } 141 142 virtual void fullName(std::string& a_s) cons 143 a_s = fName; 144 for (int i=0;i<fArrayDim;i++) { 145 char cdim[32]; 146 snpf(cdim,sizeof(cdim),"[%d]",fMaxIndex[ 147 a_s += cdim; 148 } 149 } 150 protected: //Named 151 std::string fName; 152 std::string fTitle; 153 protected: 154 int fType; //element type 155 int fSize; //sizeof element 156 int fArrayLength; //cumulative size of a 157 int fArrayDim; //number of array dime 158 int fMaxIndex[5]; //Maximum array index 159 int fOffset; //!element offset in c 160 //FIXME Int_t fNewType; //!n 161 std::string fTypeName; //Data type na 162 }; 163 164 class streamer_base : public streamer_element 165 public: //ibo 166 virtual const std::string& store_cls() const 167 static const std::string s_v("TStreamerBas 168 return s_v; 169 } 170 virtual bool stream(buffer& aBuffer) const { 171 unsigned int c; 172 if(!aBuffer.write_version(3,c)) return fal 173 if(!streamer_element::stream(aBuffer)) ret 174 if(!aBuffer.write(fBaseVersion)) return fa 175 if(!aBuffer.set_byte_count(c)) return fals 176 return true; 177 } 178 public: //streamer_element 179 virtual streamer_element* copy() const {retu 180 public: 181 streamer_base(const std::string& aName,const 182 :streamer_element(aName,aTitle,aOffset,strea 183 ,fBaseVersion(aBaseVersion) 184 { 185 if (aName=="TObject") fType = streamer__in 186 if (aName=="TNamed") fType = streamer__inf 187 } 188 virtual ~streamer_base(){} 189 public: 190 streamer_base(const streamer_base& a_from) 191 :ibo(a_from) 192 ,streamer_element(a_from) 193 ,fBaseVersion(a_from.fBaseVersion) 194 {} 195 streamer_base& operator=(const streamer_base 196 streamer_element::operator=(a_from); 197 fBaseVersion = a_from.fBaseVersion; 198 return *this; 199 } 200 protected: 201 int fBaseVersion; //version number o 202 }; 203 204 class streamer_basic_type : public streamer_el 205 public: //ibo 206 virtual const std::string& store_cls() const 207 static const std::string s_v("TStreamerBas 208 return s_v; 209 } 210 virtual bool stream(buffer& aBuffer) const { 211 unsigned int c; 212 if(!aBuffer.write_version(2,c)) return fal 213 if(!streamer_element::stream(aBuffer)) ret 214 if(!aBuffer.set_byte_count(c)) return fals 215 return true; 216 } 217 public: //streamer_element 218 virtual streamer_element* copy() const {retu 219 public: 220 streamer_basic_type(const std::string& aName 221 int aOffset,int aType,co 222 :streamer_element(aName,aTitle,aOffset,aType 223 {} 224 virtual ~streamer_basic_type(){} 225 public: 226 streamer_basic_type(const streamer_basic_typ 227 :ibo(a_from),streamer_element(a_from) 228 {} 229 streamer_basic_type& operator=(const streame 230 streamer_element::operator=(a_from); 231 return *this; 232 } 233 }; 234 235 class streamer_short : public streamer_basic_t 236 public: //streamer_element 237 virtual streamer_element* copy() const {retu 238 public: 239 streamer_short(const std::string& aName,cons 240 :streamer_basic_type(aName,aTitle,aOffset,st 241 {} 242 streamer_short(int& aOffset,const std::strin 243 :streamer_basic_type(aName,aTitle,aOffset,st 244 { 245 aOffset += streamer__info::size_SHORT; 246 } 247 virtual ~streamer_short(){} 248 public: 249 streamer_short(const streamer_short& a_from) 250 streamer_short& operator=(const streamer_sho 251 }; 252 253 class streamer_int : public streamer_basic_typ 254 public: //streamer_element 255 virtual streamer_element* copy() const {retu 256 public: 257 streamer_int(const std::string& aName,const 258 :streamer_basic_type(aName,aTitle,aOffset,st 259 {} 260 streamer_int(int& aOffset,const std::string& 261 :streamer_basic_type(aName,aTitle,aOffset,st 262 { 263 aOffset += streamer__info::size_INT; 264 } 265 virtual ~streamer_int(){} 266 public: 267 streamer_int(const streamer_int& a_from):ibo 268 streamer_int& operator=(const streamer_int& 269 }; 270 271 class streamer_uint : public streamer_basic_ty 272 public: //streamer_element 273 virtual streamer_element* copy() const {retu 274 public: 275 streamer_uint(const std::string& aName,const 276 :streamer_basic_type(aName,aTitle,aOffset,st 277 {} 278 streamer_uint(int& aOffset,const std::string 279 :streamer_basic_type(aName,aTitle,aOffset,st 280 { 281 aOffset += streamer__info::size_UINT; 282 } 283 virtual ~streamer_uint(){} 284 public: 285 streamer_uint(const streamer_uint& a_from):i 286 streamer_uint& operator=(const streamer_uint 287 }; 288 289 class streamer_float : public streamer_basic_t 290 public: //streamer_element 291 virtual streamer_element* copy() const {retu 292 public: 293 streamer_float(const std::string& aName,cons 294 :streamer_basic_type(aName,aTitle,aOffset,st 295 {} 296 streamer_float(int& aOffset,const std::strin 297 :streamer_basic_type(aName,aTitle,aOffset,st 298 { 299 aOffset += streamer__info::size_FLOAT; 300 } 301 virtual ~streamer_float(){} 302 public: 303 streamer_float(const streamer_float& a_from) 304 streamer_float& operator=(const streamer_flo 305 }; 306 307 class streamer_double : public streamer_basic_ 308 public: //streamer_element 309 virtual streamer_element* copy() const {retu 310 public: 311 streamer_double(const std::string& aName,con 312 :streamer_basic_type(aName,aTitle,aOffset,st 313 {} 314 streamer_double(int& aOffset,const std::stri 315 :streamer_basic_type(aName,aTitle,aOffset,st 316 { 317 aOffset += streamer__info::size_DOUBLE; 318 } 319 virtual ~streamer_double(){} 320 public: 321 streamer_double(const streamer_double& a_fro 322 streamer_double& operator=(const streamer_do 323 }; 324 325 class streamer_stat_t : public streamer_basic_ 326 public: //streamer_element 327 virtual streamer_element* copy() const {retu 328 public: 329 streamer_stat_t(const std::string& aName,con 330 :streamer_basic_type(aName,aTitle,aOffset,st 331 {} 332 streamer_stat_t(int& aOffset,const std::stri 333 :streamer_basic_type(aName,aTitle,aOffset,st 334 { 335 aOffset += streamer__info::size_DOUBLE; 336 } 337 virtual ~streamer_stat_t(){} 338 public: 339 streamer_stat_t(const streamer_stat_t& a_fro 340 streamer_stat_t& operator=(const streamer_st 341 }; 342 343 class streamer_bool : public streamer_basic_ty 344 public: //streamer_element 345 virtual streamer_element* copy() const {retu 346 public: 347 streamer_bool(const std::string& aName,const 348 :streamer_basic_type(aName,aTitle,aOffset,st 349 {} 350 streamer_bool(int& aOffset,const std::string 351 :streamer_basic_type(aName,aTitle,aOffset,st 352 { 353 aOffset += streamer__info::size_BOOL; 354 } 355 virtual ~streamer_bool(){} 356 public: 357 streamer_bool(const streamer_bool& a_from):i 358 streamer_bool& operator=(const streamer_bool 359 }; 360 361 class streamer_basic_pointer : public streamer 362 public: //ibo 363 virtual const std::string& store_cls() const 364 static const std::string s_v("TStreamerBas 365 return s_v; 366 } 367 virtual bool stream(buffer& aBuffer) const { 368 unsigned int c; 369 if(!aBuffer.write_version(2,c)) return fal 370 if(!streamer_element::stream(aBuffer)) ret 371 if(!aBuffer.write(fCountVersion)) return f 372 if(!aBuffer.write(fCountName)) return fals 373 if(!aBuffer.write(fCountClass)) return fal 374 if(!aBuffer.set_byte_count(c)) return fals 375 return true; 376 } 377 public: //streamer_element 378 virtual streamer_element* copy() const {retu 379 public: 380 streamer_basic_pointer(const std::string& aN 381 int aOffset,int aType 382 const std::string& aC 383 const std::string& aC 384 int aCountVersion, 385 const std::string& aT 386 :streamer_element(aName,aTitle,aOffset,aType 387 ,fCountVersion(aCountVersion) 388 ,fCountName(aCountName) 389 ,fCountClass(aCountClass) 390 {} 391 virtual ~streamer_basic_pointer(){} 392 public: 393 streamer_basic_pointer(const streamer_basic_ 394 :ibo(a_from),streamer_element(a_from) 395 ,fCountVersion(a_from.fCountVersion) 396 ,fCountName(a_from.fCountName) 397 ,fCountClass(a_from.fCountClass) 398 {} 399 streamer_basic_pointer& operator=(const stre 400 streamer_element::operator=(a_from); 401 fCountVersion = a_from.fCountVersion; 402 fCountName = a_from.fCountName; 403 fCountClass = a_from.fCountClass; 404 return *this; 405 } 406 protected: 407 int fCountVersion; //version number of 408 std::string fCountName; //name of data memb 409 std::string fCountClass; //name of the class 410 }; 411 412 class streamer_string : public streamer_elemen 413 public: //ibo 414 virtual const std::string& store_cls() const 415 static const std::string s_v("TStreamerStr 416 return s_v; 417 } 418 virtual bool stream(buffer& aBuffer) const { 419 unsigned int c; 420 if(!aBuffer.write_version(2,c)) return fal 421 if(!streamer_element::stream(aBuffer)) ret 422 if(!aBuffer.set_byte_count(c)) return fals 423 return true; 424 } 425 public: //streamer_element 426 virtual streamer_element* copy() const {retu 427 public: 428 streamer_string(const std::string& aName,con 429 :streamer_element(aName,aTitle,aOffset,strea 430 {} 431 streamer_string(int& aOffset,const std::stri 432 :streamer_element(aName,aTitle,aOffset,strea 433 { 434 aOffset += streamer__info::size_TString; 435 } 436 virtual ~streamer_string(){} 437 public: 438 streamer_string(const streamer_string& a_fro 439 streamer_string& operator=(const streamer_st 440 }; 441 442 443 class streamer_object : public streamer_elemen 444 public: //ibo 445 virtual const std::string& store_cls() const 446 static const std::string s_v("TStreamerObj 447 return s_v; 448 } 449 virtual bool stream(buffer& aBuffer) const { 450 unsigned int c; 451 if(!aBuffer.write_version(2,c)) return fal 452 if(!streamer_element::stream(aBuffer)) ret 453 if(!aBuffer.set_byte_count(c)) return fals 454 return true; 455 } 456 public: //streamer_element 457 virtual streamer_element* copy() const {retu 458 public: 459 streamer_object(const std::string& aName,con 460 :streamer_element(aName,aTitle,aOffset,0,aTy 461 fType = streamer__info::OBJECT; 462 if (aName=="TObject") fType = streamer__in 463 if (aName=="TNamed") fType = streamer__inf 464 } 465 virtual ~streamer_object(){} 466 public: 467 streamer_object(const streamer_object& a_fro 468 streamer_object& operator=(const streamer_ob 469 streamer_element::operator=(a_from); 470 return *this; 471 } 472 }; 473 474 class streamer_object_pointer : public streame 475 public: //ibo 476 virtual const std::string& store_cls() const 477 static const std::string s_v("TStreamerObj 478 return s_v; 479 } 480 virtual bool stream(buffer& aBuffer) const { 481 unsigned int c; 482 if(!aBuffer.write_version(2,c)) return fal 483 if(!streamer_element::stream(aBuffer)) ret 484 if(!aBuffer.set_byte_count(c)) return fals 485 return true; 486 } 487 public: //streamer_element 488 virtual streamer_element* copy() const {retu 489 public: 490 streamer_object_pointer(const std::string& a 491 int aOffset,const st 492 :streamer_element(aName,aTitle,aOffset,strea 493 if(aTitle.substr(0,2)=="->") fType = strea 494 } 495 virtual ~streamer_object_pointer(){} 496 public: 497 streamer_object_pointer(const streamer_objec 498 streamer_object_pointer& operator=(const str 499 streamer_element::operator=(a_from); 500 return *this; 501 } 502 }; 503 504 class streamer_object_any : public streamer_el 505 public: //ibo 506 virtual const std::string& store_cls() const 507 static const std::string s_v("TStreamerObj 508 return s_v; 509 } 510 virtual bool stream(buffer& aBuffer) const { 511 unsigned int c; 512 if(!aBuffer.write_version(2,c)) return fal 513 if(!streamer_element::stream(aBuffer)) ret 514 if(!aBuffer.set_byte_count(c)) return fals 515 return true; 516 } 517 public: //streamer_element 518 virtual streamer_element* copy() const {retu 519 public: 520 streamer_object_any(const std::string& aName 521 int aOffset,const std::s 522 :streamer_element(aName,aTitle,aOffset,strea 523 {} 524 virtual ~streamer_object_any(){} 525 public: 526 streamer_object_any(const streamer_object_an 527 streamer_object_any& operator=(const streame 528 streamer_element::operator=(a_from); 529 return *this; 530 } 531 }; 532 533 534 class streamer_STL : public streamer_element { 535 public: //ibo 536 virtual const std::string& store_cls() const 537 static const std::string s_v("TStreamerSTL 538 return s_v; 539 } 540 virtual bool stream(buffer& aBuffer) const { 541 unsigned int c; 542 if(!aBuffer.write_version(2,c)) return fal 543 if(!streamer_element::stream(aBuffer)) ret 544 if(!aBuffer.write(fSTLtype)) return false; 545 if(!aBuffer.write(fCtype)) return false; 546 if(!aBuffer.set_byte_count(c)) return fals 547 return true; 548 } 549 public: //streamer_element 550 virtual streamer_element* copy() const {retu 551 protected: 552 enum ESTLtype { kSTL = 300, kSTLstring 553 kSTLlist = 2, kSTLdeque 554 kSTLset = 5, kSTLmultim 555 556 // Instead of EDataType, we use the streamer 557 //enum EDataType { 558 // kChar_t = 1, kUChar_t = 11, kShort_t 559 // kInt_t = 3, kUInt_t = 13, kLong_t 560 // kFloat_t = 5, kDouble_t = 8, kchar = 561 //}; 562 public: 563 streamer_STL(const std::string& aName,const 564 int aOffset, 565 streamer__info::Type aType, //M 566 const std::string& aTypeName) 567 :streamer_element(aName,aTitle,aOffset,kSTL, 568 fSTLtype = kSTLvector; 569 fCtype = aType; 570 } 571 virtual ~streamer_STL(){} 572 public: 573 streamer_STL(const streamer_STL& a_from) 574 :ibo(a_from),streamer_element(a_from) 575 ,fSTLtype(a_from.fSTLtype) 576 ,fCtype(a_from.fCtype) 577 {} 578 streamer_STL& operator=(const streamer_STL& 579 streamer_element::operator=(a_from); 580 fSTLtype = a_from.fSTLtype; 581 fCtype = a_from.fCtype; 582 return *this; 583 } 584 protected: 585 int fSTLtype; //type of STL vector 586 int fCtype; //STL contained type 587 }; 588 589 }} 590 591 #endif