Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 2 // See the file tools.license for terms. 3 4 #ifndef tools_rroot_tree 5 #define tools_rroot_tree 6 7 #include "ifac" 8 #include "branch_element" 9 #include "../sout" 10 #include "iobject" 11 12 namespace tools { 13 namespace rroot { 14 15 inline const std::string& TTree_cls(){ 16 static const std::string s_v("TTree"); 17 return s_v; 18 } 19 20 class tree : public virtual iobject { 21 public: 22 static const std::string& s_class() { 23 static const std::string s_v("tools::rroot 24 return s_v; 25 } 26 virtual const std::string& s_cls() const {re 27 public: //iobject 28 virtual const std::string& name() const {ret 29 virtual const std::string& title() const {re 30 virtual const std::string& store_class_name( 31 static const std::string s_v("TTree"); 32 return s_v; 33 } 34 public: 35 tree(ifile& a_file,ifac& a_fac) 36 :m_file(a_file) 37 ,m_fac(a_fac) 38 ,m_out(a_file.out()) 39 ,m_name("") 40 ,m_title("") 41 ,m_branches(a_fac) 42 ,m_entries(0) 43 { 44 #ifdef TOOLS_MEM 45 mem::increment(s_class().c_str()); 46 #endif 47 } 48 virtual ~tree(){ 49 #ifdef TOOLS_MEM 50 mem::decrement(s_class().c_str()); 51 #endif 52 } 53 protected: 54 tree(const tree& a_from) 55 :iobject(a_from) 56 ,m_file(a_from.m_file) 57 ,m_fac(a_from.m_fac) 58 ,m_out(a_from.m_out) 59 ,m_branches(m_fac) 60 {} 61 tree& operator=(const tree&){return *this;} 62 public: 63 std::ostream& out() const {return m_out;} 64 65 ifile& file() {return m_file;} 66 ifac& fac() {return m_fac;} 67 68 const std::vector<branch*>& branches() const 69 70 bool find_entry(uint64 a_entry,uint32& a_nby 71 a_nbytes = 0; 72 if(a_entry>=m_entries) return false; 73 int nbytes = 0; 74 //fReadEntry = a_entry; 75 tools_vforit(branch*,m_branches,it) { 76 uint32 n; 77 if(!(*it)->find_entry(m_file,a_entry,n)) 78 nbytes += n; 79 } 80 a_nbytes = nbytes; 81 return true; 82 } 83 84 void dump(std::ostream& a_out,const std::str 85 a_out << a_spaces 86 << "tree :" 87 << " name=" << sout(m_name) 88 << " title=" << sout(m_title) 89 << " entries=" << m_entries 90 << std::endl; 91 _dump_branches(a_out,m_branches,a_spaces+a 92 } 93 94 branch* find_branch(const std::string& a_nam 95 return _find_branch(m_branches,a_name,a_re 96 } 97 98 branch_element* find_branch_element(const st 99 branch* b = _find_branch(m_branches,a_name 100 if(!b) return 0; 101 return id_cast<branch,branch_element>(*b); 102 } 103 104 base_leaf* find_leaf(const std::string& a_na 105 return _find_leaf(m_branches,a_name,a_recu 106 } 107 108 void find_leaves(std::vector<base_leaf*>& a_ 109 a_leaves.clear(); 110 _find_leaves(m_branches,a_leaves); 111 } 112 113 void find_branches(std::vector<branch*>& a_b 114 a_branches.clear(); 115 _find_branches(m_branches,a_branches); 116 } 117 118 branch* find_leaf_branch(const base_leaf& a_ 119 120 bool show(std::ostream& a_out,uint64 a_entry 121 a_out << "======> EVENT:" << a_entry << st 122 tools_vforit(branch*,m_branches,it) { 123 if(!(*it)->show(a_out,m_file,a_entry)) r 124 } 125 return true; 126 } 127 128 uint64 entries() const {return m_entries;} 129 130 virtual bool stream(buffer& a_buffer) { //vi 131 //uint64 m_tot_bytes; 132 //uint64 m_zip_bytes; 133 //uint64 m_saved_bytes; 134 135 short vers; 136 unsigned int _s,_c; 137 if(!a_buffer.read_version(vers,_s,_c)) ret 138 139 //::printf("debug : tree::stream : version 140 141 //if (vers > 4) { 142 //TTree::Class()->ReadBuffer(b, this, ve 143 //if (fEstimate <= 10000) fEstimate = 10 144 //m_saved_bytes = m_tot_bytes; 145 //fDirectory = gDirectory; 146 //gDirectory->Append(this); 147 //return; 148 //} 149 150 if(!Named_stream(a_buffer,m_name,m_title)) 151 152 {short color,style,width; 153 if(!AttLine_stream(a_buffer,color,style,wi 154 {short color,style; 155 if(!AttFill_stream(a_buffer,color,style)) 156 if(!AttMarker_stream(a_buffer)) return fal 157 158 if(vers<=4) { 159 int dummy_int; 160 161 if(!a_buffer.read(dummy_int)) return fal 162 if(!a_buffer.read(dummy_int)) return fal 163 {int fMaxVirtualSize; 164 if(!a_buffer.read(fMaxVirtualSize)) retu 165 {double v; 166 if(!a_buffer.read(v)) return false; 167 m_entries = uint64(v);} 168 {double v; 169 if(!a_buffer.read(v)) return false; 170 //m_tot_bytes = uint64(v); 171 } 172 {double v; 173 if(!a_buffer.read(v)) return false; 174 //m_zip_bytes = uint64(v); 175 } 176 {int fAutoSave; 177 if(!a_buffer.read(fAutoSave)) return fal 178 if(!a_buffer.read(dummy_int)) return fal 179 180 } else if(vers<=9) { 181 {double v; 182 if(!a_buffer.read(v)) return false; 183 m_entries = uint64(v);} 184 {double v; 185 if(!a_buffer.read(v)) return false; 186 //m_tot_bytes = uint64(v); 187 } 188 {double v; 189 if(!a_buffer.read(v)) return false; 190 //m_zip_bytes = uint64(v); 191 } 192 {double v; 193 if(!a_buffer.read(v)) return false; 194 //m_saved_bytes = uint64(v); 195 } 196 197 int dummy_int; 198 if(!a_buffer.read(dummy_int)) return fal 199 if(!a_buffer.read(dummy_int)) return fal 200 if(!a_buffer.read(dummy_int)) return fal 201 if(!a_buffer.read(dummy_int)) return fal 202 203 {int fMaxVirtualSize; 204 if(!a_buffer.read(fMaxVirtualSize)) retu 205 {int fAutoSave; 206 if(!a_buffer.read(fAutoSave)) return fal 207 if(!a_buffer.read(dummy_int)) return fal 208 209 } else if(vers<16) { //FIXME : what is the 210 double dummy_double; 211 int dummy_int; 212 213 {double v; 214 if(!a_buffer.read(v)) return false; 215 m_entries = uint64(v);} 216 {double v; 217 if(!a_buffer.read(v)) return false; 218 //m_tot_bytes = uint64(v); 219 } 220 {double v; 221 if(!a_buffer.read(v)) return false; 222 //m_zip_bytes = uint64(v); 223 } 224 {double v; 225 if(!a_buffer.read(v)) return false; 226 //m_saved_bytes = uint64(v); 227 } 228 if(!a_buffer.read(dummy_double)) return 229 if(!a_buffer.read(dummy_int)) return fal 230 if(!a_buffer.read(dummy_int)) return fal 231 if(!a_buffer.read(dummy_int)) return fal 232 if(!a_buffer.read(dummy_int)) return fal 233 234 {int fMaxVirtualSize; 235 if(!a_buffer.read(fMaxVirtualSize)) retu 236 {int fAutoSave; 237 if(!a_buffer.read(fAutoSave)) return fal 238 if(!a_buffer.read(dummy_int)) return fal 239 240 } else { //vers>=16 241 double dummy_double; 242 int dummy_int; 243 int64 dummy_int64; 244 245 {uint64 v; 246 if(!a_buffer.read(v)) return false; 247 m_entries = v;} 248 {uint64 v; 249 if(!a_buffer.read(v)) return false; 250 //m_tot_bytes = v; 251 } 252 {uint64 v; 253 if(!a_buffer.read(v)) return false; 254 //m_zip_bytes = v; 255 } 256 {uint64 v; 257 if(!a_buffer.read(v)) return false; 258 //m_saved_bytes = v; 259 } 260 if(vers>=18) { 261 if(!a_buffer.read(dummy_int64)) return 262 } 263 264 if(!a_buffer.read(dummy_double)) return 265 266 if(!a_buffer.read(dummy_int)) return fal 267 if(!a_buffer.read(dummy_int)) return fal 268 if(!a_buffer.read(dummy_int)) return fal 269 270 if(vers>=18) { 271 if(!a_buffer.read(dummy_int)) return f 272 } 273 int fNClusterRange; 274 if(vers>=20) { 275 if(!a_buffer.read(fNClusterRange)) ret 276 } 277 278 if(!a_buffer.read(dummy_int64)) return f 279 if(!a_buffer.read(dummy_int64)) return f 280 {uint64 fMaxVirtualSize; 281 if(!a_buffer.read(fMaxVirtualSize)) retu 282 {uint64 fAutoSave; 283 if(!a_buffer.read(fAutoSave)) return fal 284 if(vers>=18) { 285 if(!a_buffer.read(dummy_int64)) return 286 } 287 if(!a_buffer.read(dummy_int64)) return f 288 if(vers>=20) { 289 int64* fClusterRangeEnd = 0; /// 290 if(!fixed_array_stream<int64>(a_buffer 291 delete [] fClusterRangeEnd; 292 int64* fClusterSize = 0; /// 293 if(!fixed_array_stream<int64>(a_buffer 294 delete [] fClusterSize; 295 dummy _dummy; 296 if(!_dummy.stream(a_buffer)) { //TIOFe 297 m_out << "tools::rroot::tree::stream 298 return false; 299 } 300 } 301 } 302 303 //FIXME if (fEstimate <= 10000) fEstimate 304 305 //TObjArray 306 //The below m_branches.read will create le 307 //::printf("debug : tree : read branches : 308 {ifac::args args; 309 if(!m_branches.stream(a_buffer,args)) { 310 m_out << "tools::rroot::tree::stream : " 311 << "can't read branches." 312 << std::endl; 313 return false; 314 }} 315 //::printf("debug : tree : read branches : 316 317 //TObjArray 318 // We read leaves in order to keep streami 319 // In fact m_leaves are references to exis 320 // the branches in the upper line of code. 321 //::printf("debug : tree : read leaves : b 322 {obj_array<base_leaf> m_leaves(m_fac); 323 //branch b(m_out,m_fac); 324 ifac::args args; 325 //args[ifac::arg_branch()] = &b; 326 if(!m_leaves.stream(a_buffer,args)) { 327 m_out << "tools::rroot::tree::stream : " 328 << "can't read leaves." 329 << std::endl; 330 return false; 331 }} 332 //::printf("debug : tree : read leaves : e 333 334 if(vers>=10) { 335 //TList* fAliases 336 if(!dummy_TXxx_pointer_stream(a_buffer,m 337 m_out << "tools::rroot::tree::stream : 338 << "can't read fAliases." 339 << std::endl; 340 return false; 341 } 342 } 343 344 //m_saved_bytes = m_tot_bytes; 345 {std::vector<double> v; 346 if(!Array_stream<double>(a_buffer,v)) retu 347 348 {std::vector<int> v; 349 if(!Array_stream<int>(a_buffer,v)) return 350 351 if(vers>=16) { 352 //TVirtualIndex* fTreeIndex //FIXME ??? 353 if(!dummy_TXxx_pointer_stream(a_buffer,m 354 m_out << "tools::rroot::tree::stream : 355 << "can't read fTreeIndex." 356 << std::endl; 357 return false; 358 } 359 } 360 361 if(vers>=6) { 362 //TList* fFriends 363 if(!dummy_TXxx_pointer_stream(a_buffer,m 364 m_out << "tools::rroot::tree::stream : 365 << "can't read fFriends." 366 << std::endl; 367 return false; 368 } 369 } 370 371 if(vers>=16) { 372 //TList* fUserInfo 373 if(!dummy_TXxx_pointer_stream(a_buffer,m 374 m_out << "tools::rroot::tree::stream : 375 << "can't read fUserInfo." 376 << std::endl; 377 return false; 378 } 379 //TBranchRef* fBranchRef 380 if(!dummy_TXxx_pointer_stream(a_buffer,m 381 m_out << "tools::rroot::tree::stream : 382 << "can't read fBranchRef." 383 << std::endl; 384 return false; 385 } 386 } 387 388 if(!a_buffer.check_byte_count(_s,_c,TTree_ 389 390 return true; 391 } 392 protected: 393 void _dump_branches(std::ostream& a_out, 394 const std::vector 395 const std::string 396 const std::string 397 tools_vforcit(branch*,a_bs,it) { 398 if(branch_element* be = safe_cast<branch 399 a_out << a_spaces 400 << "branch_element :" 401 << " name=" << sout((*it)->name( 402 << " title=" << sout((*it)->titl 403 << " entry_number=" << be->entry 404 << " ref_cls=" << sout(be->class 405 << " (type=" << be->type() 406 << ",id=" << be->id() 407 << ",stype=" << be->streamer_typ 408 << ")." 409 << std::endl; 410 } else { 411 a_out << a_spaces 412 << "branch :" 413 << " name=" << sout((*it)->name( 414 << " title=" << sout((*it)->titl 415 << " entry_number=" << (*it)->en 416 << std::endl; 417 } 418 419 420 {const std::vector<base_leaf*>& lvs = (*i 421 tools_vforcit(base_leaf*,lvs,itl) { 422 a_out << a_spaces << a_indent 423 << "leave :" 424 << " name=" << sout((*itl)->name 425 << " title=" << sout((*itl)->tit 426 << " cls=" << sout((*itl)->s_cls 427 << std::endl; 428 }} 429 430 _dump_branches(a_out,(*it)->branches(),a 431 } 432 } 433 434 static branch* _find_branch(const std::vecto 435 tools_vforcit(branch*,a_bs,it) { 436 if(rcmp((*it)->name(),a_name)) return *i 437 if(a_recursive) { 438 branch* br = _find_branch((*it)->branc 439 if(br) return br; 440 } 441 } 442 return 0; 443 } 444 445 static base_leaf* _find_leaf(const std::vect 446 tools_vforcit(branch*,a_bs,it) { 447 tools_vforcit(base_leaf*,(*it)->leaves() 448 if(rcmp((*itl)->name(),a_name)) return 449 } 450 if(a_recursive) { 451 base_leaf* lf = _find_leaf((*it)->bran 452 if(lf) return lf; 453 } 454 } 455 return 0; 456 } 457 458 static void _find_leaves(const std::vector<b 459 tools_vforcit(branch*,a_bs,it) { 460 tools_vforcit(base_leaf*,(*it)->leaves() 461 _find_leaves((*it)->branches(),a_leaves) 462 } 463 } 464 465 static void _find_branches(const std::vector 466 tools_vforcit(branch*,a_bs,it) { 467 a_branches.push_back(*it); 468 _find_branches((*it)->branches(),a_branc 469 } 470 } 471 472 static branch* _find_leaf_branch(const std:: 473 tools_vforcit(branch*,a_bs,itb) { 474 tools_vforcit(base_leaf*,(*itb)->leaves( 475 {branch* br = _find_leaf_branch((*itb)->b 476 if(br) return br;} 477 } 478 return 0; 479 } 480 protected: 481 ifile& m_file; 482 ifac& m_fac; 483 std::ostream& m_out; 484 //Named 485 std::string m_name; 486 std::string m_title; 487 488 obj_array<branch> m_branches; 489 uint64 m_entries; // Number of entries 490 }; 491 492 }} 493 494 #endif