inlib
1.2.0
|
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved. 00002 // See the file inlib.license for terms. 00003 00004 #ifndef inlib_rroot_branch_element 00005 #define inlib_rroot_branch_element 00006 00007 #include "branch" 00008 00009 namespace inlib { 00010 namespace rroot { 00011 00012 class branch_element : public branch { 00013 public: 00014 static const std::string& s_class() { 00015 static const std::string s_v("inlib::rroot::branch_element"); 00016 return s_v; 00017 } 00018 public: //iro 00019 virtual void* cast(const std::string& a_class) const { 00020 if(void* p = inlib::cmp_cast<branch_element>(this,a_class)) {return p;} 00021 else return branch::cast(a_class); 00022 } 00023 virtual bool stream(buffer& a_buffer) { 00024 short v; 00025 unsigned int s, c; 00026 if(!a_buffer.read_version(v,s,c)) return false; 00027 if(!branch::stream(a_buffer)) return false; 00028 00029 if(v<=7) { 00030 if(!a_buffer.read(fClassName)) return false; 00031 if(!a_buffer.read(fClassVersion)) return false; 00032 if(!a_buffer.read(fID)) return false; 00033 if(!a_buffer.read(fType)) return false; 00034 if(!a_buffer.read(fStreamerType)) return false; 00035 } else { //v>=8 00036 if(!a_buffer.read(fClassName)) return false; 00037 std::string fParentName; 00038 if(!a_buffer.read(fParentName)) return false; 00039 std::string fCloneName; 00040 if(!a_buffer.read(fCloneName)) return false; 00041 int dummy_int; 00042 if(!a_buffer.read(dummy_int)) return false; //fCheckSum 00043 if(!a_buffer.read(dummy_int)) return false; //fClassVersion 00044 00045 if(!a_buffer.read(fID)) return false; 00046 if(!a_buffer.read(fType)) return false; 00047 if(!a_buffer.read(fStreamerType)) return false; 00048 00049 if(!a_buffer.read(dummy_int)) return false; //fMaximum 00050 00051 //TBranchElement* fBranchCount; 00052 {ifac::args args; 00053 iro* obj; 00054 if(!a_buffer.read_object(m_fac,args,obj)) { 00055 m_out << "inlib::rroot::base_element::stream : " 00056 << "can't read fAliases." 00057 << std::endl; 00058 return false; 00059 } 00060 delete obj;} 00061 00062 //TBranchElement* fBranchCount2; 00063 {ifac::args args; 00064 iro* obj; 00065 if(!a_buffer.read_object(m_fac,args,obj)) { 00066 m_out << "inlib::rroot::base_element::stream : " 00067 << "can't read fAliases." 00068 << std::endl; 00069 return false; 00070 } 00071 delete obj;} 00072 00073 } 00074 00075 if(!a_buffer.check_byte_count(s,c,"TBranchElement")) return false; 00076 return true; 00077 } 00078 public: //branch 00079 00080 virtual bool read_leaves(buffer& a_buffer){ 00084 if(fType==4) { 00085 // STL container master branch (has only the number of elements). 00086 //from v4-00-01 00087 int n; 00088 if(!a_buffer.read(n)) return false; 00089 //fNdata = n; 00090 00091 m_out << "inlib::rroot::branch_element::read_leaves :" 00092 << " name " << m_name << " ref_cls " << fClassName 00093 << " : type " << fType << " not treated." 00094 << std::endl; 00095 return false; 00096 00097 } else if(fType==41) { 00098 // STL container sub-branch (contains the elements). 00099 m_out << "inlib::rroot::branch_element::read_leaves :" 00100 << " name " << m_name << " ref_cls " << fClassName 00101 << " : type " << fType << " not treated." 00102 << std::endl; 00103 return false; 00104 00108 } else if(fType==3) { 00109 // TClonesArray master branch (has only the number of elements). 00110 //from v4-00-01 00111 int n; 00112 if(!a_buffer.read(n)) return false; 00113 00114 //fNdata = n; 00115 //TClonesArray *clones = (TClonesArray*)fObject; 00116 //if (!clones) return; 00117 //if (clones->IsZombie()) return; 00118 //clones->Clear(); 00119 //clones->ExpandCreateFast(fNdata); 00120 00121 m_out << "inlib::rroot::branch_element::read_leaves :" 00122 << " name " << m_name << " ref_cls " << fClassName 00123 << " : type " << fType << " not treated." 00124 << std::endl; 00125 return false; 00126 00127 } else if(fType==31) { 00128 // TClonesArray sub-branch (contains the elements). 00129 m_out << "inlib::rroot::branch_element::read_leaves :" 00130 << " name " << m_name << " ref_cls " << fClassName 00131 << " : type " << fType << " not treated." 00132 << std::endl; 00133 return false; 00134 00138 } else if(fType<=2) { 00139 // branch in split mode 00140 00141 //from v4-00-01 00142 //if (fBranchCount) fNdata = (Int_t)fBranchCount->GetValue(0,0); 00143 //else fNdata = 1; 00144 //if (!fInfo) return; 00145 //fInfo->ReadBuffer(b,fObject,fID); 00146 //if (fStreamerType == 6) fNdata = (Int_t)GetValue(0,0); 00147 00148 //from 3.0.06 00149 //if (fID >= 0) { 00150 // fInfo->ReadBuffer(b,fAddress,fID); 00151 //} else if (fID == -1) { // top level branch in non split mode 00152 // char **ppointer = (char**)fAddress; 00153 // fInfo->ReadBuffer(b,*ppointer,fID); 00154 //} 00155 00156 //m_out << "inlib::rroot::branch_element::read_leaves :" 00157 // << " name " << m_name << " ref_cls " << fClassName << " :" 00158 // << " type " << fType << " with ID " << fID << "." 00159 // << " and then ?" 00160 // << std::endl; 00161 00162 // read object ? 00163 if(!m_obj) { 00164 ifac::args args; 00165 m_obj = m_fac.create(fClassName,args); 00166 if(!m_obj) return false; 00167 } 00168 00169 if(!m_obj->stream(a_buffer)){ 00170 m_out << "inlib::rroot::branch_element::read_leaves :" 00171 << " name " << m_name << " ref_cls " << fClassName << " :" 00172 << " obj stream failed." 00173 << std::endl; 00174 return false; 00175 } 00176 00177 //m_out << "inlib::rroot::branch_element::read_leaves :" 00178 // << " name " << m_name << " ref_cls " << fClassName << " :" 00179 // << " obj streamed." 00180 // << std::endl; 00181 00182 return true; 00183 /* 00184 } else if(fType==0) { 00185 if(fID>=0) { 00186 // branch in split mode 00187 m_out << "inlib::rroot::branch_element::read_leaves :" 00188 << " name " << m_name << " ref_cls " << fClassName << " :" 00189 << " type 0 with ID " << fID << "." 00190 << std::endl; 00191 00192 return true; 00193 } else if(fID==-1) { 00194 // top level branch in non split mode 00195 m_out << "inlib::rroot::branch_element::read_leaves :" 00196 << " name " << m_name << " ref_cls " << fClassName << " :" 00197 << " type 0 with ID " << fID 00198 << " : fill object." 00199 << std::endl; 00200 00201 if(!m_obj) { 00202 m_out << "inlib::rroot::branch_element::read_leaves :" 00203 << " name " << m_name << " ref_cls " << fClassName << " :" 00204 << " m_obj is null." 00205 << std::endl; 00206 return false; 00207 } 00208 if(!m_obj->stream(a_buffer)){ 00209 m_out << "inlib::rroot::branch_element::read_leaves :" 00210 << " name " << m_name << " ref_cls " << fClassName << " :" 00211 << " obj stream failed." 00212 << std::endl; 00213 return false; 00214 } 00215 return true; 00216 00217 } else { 00218 m_out << "inlib::rroot::branch_element::read_leaves :" 00219 << " name " << m_name << " ref_cls " << fClassName << " :" 00220 << " type 0 with ID " << fID << " not treated." 00221 << std::endl; 00222 return false; 00223 } 00224 00225 //LHCb files : 00226 } else if(fType==1) { 00227 // parent branch is a base class branch. 00228 // Ok, and then ? 00229 m_out << "inlib::rroot::branch_element::read_leaves :" 00230 << " name " << m_name << " ref_cls " << fClassName << " :" 00231 << " type " << fType << " with ID " << fID << "." 00232 << std::endl; 00233 return true; 00234 */ 00235 } else { 00236 m_out << "inlib::rroot::branch_element::read_leaves :" 00237 << " name " << m_name << " ref_cls " << fClassName << " :" 00238 << " type " << fType << " with ID " << fID << "." 00239 << " unknown case." 00240 << std::endl; 00241 return false; 00242 } 00243 00244 } 00245 00246 virtual bool find_entry(uint32 a_entry,uint32& a_nbytes){ 00247 //The below line will call the upper read_leaves. 00248 if(!branch::find_entry(a_entry,a_nbytes)) return false; 00249 00250 if(m_branches.size()) { 00251 //if(!m_obj) { 00252 // m_obj = m_fac.create(fClassName); 00253 // if(!m_obj) return false; 00254 //} 00255 00256 std::vector<branch*>::iterator it; 00257 for(it=m_branches.begin();it!=m_branches.end();++it) { 00258 uint32 n; 00259 if(!(*it)->find_entry(a_entry,n)) return false; 00260 a_nbytes += n; 00261 } 00262 } 00263 00264 return true; 00265 } 00266 public: 00267 branch_element(ifile& a_file,ifac& a_fac) 00268 : branch(a_file,a_fac) 00269 ,m_obj(0) 00270 ,fClassVersion(0) 00271 ,fID(0) 00272 ,fType(0) 00273 ,fStreamerType(-1) 00274 {} 00275 00276 virtual ~branch_element(){delete m_obj;} 00277 protected: 00278 branch_element(const branch_element& a_from) 00279 :iro(a_from),branch(a_from){} 00280 branch_element& operator=(const branch_element&){return *this;} 00281 public: 00282 const std::string& class_name() const {return fClassName;} 00283 int type() const {return fType;} 00284 int streamer_type() const {return fStreamerType;} 00285 int id() const {return fID;} 00286 iro* object() {return m_obj;} 00287 protected: 00288 iro* m_obj; 00289 protected: 00290 std::string fClassName; //Class name of referenced object 00291 int fClassVersion; //Version number of class 00292 int fID; //element serial number in fInfo 00293 int fType; //branch type 00294 int fStreamerType; //branch streamer type 00295 }; 00296 00297 }} 00298 00299 #endif