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 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/tools/wroot/tree (Version 11.3.0) and /externals/g4tools/include/tools/wroot/tree (Version 11.0.p1)


  1 // Copyright (C) 2010, Guy Barrand. All rights      1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.            2 // See the file tools.license for terms.
  3                                                     3 
  4 #ifndef tools_wroot_tree                            4 #ifndef tools_wroot_tree
  5 #define tools_wroot_tree                            5 #define tools_wroot_tree
  6                                                     6 
  7 #include "itree"                                    7 #include "itree"
  8 #include "iobject"                                  8 #include "iobject"
  9 #include "idir"                                     9 #include "idir"
 10                                                    10 
 11 #include "branch_element"                          11 #include "branch_element"
 12 #include "branch_object"                           12 #include "branch_object"
 13                                                    13 
 14 namespace tools {                                  14 namespace tools {
 15 namespace wroot {                                  15 namespace wroot {
 16                                                    16 
 17 class tree : public virtual iobject, public vi     17 class tree : public virtual iobject, public virtual itree {
 18 #ifdef TOOLS_MEM                                   18 #ifdef TOOLS_MEM
 19   static const std::string& s_class() {            19   static const std::string& s_class() {
 20     static const std::string s_v("tools::wroot     20     static const std::string s_v("tools::wroot::tree");
 21     return s_v;                                    21     return s_v;
 22   }                                                22   }
 23 #endif                                             23 #endif
 24 public: //iobject                                  24 public: //iobject
 25   virtual const std::string& name() const {ret     25   virtual const std::string& name() const {return m_name;}
 26   virtual const std::string& title() const {re     26   virtual const std::string& title() const {return m_title;}
 27   virtual const std::string& store_class_name(     27   virtual const std::string& store_class_name() const {
 28     static const std::string s_v("TTree");         28     static const std::string s_v("TTree");
 29     return s_v;                                    29     return s_v;
 30   }                                                30   }
 31   virtual bool stream(buffer& a_buffer) const      31   virtual bool stream(buffer& a_buffer) const {
 32     unsigned int c;                                32     unsigned int c;
 33     if(!a_buffer.write_version(5,c)) return fa     33     if(!a_buffer.write_version(5,c)) return false;
 34                                                    34 
 35     if(!Named_stream(a_buffer,m_name,m_title))     35     if(!Named_stream(a_buffer,m_name,m_title)) return false;
 36                                                    36 
 37     // Beurk.                                      37     // Beurk.
 38     if(!AttLine_stream(a_buffer)) return false     38     if(!AttLine_stream(a_buffer)) return false;
 39     if(!AttFill_stream(a_buffer)) return false     39     if(!AttFill_stream(a_buffer)) return false;
 40     if(!AttMarker_stream(a_buffer)) return fal     40     if(!AttMarker_stream(a_buffer)) return false;
 41                                                    41 
 42     double fEntries = (double)m_entries;           42     double fEntries = (double)m_entries;
 43     if(!a_buffer.write(fEntries)) return false     43     if(!a_buffer.write(fEntries)) return false;
 44                                                    44 
 45     double fTotBytes = (double)m_tot_bytes;        45     double fTotBytes = (double)m_tot_bytes;
 46     double fZipBytes = (double)m_zip_bytes;        46     double fZipBytes = (double)m_zip_bytes;
 47     if(!a_buffer.write(fTotBytes)) return fals     47     if(!a_buffer.write(fTotBytes)) return false;
 48     if(!a_buffer.write(fZipBytes)) return fals     48     if(!a_buffer.write(fZipBytes)) return false;
 49     if(!a_buffer.write((double)0)) return fals     49     if(!a_buffer.write((double)0)) return false; //fSavedBytes
 50     if(!a_buffer.write((int)0)) return false;      50     if(!a_buffer.write((int)0)) return false;    //fTimerInterval
 51     if(!a_buffer.write((int)25)) return false;     51     if(!a_buffer.write((int)25)) return false;   //fScanField (25)
 52     if(!a_buffer.write((int)0)) return false;      52     if(!a_buffer.write((int)0)) return false;    //fUpdate
 53     if(!a_buffer.write((int)1000000000)) retur     53     if(!a_buffer.write((int)1000000000)) return false; //fMaxEntryLoop
 54     int fMaxVirtualSize = 0;                       54     int fMaxVirtualSize = 0;
 55     int fAutoSave = 100000000;                     55     int fAutoSave = 100000000;
 56     if(!a_buffer.write(fMaxVirtualSize)) retur     56     if(!a_buffer.write(fMaxVirtualSize)) return false;
 57     if(!a_buffer.write(fAutoSave)) return fals     57     if(!a_buffer.write(fAutoSave)) return false;
 58     if(!a_buffer.write((int)1000000)) return f     58     if(!a_buffer.write((int)1000000)) return false;    //fEstimate;
 59                                                    59 
 60     if(!m_branches.stream(a_buffer)) return fa     60     if(!m_branches.stream(a_buffer)) return false;
 61                                                    61 
 62    {obj_array<base_leaf> m_leaves;                 62    {obj_array<base_leaf> m_leaves;
 63     tools_vforcit(branch*,m_branches,itb) {        63     tools_vforcit(branch*,m_branches,itb) {
 64       const std::vector<base_leaf*>& leaves =      64       const std::vector<base_leaf*>& leaves = (*itb)->leaves();
 65       tools_vforcit(base_leaf*,leaves,itl) {       65       tools_vforcit(base_leaf*,leaves,itl) {
 66         m_leaves.push_back(*itl); //WARNING :      66         m_leaves.push_back(*itl); //WARNING : ownership touchy.
 67       }                                            67       }
 68     }                                              68     }
 69     if(!m_leaves.stream(a_buffer)) return fals     69     if(!m_leaves.stream(a_buffer)) return false;
 70     m_leaves.clear();} //WARNING : important.      70     m_leaves.clear();} //WARNING : important.
 71                                                    71 
 72     // fIndexValues (TArrayD).                     72     // fIndexValues (TArrayD).
 73     if(!a_buffer.write_array(std::vector<doubl     73     if(!a_buffer.write_array(std::vector<double>())) return false; //TArrayD
 74     // fIndex (TArrayI).                           74     // fIndex (TArrayI).
 75     if(!a_buffer.write_array(std::vector<int>(     75     if(!a_buffer.write_array(std::vector<int>())) return false; //TArrayI
 76                                                    76 
 77     if(!a_buffer.set_byte_count(c)) return fal     77     if(!a_buffer.set_byte_count(c)) return false;
 78     return true;                                   78     return true;
 79   }                                                79   }
 80 public: //itree                                    80 public: //itree
 81   //virtual void add_tot_bytes(uint32 a_n) {m_     81   //virtual void add_tot_bytes(uint32 a_n) {m_tot_bytes += a_n;}
 82   //virtual void add_zip_bytes(uint32 a_n) {m_     82   //virtual void add_zip_bytes(uint32 a_n) {m_zip_bytes += a_n;}
 83   virtual idir& dir() {return m_dir;}              83   virtual idir& dir() {return m_dir;}
 84   virtual const idir& dir() const {return m_di     84   virtual const idir& dir() const {return m_dir;}
 85 public:                                            85 public:
 86   tree(idir& a_dir,const std::string& a_name,c     86   tree(idir& a_dir,const std::string& a_name,const std::string& a_title,bool a_managed = true)
 87   :m_dir(a_dir)                                    87   :m_dir(a_dir)
 88   ,m_out(a_dir.file().out())                       88   ,m_out(a_dir.file().out())
 89   ,m_name(a_name)                                  89   ,m_name(a_name)
 90   ,m_title(a_title)                                90   ,m_title(a_title)
 91   ,m_entries(0)                                    91   ,m_entries(0)
 92   ,m_tot_bytes(0)                                  92   ,m_tot_bytes(0)
 93   ,m_zip_bytes(0)                                  93   ,m_zip_bytes(0)
 94   {                                                94   {
 95 #ifdef TOOLS_MEM                                   95 #ifdef TOOLS_MEM
 96     mem::increment(s_class().c_str());             96     mem::increment(s_class().c_str());
 97 #endif                                             97 #endif
 98     if(a_managed) a_dir.append_object(this); /     98     if(a_managed) a_dir.append_object(this); //a_dir takes ownership of tree.
 99   }                                                99   }
100   virtual ~tree(){                                100   virtual ~tree(){
101 #ifdef TOOLS_MEM                                  101 #ifdef TOOLS_MEM
102     mem::decrement(s_class().c_str());            102     mem::decrement(s_class().c_str());
103 #endif                                            103 #endif
104   }                                               104   }
105 protected:                                        105 protected:
106   tree(const tree& a_from)                        106   tree(const tree& a_from)
107   :iobject(a_from),itree(a_from)                  107   :iobject(a_from),itree(a_from)
108   ,m_dir(a_from.m_dir)                            108   ,m_dir(a_from.m_dir)
109   ,m_out(a_from.m_out)                            109   ,m_out(a_from.m_out)
110   {}                                              110   {}
111   tree& operator=(const tree&){return *this;}     111   tree& operator=(const tree&){return *this;}
112 public:                                           112 public:
113   std::ostream& out() const {return m_out;}       113   std::ostream& out() const {return m_out;}
114   const std::vector<branch*>& branches() const    114   const std::vector<branch*>& branches() const {return m_branches;}
115   //uint64 tot_bytes() const {return m_tot_byt    115   //uint64 tot_bytes() const {return m_tot_bytes;}
116   //uint64 zip_bytes() const {return m_zip_byt    116   //uint64 zip_bytes() const {return m_zip_bytes;}
117   uint64 entries() const {return m_entries;}      117   uint64 entries() const {return m_entries;}
118                                                   118 
119   branch* create_branch(const std::string& a_n    119   branch* create_branch(const std::string& a_name){
120     const ifile& _file = m_dir.file();            120     const ifile& _file = m_dir.file();
121     branch* br = new branch(m_out,_file.byte_s    121     branch* br = new branch(m_out,_file.byte_swap(),_file.compression(),
122                             m_dir.seek_directo    122                             m_dir.seek_directory(),a_name,m_name,_file.verbose());
123     if(!br) return 0;                             123     if(!br) return 0;
124     m_branches.push_back(br);                     124     m_branches.push_back(br);
125     return br;                                    125     return br;
126   }                                               126   }
127                                                   127 
128   ////////////////////////////////////////////    128   ////////////////////////////////////////////////
129   /// ref : //////////////////////////////////    129   /// ref : //////////////////////////////////////
130   ////////////////////////////////////////////    130   ////////////////////////////////////////////////
131   template <class TYPE>                           131   template <class TYPE>
132   leaf_ref<TYPE>* create_leaf_ref(const std::s    132   leaf_ref<TYPE>* create_leaf_ref(const std::string& a_name,const TYPE& a_ref){
133     branch* br = create_branch(a_name);           133     branch* br = create_branch(a_name);
134     if(!br) return 0;                             134     if(!br) return 0;
135     return br->create_leaf_ref<TYPE>(a_name,a_    135     return br->create_leaf_ref<TYPE>(a_name,a_ref);
136   }                                               136   }
137                                                   137 
138   leaf_string_ref* create_leaf_string_ref(cons    138   leaf_string_ref* create_leaf_string_ref(const std::string& a_name,const std::string& a_ref){
139     branch* br = create_branch(a_name);           139     branch* br = create_branch(a_name);
140     if(!br) return 0;                             140     if(!br) return 0;
141     return br->create_leaf_string_ref(a_name,a    141     return br->create_leaf_string_ref(a_name,a_ref);
142   }                                               142   }
143                                                   143 
144   template <class T>                              144   template <class T>
145   leaf_element* create_std_vector_leaf_ref(con    145   leaf_element* create_std_vector_leaf_ref(const std::string& a_name,const std::vector<T>& a_ref){
146     const ifile& _file = m_dir.file();            146     const ifile& _file = m_dir.file();
147     std_vector_be_ref<T>* br = new std_vector_    147     std_vector_be_ref<T>* br = new std_vector_be_ref<T>(m_out,_file.byte_swap(),_file.compression(),
148                                                   148                                                         m_dir.seek_directory(),a_name,m_name,a_ref,_file.verbose());
149     leaf_element* le = br->create_leaf_element    149     leaf_element* le = br->create_leaf_element(a_name);
150     m_branches.push_back(br);                     150     m_branches.push_back(br);
151     return le;                                    151     return le;
152   }                                               152   }
153   ////////////////////////////////////////////    153   ////////////////////////////////////////////////
154   ////////////////////////////////////////////    154   ////////////////////////////////////////////////
155   ////////////////////////////////////////////    155   ////////////////////////////////////////////////
156   template <class T>                              156   template <class T>
157   std_vector_be_ref<T>* create_std_vector_be_r    157   std_vector_be_ref<T>* create_std_vector_be_ref(const std::string& a_name,const std::vector<T>& a_ref){
158     const ifile& _file = m_dir.file();            158     const ifile& _file = m_dir.file();
159     std_vector_be_ref<T>* br = new std_vector_    159     std_vector_be_ref<T>* br = new std_vector_be_ref<T>(m_out,_file.byte_swap(),_file.compression(),
160                                                   160                                                         m_dir.seek_directory(),a_name,m_name,a_ref,_file.verbose());
161     m_branches.push_back(br);                     161     m_branches.push_back(br);
162     return br;                                    162     return br;
163   }                                               163   }
164                                                   164 
165   template <class T>                              165   template <class T>
166   std_vector_be<T>* create_std_vector_be(const    166   std_vector_be<T>* create_std_vector_be(const std::string& a_name,const std::vector<T>& a_def = std::vector<T>()){
167     const ifile& _file = m_dir.file();            167     const ifile& _file = m_dir.file();
168     std_vector_be<T>* br = new std_vector_be<T    168     std_vector_be<T>* br = new std_vector_be<T>(m_out,_file.byte_swap(),_file.compression(),
169                                                   169                                                 m_dir.seek_directory(),a_name,m_name,a_def,_file.verbose());
170     m_branches.push_back(br);                     170     m_branches.push_back(br);
171     return br;                                    171     return br;
172   }                                               172   }
173                                                   173 
174   template <class T>                              174   template <class T>
175   std_vector_be_pointer<T>* create_std_vector_    175   std_vector_be_pointer<T>* create_std_vector_be_pointer(const std::string& a_name,std::vector<T>* a_pointer){
176     const ifile& _file = m_dir.file();            176     const ifile& _file = m_dir.file();
177     std_vector_be_pointer<T>* br = new std_vec    177     std_vector_be_pointer<T>* br = new std_vector_be_pointer<T>(m_out,_file.byte_swap(),_file.compression(),
178                                                   178                                                                 m_dir.seek_directory(),a_name,m_name,a_pointer,_file.verbose());
179     m_branches.push_back(br);                     179     m_branches.push_back(br);
180     return br;                                    180     return br;
181   }                                               181   }
182                                                   182 
183   template <class TYPE>                           183   template <class TYPE>
184   leaf<TYPE>* create_leaf(const std::string& a    184   leaf<TYPE>* create_leaf(const std::string& a_name){
185     branch* br = create_branch(a_name);           185     branch* br = create_branch(a_name);
186     if(!br) return 0;                             186     if(!br) return 0;
187     return br->create_leaf<TYPE>(a_name);         187     return br->create_leaf<TYPE>(a_name);
188   }                                               188   }
189                                                   189 
190   leaf_object* create_leaf(const std::string&     190   leaf_object* create_leaf(const std::string& a_name,const iobject& a_obj){
191     const ifile& _file = m_dir.file();            191     const ifile& _file = m_dir.file();
192     branch_object* br = new branch_object(m_ou    192     branch_object* br = new branch_object(m_out,_file.byte_swap(),_file.compression(),
193                                           m_di    193                                           m_dir.seek_directory(),a_name,m_name,_file.verbose());
194     m_branches.push_back(br);                     194     m_branches.push_back(br);
195     return br->create_leaf(a_name,a_obj);         195     return br->create_leaf(a_name,a_obj);
196   }                                               196   }
197                                                   197 
198   bool fill(uint32& a_nbytes) {                   198   bool fill(uint32& a_nbytes) {
199     // Fill all branches of a Tree :              199     // Fill all branches of a Tree :
200     //   This function loops on all the branch    200     //   This function loops on all the branches of this tree.
201     //   For each branch, it copies to the bra    201     //   For each branch, it copies to the branch buffer (basket) the current
202     //   values of the leaves data types.         202     //   values of the leaves data types.
203     //   If a leaf is a simple data type, a si    203     //   If a leaf is a simple data type, a simple conversion to a machine
204     //   independent format has to be done.       204     //   independent format has to be done.
205     a_nbytes = 0;                                 205     a_nbytes = 0;
206     tools_vforcit(branch*,m_branches,it) {        206     tools_vforcit(branch*,m_branches,it) {
207       //FIXME if ((*it)->testBit(kDoNotProcess    207       //FIXME if ((*it)->testBit(kDoNotProcess)) continue;
208       uint32 n,add_bytes,nout;                    208       uint32 n,add_bytes,nout;
209       if(!(*it)->fill(m_dir.file(),n,add_bytes    209       if(!(*it)->fill(m_dir.file(),n,add_bytes,nout)) {a_nbytes = 0;return false;}
210       a_nbytes += n;                              210       a_nbytes += n;
211       m_tot_bytes += add_bytes;                   211       m_tot_bytes += add_bytes;
212       m_zip_bytes += nout;                        212       m_zip_bytes += nout;
213     }                                             213     }
214                                                   214 
215     m_entries++;                                  215     m_entries++;
216                                                   216 
217     //if (fTotBytes - fSavedBytes > fAutoSave)    217     //if (fTotBytes - fSavedBytes > fAutoSave) {
218     //  if(!autoSave()) return false;             218     //  if(!autoSave()) return false;
219     //}                                           219     //}
220                                                   220 
221     return true;                                  221     return true;
222   }                                               222   }
223                                                   223 
224   void reset() {                                  224   void reset() {
225     // Reset buffers and entries count in all     225     // Reset buffers and entries count in all branches/leaves
226     m_entries       = 0;                          226     m_entries       = 0;
227     m_tot_bytes     = 0;                          227     m_tot_bytes     = 0;
228     m_zip_bytes     = 0;                          228     m_zip_bytes     = 0;
229   //fSavedBytes     = 0;                          229   //fSavedBytes     = 0;
230   //fTotalBuffers   = 0;                          230   //fTotalBuffers   = 0;
231   //fChainOffset    = 0;                          231   //fChainOffset    = 0;
232    {tools_vforcit(branch*,m_branches,it) (*it)    232    {tools_vforcit(branch*,m_branches,it) (*it)->reset();}
233   }                                               233   }
234 protected:                                        234 protected:
235   idir& m_dir;                                    235   idir& m_dir;
236   std::ostream& m_out;                            236   std::ostream& m_out;
237   //Named                                         237   //Named
238   std::string m_name;                             238   std::string m_name;
239   std::string m_title;                            239   std::string m_title;
240                                                   240 
241   obj_array<branch> m_branches;                   241   obj_array<branch> m_branches;
242   uint64 m_entries;   // Number of entries        242   uint64 m_entries;   // Number of entries
243   uint64 m_tot_bytes; // Total number of bytes    243   uint64 m_tot_bytes; // Total number of bytes in branches before compression
244   uint64 m_zip_bytes; // Total number of bytes    244   uint64 m_zip_bytes; // Total number of bytes in branches after compression
245 };                                                245 };
246                                                   246 
247 }}                                                247 }}
248                                                   248 
249 #endif                                            249 #endif