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 public: //ibo
0020 virtual const std::string& store_cls() const {return branch_element_store_class();}
0021 virtual bool stream(buffer& a_buffer) const {
0022 unsigned int c;
0023 if(!a_buffer.write_version(1,c)) return false;
0024 if(!parent::stream(a_buffer)) return false;
0025
0026 if(!a_buffer.write(fClassName)) return false;
0027 if(!a_buffer.write(fClassVersion)) return false;
0028 if(!a_buffer.write(fID)) return false;
0029 if(!a_buffer.write(fType)) return false;
0030 if(!a_buffer.write(fStreamerType)) return false;
0031
0032 if(!a_buffer.set_byte_count(c)) return false;
0033 return true;
0034 }
0035
0036 public:
0037 branch_element(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
0038 seek a_seek_directory,const std::string& a_name,const std::string& a_title,bool a_verbose)
0039 :parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,a_verbose)
0040 ,fClassVersion(0)
0041 ,fID(0)
0042 ,fType(0)
0043 ,fStreamerType(-1)
0044 {
0045 }
0046 virtual ~branch_element(){
0047 }
0048 protected:
0049 branch_element(const branch_element& a_from):ibo(a_from),parent(a_from) {}
0050 branch_element& operator=(const branch_element& a_from){parent::operator=(a_from);return *this;}
0051 public:
0052 leaf_element* create_leaf_element(const std::string& a_name){
0053 leaf_element* lf = new leaf_element(m_out,a_name,fID,fType);
0054 m_leaves.push_back(lf);
0055 return lf;
0056 }
0057 protected:
0058 virtual bool fill_leaves(buffer&) {return false;} //must be derived.
0059 protected:
0060 std::string fClassName; //Class name of referenced object
0061 int fClassVersion; //Version number of class
0062 int fID; //element serial number in fInfo
0063 int fType; //branch type
0064 int fStreamerType; //branch streamer type
0065 };
0066
0067 template <class T>
0068 class std_vector_be_ref : public branch_element {
0069 typedef branch_element parent;
0070 public:
0071 std_vector_be_ref(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
0072 seek a_seek_directory,
0073 const std::string& a_name,const std::string& a_title,const std::vector<T>& a_ref,bool a_verbose)
0074 :parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,a_verbose)
0075 ,m_ref(a_ref)
0076 {
0077 fClassName = "vector<"+stype(T())+">";
0078 fClassVersion = 0;
0079 fID = -1;
0080 fType = 0;
0081 fStreamerType = -1; // TStreamerInfo::kSTLp;
0082 }
0083 virtual ~std_vector_be_ref(){
0084 }
0085 protected:
0086 std_vector_be_ref(const std_vector_be_ref& a_from)
0087 :ibo(a_from)
0088 ,parent(a_from)
0089 ,m_ref(a_from.m_ref)
0090 {}
0091 std_vector_be_ref& operator=(const std_vector_be_ref& a_from){
0092 parent::operator=(a_from);
0093 return *this;
0094 }
0095 protected:
0096 virtual bool fill_leaves(buffer& a_buffer) {
0097 unsigned int c;
0098 if(!a_buffer.write_version(4,c)) return false;
0099 if(!a_buffer.write((int)m_ref.size())) return false;
0100 if(m_ref.size()) {
0101 // The awfull below is to pass T=bool :
0102 const T& vr = m_ref[0];
0103 if(!a_buffer.write_fast_array(&vr,(int)m_ref.size())) return false;
0104 }
0105 if(!a_buffer.set_byte_count(c)) return false;
0106 return true;
0107 }
0108 public:
0109 const std::vector<T>& variable() const {return m_ref;}
0110 std::vector<T>& variable() {return const_cast< std::vector<T>& >(m_ref);}
0111 protected:
0112 const std::vector<T>& m_ref;
0113 };
0114
0115 template <class T>
0116 class std_vector_be : public std_vector_be_ref<T> {
0117 typedef std_vector_be_ref<T> parent;
0118 public:
0119 std_vector_be(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
0120 seek a_seek_directory,
0121 const std::string& a_name,const std::string& a_title,const std::vector<T>& a_def,bool a_verbose)
0122 :parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,m_value,a_verbose)
0123 ,m_def(a_def),m_value(a_def)
0124 {
0125 }
0126 virtual ~std_vector_be(){
0127 }
0128 protected:
0129 std_vector_be(const std_vector_be& a_from)
0130 :ibo(a_from)
0131 ,parent(a_from)
0132 ,m_def(a_from.m_def)
0133 ,m_value(a_from.m_value)
0134 {}
0135 std_vector_be& operator=(const std_vector_be& a_from){
0136 parent::operator=(a_from);
0137 m_def = a_from.m_def;
0138 m_value = a_from.m_value;
0139 return *this;
0140 }
0141 protected:
0142 std::vector<T> m_def;
0143 std::vector<T> m_value;
0144 };
0145
0146 template <class T>
0147 class std_vector_be_pointer : public branch_element {
0148 typedef branch_element parent;
0149 public:
0150 std_vector_be_pointer(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,
0151 seek a_seek_directory,
0152 const std::string& a_name,const std::string& a_title,std::vector<T>* a_pointer,bool a_verbose)
0153 :parent(a_out,a_byte_swap,a_compression,a_seek_directory,a_name,a_title,a_verbose)
0154 ,m_pointer(a_pointer)
0155 {
0156 fClassName = "vector<"+stype(T())+">";
0157 fClassVersion = 0;
0158 fID = -1;
0159 fType = 0;
0160 fStreamerType = -1; // TStreamerInfo::kSTLp;
0161 }
0162 virtual ~std_vector_be_pointer(){
0163 }
0164 protected:
0165 std_vector_be_pointer(const std_vector_be_pointer& a_from)
0166 :ibo(a_from)
0167 ,parent(a_from)
0168 ,m_pointer(a_from.m_pointer)
0169 {}
0170 std_vector_be_pointer& operator=(const std_vector_be_pointer& a_from){
0171 parent::operator=(a_from);
0172 return *this;
0173 }
0174 protected:
0175 virtual bool fill_leaves(buffer& a_buffer) {
0176 if(!m_pointer) return false;
0177 unsigned int c;
0178 if(!a_buffer.write_version(4,c)) return false;
0179 if(!a_buffer.write((int)m_pointer->size())) return false;
0180 if(m_pointer->size()) {
0181 // The awfull below is to pass T=bool :
0182 T& vr = (*m_pointer)[0];
0183 if(!a_buffer.write_fast_array(&vr,(int)m_pointer->size())) return false;
0184 }
0185 if(!a_buffer.set_byte_count(c)) return false;
0186 return true;
0187 }
0188 public:
0189 void set_pointer(std::vector<T>* a_pointer) {m_pointer = a_pointer;}
0190 const std::vector<T>* get_pointer() const {return m_pointer;}
0191 std::vector<T>* get_pointer() {return m_pointer;}
0192 protected:
0193 std::vector<T>* m_pointer;
0194 };
0195
0196 }}
0197
0198 #endif