Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/externals/g4tools/include/tools/waxml/ntuple

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 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/waxml/ntuple (Version 11.3.0) and /externals/g4tools/include/tools/waxml/ntuple (Version 11.1.1)


  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_waxml_ntuple                          4 #ifndef tools_waxml_ntuple
  5 #define tools_waxml_ntuple                          5 #define tools_waxml_ntuple
  6                                                     6 
  7 // A ntuple class to write at the aida tuple f      7 // A ntuple class to write at the aida tuple format.
  8 // Each add_row() write a row at the aida tupl      8 // Each add_row() write a row at the aida tuple format.
  9                                                     9 
 10 #include "../vfind"                                10 #include "../vfind"
 11 #include "../vmanip"                               11 #include "../vmanip"
 12 #include "../sout"                                 12 #include "../sout"
 13 #include "../srep"                                 13 #include "../srep"
 14 #include "../tos"                                  14 #include "../tos"
 15 #include "../forit"                                15 #include "../forit"
 16                                                    16 
 17 #include <ostream>                                 17 #include <ostream>
 18                                                    18 
 19 // for sub_ntuple :                                19 // for sub_ntuple :
 20 #include "../scast"                                20 #include "../scast"
 21 #include <sstream>                                 21 #include <sstream>
 22                                                    22 
 23 #include "../ntuple_booking"                       23 #include "../ntuple_booking"
 24                                                    24 
 25 namespace tools {                                  25 namespace tools {
 26 namespace waxml {                                  26 namespace waxml {
 27                                                    27 
 28 class ntuple {                                     28 class ntuple {
 29 protected:                                         29 protected:
 30                                                    30 
 31   class iobj {                                     31   class iobj {
 32   public:                                          32   public:
 33     virtual ~iobj(){}                              33     virtual ~iobj(){}
 34   public:                                          34   public:
 35     virtual void* cast(cid) const = 0;             35     virtual void* cast(cid) const = 0;
 36     virtual cid id_cls() const = 0;                36     virtual cid id_cls() const = 0;
 37   public:                                          37   public:
 38     virtual const std::string& name() const =      38     virtual const std::string& name() const = 0;
 39     virtual const std::string& aida_type() con     39     virtual const std::string& aida_type() const = 0;
 40   };                                               40   };
 41                                                    41 
 42   class leaf : public virtual iobj {               42   class leaf : public virtual iobj {
 43   public:                                          43   public:
 44     static cid id_class() {return 100;}            44     static cid id_class() {return 100;}
 45   public: //iobj                                   45   public: //iobj
 46     virtual void* cast(cid a_class) const {        46     virtual void* cast(cid a_class) const {
 47       if(void* p = cmp_cast<leaf>(this,a_class     47       if(void* p = cmp_cast<leaf>(this,a_class)) {return p;}
 48       return 0;                                    48       return 0;
 49     }                                              49     }
 50     virtual cid id_cls() const {return id_clas     50     virtual cid id_cls() const {return id_class();}
 51   public:                                          51   public:
 52     virtual const std::string& s_def() const =     52     virtual const std::string& s_def() const = 0;
 53     virtual void s_value(std::string&) const =     53     virtual void s_value(std::string&) const = 0;
 54   public:                                          54   public:
 55     leaf(){}                                       55     leaf(){}
 56     virtual ~leaf(){}                              56     virtual ~leaf(){}
 57     leaf(const leaf& a_from):iobj(a_from){}        57     leaf(const leaf& a_from):iobj(a_from){}
 58     leaf& operator=(const leaf&){return *this;     58     leaf& operator=(const leaf&){return *this;}
 59   };                                               59   };
 60                                                    60 
 61   static const std::string& s_aida_type(int) {     61   static const std::string& s_aida_type(int) {
 62     static const std::string s_v("int");           62     static const std::string s_v("int");
 63     return s_v;                                    63     return s_v;
 64   }                                                64   }
 65   static const std::string& s_aida_type(float)     65   static const std::string& s_aida_type(float) {
 66     static const std::string s_v("float");         66     static const std::string s_v("float");
 67     return s_v;                                    67     return s_v;
 68   }                                                68   }
 69   static const std::string& s_aida_type(double     69   static const std::string& s_aida_type(double) {
 70     static const std::string s_v("double");        70     static const std::string s_v("double");
 71     return s_v;                                    71     return s_v;
 72   }                                                72   }
 73   static const std::string& s_aida_type(const      73   static const std::string& s_aida_type(const std::string&) {
 74     static const std::string s_v("string");        74     static const std::string s_v("string");
 75     return s_v;                                    75     return s_v;
 76   }                                                76   }
 77                                                    77 
 78   static const std::string& s_aida_type_ituple     78   static const std::string& s_aida_type_ituple() {
 79     static const std::string s_v("ITuple");        79     static const std::string s_v("ITuple");
 80     return s_v;                                    80     return s_v;
 81   }                                                81   }
 82                                                    82 
 83 public:                                            83 public:
 84   template <class T>                               84   template <class T>
 85   class column : public leaf {                     85   class column : public leaf {
 86   public:                                          86   public:
 87     static cid id_class() {return 200+_cid(T()     87     static cid id_class() {return 200+_cid(T());}
 88   public: //iobj                                   88   public: //iobj
 89     virtual void* cast(cid a_class) const {        89     virtual void* cast(cid a_class) const {
 90       if(void* p = cmp_cast< column<T> >(this,     90       if(void* p = cmp_cast< column<T> >(this,a_class)) {return p;}
 91       return leaf::cast(a_class);                  91       return leaf::cast(a_class);
 92     }                                              92     }
 93     virtual cid id_cls() const {return id_clas     93     virtual cid id_cls() const {return id_class();}
 94   public:                                          94   public:
 95     virtual const std::string& name() const {r     95     virtual const std::string& name() const {return m_name;}
 96     virtual const std::string& aida_type() con     96     virtual const std::string& aida_type() const {return s_aida_type(T());}
 97   public: //leaf                                   97   public: //leaf
 98     virtual const std::string& s_def() const {     98     virtual const std::string& s_def() const {return m_def;}
 99     virtual void s_value(std::string& a_s) con     99     virtual void s_value(std::string& a_s) const {a_s = tos(m_tmp);}
100   public:                                         100   public:
101     column(const std::string& a_name,const T&     101     column(const std::string& a_name,const T& a_def)
102     :m_name(a_name),m_def(tos(a_def)),m_tmp(a_    102     :m_name(a_name),m_def(tos(a_def)),m_tmp(a_def)
103     {}                                            103     {}
104     virtual ~column(){}                           104     virtual ~column(){}
105   protected:                                      105   protected:
106     column(const column& a_from)                  106     column(const column& a_from)
107     :leaf(a_from)                                 107     :leaf(a_from)
108     ,m_name(a_from.m_name)                        108     ,m_name(a_from.m_name)
109     ,m_def(a_from.m_def)                          109     ,m_def(a_from.m_def)
110     ,m_tmp(a_from.m_tmp)                          110     ,m_tmp(a_from.m_tmp)
111     {}                                            111     {}
112     column& operator=(const column& a_from){      112     column& operator=(const column& a_from){
113       m_name = a_from.m_name;                     113       m_name = a_from.m_name;
114       m_def = a_from.m_def;                       114       m_def = a_from.m_def;
115       m_tmp = a_from.m_tmp;                       115       m_tmp = a_from.m_tmp;
116       return *this;                               116       return *this;
117     }                                             117     }
118   public:                                         118   public:
119     bool fill(const T& a_value) {m_tmp = a_val    119     bool fill(const T& a_value) {m_tmp = a_value;return true;}
120   protected:                                      120   protected:
121     std::string m_name;                           121     std::string m_name;
122     std::string m_def;                            122     std::string m_def;
123     T m_tmp;                                      123     T m_tmp;
124   };                                              124   };
125                                                   125 
126                                                   126 
127   class sub_ntuple : public virtual iobj {        127   class sub_ntuple : public virtual iobj {
128   public:                                         128   public:
129     static cid id_class() {return 300;}           129     static cid id_class() {return 300;}
130   public: //iobj                                  130   public: //iobj
131     virtual void* cast(cid a_class) const {       131     virtual void* cast(cid a_class) const {
132       if(void* p = cmp_cast<sub_ntuple>(this,a    132       if(void* p = cmp_cast<sub_ntuple>(this,a_class)) {return p;}
133       return 0;                                   133       return 0;
134     }                                             134     }
135     virtual cid id_cls() const {return id_clas    135     virtual cid id_cls() const {return id_class();}
136   public:                                         136   public:
137     virtual const std::string& name() const {r    137     virtual const std::string& name() const {return m_name;}
138     virtual const std::string& aida_type() con    138     virtual const std::string& aida_type() const {return s_aida_type_ituple();}
139   public:                                         139   public:
140     sub_ntuple(const std::string& a_name,const    140     sub_ntuple(const std::string& a_name,const std::string& a_spaces)
141     :m_name(a_name),m_spaces(a_spaces){}          141     :m_name(a_name),m_spaces(a_spaces){}
142     virtual ~sub_ntuple(){}                       142     virtual ~sub_ntuple(){}
143   protected:                                      143   protected:
144     sub_ntuple(const sub_ntuple& a_from)          144     sub_ntuple(const sub_ntuple& a_from)
145     :iobj(a_from),m_name(a_from.m_name){}         145     :iobj(a_from),m_name(a_from.m_name){}
146     sub_ntuple& operator=(const sub_ntuple&){r    146     sub_ntuple& operator=(const sub_ntuple&){return *this;}
147   public:                                         147   public:
148     template <class T>                            148     template <class T>
149     column<T>* create_column(const std::string    149     column<T>* create_column(const std::string& a_name,const T& a_def = T()) {
150       if(find_named<iobj>(m_cols,a_name)) retu    150       if(find_named<iobj>(m_cols,a_name)) return 0;
151       column<T>* col = new column<T>(a_name,a_    151       column<T>* col = new column<T>(a_name,a_def);
152       if(!col) return 0;                          152       if(!col) return 0;
153       m_cols.push_back(col);                      153       m_cols.push_back(col);
154       return col;                                 154       return col;
155     }                                             155     }
156                                                   156 
157     sub_ntuple* create_sub_ntuple(const std::s    157     sub_ntuple* create_sub_ntuple(const std::string& a_name){
158       if(find_named<iobj>(m_cols,a_name)) retu    158       if(find_named<iobj>(m_cols,a_name)) return 0;
159       std::string spaces;                         159       std::string spaces;
160       for(unsigned int i=0;i<4;i++) spaces +=     160       for(unsigned int i=0;i<4;i++) spaces += " ";
161       sub_ntuple* col = new sub_ntuple(a_name,    161       sub_ntuple* col = new sub_ntuple(a_name,m_spaces+spaces);
162       if(!col) return 0;                          162       if(!col) return 0;
163       m_cols.push_back(col);                      163       m_cols.push_back(col);
164       return col;                                 164       return col;
165     }                                             165     }
166                                                   166 
167                                                   167 
168     const std::vector<iobj*>& columns() const     168     const std::vector<iobj*>& columns() const {return m_cols;}
169                                                   169 
170     std::string booking(bool a_xml_esc) const     170     std::string booking(bool a_xml_esc) const {
171       std::string _s;                             171       std::string _s;
172       get_booking(m_cols,a_xml_esc,_s);           172       get_booking(m_cols,a_xml_esc,_s);
173       return _s;                                  173       return _s;
174     }                                             174     }
175     void reset() {m_tmp.clear();}                 175     void reset() {m_tmp.clear();}
176     const std::string& value() const {return m    176     const std::string& value() const {return m_tmp;}
177                                                   177 
178     bool add_row() {                              178     bool add_row() {
179       if(m_cols.empty()) return false;            179       if(m_cols.empty()) return false;
180       std::ostringstream sout;                    180       std::ostringstream sout;
181       sout << m_spaces << "<row>" << std::endl    181       sout << m_spaces << "<row>" << std::endl;
182       tools_vforcit(iobj*,m_cols,it) {            182       tools_vforcit(iobj*,m_cols,it) {
183         if(sub_ntuple* sub = id_cast<iobj,sub_    183         if(sub_ntuple* sub = id_cast<iobj,sub_ntuple>(*(*it))) {
184           sout << m_spaces << "  <entryITuple>    184           sout << m_spaces << "  <entryITuple>" << std::endl;
185           sout << sub->value();                   185           sout << sub->value();
186           sout << m_spaces << "  </entryITuple    186           sout << m_spaces << "  </entryITuple>" << std::endl;
187           sub->reset();                           187           sub->reset();
188         } else if(leaf* lf = id_cast<iobj,leaf    188         } else if(leaf* lf = id_cast<iobj,leaf>(*(*it))){
189           std::string _sv;                        189           std::string _sv;
190           lf->s_value(_sv);                       190           lf->s_value(_sv);
191           sout << m_spaces << "  <entry"          191           sout << m_spaces << "  <entry"
192                << " value=\"" << _sv              192                << " value=\"" << _sv
193                << "\"/>" << std::endl;            193                << "\"/>" << std::endl;
194         }                                         194         }
195       }                                           195       }
196       sout << m_spaces << "</row>" << std::end    196       sout << m_spaces << "</row>" << std::endl;
197                                                   197 
198       m_tmp += sout.str();                        198       m_tmp += sout.str();
199                                                   199 
200       return true;                                200       return true;
201     }                                             201     }
202   protected:                                      202   protected:
203     std::string m_name;                           203     std::string m_name;
204     std::string m_spaces;                         204     std::string m_spaces;
205     std::vector<iobj*> m_cols;                    205     std::vector<iobj*> m_cols;
206     std::string m_tmp;                            206     std::string m_tmp;
207   };                                              207   };
208                                                   208 
209   template <class T>                              209   template <class T>
210   class std_vector_column : public leaf {         210   class std_vector_column : public leaf {
211   public:                                         211   public:
212     static cid id_class() {return 200+_cid_std    212     static cid id_class() {return 200+_cid_std_vector<T>();}
213   public: //iobj                                  213   public: //iobj
214     virtual void* cast(cid a_class) const {       214     virtual void* cast(cid a_class) const {
215       if(void* p = cmp_cast<std_vector_column>    215       if(void* p = cmp_cast<std_vector_column>(this,a_class)) {return p;}
216       return leaf::cast(a_class);                 216       return leaf::cast(a_class);
217     }                                             217     }
218     virtual cid id_cls() const {return id_clas    218     virtual cid id_cls() const {return id_class();}
219   public:                                         219   public:
220     virtual const std::string& name() const {r    220     virtual const std::string& name() const {return m_name;}
221     virtual const std::string& aida_type() con    221     virtual const std::string& aida_type() const {return s_aida_type(T());}
222   public: //leaf                                  222   public: //leaf
223     virtual const std::string& s_def() const {    223     virtual const std::string& s_def() const {return m_def;} //not used.
224     virtual void s_value(std::string& a_s) con    224     virtual void s_value(std::string& a_s) const {
225       std::ostringstream sout;                    225       std::ostringstream sout;
226       sout << m_spaces << "<entryITuple>" << s    226       sout << m_spaces << "<entryITuple>" << std::endl;
227       typedef typename std::vector<T>::const_i    227       typedef typename std::vector<T>::const_iterator it_t;
228       for(it_t it=m_user_vec.begin();it!=m_use    228       for(it_t it=m_user_vec.begin();it!=m_user_vec.end();++it) {
229         sout << m_spaces << "  <row><entry" <<    229         sout << m_spaces << "  <row><entry" << " value=\"" << tos(*it) << "\"/></row>" << std::endl;
230       }                                           230       }
231       sout << m_spaces << "</entryITuple>" <<     231       sout << m_spaces << "</entryITuple>" << std::endl;
232       a_s = sout.str();                           232       a_s = sout.str();
233     }                                             233     }
234   public:                                         234   public:
235     std_vector_column(const std::string& a_nam    235     std_vector_column(const std::string& a_name,std::vector<T>& a_user_vec,const std::string& a_spaces)
236     :m_name(a_name)                               236     :m_name(a_name)
237     ,m_user_vec(a_user_vec)                       237     ,m_user_vec(a_user_vec)
238     ,m_spaces(a_spaces)                           238     ,m_spaces(a_spaces)
239     {}                                            239     {}
240     virtual ~std_vector_column(){}                240     virtual ~std_vector_column(){}
241   protected:                                      241   protected:
242     std_vector_column(const std_vector_column&    242     std_vector_column(const std_vector_column& a_from)
243     :leaf(a_from)                                 243     :leaf(a_from)
244     ,m_name(a_from.m_name)                        244     ,m_name(a_from.m_name)
245     ,m_user_vec(a_from.m_user_vec)                245     ,m_user_vec(a_from.m_user_vec)
246     ,m_spaces(a_from.m_spaces)                    246     ,m_spaces(a_from.m_spaces)
247     {}                                            247     {}
248     std_vector_column& operator=(const std_vec    248     std_vector_column& operator=(const std_vector_column& a_from){
249       m_name = a_from.m_name;                     249       m_name = a_from.m_name;
250       m_spaces = a_from.m_spaces;                 250       m_spaces = a_from.m_spaces;
251       return *this;                               251       return *this;
252     }                                             252     }
253   protected:                                      253   protected:
254     std::string m_name;                           254     std::string m_name;
255     std::string m_def; //not used;                255     std::string m_def; //not used;
256     std::vector<T>& m_user_vec;                   256     std::vector<T>& m_user_vec;
257     std::string m_spaces;                         257     std::string m_spaces;
258   };                                              258   };
259                                                   259 
260   static leaf* is_std_vector_column(iobj& a_ob    260   static leaf* is_std_vector_column(iobj& a_obj) {
261     //200+20+id(basic type) ?                     261     //200+20+id(basic type) ?
262     int _id = (int)a_obj.id_cls()-220;            262     int _id = (int)a_obj.id_cls()-220;
263     if((_id<=0)||(_id>=20)) return 0;             263     if((_id<=0)||(_id>=20)) return 0;
264     return id_cast<iobj,leaf>(a_obj);             264     return id_cast<iobj,leaf>(a_obj);
265   }                                               265   }
266                                                   266 
267 public:                                           267 public:
268   ntuple(std::ostream& a_writer,unsigned int a    268   ntuple(std::ostream& a_writer,unsigned int a_spaces = 0)
269   :m_writer(a_writer){                            269   :m_writer(a_writer){
270     for(unsigned int i=0;i<a_spaces;i++) m_spa    270     for(unsigned int i=0;i<a_spaces;i++) m_spaces += " ";
271   }                                               271   }
272   ntuple(std::ostream& a_writer,                  272   ntuple(std::ostream& a_writer,
273          std::ostream& a_out,                     273          std::ostream& a_out,
274          const ntuple_booking& a_bkg,             274          const ntuple_booking& a_bkg,
275          unsigned int a_spaces = 0)               275          unsigned int a_spaces = 0)
276   :m_writer(a_writer){                            276   :m_writer(a_writer){
277     for(unsigned int i=0;i<a_spaces;i++) m_spa    277     for(unsigned int i=0;i<a_spaces;i++) m_spaces += " ";
278                                                   278 
279     const std::vector<column_booking>& cols =     279     const std::vector<column_booking>& cols = a_bkg.columns();
280     tools_vforcit(column_booking,cols,it){        280     tools_vforcit(column_booking,cols,it){
281                                                   281 
282       if((*it).cls_id()==_cid(int(0))) {          282       if((*it).cls_id()==_cid(int(0))) {
283         create_column<int>((*it).name());         283         create_column<int>((*it).name());
284       } else if((*it).cls_id()==_cid(float(0))    284       } else if((*it).cls_id()==_cid(float(0))) {
285         create_column<float>((*it).name());       285         create_column<float>((*it).name());
286       } else if((*it).cls_id()==_cid(double(0)    286       } else if((*it).cls_id()==_cid(double(0))) {
287         create_column<double>((*it).name());      287         create_column<double>((*it).name());
288       } else if((*it).cls_id()==_cid(std::stri    288       } else if((*it).cls_id()==_cid(std::string())) {
289         create_column<std::string>((*it).name(    289         create_column<std::string>((*it).name());
290                                                   290 
291       } else if((*it).cls_id()==_cid_std_vecto    291       } else if((*it).cls_id()==_cid_std_vector<int>()) {
292         std::vector<int>* vec = (std::vector<i    292         std::vector<int>* vec = (std::vector<int>*)(*it).user_obj();
293         if(vec) {                                 293         if(vec) {
294           create_column<int>((*it).name(),*vec    294           create_column<int>((*it).name(),*vec);
295         } else {                                  295         } else {
296           a_out << "tools::waxml::ntuple :"       296           a_out << "tools::waxml::ntuple :"
297                 << " for std::vector column "     297                 << " for std::vector column " << sout((*it).name())
298                 << ", the user vector pointer     298                 << ", the user vector pointer is null."
299                 << std::endl;                     299                 << std::endl;
300           safe_clear<iobj>(m_cols);               300           safe_clear<iobj>(m_cols);
301           return;                                 301           return;
302         }                                         302         }
303       } else if((*it).cls_id()==_cid_std_vecto    303       } else if((*it).cls_id()==_cid_std_vector<float>()) {
304         std::vector<float>* vec = (std::vector    304         std::vector<float>* vec = (std::vector<float>*)(*it).user_obj();
305         if(vec) {                                 305         if(vec) {
306           create_column<float>((*it).name(),*v    306           create_column<float>((*it).name(),*vec);
307         } else {                                  307         } else {
308           a_out << "tools::waxml::ntuple :"       308           a_out << "tools::waxml::ntuple :"
309                 << " for std::vector column "     309                 << " for std::vector column " << sout((*it).name())
310                 << ", the user vector pointer     310                 << ", the user vector pointer is null."
311                 << std::endl;                     311                 << std::endl;
312           safe_clear<iobj>(m_cols);               312           safe_clear<iobj>(m_cols);
313           return;                                 313           return;
314         }                                         314         }
315       } else if((*it).cls_id()==_cid_std_vecto    315       } else if((*it).cls_id()==_cid_std_vector<double>()) {
316         std::vector<double>* vec = (std::vecto    316         std::vector<double>* vec = (std::vector<double>*)(*it).user_obj();
317         if(vec) {                                 317         if(vec) {
318           create_column<double>((*it).name(),*    318           create_column<double>((*it).name(),*vec);
319         } else {                                  319         } else {
320           a_out << "tools::waxml::ntuple :"       320           a_out << "tools::waxml::ntuple :"
321                 << " for std::vector column "     321                 << " for std::vector column " << sout((*it).name())
322                 << ", the user vector pointer     322                 << ", the user vector pointer is null."
323                 << std::endl;                     323                 << std::endl;
324           safe_clear<iobj>(m_cols);               324           safe_clear<iobj>(m_cols);
325           return;                                 325           return;
326         }                                         326         }
327                                                   327 
328       } else if((*it).cls_id()==_cid_std_vecto    328       } else if((*it).cls_id()==_cid_std_vector<std::string>()) {
329         std::vector<std::string>* vec = (std::    329         std::vector<std::string>* vec = (std::vector<std::string>*)(*it).user_obj();
330         if(vec) {                                 330         if(vec) {
331           create_column<std::string>((*it).nam    331           create_column<std::string>((*it).name(),*vec);
332         } else {                                  332         } else {
333           a_out << "tools::waxml::ntuple :"       333           a_out << "tools::waxml::ntuple :"
334                 << " for std::vector column "     334                 << " for std::vector column " << sout((*it).name())
335                 << ", the user vector pointer     335                 << ", the user vector pointer is null."
336                 << std::endl;                     336                 << std::endl;
337           safe_clear<iobj>(m_cols);               337           safe_clear<iobj>(m_cols);
338           return;                                 338           return;
339         }                                         339         }
340                                                   340 
341       } else {                                    341       } else {
342         a_out << "tools::waxml::ntuple :"         342         a_out << "tools::waxml::ntuple :"
343               << " for column " << sout((*it).    343               << " for column " << sout((*it).name())
344               << ", type with cid " << (*it).c    344               << ", type with cid " << (*it).cls_id() << " not yet handled."
345               << std::endl;                       345               << std::endl;
346         //throw                                   346         //throw
347         safe_clear<iobj>(m_cols);                 347         safe_clear<iobj>(m_cols);
348         return;                                   348         return;
349       }                                           349       }
350     }                                             350     }
351   }                                               351   }
352   virtual ~ntuple() {                             352   virtual ~ntuple() {
353     safe_clear<iobj>(m_cols);                     353     safe_clear<iobj>(m_cols);
354   }                                               354   }
355 protected:                                        355 protected:
356   ntuple(const ntuple& a_from)                    356   ntuple(const ntuple& a_from)
357   :m_writer(a_from.m_writer)                      357   :m_writer(a_from.m_writer)
358   ,m_spaces(a_from.m_spaces)                      358   ,m_spaces(a_from.m_spaces)
359   {}                                              359   {}
360   ntuple& operator=(const ntuple& a_from){        360   ntuple& operator=(const ntuple& a_from){
361     m_spaces = a_from.m_spaces;                   361     m_spaces = a_from.m_spaces;
362     return *this;                                 362     return *this;
363   }                                               363   }
364 public:                                           364 public:
365   const std::vector<iobj*>& columns() const {r    365   const std::vector<iobj*>& columns() const {return m_cols;}
366                                                   366 
367   template <class T>                              367   template <class T>
368   column<T>* create_column(const std::string&     368   column<T>* create_column(const std::string& a_name,const T& a_def = T()) {
369     if(find_named<iobj>(m_cols,a_name)) return    369     if(find_named<iobj>(m_cols,a_name)) return 0;
370     column<T>* col = new column<T>(a_name,a_de    370     column<T>* col = new column<T>(a_name,a_def);
371     if(!col) return 0;                            371     if(!col) return 0;
372     m_cols.push_back(col);                        372     m_cols.push_back(col);
373     return col;                                   373     return col;
374   }                                               374   }
375                                                   375 
376   template <class T>                              376   template <class T>
377   std_vector_column<T>* create_column(const st    377   std_vector_column<T>* create_column(const std::string& a_name,std::vector<T>& a_user_vec) {
378     if(find_named<iobj>(m_cols,a_name)) return    378     if(find_named<iobj>(m_cols,a_name)) return 0;
379     std::string spaces;                           379     std::string spaces;
380     for(unsigned int i=0;i<8;i++) spaces += "     380     for(unsigned int i=0;i<8;i++) spaces += " ";
381     std_vector_column<T>* col = new std_vector    381     std_vector_column<T>* col = new std_vector_column<T>(a_name,a_user_vec,m_spaces+spaces);
382     if(!col) return 0;                            382     if(!col) return 0;
383     m_cols.push_back(col);                        383     m_cols.push_back(col);
384     return col;                                   384     return col;
385   }                                               385   }
386                                                   386 
387   template <class T>                              387   template <class T>
388   column<T>* find_column(const std::string& a_    388   column<T>* find_column(const std::string& a_name) {
389     iobj* col = find_named<iobj>(m_cols,a_name    389     iobj* col = find_named<iobj>(m_cols,a_name);
390     if(!col) return 0;                            390     if(!col) return 0;
391     return id_cast<iobj, column<T> >(*col);       391     return id_cast<iobj, column<T> >(*col);
392   }                                               392   }
393                                                   393 
394   sub_ntuple* create_sub_ntuple(const std::str    394   sub_ntuple* create_sub_ntuple(const std::string& a_name){
395     if(find_named<iobj>(m_cols,a_name)) return    395     if(find_named<iobj>(m_cols,a_name)) return 0;
396     std::string spaces;                           396     std::string spaces;
397     for(unsigned int i=0;i<10;i++) spaces += "    397     for(unsigned int i=0;i<10;i++) spaces += " ";
398     sub_ntuple* col = new sub_ntuple(a_name,m_    398     sub_ntuple* col = new sub_ntuple(a_name,m_spaces+spaces);
399     if(!col) return 0;                            399     if(!col) return 0;
400     m_cols.push_back(col);                        400     m_cols.push_back(col);
401     return col;                                   401     return col;
402   }                                               402   }
403                                                   403 
404   void write_header(const std::string& a_path,    404   void write_header(const std::string& a_path,const std::string& a_name,const std::string& a_title){
405                                                   405 
406     // <tuple> :                                  406     // <tuple> :
407     m_writer << m_spaces << "  <tuple"            407     m_writer << m_spaces << "  <tuple"
408              << " path=" << sout(to_xml(a_path    408              << " path=" << sout(to_xml(a_path))
409              << " name=" << sout(to_xml(a_name    409              << " name=" << sout(to_xml(a_name))
410              << " title=" << sout(to_xml(a_tit    410              << " title=" << sout(to_xml(a_title))
411              << ">" << std::endl;                 411              << ">" << std::endl;
412                                                   412 
413     // <columns> :                                413     // <columns> :
414     m_writer << m_spaces << "    <columns>" <<    414     m_writer << m_spaces << "    <columns>" << std::endl;
415                                                   415 
416     tools_vforcit(iobj*,m_cols,it) {              416     tools_vforcit(iobj*,m_cols,it) {
417       if(leaf* vlf = is_std_vector_column(*(*i    417       if(leaf* vlf = is_std_vector_column(*(*it))) {
418         m_writer << m_spaces << "      <column    418         m_writer << m_spaces << "      <column"
419                  << " name=" << sout(to_xml((*    419                  << " name=" << sout(to_xml((*it)->name()))
420                  << " type=" << sout("ITuple")    420                  << " type=" << sout("ITuple")
421                  << " booking=\"{" << vlf->aid    421                  << " booking=\"{" << vlf->aida_type() << " " << to_xml((*it)->name())
422                  << "}\""                         422                  << "}\""
423                  << "/>" << std::endl;            423                  << "/>" << std::endl;
424       } else if(sub_ntuple* sub = id_cast<iobj    424       } else if(sub_ntuple* sub = id_cast<iobj,sub_ntuple>(*(*it))){
425         m_writer << m_spaces << "      <column    425         m_writer << m_spaces << "      <column"
426                  << " name=" << sout(to_xml((*    426                  << " name=" << sout(to_xml((*it)->name()))
427                  << " type=" << sout("ITuple")    427                  << " type=" << sout("ITuple")
428                  << " booking=" << sout(sub->b    428                  << " booking=" << sout(sub->booking(true))
429                  << "/>" << std::endl;            429                  << "/>" << std::endl;
430       } else if(/*leaf* lf =*/ id_cast<iobj,le    430       } else if(/*leaf* lf =*/ id_cast<iobj,leaf>(*(*it))){
431         m_writer << m_spaces << "      <column    431         m_writer << m_spaces << "      <column"
432                  << " name=" << sout(to_xml((*    432                  << " name=" << sout(to_xml((*it)->name()))
433                  << " type=" << sout((*it)->ai    433                  << " type=" << sout((*it)->aida_type())
434                //<< " default=" << sout(lf->s_    434                //<< " default=" << sout(lf->s_def()) //not understood by jas3
435                  << "/>" << std::endl;            435                  << "/>" << std::endl;
436       }                                           436       }
437     }                                             437     }
438                                                   438 
439     m_writer << m_spaces << "    </columns>" <    439     m_writer << m_spaces << "    </columns>" << std::endl;
440                                                   440 
441     // rows :                                     441     // rows :
442     m_writer << m_spaces << "    <rows>" << st    442     m_writer << m_spaces << "    <rows>" << std::endl;
443   }                                               443   }
444                                                   444 
445   bool add_row() {                                445   bool add_row() {
446     if(m_cols.empty()) return false;              446     if(m_cols.empty()) return false;
447     m_writer << m_spaces << "      <row>" << s    447     m_writer << m_spaces << "      <row>" << std::endl;
448     tools_vforcit(iobj*,m_cols,it) {              448     tools_vforcit(iobj*,m_cols,it) {
449       if(leaf* vlf = is_std_vector_column(*(*i    449       if(leaf* vlf = is_std_vector_column(*(*it))) {
450         std::string _sv;                          450         std::string _sv;
451         vlf->s_value(_sv);                        451         vlf->s_value(_sv);
452         m_writer << _sv;                          452         m_writer << _sv;
453       } else if(sub_ntuple* sub = id_cast<iobj    453       } else if(sub_ntuple* sub = id_cast<iobj,sub_ntuple>(*(*it))){
454         m_writer << m_spaces << "        <entr    454         m_writer << m_spaces << "        <entryITuple>" << std::endl;
455         m_writer << sub->value();                 455         m_writer << sub->value();
456         m_writer << m_spaces << "        </ent    456         m_writer << m_spaces << "        </entryITuple>" << std::endl;
457         sub->reset();                             457         sub->reset();
458       } else if(leaf* lf = id_cast<iobj,leaf>(    458       } else if(leaf* lf = id_cast<iobj,leaf>(*(*it))){
459         std::string _sv;                          459         std::string _sv;
460         lf->s_value(_sv);                         460         lf->s_value(_sv);
461         m_writer << m_spaces << "        <entr    461         m_writer << m_spaces << "        <entry"
462                  << " value=" << sout(_sv)        462                  << " value=" << sout(_sv)
463                  << "/>" << std::endl;            463                  << "/>" << std::endl;
464       }                                           464       }
465     }                                             465     }
466     m_writer << m_spaces << "      </row>" <<     466     m_writer << m_spaces << "      </row>" << std::endl;
467     return true;                                  467     return true;
468   }                                               468   }
469                                                   469 
470   void write_trailer() {                          470   void write_trailer() {
471     m_writer << m_spaces << "    </rows>" << s    471     m_writer << m_spaces << "    </rows>" << std::endl;
472     m_writer << m_spaces << "  </tuple>" << st    472     m_writer << m_spaces << "  </tuple>" << std::endl;
473   }                                               473   }
474                                                   474 
475   std::string booking(bool a_xml_esc) const {     475   std::string booking(bool a_xml_esc) const {
476     std::string _s;                               476     std::string _s;
477     get_booking(m_cols,a_xml_esc,_s);             477     get_booking(m_cols,a_xml_esc,_s);
478     return _s;                                    478     return _s;
479   }                                               479   }
480                                                   480 
481 protected:                                        481 protected:
482   static void get_booking(const std::vector<io    482   static void get_booking(const std::vector<iobj*>& a_cols,bool a_xml_esc,
483                           std::string& a_strin    483                           std::string& a_string) {
484     a_string += "{"; //we need the + because o    484     a_string += "{"; //we need the + because of the tuple in tuple.
485                                                   485 
486     tools_vforcit(iobj*,a_cols,it) {              486     tools_vforcit(iobj*,a_cols,it) {
487       if(it!=a_cols.begin()) a_string += ",";     487       if(it!=a_cols.begin()) a_string += ",";
488                                                   488 
489       std::string sname = (*it)->name();          489       std::string sname = (*it)->name();
490       if(a_xml_esc) sname = to_xml(sname);        490       if(a_xml_esc) sname = to_xml(sname);
491                                                   491 
492       if(leaf* vlf = is_std_vector_column(*(*i    492       if(leaf* vlf = is_std_vector_column(*(*it))) {
493         a_string += "ITuple " + (*it)->name()     493         a_string += "ITuple " + (*it)->name() + " = {" + vlf->aida_type() + " " + sname + "}";
494                                                   494 
495       } else if(sub_ntuple* sub = id_cast<iobj    495       } else if(sub_ntuple* sub = id_cast<iobj,sub_ntuple>(*(*it))){
496         a_string += (*it)->aida_type() + " " +    496         a_string += (*it)->aida_type() + " " + sname + " = ";
497                                                   497 
498         get_booking(sub->columns(),a_xml_esc,a    498         get_booking(sub->columns(),a_xml_esc,a_string);
499       } else if(leaf* lf = id_cast<iobj,leaf>(    499       } else if(leaf* lf = id_cast<iobj,leaf>(*(*it))){
500         a_string += (*it)->aida_type() + " " +    500         a_string += (*it)->aida_type() + " " + sname + " = " + lf->s_def();
501       }                                           501       }
502     }                                             502     }
503     a_string += "}";                              503     a_string += "}";
504   }                                               504   }
505                                                   505 
506 protected:                                        506 protected:
507   std::ostream& m_writer;                         507   std::ostream& m_writer;
508   //std::string m_path;                           508   //std::string m_path;
509   //std::string m_name;                           509   //std::string m_name;
510   //std::string m_title;                          510   //std::string m_title;
511   std::string m_spaces;                           511   std::string m_spaces;
512   std::vector<iobj*> m_cols;                      512   std::vector<iobj*> m_cols;
513 };                                                513 };
514                                                   514 
515 }}                                                515 }}
516                                                   516 
517 #endif                                            517 #endif