Warning, /include/Geant4/tools/rroot/info 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_info
0005 #define tools_rroot_info
0006
0007 //#include "buffer"
0008 //#include "element"
0009 #include "named"
0010 #include "obj_array"
0011 #include "../forit"
0012
0013 namespace tools {
0014 namespace rroot {
0015
0016 class streamer_element : public virtual iro {
0017 static const std::string& s_store_class() {
0018 static const std::string s_v("TStreamerElement");
0019 return s_v;
0020 }
0021 public:
0022 static const std::string& s_class() {
0023 static const std::string s_v("tools::rroot::streamer_element");
0024 return s_v;
0025 }
0026 static cid id_class() {return streamer_element_cid();}
0027 public: //iro
0028 virtual void* cast(const std::string& a_class) const {
0029 if(void* p = cmp_cast<streamer_element>(this,a_class)) return p;
0030 return 0;
0031 }
0032 virtual void* cast(cid a_class) const {
0033 if(void* p = cmp_cast<streamer_element>(this,a_class)) {return p;}
0034 else return 0;
0035 }
0036 virtual const std::string& s_cls() const {return s_class();}
0037 virtual iro* copy() const {return new streamer_element(*this);}
0038
0039 virtual bool stream(buffer& a_buffer) {
0040 short v;
0041 unsigned int _s,_c;
0042 if(!a_buffer.read_version(v,_s,_c)) return false;
0043 if(!Named_stream(a_buffer,fName,fTitle)) return false;
0044 if(!a_buffer.read(fType)) return false;
0045 if(!a_buffer.read(fSize)) return false;
0046 if(!a_buffer.read(fArrayLength)) return false;
0047 if(!a_buffer.read(fArrayDim)) return false;
0048 if(!a_buffer.read_fast_array<int>(fMaxIndex,5)) return false;
0049 if(!a_buffer.read(fTypeName)) return false;
0050 return a_buffer.check_byte_count(_s,_c,s_store_class());
0051 }
0052 public:
0053 virtual void out(std::ostream& aOut) const {
0054 std::string _fname;
0055 fullName(_fname);
0056 char _s[128];
0057 snpf(_s,sizeof(_s)," %-14s%-15s offset=%3d type=%2d %-20s",
0058 fTypeName.c_str(),_fname.c_str(),fOffset,fType,fTitle.c_str());
0059 aOut << _s << std::endl;
0060 }
0061 public:
0062 streamer_element()
0063 :fName(),fTitle(),fType(-1)
0064 ,fSize(0),fArrayLength(0),fArrayDim(0),fOffset(0)
0065 ,fTypeName(){
0066 #ifdef TOOLS_MEM
0067 mem::increment(s_class().c_str());
0068 #endif
0069 for(int i=0;i<5;i++) fMaxIndex[i] = 0;
0070 }
0071 virtual ~streamer_element(){
0072 #ifdef TOOLS_MEM
0073 mem::decrement(s_class().c_str());
0074 #endif
0075 }
0076 protected:
0077 streamer_element(const streamer_element& a_from)
0078 :iro(a_from)
0079 ,fName(a_from.fName),fTitle(a_from.fTitle)
0080 ,fType(a_from.fType),fSize(a_from.fSize)
0081 ,fArrayLength(a_from.fArrayLength)
0082 ,fArrayDim(a_from.fArrayDim),fOffset(a_from.fOffset)
0083 ,fTypeName(a_from.fTypeName){
0084 #ifdef TOOLS_MEM
0085 mem::increment(s_class().c_str());
0086 #endif
0087 for(int i=0;i<5;i++) fMaxIndex[i] = a_from.fMaxIndex[i];
0088 }
0089 streamer_element& operator=(const streamer_element& a_from){
0090 fName = a_from.fName;
0091 fTitle = a_from.fTitle;
0092 fType = a_from.fType;
0093 fSize = a_from.fSize;
0094 fArrayLength = a_from.fArrayLength;
0095 fArrayDim = a_from.fArrayDim;
0096 fOffset = a_from.fOffset;
0097 fTypeName = a_from.fTypeName;
0098 for(int i=0;i<5;i++) fMaxIndex[i] = a_from.fMaxIndex[i];
0099 return *this;
0100 }
0101 public:
0102 virtual void fullName(std::string& a_s) const {
0103 a_s = fName;
0104 for (int i=0;i<fArrayDim;i++) {
0105 char cdim[32];
0106 snpf(cdim,sizeof(cdim),"[%d]",fMaxIndex[i]);
0107 a_s += cdim;
0108 }
0109 }
0110 const std::string& type_name() const {return fTypeName;}
0111 protected: //Named
0112 std::string fName;
0113 std::string fTitle;
0114 protected:
0115 int fType; //element type
0116 int fSize; //sizeof element
0117 int fArrayLength; //cumulative size of all array dims
0118 int fArrayDim; //number of array dimensions
0119 int fMaxIndex[5]; //Maximum array index for array dimension "dim"
0120 int fOffset; //!element offset in class
0121 //FIXME Int_t fNewType; //!new element type when reading
0122 std::string fTypeName; //Data type name of data member
0123 };
0124
0125 class dummy_streamer_element : public streamer_element {
0126 typedef streamer_element parent;
0127 public: //iro
0128 virtual iro* copy() const {return new dummy_streamer_element(*this);}
0129 virtual bool stream(buffer& a_buffer) {
0130 //the below code skips correctly the data in the file.
0131 uint32 startpos = a_buffer.length();
0132 short v;
0133 unsigned int _s,_c;
0134 if(!a_buffer.read_version(v,_s,_c)) return false;
0135
0136 if(!parent::stream(a_buffer)) return false;
0137
0138 a_buffer.set_offset(startpos+_c+sizeof(unsigned int));
0139 if(!a_buffer.check_byte_count(_s,_c,"dummy_streamer_element")) return false;
0140 return true;
0141 }
0142 public:
0143 dummy_streamer_element(){}
0144 virtual ~dummy_streamer_element(){}
0145 protected:
0146 dummy_streamer_element(const dummy_streamer_element& a_from):iro(a_from),parent(a_from){}
0147 dummy_streamer_element& operator=(const dummy_streamer_element& a_from){
0148 parent::operator=(a_from);
0149 return *this;
0150 }
0151 };
0152
0153 class streamer_info : public virtual iro {
0154 static const std::string& s_store_class() {
0155 static const std::string s_v("TStreamerInfo");
0156 return s_v;
0157 }
0158 public:
0159 static const std::string& s_class() {
0160 static const std::string s_v("tools::rroot::streamer_info");
0161 return s_v;
0162 }
0163 static cid id_class() {return streamer_info_cid();}
0164 public: //iro
0165 virtual void* cast(const std::string& a_class) const {
0166 if(void* p = cmp_cast<streamer_info>(this,a_class)) return p;
0167 return 0;
0168 }
0169 virtual void* cast(cid a_class) const {
0170 if(void* p = cmp_cast<streamer_info>(this,a_class)) {return p;}
0171 else return 0;
0172 }
0173 virtual const std::string& s_cls() const {return s_class();}
0174 virtual iro* copy() const {return new streamer_info(*this);}
0175
0176 virtual bool stream(buffer& a_buffer) {
0177 short v;
0178 unsigned int _s,_c;
0179 if(!a_buffer.read_version(v,_s,_c)) return false;
0180
0181 if(!Named_stream(a_buffer,m_name,m_title)) return false;
0182 if(!a_buffer.read(m_check_sum)) return false;
0183 if(!a_buffer.read(m_streamed_class_version)) return false;
0184
0185 //TObjArray *fElements; //Array of TStreamerElements
0186 {obj_array<streamer_element>* obj;
0187 ifac::args args;
0188 args[ifac::arg_class()] = (void*)&(streamer_element::s_class());
0189 bool obj_created;
0190 if(!pointer_stream(a_buffer,m_fac,args,obj,obj_created)) {
0191 a_buffer.out() << "tools::rroot::streamer_info::stream : "
0192 << "can't read fElements."
0193 << std::endl;
0194 return false;
0195 }
0196 if(obj) m_elements.operator=(*obj);
0197 if(obj_created) delete obj;}
0198
0199 return a_buffer.check_byte_count(_s,_c,s_store_class());
0200 }
0201 public:
0202 void out(std::ostream& a_out) const {
0203 a_out << "streamer_info for class :"
0204 << " " << m_name << ", version=" << m_streamed_class_version
0205 << std::endl;
0206 tools_vforcit(streamer_element*,m_elements,it) (*it)->out(a_out);
0207 }
0208 public:
0209 streamer_info(ifac& a_fac)
0210 :m_fac(a_fac)
0211 ,m_name()
0212 ,m_title()
0213 ,m_check_sum(0)
0214 ,m_streamed_class_version(0)
0215 ,m_elements(a_fac)
0216 {
0217 #ifdef TOOLS_MEM
0218 mem::increment(s_class().c_str());
0219 #endif
0220 }
0221 virtual ~streamer_info(){
0222 #ifdef TOOLS_MEM
0223 mem::decrement(s_class().c_str());
0224 #endif
0225 }
0226 protected:
0227 streamer_info(const streamer_info& a_from)
0228 :iro(a_from)
0229 ,m_fac(a_from.m_fac)
0230 ,m_name(a_from.m_name)
0231 ,m_title(a_from.m_name)
0232 ,m_check_sum(a_from.m_check_sum)
0233 ,m_streamed_class_version(a_from.m_streamed_class_version)
0234 ,m_elements(a_from.m_elements)
0235 {
0236 #ifdef TOOLS_MEM
0237 mem::increment(s_class().c_str());
0238 #endif
0239 }
0240 streamer_info& operator=(const streamer_info& a_from){
0241 m_name = a_from.m_name;
0242 m_title = a_from.m_name;
0243 m_check_sum = a_from.m_check_sum;
0244 m_streamed_class_version = a_from.m_streamed_class_version;
0245 m_elements = a_from.m_elements;
0246 return *this;
0247 }
0248 public:
0249 const std::string& name() const {return m_name;}
0250 streamer_element* find_streamer_element(size_t a_index) const {
0251 if(a_index>=m_elements.size()) return 0;
0252 return m_elements[a_index];
0253 }
0254 protected:
0255 ifac& m_fac;
0256 protected: //Named
0257 std::string m_name;
0258 std::string m_title;
0259 protected:
0260 unsigned int m_check_sum; //checksum of original class
0261 int m_streamed_class_version; //Class version identifier
0262 //int fNumber; //!Unique identifier
0263 obj_array<streamer_element> m_elements; //Array of TStreamerElements
0264 };
0265
0266 }}
0267
0268 #endif