Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/rroot/branch_element is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_rroot_branch_element
0005 #define tools_rroot_branch_element
0006 
0007 #include "branch"
0008 #include "stl_vector"
0009 
0010 #include "info"
0011 #include "obj_list"
0012 
0013 //#define TOOLS_RROOT_BRANCH_ELEMENT_DUMP
0014 
0015 namespace tools {
0016 namespace rroot {
0017 
0018 class branch_element : public branch {
0019   typedef branch parent;
0020 public:
0021   static const std::string& s_class() {
0022     static const std::string s_v("tools::rroot::branch_element");
0023     return s_v;
0024   }
0025 public: //iro
0026   virtual void* cast(const std::string& a_class) const {
0027     if(void* p = cmp_cast<branch_element>(this,a_class)) return p;
0028     return parent::cast(a_class);
0029   }
0030   virtual const std::string& s_cls() const {return s_class();}
0031 public:
0032   static cid id_class() {return branch_element_cid();}
0033   virtual void* cast(cid a_class) const {
0034     if(void* p = cmp_cast<branch_element>(this,a_class)) {return p;}
0035     return parent::cast(a_class);
0036   }
0037 public:
0038   virtual bool stream(buffer& a_buffer) {
0039     _clear();
0040 
0041     short v;
0042     unsigned int _s,_c;
0043     if(!a_buffer.read_version(v,_s,_c)) return false;
0044 
0045     //::printf("debug : tools::branch_element::stream : version %d, count %d\n",v,c);
0046 
0047     if(!parent::stream(a_buffer)) {
0048       m_out << "tools::rroot::branch_element::stream : parent::stream() failed." << std::endl;
0049       return false;
0050     }
0051 
0052     if(v<=7) {
0053       if(!a_buffer.read(fClassName)) return false;
0054       if(!a_buffer.read(fClassVersion)) return false;
0055       if(!a_buffer.read(fID)) return false;
0056       if(!a_buffer.read(fType)) return false;
0057       if(!a_buffer.read(fStreamerType)) return false;
0058     } else { //v>=8
0059       if(!a_buffer.read(fClassName)) return false;
0060       //::printf("debug : tools::branch_element::stream : fClassName \"%s\"\n",fClassName.c_str());
0061       std::string fParentName;
0062       if(!a_buffer.read(fParentName)) return false;
0063       //::printf("debug : tools::branch_element::stream : fParentName \"%s\"\n",fParentName.c_str());
0064       std::string fCloneName;
0065       if(!a_buffer.read(fCloneName)) return false;
0066       //::printf("debug : tools::branch_element::stream : fCloneName \"%s\"\n",fCloneName.c_str());
0067       int dummy_int;
0068       if(!a_buffer.read(dummy_int)) return false; //fCheckSum
0069       //::printf("debug : tools::branch_element::stream : fCheckSum %d\n",dummy_int);
0070 
0071       if(v>=10) {
0072         short dummy_short;
0073         if(!a_buffer.read(dummy_short)) return false; //fClassVersion
0074         //::printf("debug : tools::branch_element::stream : fClassVersion %d\n",dummy_short);
0075       } else {
0076         if(!a_buffer.read(dummy_int)) return false; //fClassVersion
0077       }
0078 
0079       if(!a_buffer.read(fID)) return false;
0080       //::printf("debug : tools::branch_element::stream : fID %d\n",fID);
0081       if(!a_buffer.read(fType)) return false;
0082       //::printf("debug : tools::branch_element::stream : fType %d\n",fType);
0083       if(!a_buffer.read(fStreamerType)) return false;
0084       //::printf("debug : tools::branch_element::stream : fStreamerType %d\n",fStreamerType);
0085 
0086       if(!a_buffer.read(dummy_int)) return false; //fMaximum
0087       //::printf("debug : tools::branch_element::stream : fMaximum %d\n",dummy_int);
0088 
0089       //TBranchElement* fBranchCount;
0090       ifac::args args;
0091       if(!pointer_stream(a_buffer,m_fac,args,fBranchCount,fBranchCount_created)) {
0092         m_out << "tools::rroot::branch_element::stream : "
0093               << "can't read fBranchCount."
0094               << std::endl;
0095         return false;
0096       }
0097 
0098       //TBranchElement* fBranchCount2;
0099       if(!pointer_stream(a_buffer,m_fac,args,fBranchCount2,fBranchCount2_created)) {
0100         m_out << "tools::rroot::branch_element::stream : "
0101               << "can't read fBranchCount2."
0102               << std::endl;
0103         _clear();
0104         return false;
0105       }
0106 
0107     }
0108 
0109     if(!a_buffer.check_byte_count(_s,_c,"TBranchElement")) {_clear();return false;}
0110     return true;
0111   }
0112 public: //branch
0113 
0114   virtual bool read_leaves(ifile& a_file,buffer& a_buffer){
0115 
0116     // For k<type> value, see the below commented enum EReadWrite from ROOT-6.12.06 code.
0117     static int kInt      = 3;
0118     static int kDouble   = 8;
0119     static int kDouble32 = 9;
0120     static int kUInt     = 13;
0121     static int kBits     = 15;  // In v4-00-01 version 8, it is Long64_t.
0122     static int kObject   = 61;
0123     static int kObjectP  = 64;
0124 
0125     if(fType==3) { // TClonesArray master branch (has only the number of elements).
0126       //from v4-00-01
0127       int n;
0128       if(!a_buffer.read(n)) return false;
0129       /* ROOT-6.12.06 code :
0130       if ((n < 0) || (n > fMaximum)) {
0131          if (IsMissingCollection()) {
0132             n = 0;
0133             b.SetBufferOffset(b.Length() - sizeof(n));
0134          } else {
0135             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());
0136             n = 0;
0137          }
0138       }*/
0139       //::printf("debug : uuuu : ndata %d\n",n);
0140       fNdata = n;
0141 
0142       //TClonesArray *clones = (TClonesArray*)fObject;
0143       //if (!clones) return;
0144       //if (clones->IsZombie()) return;
0145       //clones->Clear();
0146       //clones->ExpandCreateFast(fNdata);
0147 
0148       //m_out << "debug : tools::rroot::branch_element::read_leaves :"
0149       //      << " name " << m_name << " ref_cls " << fClassName
0150       //      << " : type " << fType << ", fNdata " << n
0151       //      << std::endl;
0152       return true;
0153 
0154     } else if(fType==31) { // TClonesArray sub-branch (contains the elements).
0155       if(fStreamerType==kObject) { //to read EsbRoot fgd_dig.root.
0156         int ndata = fBranchCount->get_ndata();
0157 #ifdef TOOLS_RROOT_BRANCH_ELEMENT_DUMP
0158         ::printf("debug : %s : fClassName %s : fID %d : kObject : ndata %d\n",m_name.c_str(),fClassName.c_str(),fID,ndata);
0159 #endif
0160         streamer_info* _info = a_file.find_streamer_info(fClassName);
0161         if(!_info) {
0162           m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
0163                 << " read(kObject) : streamer_infos for ref_cls " << fClassName << " not found."
0164                 << std::endl;
0165           return false;
0166         }
0167         streamer_element* _element = _info->find_streamer_element(fID);
0168         if(!_element) {
0169           m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
0170                 << " read(kObject) : for ref_cls " << fClassName << ", fID " << fID << " streamer element not found."
0171                 << std::endl;
0172           return false;
0173         }
0174         //::printf("debug : element type name %s\n",_element->type_name().c_str());
0175 
0176         obj_list* _list = 0;
0177         if(!m_obj) {
0178           _list = new obj_list(m_fac);
0179           m_obj = _list;
0180         } else {
0181           _list = id_cast<iro,obj_list>(*m_obj);
0182           if(!_list) {
0183             m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
0184                   << " read(kObject) : m_obj is not an obj_list."
0185                   << std::endl;
0186             return false;
0187           }
0188         }
0189 
0190         _list->safe_clear();
0191 
0192         for(int index=0;index<ndata;index++) {
0193           ifac::args args;
0194           iro* _obj = m_fac.create(_element->type_name(),args);
0195           if(!_obj) {_list->safe_clear();return false;}
0196           if(!_obj->stream(a_buffer)){
0197             m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
0198                   << " kObject : obj stream of class " << sout(_element->type_name())
0199                   << " failed at index " << index << " (" << ndata << ")." << std::endl;
0200             _list->safe_clear();
0201             return false;
0202           }
0203           _list->add_object(_obj); //give ownership.
0204         }
0205 
0206         return true;
0207       }
0208       if(fStreamerType==kObjectP) return true;
0209       //from v4-00-01
0210       if(fStreamerType==kDouble32) {
0211         int ndata = fBranchCount->get_ndata();
0212 #ifdef TOOLS_RROOT_BRANCH_ELEMENT_DUMP
0213         ::printf("debug : %s : fID %d : double32 : ndata %d\n",m_name.c_str(),fID,ndata);
0214 #endif
0215         stl_vector<double>* vec = 0;
0216         if(!m_obj) {
0217           vec = new stl_vector<double>;
0218           m_obj = vec;
0219         } else {
0220           vec = id_cast<iro, stl_vector<double> >(*m_obj);
0221           if(!vec) {
0222             m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
0223                   << " read(kDouble32) : m_obj is not a stl_vector<double>."
0224                   << std::endl;
0225             return false;
0226           }
0227         }
0228 
0229         vec->resize(ndata);
0230         float afloat;
0231         for(int ii=0;ii<ndata;ii++) {
0232           if(!a_buffer.read(afloat)) {
0233             m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
0234                   << " read(float) failed."
0235                   << std::endl;
0236             vec->clear();
0237             return false;
0238           }
0239           //::printf("debug : zzzz %g\n",afloat);
0240           (*vec)[ii] = afloat;
0241         }
0242 
0243         return true;
0244 
0245       } else if(fStreamerType==kDouble) {
0246         int ndata = fBranchCount->get_ndata();
0247 #ifdef TOOLS_RROOT_BRANCH_ELEMENT_DUMP
0248         ::printf("debug : %s : fID %d : double : ndata %d\n",m_name.c_str(),fID,ndata);
0249 #endif
0250         stl_vector<double>* vec = 0;
0251         if(!m_obj) {
0252           vec = new stl_vector<double>;
0253           m_obj = vec;
0254         } else {
0255           vec = id_cast<iro, stl_vector<double> >(*m_obj);
0256           if(!vec) {
0257             m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
0258                   << " read(kDouble) : m_obj is not a stl_vector<double>."
0259                   << std::endl;
0260             return false;
0261           }
0262         }
0263 
0264         vec->resize(ndata);
0265         double* _value = vec_data(*vec);
0266         if(!a_buffer.read_fast_array(_value,ndata)) {
0267           m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
0268                 << " read_fast_array(double) failed."
0269                 << std::endl;
0270           vec->clear();
0271           return false;
0272         }
0273 
0274         return true;
0275 
0276       } else if(fStreamerType==kInt) {
0277         int ndata = fBranchCount->get_ndata();
0278 #ifdef TOOLS_RROOT_BRANCH_ELEMENT_DUMP
0279         ::printf("debug : %s : fID %d : int : ndata %d\n",m_name.c_str(),fID,ndata);
0280 #endif
0281         stl_vector<int>* vec = 0;
0282         if(!m_obj) {
0283           vec = new stl_vector<int>;
0284           m_obj = vec;
0285         } else {
0286           vec = id_cast<iro, stl_vector<int> >(*m_obj);
0287           if(!vec) {
0288             m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
0289                   << " read(kInt) : m_obj is not a stl_vector<int>."
0290                   << std::endl;
0291             return false;
0292           }
0293         }
0294 
0295         vec->resize(ndata);
0296         int* _value = vec_data(*vec);
0297         if(!a_buffer.read_fast_array(_value,ndata)) {
0298           m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
0299                 << " read_fast_array(int) failed."
0300                 << std::endl;
0301           vec->clear();
0302           return false;
0303         }
0304 
0305         return true;
0306 
0307       } else if((fStreamerType==kUInt)||(fStreamerType==kBits)) {
0308         int ndata = fBranchCount->get_ndata();
0309 #ifdef TOOLS_RROOT_BRANCH_ELEMENT_DUMP
0310         if(fStreamerType==kUInt) ::printf("debug : %s : fID %d : uint : ndata %d\n",m_name.c_str(),fID,ndata);
0311         else                     ::printf("debug : %s : fID %d : bits : ndata %d\n",m_name.c_str(),fID,ndata);
0312 #endif
0313         stl_vector<uint32>* vec = 0;
0314         if(!m_obj) {
0315           vec = new stl_vector<uint32>;
0316           m_obj = vec;
0317         } else {
0318           vec = id_cast<iro, stl_vector<uint32> >(*m_obj);
0319           if(!vec) {
0320             m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
0321                   << " read(kUInt) : m_obj is not a stl_vector<uint32>."
0322                   << std::endl;
0323             return false;
0324           }
0325         }
0326 
0327         vec->resize(ndata);
0328         uint32* _value = vec_data(*vec);
0329         if(!a_buffer.read_fast_array(_value,ndata)) {
0330           m_out << "tools::rroot::branch_element::read_leaves : " << sout(m_name) << " :"
0331                 << " read_fast_array(uint) failed."
0332                 << std::endl;
0333           vec->clear();
0334           return false;
0335         }
0336 
0337         return true;
0338 
0339       } else {
0340         m_out << "tools::rroot::branch_element::read_leaves :"
0341               << " name " << m_name << " ref_cls " << fClassName
0342               << " : for type " << fType << ", stream_type " << fStreamerType << " not treated."
0343               << std::endl;
0344         return false;
0345       }
0346         /*
0347         //m_obj = clones_array<float>(m_fac,true,false);  //true = owner of objects.
0348         uint32 ndata = 1;
0349         float* _value = new float[ndata];
0350         if(!a_buffer.read_fast_array(_value,ndata)) {
0351           m_out << "tools::rroot::branch_element::read_leaves : \"" << name() << "\" :"
0352                 << " read_fast_array failed."
0353                 << std::endl;
0354           return false;
0355         }
0356         */
0357   //} else if(fType<=2) { //in v5-18-00d
0358     } else if(fType==0) { // to read wroot.root of examples/cpp/wroot.cpp.
0359 //     if(fID>=0) {
0360 //       // branch in split mode
0361 //       m_out << "tools::rroot::branch_element::read_leaves :"
0362 //             << " name " << m_name << " ref_cls " << fClassName << " :"
0363 //             << " type 0 with ID " << fID << "."
0364 //             << std::endl;
0365 //       return true;
0366 //
0367 
0368        if((fID==-1)||
0369           (fID==1)     // for pmx to read LHCb files :
0370          ){
0371          //from v4-00-01
0372          //if (fBranchCount) fNdata = (Int_t)fBranchCount->GetValue(0,0);
0373          //else fNdata = 1;
0374          if(fBranchCount) {
0375            fNdata = fBranchCount->get_ndata();
0376            //::printf("debug : branch_element::read_leaves : (fType==0,fID==-1) : fNdata %d\n",fNdata);
0377          } else {
0378            fNdata = 1;
0379          }
0380 
0381          // read object :
0382          bool created = false;
0383          if(!m_obj) {
0384            ifac::args args;
0385            m_obj = m_fac.create(fClassName,args);
0386            if(!m_obj) return false;
0387            created = true;
0388          }
0389 
0390          if(!m_obj->stream(a_buffer)){
0391            m_out << "tools::rroot::branch_element::read_leaves :"
0392                  << " name " << sout(m_name) << ", ref_cls " << sout(fClassName) << " :"
0393                  << " obj stream failed."
0394                  << std::endl;
0395            if(created) {delete m_obj;m_obj = 0;}
0396            return false;
0397          }
0398 
0399          return true;
0400 
0401        } else {
0402          m_out << "tools::rroot::branch_element::read_leaves :"
0403                << " name " << m_name << " ref_cls " << fClassName << " :"
0404                << " type 0 with ID " << fID << " not treated."
0405                << std::endl;
0406          return false;
0407        }
0408 
0409     }
0410 
0411     m_out << "tools::rroot::branch_element::read_leaves :"
0412           << " name " << m_name << " ref_cls " << fClassName
0413           << " : type " << fType << " not treated, stream_type is " << fStreamerType << "."
0414           << std::endl;
0415     return false;
0416 
0417 /*
0418     ///////////////////////////////////////////////////////
0419     /// STL container /////////////////////////////////////
0420     ///////////////////////////////////////////////////////
0421     if(fType==4) {
0422       // STL container master branch (has only the number of elements).
0423       //from v4-00-01
0424       int n;
0425       if(!a_buffer.read(n)) return false;
0426       //fNdata = n;
0427 
0428       m_out << "tools::rroot::branch_element::read_leaves :"
0429             << " name " << m_name << " ref_cls " << fClassName
0430             << " : type " << fType << " not treated."
0431             << std::endl;
0432       return false;
0433 
0434     } else if(fType==41) {
0435       // STL container sub-branch (contains the elements).
0436       m_out << "tools::rroot::branch_element::read_leaves :"
0437             << " name " << m_name << " ref_cls " << fClassName
0438             << " : type " << fType << " not treated."
0439             << std::endl;
0440       return false;
0441 
0442     ///////////////////////////////////////////////////////
0443     /// TClonesArray container ////////////////////////////
0444     ///////////////////////////////////////////////////////
0445     } else if(fType==3) {
0446       // TClonesArray master branch (has only the number of elements).
0447       //from v4-00-01
0448       int n;
0449       if(!a_buffer.read(n)) return false;
0450 
0451       //fNdata = n;
0452       //TClonesArray *clones = (TClonesArray*)fObject;
0453       //if (!clones) return;
0454       //if (clones->IsZombie()) return;
0455       //clones->Clear();
0456       //clones->ExpandCreateFast(fNdata);
0457 
0458       m_out << "tools::rroot::branch_element::read_leaves :"
0459             << " name " << m_name << " ref_cls " << fClassName
0460             << " : type " << fType << " not treated."
0461             << std::endl;
0462       return false;
0463 
0464     } else if(fType==31) {
0465       // TClonesArray sub-branch (contains the elements).
0466       m_out << "tools::rroot::branch_element::read_leaves :"
0467             << " name " << m_name << " ref_cls " << fClassName
0468             << " : type " << fType << " not treated."
0469             << std::endl;
0470       return false;
0471 
0472     ///////////////////////////////////////////////////////
0473     ///////////////////////////////////////////////////////
0474     ///////////////////////////////////////////////////////
0475     } else if(fType<=2) {
0476       // branch in split mode
0477 
0478       //from v4-00-01
0479       //if (fBranchCount) fNdata = (Int_t)fBranchCount->GetValue(0,0);
0480       //else fNdata = 1;
0481       //if (!fInfo) return;
0482       //fInfo->ReadBuffer(b,fObject,fID);
0483       //if (fStreamerType == 6) fNdata = (Int_t)GetValue(0,0);
0484 
0485       //from 3.0.06
0486       //if (fID >= 0) {
0487       //  fInfo->ReadBuffer(b,fAddress,fID);
0488       //} else if (fID == -1) {   // top level branch in non split mode
0489       //  char **ppointer = (char**)fAddress;
0490       //  fInfo->ReadBuffer(b,*ppointer,fID);
0491       //}
0492 
0493       //m_out << "tools::rroot::branch_element::read_leaves :"
0494       //      << " name " << m_name << " ref_cls " << fClassName << " :"
0495       //      << " type " << fType << " with ID " << fID << "."
0496       //      << " and then ?"
0497       //      << std::endl;
0498 
0499       // read object ?
0500       bool created = false;
0501       if(!m_obj) {
0502         ifac::args args;
0503         m_obj = m_fac.create(fClassName,args);
0504         if(!m_obj) return false;
0505         created = true;
0506       }
0507 
0508       if(!m_obj->stream(a_buffer)){
0509         m_out << "tools::rroot::branch_element::read_leaves :"
0510               << " name " << m_name << " ref_cls " << fClassName << " :"
0511               << " obj stream failed."
0512               << std::endl;
0513         if(created) {delete m_obj;m_obj = 0;}
0514         return false;
0515       }
0516 
0517       //m_out << "tools::rroot::branch_element::read_leaves :"
0518       //      << " name " << m_name << " ref_cls " << fClassName << " :"
0519       //      << " obj streamed."
0520       //      << std::endl;
0521 
0522       return true;
0523 
0524 //  } else if(fType==0) {
0525 //     if(fID>=0) {
0526 //       // branch in split mode
0527 //       m_out << "tools::rroot::branch_element::read_leaves :"
0528 //             << " name " << m_name << " ref_cls " << fClassName << " :"
0529 //             << " type 0 with ID " << fID << "."
0530 //             << std::endl;
0531 //       return true;
0532 //
0533 //     } else if(fID==-1) {
0534 //       // top level branch in non split mode
0535 //       m_out << "tools::rroot::branch_element::read_leaves :"
0536 //             << " name " << m_name << " ref_cls " << fClassName << " :"
0537 //             << " type 0 with ID " << fID
0538 //             << " : fill object."
0539 //             << std::endl;
0540 
0541 //       if(!m_obj) {
0542 //         m_out << "tools::rroot::branch_element::read_leaves :"
0543 //               << " name " << m_name << " ref_cls " << fClassName << " :"
0544 //               << " m_obj is null."
0545 //               << std::endl;
0546 //         return false;
0547 //       }
0548 //       if(!m_obj->stream(a_buffer)){
0549 //         m_out << "tools::rroot::branch_element::read_leaves :"
0550 //               << " name " << m_name << " ref_cls " << fClassName << " :"
0551 //               << " obj stream failed."
0552 //               << std::endl;
0553 //         return false;
0554 //       }
0555 //       return true;
0556 
0557 //     } else {
0558 //       m_out << "tools::rroot::branch_element::read_leaves :"
0559 //             << " name " << m_name << " ref_cls " << fClassName << " :"
0560 //             << " type 0 with ID " << fID << " not treated."
0561 //             << std::endl;
0562 //       return false;
0563 //     }
0564 
0565 //  //LHCb files :
0566 //  } else if(fType==1) {
0567 //    // parent branch is a base class branch.
0568 //    // Ok, and then ?
0569 //    m_out << "tools::rroot::branch_element::read_leaves :"
0570 //          << " name " << m_name << " ref_cls " << fClassName << " :"
0571 //          << " type " << fType << " with ID " << fID << "."
0572 //          << std::endl;
0573 //    return true;
0574 
0575     } else {
0576       m_out << "tools::rroot::branch_element::read_leaves :"
0577             << " name " << m_name << " ref_cls " << fClassName << " :"
0578             << " type " << fType << " with ID " << fID << "."
0579             << " unknown case."
0580             << std::endl;
0581       return false;
0582     }
0583 */
0584   }
0585 
0586   virtual bool find_entry(ifile& a_file,uint64 a_entry,uint32& a_nbytes){
0587     //The below line will call the upper read_leaves.
0588     if(!parent::find_entry(a_file,a_entry,a_nbytes)) return false;
0589 
0590     if(m_branches.size()) {
0591       //if(!m_obj) {
0592       //  m_obj = m_fac.create(fClassName);
0593       //  if(!m_obj) return false;
0594       //}
0595 
0596       tools_vforcit(branch*,m_branches,it) {
0597         uint32 n;
0598         if(!(*it)->find_entry(a_file,a_entry,n)) return false;
0599         a_nbytes += n;
0600       }
0601     }
0602 
0603     return true;
0604   }
0605 
0606   virtual bool show(std::ostream& a_out,ifile& a_file,uint64 a_entry){
0607     uint32 n;
0608     if(!find_entry(a_file,a_entry,n)) return false;
0609 
0610    {std::string _s;
0611     uint32 len = uint32(name().size())+128;
0612     sprintf(_s,len," %-15s = ",name().c_str());
0613     a_out << _s;}
0614 
0615     a_out << m_obj << std::endl;
0616 
0617     return true;
0618     //return parent::show(a_out,a_file,a_entry);
0619   }
0620 public:
0621   branch_element(std::ostream& a_out,ifac& a_fac)
0622   :parent(a_out,a_fac)
0623   ,m_obj(0)
0624   ,fClassVersion(0)
0625   ,fID(0)
0626   ,fType(0)
0627   ,fStreamerType(-1)
0628   ,fBranchCount(0)   //not owner
0629   ,fBranchCount_created(false)
0630   ,fBranchCount2(0)  //not owner
0631   ,fBranchCount2_created(false)
0632   ,fNdata(1)
0633   {}
0634 
0635   virtual ~branch_element() {
0636     _clear();
0637     if(m_obj) delete m_obj;
0638   }
0639 protected:
0640   branch_element(const branch_element& a_from):iro(a_from),parent(a_from){}
0641   branch_element& operator=(const branch_element&){return *this;}
0642 public:
0643   const std::string& class_name() const {return fClassName;}
0644   int type() const {return fType;}
0645   int streamer_type() const {return fStreamerType;}
0646   int id() const {return fID;}
0647   iro* object() {return m_obj;}
0648   int get_ndata() const {return fNdata;}
0649 
0650   template <class T>
0651   stl_vector<T>* object_to_stl_vector() const {
0652     if(!m_obj) {
0653       m_out << "tools::rroot::branch_element::object_to_stl_vector : there is no object." << std::endl;
0654       return 0;
0655     }
0656     stl_vector<T>* od = id_cast<iro, stl_vector<T> >(*m_obj);
0657     if(!od) {
0658       m_out << "tools::rroot::branch_element::object_to_stl_vector :"
0659             << " object of class " << sout(m_obj->s_cls()) << " not a tools::rroot::stl_vector<T>."
0660             << std::endl;
0661       return 0;
0662     }
0663     return od; //WARNING : we are not owner.
0664   }
0665 
0666   obj_list* object_to_obj_list() const {
0667     if(!m_obj) {
0668       m_out << "tools::rroot::branch_element::object_to_obj_list : there is no object." << std::endl;
0669       return 0;
0670     }
0671     obj_list* od = id_cast<iro,obj_list>(*m_obj);
0672     if(!od) {
0673       m_out << "tools::rroot::branch_element::object_to_obj_list :"
0674             << " object of class " << sout(m_obj->s_cls()) << " not a tools::rroot::obj_list."
0675             << std::endl;
0676       return 0;
0677     }
0678     return od; //WARNING : we are not owner.
0679   }
0680 
0681   template <class T>
0682   stl_vector<T>* find_entry_vec(ifile& a_file,uint64 a_event) {
0683     unsigned int n;
0684     if(!find_entry(a_file,a_event,n)) {
0685       m_out << "tools::rroot::branch_element::find_entry_vec : find_entry() failed." << std::endl;
0686       return 0;
0687     }
0688     if(!m_obj) {
0689       m_out << "tools::rroot::branch_element::find_entry_vec : no object found." << std::endl;
0690       return 0;
0691     }
0692     stl_vector<T>* od = id_cast<iro, stl_vector<T> >(*m_obj);
0693     if(!od) {
0694       m_out << "tools::rroot::branch_element::find_entry_vec :"
0695             << " object not a tools::rroot::stl_vector<T>."
0696             << std::endl;
0697       return 0;
0698     }
0699     return od; //WARNING : we are not owner.
0700   }
0701 
0702 protected:
0703   void _clear() {
0704     if(fBranchCount_created) {delete fBranchCount;fBranchCount = 0;fBranchCount_created = false;}
0705     if(fBranchCount2_created) {delete fBranchCount2;fBranchCount2 = 0;fBranchCount2_created = false;}
0706   }
0707 protected:
0708   iro* m_obj;
0709 protected:
0710   std::string fClassName; //Class name of referenced object
0711   int fClassVersion;  //Version number of class
0712   int fID;            //element serial number in fInfo
0713   int fType;          //branch type
0714   int fStreamerType;  //branch streamer type
0715   branch_element* fBranchCount;  // pointer to primary branchcount branch
0716   bool fBranchCount_created;
0717   branch_element* fBranchCount2; // pointer to secondary branchcount branch
0718   bool fBranchCount2_created;
0719   int fNdata;         // Number of data in this branch
0720 };
0721 
0722 }}
0723 
0724 #ifdef TOOLS_RROOT_BRANCH_ELEMENT_DUMP
0725 #undef TOOLS_RROOT_BRANCH_ELEMENT_DUMP
0726 #endif
0727 
0728 #endif
0729 
0730 ////////////////////////////////////////////////////////////
0731 ////////////////////////////////////////////////////////////
0732 ////////////////////////////////////////////////////////////
0733 /* In v4-00-01 version 8 :
0734           case  1:  {b.ReadFastArray((Char_t*)  fAddress, n); break;}
0735           case  2:  {b.ReadFastArray((Short_t*) fAddress, n); break;}
0736           case  3:  {b.ReadFastArray((Int_t*)   fAddress, n); break;}
0737           case  4:  {b.ReadFastArray((Long_t*)  fAddress, n); break;}
0738           case  5:  {b.ReadFastArray((Float_t*) fAddress, n); break;}
0739           case  6:  {b.ReadFastArray((Int_t*)   fAddress, n); break;}
0740           case  8:  {b.ReadFastArray((Double_t*)fAddress, n); break;}
0741           case 11:  {b.ReadFastArray((UChar_t*) fAddress, n); break;}
0742           case 12:  {b.ReadFastArray((UShort_t*)fAddress, n); break;}
0743           case 13:  {b.ReadFastArray((UInt_t*)  fAddress, n); break;}
0744           case 14:  {b.ReadFastArray((ULong_t*) fAddress, n); break;}
0745           case 15:  {b.ReadFastArray((Long64_t*)fAddress, n); break;}
0746           case 16:  {b.ReadFastArray((ULong64_t*)fAddress, n); break;}
0747                   case  9:  {Double_t *xx = (Double_t*)fAddress;
0748                                     Float_t afloat;
0749                                                 for (Int_t ii=0;ii<n;ii++) {
0750                                             b>> afloat; xx[ii] = Double_t(afloat);
0751                                                 } break;}
0752 */
0753 /* 6.12.06 version 10 : fStreamerType : from meta/inc/TVirtualStreamerInfo.h :
0754 
0755    enum EReadWrite {
0756       kBase        =  0,  kOffsetL = 20,  kOffsetP = 40,  kCounter =  6,  kCharStar = 7,
0757       kChar        =  1,  kShort   =  2,  kInt     =  3,  kLong    =  4,  kFloat    = 5,
0758       kDouble      =  8,  kDouble32=  9,
0759       kUChar       = 11,  kUShort  = 12,  kUInt    = 13,  kULong   = 14,  kBits     = 15,
0760       kLong64      = 16,  kULong64 = 17,  kBool    = 18,  kFloat16 = 19,
0761       kObject      = 61,  kAny     = 62,  kObjectp = 63,  kObjectP = 64,  kTString  = 65,
0762       kTObject     = 66,  kTNamed  = 67,  kAnyp    = 68,  kAnyP    = 69,  kAnyPnoVT = 70,
0763       kSTLp        = 71,
0764       kSkip        = 100, kSkipL = 120, kSkipP   = 140,
0765       kConv        = 200, kConvL = 220, kConvP   = 240,
0766       kSTL         = ROOT::kSTLany, // 300
0767       kSTLstring   = ROOT::kSTLstring, // 365
0768       kStreamer    = 500, kStreamLoop = 501,
0769       kCache       = 600,  // Cache the value in memory than is not part of the object but is accessible via a SchemaRule
0770       kArtificial  = 1000,
0771       kCacheNew    = 1001,
0772       kCacheDelete = 1002,
0773       kNeedObjectForVirtualBaseClass = 99997,
0774       kMissing     = 99999
0775    };
0776 
0777 // Some comments about EReadWrite
0778 // kBase    : base class element
0779 // kOffsetL : fixed size array
0780 // kOffsetP : pointer to object
0781 // kCounter : counter for array size
0782 // kCharStar: pointer to array of char
0783 // kBits    : TObject::fBits in case of a referenced object
0784 // kObject  : Class  derived from TObject
0785 // kObjectp : Class* derived from TObject and with    comment field //->Class
0786 // kObjectP : Class* derived from TObject and with NO comment field //->Class
0787 // kAny     : Class  not derived from TObject
0788 // kAnyp    : Class* not derived from TObject with    comment field //->Class
0789 // kAnyP    : Class* not derived from TObject with NO comment field //->Class
0790 // kAnyPnoVT: Class* not derived from TObject with NO comment field //->Class and Class has NO virtual table
0791 // kSTLp    : Pointer to STL container.
0792 // kTString : TString, special case
0793 // kTObject : TObject, special case
0794 // kTNamed  : TNamed , special case
0795 
0796 */