Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/externals/g4tools/include/tools/rroot/branch_element

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.
  3 
  4 #ifndef tools_rroot_branch_element
  5 #define tools_rroot_branch_element
  6 
  7 #include "branch"
  8 #include "stl_vector"
  9 
 10 #include "info"
 11 #include "obj_list"
 12 
 13 //#define TOOLS_RROOT_BRANCH_ELEMENT_DUMP
 14 
 15 namespace tools {
 16 namespace rroot {
 17 
 18 class branch_element : public branch {
 19   typedef branch parent;
 20 public:
 21   static const std::string& s_class() {
 22     static const std::string s_v("tools::rroot::branch_element");
 23     return s_v;
 24   }
 25 public: //iro
 26   virtual void* cast(const std::string& a_class) const {
 27     if(void* p = cmp_cast<branch_element>(this,a_class)) return p;
 28     return parent::cast(a_class);
 29   }
 30   virtual const std::string& s_cls() const {return s_class();}
 31 public:
 32   static cid id_class() {return branch_element_cid();}
 33   virtual void* cast(cid a_class) const {
 34     if(void* p = cmp_cast<branch_element>(this,a_class)) {return p;}
 35     return parent::cast(a_class);
 36   }
 37 public:
 38   virtual bool stream(buffer& a_buffer) {
 39     _clear();
 40 
 41     short v;
 42     unsigned int _s,_c;
 43     if(!a_buffer.read_version(v,_s,_c)) return false;
 44 
 45     //::printf("debug : tools::branch_element::stream : version %d, count %d\n",v,c);
 46 
 47     if(!parent::stream(a_buffer)) {
 48       m_out << "tools::rroot::branch_element::stream : parent::stream() failed." << std::endl;
 49       return false;
 50     }
 51 
 52     if(v<=7) {
 53       if(!a_buffer.read(fClassName)) return false;
 54       if(!a_buffer.read(fClassVersion)) return false;
 55       if(!a_buffer.read(fID)) return false;
 56       if(!a_buffer.read(fType)) return false;
 57       if(!a_buffer.read(fStreamerType)) return false;
 58     } else { //v>=8
 59       if(!a_buffer.read(fClassName)) return false;
 60       //::printf("debug : tools::branch_element::stream : fClassName \"%s\"\n",fClassName.c_str());
 61       std::string fParentName;
 62       if(!a_buffer.read(fParentName)) return false;
 63       //::printf("debug : tools::branch_element::stream : fParentName \"%s\"\n",fParentName.c_str());
 64       std::string fCloneName;
 65       if(!a_buffer.read(fCloneName)) return false;
 66       //::printf("debug : tools::branch_element::stream : fCloneName \"%s\"\n",fCloneName.c_str());
 67       int dummy_int;
 68       if(!a_buffer.read(dummy_int)) return false; //fCheckSum
 69       //::printf("debug : tools::branch_element::stream : fCheckSum %d\n",dummy_int);
 70 
 71       if(v>=10) {
 72         short dummy_short;
 73         if(!a_buffer.read(dummy_short)) return false; //fClassVersion
 74         //::printf("debug : tools::branch_element::stream : fClassVersion %d\n",dummy_short);
 75       } else {
 76         if(!a_buffer.read(dummy_int)) return false; //fClassVersion
 77       }
 78 
 79       if(!a_buffer.read(fID)) return false;
 80       //::printf("debug : tools::branch_element::stream : fID %d\n",fID);
 81       if(!a_buffer.read(fType)) return false;
 82       //::printf("debug : tools::branch_element::stream : fType %d\n",fType);
 83       if(!a_buffer.read(fStreamerType)) return false;
 84       //::printf("debug : tools::branch_element::stream : fStreamerType %d\n",fStreamerType);
 85 
 86       if(!a_buffer.read(dummy_int)) return false; //fMaximum
 87       //::printf("debug : tools::branch_element::stream : fMaximum %d\n",dummy_int);
 88 
 89       //TBranchElement* fBranchCount;
 90       ifac::args args;
 91       if(!pointer_stream(a_buffer,m_fac,args,fBranchCount,fBranchCount_created)) {
 92         m_out << "tools::rroot::branch_element::stream : "
 93               << "can't read fBranchCount."
 94               << std::endl;
 95         return false;
 96       }
 97 
 98       //TBranchElement* fBranchCount2;
 99       if(!pointer_stream(a_buffer,m_fac,args,fBranchCount2,fBranchCount2_created)) {
100         m_out << "tools::rroot::branch_element::stream : "
101               << "can't read fBranchCount2."
102               << std::endl;
103         _clear();
104         return false;
105       }
106 
107     }
108 
109     if(!a_buffer.check_byte_count(_s,_c,"TBranchElement")) {_clear();return false;}
110     return true;
111   }
112 public: //branch
113 
114   virtual bool read_leaves(ifile& a_file,buffer& a_buffer){
115 
116     // For k<type> value, see the below commented enum EReadWrite from ROOT-6.12.06 code.
117     static int kInt      = 3;
118     static int kDouble   = 8;
119     static int kDouble32 = 9;
120     static int kUInt     = 13;
121     static int kBits     = 15;  // In v4-00-01 version 8, it is Long64_t.
122     static int kObject   = 61;
123     static int kObjectP  = 64;
124 
125     if(fType==3) { // TClonesArray master branch (has only the number of elements).
126       //from v4-00-01
127       int n;
128       if(!a_buffer.read(n)) return false;
129       /* ROOT-6.12.06 code :
130       if ((n < 0) || (n > fMaximum)) {
131          if (IsMissingCollection()) {
132             n = 0;
133             b.SetBufferOffset(b.Length() - sizeof(n));
134          } else {
135             Error("ReadLeaves", "Incorrect size read for the container in %s\nThe size read is %d when the maximum is %d\nThe size is reset to 0 for this entry (%lld)", GetName(), n, fMaximum, GetReadEntry());
136             n = 0;
137          }
138       }*/
139       //::printf("debug : uuuu : ndata %d\n",n);
140       fNdata = n;
141 
142       //TClonesArray *clones = (TClonesArray*)fObject;
143       //if (!clones) return;
144       //if (clones->IsZombie()) return;
145       //clones->Clear();
146       //clones->ExpandCreateFast(fNdata);
147 
148       //m_out << "debug : tools::rroot::branch_element::read_leaves :"
149       //      << " name " << m_name << " ref_cls " << fClassName
150       //      << " : type " << fType << ", fNdata " << n
151       //      << std::endl;
152       return true;
153 
154     } else if(fType==31) { // TClonesArray sub-branch (contains the elements).
155       if(fStreamerType==kObject) { //to read EsbRoot fgd_dig.root.
156         int ndata = fBranchCount->get_ndata();
157 #ifdef TOOLS_RROOT_BRANCH_ELEMENT_DUMP
158         ::printf("debug : %s : fClassName %s : fID %d : kObject : ndata %d\n",m_name.c_str(),fClassName.c_str(),fID,ndata);
159 #endif
160         streamer_info* _info = a_file.find_streamer_info(fClassName);
161         if(!_info) {
162           m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
163                 << " read(kObject) : streamer_infos for ref_cls " << fClassName << " not found."
164                 << std::endl;
165           return false;
166         }
167         streamer_element* _element = _info->find_streamer_element(fID);
168         if(!_element) {
169           m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
170                 << " read(kObject) : for ref_cls " << fClassName << ", fID " << fID << " streamer element not found."
171                 << std::endl;
172           return false;
173         }
174         //::printf("debug : element type name %s\n",_element->type_name().c_str());
175 
176         obj_list* _list = 0;
177         if(!m_obj) {
178           _list = new obj_list(m_fac);
179           m_obj = _list;
180         } else {
181           _list = id_cast<iro,obj_list>(*m_obj);
182           if(!_list) {
183             m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
184                   << " read(kObject) : m_obj is not an obj_list."
185                   << std::endl;
186             return false;
187           }
188         }
189 
190         _list->safe_clear();
191 
192         for(int index=0;index<ndata;index++) {
193           ifac::args args;
194           iro* _obj = m_fac.create(_element->type_name(),args);
195           if(!_obj) {_list->safe_clear();return false;}
196           if(!_obj->stream(a_buffer)){
197             m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
198                   << " kObject : obj stream of class " << sout(_element->type_name())
199                   << " failed at index " << index << " (" << ndata << ")." << std::endl;
200             _list->safe_clear();
201             return false;
202           }
203           _list->add_object(_obj); //give ownership.
204         }
205 
206         return true;
207       }
208       if(fStreamerType==kObjectP) return true;
209       //from v4-00-01
210       if(fStreamerType==kDouble32) {
211         int ndata = fBranchCount->get_ndata();
212 #ifdef TOOLS_RROOT_BRANCH_ELEMENT_DUMP
213         ::printf("debug : %s : fID %d : double32 : ndata %d\n",m_name.c_str(),fID,ndata);
214 #endif
215         stl_vector<double>* vec = 0;
216         if(!m_obj) {
217           vec = new stl_vector<double>;
218           m_obj = vec;
219         } else {
220           vec = id_cast<iro, stl_vector<double> >(*m_obj);
221           if(!vec) {
222             m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
223                   << " read(kDouble32) : m_obj is not a stl_vector<double>."
224                   << std::endl;
225             return false;
226           }
227         }
228 
229         vec->resize(ndata);
230         float afloat;
231         for(int ii=0;ii<ndata;ii++) {
232           if(!a_buffer.read(afloat)) {
233             m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
234                   << " read(float) failed."
235                   << std::endl;
236             vec->clear();
237             return false;
238           }
239           //::printf("debug : zzzz %g\n",afloat);
240           (*vec)[ii] = afloat;
241         }
242 
243         return true;
244 
245       } else if(fStreamerType==kDouble) {
246         int ndata = fBranchCount->get_ndata();
247 #ifdef TOOLS_RROOT_BRANCH_ELEMENT_DUMP
248         ::printf("debug : %s : fID %d : double : ndata %d\n",m_name.c_str(),fID,ndata);
249 #endif
250         stl_vector<double>* vec = 0;
251         if(!m_obj) {
252           vec = new stl_vector<double>;
253           m_obj = vec;
254         } else {
255           vec = id_cast<iro, stl_vector<double> >(*m_obj);
256           if(!vec) {
257             m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
258                   << " read(kDouble) : m_obj is not a stl_vector<double>."
259                   << std::endl;
260             return false;
261           }
262         }
263 
264         vec->resize(ndata);
265         double* _value = vec_data(*vec);
266         if(!a_buffer.read_fast_array(_value,ndata)) {
267           m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
268                 << " read_fast_array(double) failed."
269                 << std::endl;
270           vec->clear();
271           return false;
272         }
273 
274         return true;
275 
276       } else if(fStreamerType==kInt) {
277         int ndata = fBranchCount->get_ndata();
278 #ifdef TOOLS_RROOT_BRANCH_ELEMENT_DUMP
279         ::printf("debug : %s : fID %d : int : ndata %d\n",m_name.c_str(),fID,ndata);
280 #endif
281         stl_vector<int>* vec = 0;
282         if(!m_obj) {
283           vec = new stl_vector<int>;
284     m_obj = vec;
285         } else {
286           vec = id_cast<iro, stl_vector<int> >(*m_obj);
287           if(!vec) {
288             m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
289                   << " read(kInt) : m_obj is not a stl_vector<int>."
290                   << std::endl;
291             return false;
292           }
293         }
294 
295         vec->resize(ndata);
296         int* _value = vec_data(*vec);
297         if(!a_buffer.read_fast_array(_value,ndata)) {
298           m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
299                 << " read_fast_array(int) failed."
300                 << std::endl;
301           vec->clear();
302           return false;
303         }
304 
305         return true;
306 
307       } else if((fStreamerType==kUInt)||(fStreamerType==kBits)) {
308         int ndata = fBranchCount->get_ndata();
309 #ifdef TOOLS_RROOT_BRANCH_ELEMENT_DUMP
310         if(fStreamerType==kUInt) ::printf("debug : %s : fID %d : uint : ndata %d\n",m_name.c_str(),fID,ndata);
311         else                     ::printf("debug : %s : fID %d : bits : ndata %d\n",m_name.c_str(),fID,ndata);
312 #endif
313         stl_vector<uint32>* vec = 0;
314         if(!m_obj) {
315           vec = new stl_vector<uint32>;
316     m_obj = vec;
317         } else {
318           vec = id_cast<iro, stl_vector<uint32> >(*m_obj);
319           if(!vec) {
320             m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
321                   << " read(kUInt) : m_obj is not a stl_vector<uint32>."
322                   << std::endl;
323             return false;
324           }
325         }
326 
327         vec->resize(ndata);
328         uint32* _value = vec_data(*vec);
329         if(!a_buffer.read_fast_array(_value,ndata)) {
330           m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
331                 << " read_fast_array(uint) failed."
332                 << std::endl;
333           vec->clear();
334           return false;
335         }
336 
337         return true;
338 
339       } else {
340         m_out << "tools::rroot::branch_element::read_leaves :"
341               << " name " << m_name << " ref_cls " << fClassName
342               << " : for type " << fType << ", stream_type " << fStreamerType << " not treated."
343               << std::endl;
344         return false;
345       }
346   /*
347         //m_obj = clones_array<float>(m_fac,true,false);  //true = owner of objects.
348         uint32 ndata = 1;
349         float* _value = new float[ndata];
350         if(!a_buffer.read_fast_array(_value,ndata)) {
351           m_out << "tools::rroot::branch_element::read_leaves : \"" << name() << "\" :"
352                 << " read_fast_array failed."
353                 << std::endl;
354           return false;
355         }
356   */
357   //} else if(fType<=2) { //in v5-18-00d
358     } else if(fType==0) { // to read wroot.root of examples/cpp/wroot.cpp.
359 //     if(fID>=0) {
360 //       // branch in split mode
361 //       m_out << "tools::rroot::branch_element::read_leaves :"
362 //             << " name " << m_name << " ref_cls " << fClassName << " :"
363 //             << " type 0 with ID " << fID << "."
364 //             << std::endl;
365 //       return true;
366 //
367 
368        if((fID==-1)||
369           (fID==1)     // for pmx to read LHCb files :
370          ){
371          //from v4-00-01
372          //if (fBranchCount) fNdata = (Int_t)fBranchCount->GetValue(0,0);
373          //else fNdata = 1;
374    if(fBranchCount) {
375            fNdata = fBranchCount->get_ndata();
376            //::printf("debug : branch_element::read_leaves : (fType==0,fID==-1) : fNdata %d\n",fNdata);
377    } else {
378      fNdata = 1;
379    }
380 
381          // read object :
382    bool created = false;
383          if(!m_obj) {
384            ifac::args args;
385            m_obj = m_fac.create(fClassName,args);
386            if(!m_obj) return false;
387      created = true;
388          }
389 
390          if(!m_obj->stream(a_buffer)){
391            m_out << "tools::rroot::branch_element::read_leaves :"
392                  << " name " << sout(m_name) << ", ref_cls " << sout(fClassName) << " :"
393                  << " obj stream failed."
394                  << std::endl;
395      if(created) {delete m_obj;m_obj = 0;}
396            return false;
397          }
398 
399          return true;
400 
401        } else {
402          m_out << "tools::rroot::branch_element::read_leaves :"
403                << " name " << m_name << " ref_cls " << fClassName << " :"
404                << " type 0 with ID " << fID << " not treated."
405                << std::endl;
406          return false;
407        }
408 
409     }
410 
411     m_out << "tools::rroot::branch_element::read_leaves :"
412           << " name " << m_name << " ref_cls " << fClassName
413           << " : type " << fType << " not treated, stream_type is " << fStreamerType << "."
414           << std::endl;
415     return false;
416 
417 /*
418     ///////////////////////////////////////////////////////
419     /// STL container /////////////////////////////////////
420     ///////////////////////////////////////////////////////
421     if(fType==4) {
422       // STL container master branch (has only the number of elements).
423       //from v4-00-01
424       int n;
425       if(!a_buffer.read(n)) return false;
426       //fNdata = n;
427 
428       m_out << "tools::rroot::branch_element::read_leaves :"
429             << " name " << m_name << " ref_cls " << fClassName
430             << " : type " << fType << " not treated."
431             << std::endl;
432       return false;
433 
434     } else if(fType==41) {
435       // STL container sub-branch (contains the elements).
436       m_out << "tools::rroot::branch_element::read_leaves :"
437             << " name " << m_name << " ref_cls " << fClassName
438             << " : type " << fType << " not treated."
439             << std::endl;
440       return false;
441 
442     ///////////////////////////////////////////////////////
443     /// TClonesArray container ////////////////////////////
444     ///////////////////////////////////////////////////////
445     } else if(fType==3) {
446       // TClonesArray master branch (has only the number of elements).
447       //from v4-00-01
448       int n;
449       if(!a_buffer.read(n)) return false;
450 
451       //fNdata = n;
452       //TClonesArray *clones = (TClonesArray*)fObject;
453       //if (!clones) return;
454       //if (clones->IsZombie()) return;
455       //clones->Clear();
456       //clones->ExpandCreateFast(fNdata);
457 
458       m_out << "tools::rroot::branch_element::read_leaves :"
459             << " name " << m_name << " ref_cls " << fClassName
460             << " : type " << fType << " not treated."
461             << std::endl;
462       return false;
463 
464     } else if(fType==31) {
465       // TClonesArray sub-branch (contains the elements).
466       m_out << "tools::rroot::branch_element::read_leaves :"
467             << " name " << m_name << " ref_cls " << fClassName
468             << " : type " << fType << " not treated."
469             << std::endl;
470       return false;
471 
472     ///////////////////////////////////////////////////////
473     ///////////////////////////////////////////////////////
474     ///////////////////////////////////////////////////////
475     } else if(fType<=2) {
476       // branch in split mode
477 
478       //from v4-00-01
479       //if (fBranchCount) fNdata = (Int_t)fBranchCount->GetValue(0,0);
480       //else fNdata = 1;
481       //if (!fInfo) return;
482       //fInfo->ReadBuffer(b,fObject,fID);
483       //if (fStreamerType == 6) fNdata = (Int_t)GetValue(0,0);
484 
485       //from 3.0.06
486       //if (fID >= 0) {
487       //  fInfo->ReadBuffer(b,fAddress,fID);
488       //} else if (fID == -1) {   // top level branch in non split mode
489       //  char **ppointer = (char**)fAddress;
490       //  fInfo->ReadBuffer(b,*ppointer,fID);
491       //}
492 
493       //m_out << "tools::rroot::branch_element::read_leaves :"
494       //      << " name " << m_name << " ref_cls " << fClassName << " :"
495       //      << " type " << fType << " with ID " << fID << "."
496       //      << " and then ?"
497       //      << std::endl;
498 
499       // read object ?
500       bool created = false;
501       if(!m_obj) {
502         ifac::args args;
503         m_obj = m_fac.create(fClassName,args);
504         if(!m_obj) return false;
505         created = true;
506       }
507 
508       if(!m_obj->stream(a_buffer)){
509         m_out << "tools::rroot::branch_element::read_leaves :"
510               << " name " << m_name << " ref_cls " << fClassName << " :"
511               << " obj stream failed."
512               << std::endl;
513         if(created) {delete m_obj;m_obj = 0;}
514         return false;
515       }
516 
517       //m_out << "tools::rroot::branch_element::read_leaves :"
518       //      << " name " << m_name << " ref_cls " << fClassName << " :"
519       //      << " obj streamed."
520       //      << std::endl;
521 
522       return true;
523 
524 //  } else if(fType==0) {
525 //     if(fID>=0) {
526 //       // branch in split mode
527 //       m_out << "tools::rroot::branch_element::read_leaves :"
528 //             << " name " << m_name << " ref_cls " << fClassName << " :"
529 //             << " type 0 with ID " << fID << "."
530 //             << std::endl;
531 //       return true;
532 //
533 //     } else if(fID==-1) {
534 //       // top level branch in non split mode
535 //       m_out << "tools::rroot::branch_element::read_leaves :"
536 //             << " name " << m_name << " ref_cls " << fClassName << " :"
537 //             << " type 0 with ID " << fID
538 //             << " : fill object."
539 //             << std::endl;
540 
541 //       if(!m_obj) {
542 //         m_out << "tools::rroot::branch_element::read_leaves :"
543 //               << " name " << m_name << " ref_cls " << fClassName << " :"
544 //               << " m_obj is null."
545 //               << std::endl;
546 //         return false;
547 //       }
548 //       if(!m_obj->stream(a_buffer)){
549 //         m_out << "tools::rroot::branch_element::read_leaves :"
550 //               << " name " << m_name << " ref_cls " << fClassName << " :"
551 //               << " obj stream failed."
552 //               << std::endl;
553 //         return false;
554 //       }
555 //       return true;
556 
557 //     } else {
558 //       m_out << "tools::rroot::branch_element::read_leaves :"
559 //             << " name " << m_name << " ref_cls " << fClassName << " :"
560 //             << " type 0 with ID " << fID << " not treated."
561 //             << std::endl;
562 //       return false;
563 //     }
564 
565 //  //LHCb files :
566 //  } else if(fType==1) {
567 //    // parent branch is a base class branch.
568 //    // Ok, and then ?
569 //    m_out << "tools::rroot::branch_element::read_leaves :"
570 //          << " name " << m_name << " ref_cls " << fClassName << " :"
571 //          << " type " << fType << " with ID " << fID << "."
572 //          << std::endl;
573 //    return true;
574 
575     } else {
576       m_out << "tools::rroot::branch_element::read_leaves :"
577             << " name " << m_name << " ref_cls " << fClassName << " :"
578             << " type " << fType << " with ID " << fID << "."
579             << " unknown case."
580             << std::endl;
581       return false;
582     }
583 */
584   }
585 
586   virtual bool find_entry(ifile& a_file,uint64 a_entry,uint32& a_nbytes){
587     //The below line will call the upper read_leaves.
588     if(!parent::find_entry(a_file,a_entry,a_nbytes)) return false;
589 
590     if(m_branches.size()) {
591       //if(!m_obj) {
592       //  m_obj = m_fac.create(fClassName);
593       //  if(!m_obj) return false;
594       //}
595 
596       tools_vforcit(branch*,m_branches,it) {
597         uint32 n;
598         if(!(*it)->find_entry(a_file,a_entry,n)) return false;
599         a_nbytes += n;
600       }
601     }
602 
603     return true;
604   }
605 
606   virtual bool show(std::ostream& a_out,ifile& a_file,uint64 a_entry){
607     uint32 n;
608     if(!find_entry(a_file,a_entry,n)) return false;
609 
610    {std::string _s;
611     uint32 len = uint32(name().size())+128;
612     sprintf(_s,len," %-15s = ",name().c_str());
613     a_out << _s;}
614 
615     a_out << m_obj << std::endl;
616 
617     return true;
618     //return parent::show(a_out,a_file,a_entry);
619   }
620 public:
621   branch_element(std::ostream& a_out,ifac& a_fac)
622   :parent(a_out,a_fac)
623   ,m_obj(0)
624   ,fClassVersion(0)
625   ,fID(0)
626   ,fType(0)
627   ,fStreamerType(-1)
628   ,fBranchCount(0)   //not owner
629   ,fBranchCount_created(false)
630   ,fBranchCount2(0)  //not owner
631   ,fBranchCount2_created(false)
632   ,fNdata(1)
633   {}
634 
635   virtual ~branch_element() {
636     _clear();
637     if(m_obj) delete m_obj;
638   }
639 protected:
640   branch_element(const branch_element& a_from):iro(a_from),parent(a_from){}
641   branch_element& operator=(const branch_element&){return *this;}
642 public:
643   const std::string& class_name() const {return fClassName;}
644   int type() const {return fType;}
645   int streamer_type() const {return fStreamerType;}
646   int id() const {return fID;}
647   iro* object() {return m_obj;}
648   int get_ndata() const {return fNdata;}
649 
650   template <class T>
651   stl_vector<T>* object_to_stl_vector() const {
652     if(!m_obj) {
653       m_out << "tools::rroot::branch_element::object_to_stl_vector : there is no object." << std::endl;
654       return 0;
655     }
656     stl_vector<T>* od = id_cast<iro, stl_vector<T> >(*m_obj);
657     if(!od) {
658       m_out << "tools::rroot::branch_element::object_to_stl_vector :"
659             << " object of class " << sout(m_obj->s_cls()) << " not a tools::rroot::stl_vector<T>."
660       << std::endl;
661       return 0;
662     }
663     return od; //WARNING : we are not owner.
664   }
665 
666   obj_list* object_to_obj_list() const {
667     if(!m_obj) {
668       m_out << "tools::rroot::branch_element::object_to_obj_list : there is no object." << std::endl;
669       return 0;
670     }
671     obj_list* od = id_cast<iro,obj_list>(*m_obj);
672     if(!od) {
673       m_out << "tools::rroot::branch_element::object_to_obj_list :"
674             << " object of class " << sout(m_obj->s_cls()) << " not a tools::rroot::obj_list."
675       << std::endl;
676       return 0;
677     }
678     return od; //WARNING : we are not owner.
679   }
680 
681   template <class T>
682   stl_vector<T>* find_entry_vec(ifile& a_file,uint64 a_event) {
683     unsigned int n;
684     if(!find_entry(a_file,a_event,n)) {
685       m_out << "tools::rroot::branch_element::find_entry_vec : find_entry() failed." << std::endl;
686       return 0;
687     }
688     if(!m_obj) {
689       m_out << "tools::rroot::branch_element::find_entry_vec : no object found." << std::endl;
690       return 0;
691     }
692     stl_vector<T>* od = id_cast<iro, stl_vector<T> >(*m_obj);
693     if(!od) {
694       m_out << "tools::rroot::branch_element::find_entry_vec :"
695             << " object not a tools::rroot::stl_vector<T>."
696       << std::endl;
697       return 0;
698     }
699     return od; //WARNING : we are not owner.
700   }
701 
702 protected:
703   void _clear() {
704     if(fBranchCount_created) {delete fBranchCount;fBranchCount = 0;fBranchCount_created = false;}
705     if(fBranchCount2_created) {delete fBranchCount2;fBranchCount2 = 0;fBranchCount2_created = false;}
706   }
707 protected:
708   iro* m_obj;
709 protected:
710   std::string fClassName; //Class name of referenced object
711   int fClassVersion;  //Version number of class
712   int fID;            //element serial number in fInfo
713   int fType;          //branch type
714   int fStreamerType;  //branch streamer type
715   branch_element* fBranchCount;  // pointer to primary branchcount branch
716   bool fBranchCount_created;
717   branch_element* fBranchCount2; // pointer to secondary branchcount branch
718   bool fBranchCount2_created;
719   int fNdata;         // Number of data in this branch
720 };
721 
722 }}
723 
724 #ifdef TOOLS_RROOT_BRANCH_ELEMENT_DUMP
725 #undef TOOLS_RROOT_BRANCH_ELEMENT_DUMP
726 #endif
727 
728 #endif
729 
730 ////////////////////////////////////////////////////////////
731 ////////////////////////////////////////////////////////////
732 ////////////////////////////////////////////////////////////
733 /* In v4-00-01 version 8 :
734           case  1:  {b.ReadFastArray((Char_t*)  fAddress, n); break;}
735           case  2:  {b.ReadFastArray((Short_t*) fAddress, n); break;}
736           case  3:  {b.ReadFastArray((Int_t*)   fAddress, n); break;}
737           case  4:  {b.ReadFastArray((Long_t*)  fAddress, n); break;}
738           case  5:  {b.ReadFastArray((Float_t*) fAddress, n); break;}
739           case  6:  {b.ReadFastArray((Int_t*)   fAddress, n); break;}
740           case  8:  {b.ReadFastArray((Double_t*)fAddress, n); break;}
741           case 11:  {b.ReadFastArray((UChar_t*) fAddress, n); break;}
742           case 12:  {b.ReadFastArray((UShort_t*)fAddress, n); break;}
743           case 13:  {b.ReadFastArray((UInt_t*)  fAddress, n); break;}
744           case 14:  {b.ReadFastArray((ULong_t*) fAddress, n); break;}
745           case 15:  {b.ReadFastArray((Long64_t*)fAddress, n); break;}
746           case 16:  {b.ReadFastArray((ULong64_t*)fAddress, n); break;}
747       case  9:  {Double_t *xx = (Double_t*)fAddress;
748                   Float_t afloat;
749             for (Int_t ii=0;ii<n;ii++) {
750                     b>> afloat; xx[ii] = Double_t(afloat);
751             } break;}
752 */
753 /* 6.12.06 version 10 : fStreamerType : from meta/inc/TVirtualStreamerInfo.h :
754 
755    enum EReadWrite {
756       kBase        =  0,  kOffsetL = 20,  kOffsetP = 40,  kCounter =  6,  kCharStar = 7,
757       kChar        =  1,  kShort   =  2,  kInt     =  3,  kLong    =  4,  kFloat    = 5,
758       kDouble      =  8,  kDouble32=  9,
759       kUChar       = 11,  kUShort  = 12,  kUInt    = 13,  kULong   = 14,  kBits     = 15,
760       kLong64      = 16,  kULong64 = 17,  kBool    = 18,  kFloat16 = 19,
761       kObject      = 61,  kAny     = 62,  kObjectp = 63,  kObjectP = 64,  kTString  = 65,
762       kTObject     = 66,  kTNamed  = 67,  kAnyp    = 68,  kAnyP    = 69,  kAnyPnoVT = 70,
763       kSTLp        = 71,
764       kSkip        = 100, kSkipL = 120, kSkipP   = 140,
765       kConv        = 200, kConvL = 220, kConvP   = 240,
766       kSTL         = ROOT::kSTLany, // 300
767       kSTLstring   = ROOT::kSTLstring, // 365
768       kStreamer    = 500, kStreamLoop = 501,
769       kCache       = 600,  // Cache the value in memory than is not part of the object but is accessible via a SchemaRule
770       kArtificial  = 1000,
771       kCacheNew    = 1001,
772       kCacheDelete = 1002,
773       kNeedObjectForVirtualBaseClass = 99997,
774       kMissing     = 99999
775    };
776 
777 // Some comments about EReadWrite
778 // kBase    : base class element
779 // kOffsetL : fixed size array
780 // kOffsetP : pointer to object
781 // kCounter : counter for array size
782 // kCharStar: pointer to array of char
783 // kBits    : TObject::fBits in case of a referenced object
784 // kObject  : Class  derived from TObject
785 // kObjectp : Class* derived from TObject and with    comment field //->Class
786 // kObjectP : Class* derived from TObject and with NO comment field //->Class
787 // kAny     : Class  not derived from TObject
788 // kAnyp    : Class* not derived from TObject with    comment field //->Class
789 // kAnyP    : Class* not derived from TObject with NO comment field //->Class
790 // kAnyPnoVT: Class* not derived from TObject with NO comment field //->Class and Class has NO virtual table
791 // kSTLp    : Pointer to STL container.
792 // kTString : TString, special case
793 // kTObject : TObject, special case
794 // kTNamed  : TNamed , special case
795 
796 */