Back to home page

EIC code displayed by LXR

 
 

    


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