Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/wroot/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_wroot_branch_element
0005 #define tools_wroot_branch_element
0006 
0007 #include "branch"
0008 
0009 namespace tools {
0010 namespace wroot {
0011 
0012 inline const std::string& branch_element_store_class() {
0013   static const std::string s_v("TBranchElement");
0014   return s_v;
0015 }
0016 
0017 class branch_element : public branch {
0018   typedef branch parent;
0019 #ifdef TOOLS_MEM
0020   static const std::string& s_class() {
0021     static const std::string s_v("tools::wroot::branch_element");
0022     return s_v;
0023   }
0024 #endif
0025 public: //ibo
0026   virtual const std::string& store_cls() const {return branch_element_store_class();}
0027   virtual bool stream(buffer& a_buffer) const {
0028     unsigned int c;
0029     if(!a_buffer.write_version(1,c)) return false;
0030     if(!parent::stream(a_buffer)) return false;
0031 
0032     if(!a_buffer.write(fClassName)) return false;
0033     if(!a_buffer.write(fClassVersion)) return false;
0034     if(!a_buffer.write(fID)) return false;
0035     if(!a_buffer.write(fType)) return false;
0036     if(!a_buffer.write(fStreamerType)) return false;
0037 
0038     if(!a_buffer.set_byte_count(c)) return false;
0039     return true;
0040   }
0041 
0042 public:
0043   branch_element(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
0044                  seek a_seek_directory,const std::string& a_name,const std::string& a_title,bool a_verbose)
0045   :parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,a_verbose)
0046   ,fClassVersion(0)
0047   ,fID(0)
0048   ,fType(0)
0049   ,fStreamerType(-1)
0050   {
0051 #ifdef TOOLS_MEM
0052     mem::increment(s_class().c_str());
0053 #endif
0054   }
0055   virtual ~branch_element(){
0056 #ifdef TOOLS_MEM
0057     mem::decrement(s_class().c_str());
0058 #endif
0059   }
0060 protected:
0061   branch_element(const branch_element& a_from):ibo(a_from),parent(a_from) {}
0062   branch_element& operator=(const branch_element& a_from){parent::operator=(a_from);return *this;}
0063 public:
0064   leaf_element* create_leaf_element(const std::string& a_name){
0065     leaf_element* lf = new leaf_element(m_out,a_name,fID,fType);
0066     m_leaves.push_back(lf);
0067     return lf;
0068   }
0069 protected:
0070   virtual bool fill_leaves(buffer&) {return false;} //must be derived.
0071 protected:
0072   std::string fClassName; //Class name of referenced object
0073   int fClassVersion;      //Version number of class
0074   int fID;                //element serial number in fInfo
0075   int fType;              //branch type
0076   int fStreamerType;      //branch streamer type
0077 };
0078 
0079 template <class T>
0080 class std_vector_be_ref : public branch_element {
0081   typedef branch_element parent;
0082 #ifdef TOOLS_MEM
0083   static const std::string& s_class() {
0084     static const std::string s_v("tools::wroot::std_vector_be_ref");
0085     return s_v;
0086   }
0087 #endif
0088 public:
0089   std_vector_be_ref(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
0090                     seek a_seek_directory,
0091                     const std::string& a_name,const std::string& a_title,const std::vector<T>& a_ref,bool a_verbose)
0092   :parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,a_verbose)
0093   ,m_ref(a_ref)
0094   {
0095 #ifdef TOOLS_MEM
0096     mem::increment(s_class().c_str());
0097 #endif
0098     fClassName = "vector<"+stype(T())+">";
0099     fClassVersion = 0;
0100     fID = -1;
0101     fType = 0;
0102     fStreamerType  = -1; // TStreamerInfo::kSTLp;
0103   }
0104   virtual ~std_vector_be_ref(){
0105 #ifdef TOOLS_MEM
0106     mem::decrement(s_class().c_str());
0107 #endif
0108   }
0109 protected:
0110   std_vector_be_ref(const std_vector_be_ref& a_from)
0111   :ibo(a_from)
0112   ,parent(a_from)
0113   ,m_ref(a_from.m_ref)
0114   {}
0115   std_vector_be_ref& operator=(const std_vector_be_ref& a_from){
0116     parent::operator=(a_from);
0117     return *this;
0118   }
0119 protected:
0120   virtual bool fill_leaves(buffer& a_buffer) {
0121     unsigned int c;
0122     if(!a_buffer.write_version(4,c)) return false;
0123     if(!a_buffer.write((int)m_ref.size())) return false;
0124     if(m_ref.size()) {
0125       // The awfull below is to pass T=bool :
0126       const T& vr = m_ref[0];
0127       if(!a_buffer.write_fast_array(&vr,(int)m_ref.size())) return false;
0128     }
0129     if(!a_buffer.set_byte_count(c)) return false;
0130     return true;
0131   }
0132 public:
0133   const std::vector<T>& variable() const {return m_ref;}
0134   std::vector<T>& variable() {return const_cast< std::vector<T>& >(m_ref);}
0135 protected:
0136   const std::vector<T>& m_ref;
0137 };
0138 
0139 template <class T>
0140 class std_vector_be : public std_vector_be_ref<T> {
0141   typedef std_vector_be_ref<T> parent;
0142 #ifdef TOOLS_MEM
0143   static const std::string& s_class() {
0144     static const std::string s_v("tools::wroot::std_vector_be");
0145     return s_v;
0146   }
0147 #endif
0148 public:
0149   std_vector_be(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
0150                 seek a_seek_directory,
0151                 const std::string& a_name,const std::string& a_title,const std::vector<T>& a_def,bool a_verbose)
0152   :parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,m_value,a_verbose)
0153   ,m_def(a_def),m_value(a_def)
0154   {
0155 #ifdef TOOLS_MEM
0156     mem::increment(s_class().c_str());
0157 #endif
0158   }
0159   virtual ~std_vector_be(){
0160 #ifdef TOOLS_MEM
0161     mem::decrement(s_class().c_str());
0162 #endif
0163   }
0164 protected:
0165   std_vector_be(const std_vector_be& a_from)
0166   :ibo(a_from)
0167   ,parent(a_from)
0168   ,m_def(a_from.m_def)
0169   ,m_value(a_from.m_value)
0170   {}
0171   std_vector_be& operator=(const std_vector_be& a_from){
0172     parent::operator=(a_from);
0173     m_def = a_from.m_def;
0174     m_value = a_from.m_value;
0175     return *this;
0176   }
0177 protected:
0178   std::vector<T> m_def;
0179   std::vector<T> m_value;
0180 };
0181 
0182 template <class T>
0183 class std_vector_be_pointer : public branch_element {
0184   typedef branch_element parent;
0185 #ifdef TOOLS_MEM
0186   static const std::string& s_class() {
0187     static const std::string s_v("tools::wroot::std_vector_be_pointer");
0188     return s_v;
0189   }
0190 #endif
0191 public:
0192   std_vector_be_pointer(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
0193                     seek a_seek_directory,
0194                     const std::string& a_name,const std::string& a_title,std::vector<T>* a_pointer,bool a_verbose)
0195   :parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,a_verbose)
0196   ,m_pointer(a_pointer)
0197   {
0198 #ifdef TOOLS_MEM
0199     mem::increment(s_class().c_str());
0200 #endif
0201     fClassName = "vector<"+stype(T())+">";
0202     fClassVersion = 0;
0203     fID = -1;
0204     fType = 0;
0205     fStreamerType  = -1; // TStreamerInfo::kSTLp;
0206   }
0207   virtual ~std_vector_be_pointer(){
0208 #ifdef TOOLS_MEM
0209     mem::decrement(s_class().c_str());
0210 #endif
0211   }
0212 protected:
0213   std_vector_be_pointer(const std_vector_be_pointer& a_from)
0214   :ibo(a_from)
0215   ,parent(a_from)
0216   ,m_pointer(a_from.m_pointer)
0217   {}
0218   std_vector_be_pointer& operator=(const std_vector_be_pointer& a_from){
0219     parent::operator=(a_from);
0220     return *this;
0221   }
0222 protected:
0223   virtual bool fill_leaves(buffer& a_buffer) {
0224     if(!m_pointer) return false;
0225     unsigned int c;
0226     if(!a_buffer.write_version(4,c)) return false;
0227     if(!a_buffer.write((int)m_pointer->size())) return false;
0228     if(m_pointer->size()) {
0229       // The awfull below is to pass T=bool :
0230       T& vr = (*m_pointer)[0];
0231       if(!a_buffer.write_fast_array(&vr,(int)m_pointer->size())) return false;
0232     }
0233     if(!a_buffer.set_byte_count(c)) return false;
0234     return true;
0235   }
0236 public:
0237   void set_pointer(std::vector<T>* a_pointer) {m_pointer = a_pointer;}
0238   const std::vector<T>* get_pointer() const {return m_pointer;}
0239   std::vector<T>* get_pointer() {return m_pointer;}
0240 protected:
0241   std::vector<T>* m_pointer;
0242 };
0243 
0244 }}
0245 
0246 #endif