Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/aida_ntuple 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_aida_ntuple
0005 #define tools_aida_ntuple
0006 
0007 // An in memory ntuple able to have "sub ntuple" on a column.
0008 // It is used in ioda to read ntuples in XML/AIDA files.
0009 
0010 #include "vmanip"
0011 #include "typedefs"
0012 #include "scast"
0013 #include "forit"
0014 #include "ntuple_binding"
0015 #include "mnmx"
0016 
0017 #include <string>
0018 #include <vector>
0019 #include <ostream>
0020 
0021 namespace tools {
0022 namespace aida {
0023 
0024 class base_col {
0025 public:
0026   static const std::string& s_class() {
0027     static const std::string s_v("tools::aida::base_col");
0028     return s_v;
0029   }
0030   virtual void* cast(const std::string& a_class) const {
0031     if(void* p = cmp_cast<base_col>(this,a_class)) {return p;}
0032     return 0;
0033   }
0034 public:
0035   virtual base_col* copy() const = 0;
0036   virtual uint64 num_elems() const = 0;
0037   virtual bool add() = 0;
0038   virtual bool reset() = 0;
0039   //binded column reading API :
0040   virtual bool fetch_entry() const = 0;
0041   virtual void set_user_variable(void*) = 0;
0042 protected:
0043   base_col(std::ostream& a_out,const std::string& a_name)
0044   :m_out(a_out)
0045   ,m_name(a_name),m_index(0){
0046   }
0047 public:
0048   virtual ~base_col(){
0049   }
0050 protected:
0051   base_col(const base_col& a_from)
0052   :m_out(a_from.m_out)
0053   ,m_name(a_from.m_name)
0054   ,m_index(a_from.m_index){
0055   }
0056   base_col& operator=(const base_col& a_from){
0057     m_name = a_from.m_name;
0058     m_index = a_from.m_index;
0059     return *this;
0060   }
0061 public:
0062   const std::string& name() const {return m_name;}
0063 
0064   void set_index(uint64 a_index){m_index = a_index;}
0065 protected:
0066   std::ostream& m_out;
0067   std::string m_name;
0068   uint64 m_index;
0069 };
0070 
0071 class base_ntu {
0072 public:
0073   static const std::string& s_class() {
0074     static const std::string s_v("tools::aida::base_ntu");
0075     return s_v;
0076   }
0077   virtual void* cast(const std::string& a_class) const {
0078     if(void* p = cmp_cast<base_ntu>(this,a_class)) {return p;}
0079     return 0;
0080   }
0081 protected:
0082   base_ntu(std::ostream& a_out,const std::string& a_title)
0083   :m_out(a_out),m_title(a_title),m_index(-1){
0084   }
0085   virtual ~base_ntu() {
0086     clear();
0087   }
0088 protected:
0089   base_ntu(const base_ntu& a_from)
0090   :m_out(a_from.m_out)
0091   ,m_title(a_from.m_title),m_index(a_from.m_index)
0092   {
0093     tools_vforcit(base_col*,a_from.m_cols,it) {
0094       base_col* column = (*it)->copy();
0095       if(!column) {
0096         m_out << s_class() << "::cstor :"
0097               << " can't copy column."
0098               << std::endl;
0099         safe_clear<base_col>(m_cols);
0100         m_index = -1;
0101         return; //throw
0102       }
0103       m_cols.push_back(column);
0104     }
0105   }
0106   base_ntu& operator=(const base_ntu& a_from){
0107     if(&a_from==this) return *this;
0108 
0109     safe_clear<base_col>(m_cols);
0110     m_index = a_from.m_index;
0111 
0112     m_title = a_from.m_title;
0113     tools_vforcit(base_col*,a_from.m_cols,it) {
0114       base_col* column = (*it)->copy();
0115       if(!column) {
0116         m_out << s_class() << "::operator=() :"
0117               << " can't copy column."
0118               << std::endl;
0119         safe_clear<base_col>(m_cols);
0120         m_index = -1;
0121         return *this;
0122       }
0123       m_cols.push_back(column);
0124     }
0125 
0126     return *this;
0127   }
0128 public:
0129   std::ostream& out() const {return m_out;}
0130   const std::vector<base_col*>& columns() const {return m_cols;}
0131   size_t number_of_columns() const {return m_cols.size();}
0132 
0133   void column_names(std::vector<std::string>& a_names) const {
0134     a_names.clear();
0135     tools_vforcit(base_col*,m_cols,it) a_names.push_back((*it)->name());
0136   }
0137 
0138   const std::string& title() const {return m_title;}
0139   void set_title(const std::string& a_title) {m_title = a_title;}
0140 
0141   uint64 rows() const {
0142     if(m_cols.empty()) return 0;
0143     return m_cols.front()->num_elems();
0144   }
0145   bool number_of_entries(uint64& a_value) const {
0146     if(m_cols.empty()) {a_value = 0;return false;}
0147     a_value = m_cols.front()->num_elems();
0148     return true;
0149   }
0150 
0151   void clear() { //must not be confused with reset().
0152     safe_clear<base_col>(m_cols);
0153     m_index = -1;
0154   }
0155 
0156   bool reset() { //clear data in columns (but not the column set)
0157     bool status = true;
0158     tools_vforit(base_col*,m_cols,it) {
0159       if(!(*it)->reset()) status = false;
0160     }
0161     m_index = -1;
0162     return status;
0163   }
0164 
0165   // reading :
0166   void start() {m_index = -1;set_columns_index(0);}
0167   bool next() {
0168     // a tuple loop is of the form :
0169     //  tuple.start();
0170     //  while(tuple.next()) {
0171     //    ...
0172     //    double v;
0173     //    if(!col->get_entry(v)) {}
0174     //    ...
0175     //  }
0176     if((m_index+1)>=(int64)rows()) return false;
0177     m_index++;
0178     set_columns_index(m_index);
0179     return true;
0180   }
0181   int64 row_index() const {return m_index;}
0182 
0183   // filling :
0184   bool add_row() {
0185     bool status = true;
0186     tools_vforit(base_col*,m_cols,it) {
0187       if(!(*it)->add()) status = false;
0188     }
0189     return status;
0190   }
0191 public:
0192   base_col* find_column(const std::string& a_name){
0193     return find_named<base_col>(m_cols,a_name);
0194   }
0195 
0196   void add_column(base_col* a_col) { //we take ownership.
0197     m_cols.push_back(a_col);
0198   }
0199 
0200 protected:
0201   void set_columns_index(uint64 a_index) {
0202     tools_vforit(base_col*,m_cols,it) {
0203       (*it)->set_index(a_index);
0204     }
0205   }
0206 protected:
0207   std::ostream& m_out;
0208   std::string m_title;
0209   int64 m_index;
0210   std::vector<base_col*> m_cols;
0211 };
0212 
0213 }}
0214 
0215 #include "tos"
0216 #include "sto"
0217 #include "columns"
0218 #include "stype"
0219 
0220 namespace tools {
0221 namespace aida {
0222 
0223 inline const std::string& s_aida_type(short) {
0224   static const std::string s_v("short");
0225   return s_v;
0226 }
0227 inline const std::string& s_aida_type(int) {
0228   static const std::string s_v("int");
0229   return s_v;
0230 }
0231 inline const std::string& s_aida_type(float) {
0232   static const std::string s_v("float");
0233   return s_v;
0234 }
0235 inline const std::string& s_aida_type(double) {
0236   static const std::string s_v("double");
0237   return s_v;
0238 }
0239 
0240 inline const std::string& s_aida_type(bool) {
0241   static const std::string s_v("boolean");
0242   return s_v;
0243 }
0244 inline const std::string& s_aida_type(const std::string&) {
0245   static const std::string s_v("string");
0246   return s_v;
0247 }
0248 inline const std::string& s_aida_type(int64) {
0249   static const std::string s_v("long");
0250   return s_v;
0251 }
0252 
0253 inline const std::string& s_aida_type_ituple() {
0254   static const std::string s_v("ITuple");
0255   return s_v;
0256 }
0257 
0258 /////////////////////////////////////////
0259 /// not AIDA ! //////////////////////////
0260 /////////////////////////////////////////
0261 inline const std::string& s_aida_type(unsigned short) {
0262   static const std::string s_v("ushort");
0263   return s_v;
0264 }
0265 inline const std::string& s_aida_type(unsigned int) {
0266   static const std::string s_v("uint");
0267   return s_v;
0268 }
0269 inline const std::string& s_aida_type(uint64) {
0270   static const std::string s_v("ulong");
0271   return s_v;
0272 }
0273 
0274 class aida_base_col : public base_col {
0275 public:
0276   static const std::string& s_class() {
0277     static const std::string s_v("tools::aida::aida_base_col");
0278     return s_v;
0279   }
0280   virtual void* cast(const std::string& a_class) const {
0281     if(void* p = cmp_cast<aida_base_col>(this,a_class)) {return p;}
0282     return base_col::cast(a_class);
0283   }
0284 public:
0285   virtual const std::string& aida_type() const = 0;
0286   virtual bool s_default_value(std::string&) const = 0;
0287   virtual bool s_value(std::string&) const = 0;
0288   virtual bool s_fill(const std::string&) = 0;
0289 public:
0290   aida_base_col(std::ostream& a_out,const std::string& a_name)
0291   :base_col(a_out,a_name){}
0292 public:
0293   virtual ~aida_base_col(){}
0294 public:
0295   aida_base_col(const aida_base_col& a_from)
0296   :base_col(a_from)
0297   {}
0298   aida_base_col& operator=(const aida_base_col& a_from){
0299     base_col::operator=(a_from);
0300     return *this;
0301   }
0302 };
0303 
0304 inline bool s__fill(const std::string& a_s,std::string& a_v) {
0305   a_v = a_s;
0306   return true;
0307 }
0308 inline bool s__fill(const std::string& a_s,char& a_v) {
0309   //for exlib/cbk/aida_ntu
0310   if(a_s.empty()) return false;
0311   a_v = a_s[0];
0312   return true;
0313 }
0314 inline bool s__fill(const std::string& a_s,unsigned char& a_v) {
0315   //for exlib/cbk/aida_ntu
0316   if(a_s.empty()) return false;
0317   a_v = a_s[0];
0318   return true;
0319 }
0320 inline bool s__fill(const std::string& a_s,bool& a_v) {
0321   return to(a_s,a_v);
0322 }
0323 inline bool s__fill(const std::string& a_s,short& a_v) {
0324   return to<short>(a_s,a_v);
0325 }
0326 inline bool s__fill(const std::string& a_s,unsigned short& a_v) {
0327   return to<unsigned short>(a_s,a_v);
0328 }
0329 inline bool s__fill(const std::string& a_s,int& a_v) {
0330   return to<int>(a_s,a_v);
0331 }
0332 inline bool s__fill(const std::string& a_s,unsigned int& a_v) {
0333   return to<unsigned int>(a_s,a_v);
0334 }
0335 inline bool s__fill(const std::string& a_s,int64& a_v) {
0336   return to<int64>(a_s,a_v);
0337 }
0338 inline bool s__fill(const std::string& a_s,uint64& a_v) {
0339   return to<uint64>(a_s,a_v);
0340 }
0341 inline bool s__fill(const std::string& a_s,float& a_v) {
0342   return to<float>(a_s,a_v);
0343 }
0344 inline bool s__fill(const std::string& a_s,double& a_v) {
0345   return to<double>(a_s,a_v);
0346 }
0347 
0348 template <class T>
0349 class aida_col : public aida_base_col {
0350 public:
0351   typedef T entry_t;
0352 public:
0353   static const std::string& s_class() {
0354     static const std::string s_v("tools::aida::aida_col<"+stype(T())+">");
0355     return s_v;
0356   }
0357   virtual void* cast(const std::string& a_class) const {
0358     if(void* p = cmp_cast< aida_col<T> >(this,a_class)) {return p;}
0359     return aida_base_col::cast(a_class);
0360   }
0361 public:
0362   virtual base_col* copy() const {return new aida_col(*this);}
0363   virtual bool add() {m_data.push_back(m_tmp);m_tmp = m_default;return true;}
0364   virtual bool reset() {
0365     m_data.clear();
0366     m_index = 0;
0367     m_tmp = m_default;
0368     return true;
0369   }
0370   virtual uint64 num_elems() const {return m_data.size();}
0371 public:
0372   virtual const std::string& aida_type() const {return s_aida_type(T());}
0373   virtual bool s_default_value(std::string& a_s) const {
0374     a_s = tos(m_default);
0375     return true;
0376   }
0377   virtual bool s_value(std::string& a_s) const {
0378     typedef typename std::vector<T>::size_type sz_t;
0379     a_s = tos(m_data[sz_t(m_index)]);
0380     return true;
0381   }
0382 
0383   // for exlib/raxml/tuple :
0384   virtual bool s_fill(const std::string& a_s) {
0385     //if(!to<T>(a_s,m_tmp)) {
0386     if(!s__fill(a_s,m_tmp)) {
0387       m_out << s_class() << "::fill :"
0388             << " can't convert " << sout(a_s) << "."
0389             << std::endl;
0390       return false;
0391     }
0392     return true;
0393   }
0394 
0395   virtual void set_user_variable(void* a_user_var) {m_user_var = (T*)a_user_var;} //not owner.
0396 public:
0397   aida_col(std::ostream& a_out,const std::string& a_name,const T& a_def)
0398   :aida_base_col(a_out,a_name)
0399   ,m_default(a_def)
0400   ,m_tmp(a_def)
0401   ,m_user_var(0) //not owner
0402   {}
0403 public:
0404   virtual ~aida_col(){}
0405 public:
0406   aida_col(const aida_col& a_from)
0407   :aida_base_col(a_from)
0408   ,m_data(a_from.m_data)
0409   ,m_default(a_from.m_default)
0410   ,m_tmp(a_from.m_tmp)
0411   ,m_user_var(a_from.m_user_var)
0412   {}
0413   aida_col& operator=(const aida_col& a_from){
0414     aida_base_col::operator=(a_from);
0415     if(&a_from==this) return *this;
0416     m_data = a_from.m_data;
0417     m_default = a_from.m_default;
0418     m_tmp = a_from.m_tmp;
0419     m_user_var = a_from.m_user_var;
0420     return *this;
0421   }
0422 public:
0423   bool fill(const T& a_value) {m_tmp = a_value;return true;}
0424   bool get_entry(T& a_v) const {
0425     if(m_index>=m_data.size()) {
0426       m_out << s_class() << "::get_entry :"
0427             << " bad index " << m_index
0428             << ". Vec size is " << m_data.size() << "."
0429             << "."
0430             << std::endl;
0431       a_v = T();
0432       return false;
0433     }
0434     typedef typename std::vector<T>::size_type sz_t;
0435     a_v = m_data[sz_t(m_index)];
0436     return true;
0437   }
0438   virtual bool fetch_entry() const {
0439     //NOTE : it is ok to have a NULL m_user_var.
0440     if(m_index>=m_data.size()) {
0441       m_out << s_class() << "::get_entry :"
0442             << " bad index " << m_index
0443             << ". Vec size is " << m_data.size() << "."
0444             << "."
0445             << std::endl;
0446       if(m_user_var) *m_user_var = T();
0447       return false;
0448     }
0449     typedef typename std::vector<T>::size_type sz_t;
0450     if(m_user_var) *m_user_var = m_data[sz_t(m_index)];
0451     return true;
0452   }
0453 protected:
0454   std::vector<T> m_data;
0455   T m_default;
0456   T m_tmp;
0457   T* m_user_var;
0458 };
0459 
0460 class ntuple : public base_ntu {
0461 public:
0462   static cid id_class() {return 2000;} //for ntuple_binding.
0463 public:
0464   static const std::string& s_class() {
0465     static const std::string s_v("tools::aida::ntuple");
0466     return s_v;
0467   }
0468   virtual void* cast(const std::string& a_class) const {
0469     if(void* p = cmp_cast<ntuple>(this,a_class)) {return p;}
0470     return base_ntu::cast(a_class);
0471   }
0472   virtual const std::string& s_cls() const {return s_class();}
0473 public:
0474   ntuple(std::ostream& a_out,const std::string& a_title)
0475   :base_ntu(a_out,a_title)
0476   {}
0477   virtual ~ntuple() {}
0478 public:
0479   ntuple(const ntuple& a_from): base_ntu(a_from){}
0480   ntuple& operator=(const ntuple& a_from){
0481     base_ntu::operator=(a_from);
0482     return *this;
0483   }
0484 public:
0485   template <class T>
0486   aida_col<T>* create_col(const std::string& a_name,const T& a_def = T()) {
0487     if(find_named<base_col>(m_cols,a_name)) {
0488       m_out << s_class() << "::create_col :"
0489             << " a column with name " << sout(a_name) << " already exists."
0490             << std::endl;
0491       return 0;
0492     }
0493     aida_col<T>* col = new aida_col<T>(m_out,a_name,a_def);
0494     if(!col) {
0495       m_out << s_class() << "::create_col :"
0496             << " can't create aida_col<T> " << sout(a_name) << "."
0497             << std::endl;
0498       return 0;
0499     }
0500     m_cols.push_back(col);
0501     return col;
0502   }
0503 
0504   template <class T>
0505   aida_col<T>* find_column(const std::string& a_name){
0506     base_col* col = find_named<base_col>(m_cols,a_name);
0507     if(!col) return 0;
0508     return safe_cast<base_col, aida_col<T> >(*col);
0509   }
0510 
0511   template <class T>
0512   bool find_column(const std::string& a_name,aida_col<T>*& a_col,bool a_case_sensitive = true) { //for exlib::evaluator.
0513     base_col* col = a_case_sensitive ? find_named<base_col>(m_cols,a_name) : find_named_case_insensitive<base_col>(m_cols,a_name);
0514     if(!col) {a_col = 0;return false;}
0515     a_col = safe_cast<base_col, aida_col<T> >(*col);
0516     return a_col?true:false;
0517   }
0518 
0519   aida_base_col* find_aida_base_column(const std::string& a_name,bool a_case_sensitive = true){ //for opaw/panntu.
0520     base_col* col = a_case_sensitive ? find_named<base_col>(m_cols,a_name) : find_named_case_insensitive<base_col>(m_cols,a_name);
0521     if(!col) return 0;
0522     return safe_cast<base_col,aida_base_col>(*col);
0523   }
0524 
0525   bool get_row() const {
0526     bool status = true;
0527     tools_vforcit(base_col*,m_cols,it) {
0528       if(!(*it)->fetch_entry()) status = false;
0529     }
0530     return status;
0531   }
0532 
0533   bool set_binding(std::ostream& a_out,const ntuple_binding& a_bd = ntuple_binding()) {
0534     tools_vforcit(column_binding,a_bd.columns(),itb) {
0535       bool found = false;
0536       tools_vforcit(base_col*,m_cols,itc) {
0537         if((*itc)->name()==(*itb).name()) {
0538           (*itc)->set_user_variable((*itb).user_obj());
0539           found = true;
0540         }
0541       }
0542       if(!found) {
0543         a_out << "tools::aida::ntuple :"
0544               << " binding name " << sout((*itb).name()) << " does not match any ntuple column."
0545               << std::endl;
0546         return false;
0547       }
0548     }
0549     return true;
0550   }
0551 
0552   template <class T>
0553   bool column_min(unsigned int a_col,T& a_value) {
0554     a_value = T();
0555     if(m_cols.empty()) return false;
0556     if(a_col>=m_cols.size()) return false;
0557     base_col* _base_col = m_cols[a_col];
0558     aida_col<T>* _col = safe_cast<base_col, aida_col<T> >(*_base_col);
0559     if(!_col) return false;
0560     start();
0561     uint64 _rows = rows();
0562     T v;
0563    {for(uint64 row=0;row<_rows;row++) {
0564       if(!next()) {a_value = T();return false;}
0565       if(!_col->get_entry(v)) {}
0566       if(!row) {
0567         a_value = v;
0568       } else {
0569         a_value = min_of<T>(a_value,v);
0570       }
0571     }}
0572     return true;
0573   }
0574 
0575   template <class T>
0576   bool column_max(unsigned int a_col,T& a_value) {
0577     a_value = T();
0578     if(m_cols.empty()) return false;
0579     if(a_col>=m_cols.size()) return false;
0580     base_col* _base_col = m_cols[a_col];
0581     aida_col<T>* _col = safe_cast<base_col, aida_col<T> >(*_base_col);
0582     if(!_col) return false;
0583     start();
0584     uint64 _rows = rows();
0585     T v;
0586    {for(uint64 row=0;row<_rows;row++) {
0587       if(!next()) {a_value = T();return false;}
0588       if(!_col->get_entry(v)) {}
0589       if(!row) {
0590         a_value = v;
0591       } else {
0592         a_value = max_of<T>(a_value,v);
0593       }
0594     }}
0595     return true;
0596   }
0597 
0598 };
0599 
0600 ////////////////////////////////////////////////////////////
0601 /// some special column that can't be done with aida_col<T> ////
0602 ////////////////////////////////////////////////////////////
0603 
0604 class aida_col_ntu : public base_col {
0605 public:
0606   static const std::string& s_class() {
0607     static const std::string s_v("tools::aida::aida_col_ntu");
0608     return s_v;
0609   }
0610   virtual void* cast(const std::string& a_class) const {
0611     if(void* p = cmp_cast<aida_col_ntu>(this,a_class)) {return p;}
0612     return base_col::cast(a_class);
0613   }
0614 public:
0615   virtual base_col* copy() const {return new aida_col_ntu(*this);}
0616   virtual bool add() {m_data.push_back(m_tmp);m_tmp.reset();return true;}
0617   virtual bool reset() {m_data.clear();m_index = 0;return true;}
0618   virtual uint64 num_elems() const {return m_data.size();}
0619 public:
0620   base_ntu* get_entry() {
0621     if(m_index>=m_data.size()) {
0622       m_out << s_class() << "::get_entry :"
0623             << " bad index " << m_index
0624             << ". Vec size is " << m_data.size() << "."
0625             << "."
0626             << std::endl;
0627       return 0;
0628     }
0629     typedef std::vector<ntuple>::size_type sz_t;
0630     return &(m_data[sz_t(m_index)]);
0631   }
0632 
0633   virtual void set_user_variable(void* a_user_var) {m_user_var = (ntuple*)a_user_var;} //not owner.
0634   virtual bool fetch_entry() const {
0635     if(m_index>=m_data.size()) {
0636       m_out << s_class() << "::fetch_entry :"
0637             << " bad index " << m_index
0638             << ". Vec size is " << m_data.size() << "."
0639             << "."
0640             << std::endl;
0641       if(m_user_var) *m_user_var = ntuple(m_out,"");
0642       return false;
0643     }
0644     typedef std::vector<ntuple>::size_type sz_t;
0645     if(m_user_var) *m_user_var = m_data[sz_t(m_index)];
0646     return true;
0647   }
0648 
0649   virtual base_ntu* get_to_fill() {return &m_tmp;}
0650 public:
0651   aida_col_ntu(std::ostream& a_out,const std::string& a_name)
0652   :base_col(a_out,a_name)
0653   ,m_tmp(a_out,"tmp")
0654   ,m_user_var(0) //not owner
0655   {}
0656 public:
0657   virtual ~aida_col_ntu(){}
0658 public:
0659   aida_col_ntu(const aida_col_ntu& a_from)
0660   :base_col(a_from)
0661   ,m_data(a_from.m_data)
0662 
0663   ,m_tmp(a_from.m_tmp)
0664   ,m_user_var(a_from.m_user_var)
0665   {}
0666   aida_col_ntu& operator=(const aida_col_ntu& a_from){
0667     base_col::operator=(a_from);
0668     if(&a_from==this) return *this;
0669     m_data = a_from.m_data;
0670 
0671     m_tmp = a_from.m_tmp;
0672     m_user_var = a_from.m_user_var;
0673     return *this;
0674   }
0675 protected:
0676   std::vector<ntuple> m_data;
0677   ntuple m_tmp;
0678   ntuple* m_user_var;
0679 };
0680 
0681 inline bool create_cols_from_vals(ntuple& a_ntu,
0682                                   const std::vector<value>& a_vars,
0683                                   bool a_verbose = false){
0684   tools_vforcit(value,a_vars,it) {
0685       if((*it).type()==value::VOID_STAR) {
0686         if(a_verbose){
0687           a_ntu.out() << "tools::aida::create_cols_from_vals :"
0688                       << " ITuple : " << (*it).label() << " : begin "
0689                       << std::endl;
0690         }
0691         std::vector<value>* vars = (std::vector<value>*)(*it).get_void_star();
0692 
0693         aida_col_ntu* col_ntu = new aida_col_ntu(a_ntu.out(),(*it).label());
0694         // create sub columns on the "fillable" of col_ntu :
0695         base_ntu* sub_base_ntu = col_ntu->get_to_fill();
0696         if(!sub_base_ntu) {
0697           delete col_ntu;
0698           return false;
0699         }
0700         ntuple* sub_aida = safe_cast<base_ntu,ntuple>(*sub_base_ntu);
0701         if(!sub_aida) {
0702           delete col_ntu;
0703           return false;
0704         }
0705 
0706         if(!create_cols_from_vals(*sub_aida,*vars,a_verbose)) {
0707           delete col_ntu;
0708           return false;
0709         }
0710 
0711         a_ntu.add_column(col_ntu);
0712 
0713     } else {
0714         if(a_verbose){
0715           std::string stype;
0716           (*it).s_type(stype);
0717           std::string sval;
0718           (*it).tos(sval);
0719           a_ntu.out() << "tools::aida::create_cols_from_vals :"
0720                       << " " << stype << " : "
0721                       << (*it).label() << " : "
0722                       << sval
0723                       << std::endl;
0724         }
0725 
0726         //   char,short,int,float,double
0727         //   byte,boolean,string,long(for int64)
0728         //   double[]
0729 
0730         base_col* col = 0;
0731         if((*it).type()==value::SHORT) {
0732           col = a_ntu.create_col<short>((*it).label(),(*it).get_short());
0733         } else if((*it).type()==value::INT) {
0734           col = a_ntu.create_col<int>((*it).label(),(*it).get_int());
0735         } else if((*it).type()==value::INT64) {
0736           col = a_ntu.create_col<int64>((*it).label(),(*it).get_int64());
0737         } else if((*it).type()==value::FLOAT) {
0738           col = a_ntu.create_col<float>((*it).label(),(*it).get_float());
0739         } else if((*it).type()==value::DOUBLE) {
0740           col = a_ntu.create_col<double>((*it).label(),(*it).get_double());
0741         } else if((*it).type()==value::UNSIGNED_SHORT) {
0742           col = a_ntu.create_col<unsigned short>((*it).label(),(*it).get_unsigned_short());
0743         } else if((*it).type()==value::UNSIGNED_INT) {
0744           col = a_ntu.create_col<unsigned int>((*it).label(),(*it).get_unsigned_int());
0745         } else if((*it).type()==value::UNSIGNED_INT64) {
0746           col = a_ntu.create_col<uint64>((*it).label(),(*it).get_unsigned_int64());
0747 
0748         } else if((*it).type()==value::BOOL) {
0749           col = a_ntu.create_col<bool>((*it).label(),(*it).get_bool());
0750         } else if((*it).type()==value::STRING) {
0751           col = a_ntu.create_col<std::string>((*it).label(),(*it).get_string());
0752         } else if((*it).type()==value::INT64) {
0753           col = a_ntu.create_col<int64>((*it).label(),(*it).get_int64());
0754         }
0755 
0756         if(!col) {
0757           std::string stype;
0758           (*it).s_type(stype);
0759           std::string sval;
0760           (*it).tos(sval);
0761           a_ntu.out() << "tools::aida::create_cols_from_vals :"
0762                       << " failed for " << stype << " : "
0763                       << (*it).label() << " : "
0764                       << sval
0765                       << std::endl;
0766           return false;
0767         }
0768       }
0769   }
0770   return true;
0771 }
0772 
0773 // for raxml :
0774 inline bool create_col(ntuple& a_ntu,
0775                        const std::string& a_type,
0776                        const std::string& a_name,
0777                        const std::string& a_s, //def or booking.
0778                        bool a_is_ntu){
0779   if(a_type==s_aida_type((short)0)) {
0780     short v = 0;
0781     if(a_s.size()&&!to<short>(a_s,v)) {
0782       a_ntu.out() << "tools::aida::create_col :"
0783                   << " can't convert def " << sout(a_s)
0784                   << " to a " << a_type
0785                   << std::endl;
0786       return false;
0787     }
0788     if(!a_ntu.create_col<short>(a_name,v)) {
0789       a_ntu.out() << "tools::aida::create_col :"
0790                   << " can't create column of type " << sout(a_type)
0791                   << std::endl;
0792       return false;
0793     }
0794 
0795   } else if(a_type==s_aida_type((int)0)) {
0796     int v = 0;
0797     if(a_s.size()&&!to<int>(a_s,v)) {
0798       a_ntu.out() << "tools::aida::create_col :"
0799                   << " can't convert def " << sout(a_s)
0800                   << " to a " << a_type
0801                   << std::endl;
0802       return false;
0803     }
0804     if(!a_ntu.create_col<int>(a_name,v)) {
0805       a_ntu.out() << "tools::aida::create_col :"
0806                   << " can't create column of type " << sout(a_type)
0807                   << std::endl;
0808       return false;
0809     }
0810 
0811   } else if(a_type==s_aida_type((int64)0)) {
0812     int64 v = 0;
0813     if(a_s.size()&&!to<int64>(a_s,v)) {
0814       a_ntu.out() << "tools::aida::create_col :"
0815                   << " can't convert def " << sout(a_s)
0816                   << " to a " << a_type
0817                   << std::endl;
0818       return false;
0819     }
0820     if(!a_ntu.create_col<int64>(a_name,v)) {
0821       a_ntu.out() << "tools::aida::create_col :"
0822                   << " can't create column of type " << sout(a_type)
0823                   << std::endl;
0824       return false;
0825     }
0826 
0827   } else if(a_type==s_aida_type((float)0)) {
0828     float v = 0;
0829     if(a_s.size()&&!to<float>(a_s,v)) {
0830       a_ntu.out() << "tools::aida::create_col :"
0831                   << " can't convert def " << sout(a_s)
0832                   << " to a " << a_type
0833                   << std::endl;
0834       return false;
0835     }
0836     if(!a_ntu.create_col<float>(a_name,v)) {
0837       a_ntu.out() << "tools::aida::create_col :"
0838                   << " can't create column of type " << sout(a_type)
0839                   << std::endl;
0840       return false;
0841     }
0842 
0843 
0844   } else if(a_type==s_aida_type((double)0)) {
0845     double v = 0;
0846     if(a_s.size()&&!to<double>(a_s,v)) {
0847       a_ntu.out() << "tools::aida::create_col :"
0848                   << " can't convert def " << sout(a_s)
0849                   << " to a " << a_type
0850                   << std::endl;
0851       return false;
0852     }
0853     if(!a_ntu.create_col<double>(a_name,v)) {
0854       a_ntu.out() << "tools::aida::create_col :"
0855                   << " can't create column of type " << sout(a_type)
0856                   << std::endl;
0857       return false;
0858     }
0859   } else if(a_type==s_aida_type((unsigned short)0)) {
0860     unsigned short v = 0;
0861     if(a_s.size()&&!to<unsigned short>(a_s,v)) {
0862       a_ntu.out() << "tools::aida::create_col :"
0863                   << " can't convert def " << sout(a_s)
0864                   << " to a " << a_type
0865                   << std::endl;
0866       return false;
0867     }
0868     if(!a_ntu.create_col<unsigned short>(a_name,v)) {
0869       a_ntu.out() << "tools::aida::create_col :"
0870                   << " can't create column of type " << sout(a_type)
0871                   << std::endl;
0872       return false;
0873     }
0874 
0875   } else if(a_type==s_aida_type((unsigned int)0)) {
0876     unsigned int v = 0;
0877     if(a_s.size()&&!to<unsigned int>(a_s,v)) {
0878       a_ntu.out() << "tools::aida::create_col :"
0879                   << " can't convert def " << sout(a_s)
0880                   << " to a " << a_type
0881                   << std::endl;
0882       return false;
0883     }
0884     if(!a_ntu.create_col<unsigned int>(a_name,v)) {
0885       a_ntu.out() << "tools::aida::create_col :"
0886                   << " can't create column of type " << sout(a_type)
0887                   << std::endl;
0888       return false;
0889     }
0890 
0891   } else if(a_type==s_aida_type((uint64)0)) {
0892     uint64 v = 0;
0893     if(a_s.size()&&!to<uint64>(a_s,v)) {
0894       a_ntu.out() << "tools::aida::create_col :"
0895                   << " can't convert def " << sout(a_s)
0896                   << " to a " << a_type
0897                   << std::endl;
0898       return false;
0899     }
0900     if(!a_ntu.create_col<uint64>(a_name,v)) {
0901       a_ntu.out() << "tools::aida::create_col :"
0902                   << " can't create column of type " << sout(a_type)
0903                   << std::endl;
0904       return false;
0905     }
0906 
0907   /////////////////////////////////////////
0908   /////////////////////////////////////////
0909   } else if(a_type==s_aida_type((bool)true)) {
0910     bool v = false;
0911     if(a_s.size()&&!to(a_s,v)) {
0912       a_ntu.out() << "tools::aida::create_col :"
0913                   << " can't convert def " << sout(a_s)
0914                   << " to a " << a_type
0915                   << std::endl;
0916       return false;
0917     }
0918     if(!a_ntu.create_col<bool>(a_name,v)) {
0919       a_ntu.out() << "tools::aida::create_col :"
0920                   << " can't create column of type " << sout(a_type)
0921                   << std::endl;
0922       return false;
0923     }
0924 
0925   } else if(a_type==s_aida_type(std::string())) {
0926     if(!a_ntu.create_col<std::string>(a_name,a_s)) {
0927       a_ntu.out() << "tools::aida::create_col :"
0928                   << " can't create column of type " << sout(a_type)
0929                   << std::endl;
0930       return false;
0931     }
0932 
0933   } else if(a_type==s_aida_type((int64)0)) {
0934     int64 v = 0;
0935     if(a_s.size()&&!to<int64>(a_s,v)) {
0936       a_ntu.out() << "tools::aida::create_col :"
0937                   << " can't convert def " << sout(a_s)
0938                   << " to a " << a_type
0939                   << std::endl;
0940       return false;
0941     }
0942     if(!a_ntu.create_col<int64>(a_name,v)) {
0943       a_ntu.out() << "tools::aida::create_col :"
0944                   << " can't create column of type " << sout(a_type)
0945                   << std::endl;
0946       return false;
0947     }
0948 
0949   } else if(a_type==s_aida_type_ituple()) {
0950     // we expect a booking string on a_s.
0951 
0952     if(!a_is_ntu) {
0953       a_ntu.out() << "tools::aida::create_col :"
0954                   << " mismatch a_is_ntu/a_type."
0955                   << std::endl;
0956       return false;
0957     }
0958     if(a_s.empty()) {
0959       a_ntu.out() << "tools::aida::create_col :"
0960                   << " empty booking string."
0961                   << std::endl;
0962       return false;
0963     }
0964 
0965     columns::finder f(a_ntu.out(),a_s);
0966     if(!f.find_variables()) {
0967       a_ntu.out() << "tools::aida::create_col :"
0968             << " find_variables() failed for " << sout(a_s) << "."
0969             << std::endl;
0970       return false;
0971     }
0972 
0973     aida_col_ntu* col_ntu = new aida_col_ntu(a_ntu.out(),a_name);
0974     //create columns on the fillable.
0975     base_ntu* sub_base_ntu = col_ntu->get_to_fill();
0976     if(!sub_base_ntu) {delete col_ntu;return false;}
0977     ntuple* sub_aida = safe_cast<base_ntu,ntuple>(*sub_base_ntu);
0978     if(!sub_aida) {delete col_ntu;return false;}
0979 
0980     std::vector<value> vars;f.result(vars);
0981     if(!create_cols_from_vals(*sub_aida,vars)) {
0982       columns::delete_columns(vars);
0983       delete col_ntu;
0984       return false;
0985     }
0986     columns::delete_columns(vars);
0987     a_ntu.add_column(col_ntu);
0988 
0989     //FIXME : double[]
0990 
0991   } else {
0992     a_ntu.out() << "tools::aida::create_col :"
0993                 << " col type " << sout(a_type)
0994                 << " not yet handled."
0995                 << std::endl;
0996     return false;
0997   }
0998 
0999   return true;
1000 }
1001 
1002 
1003 }}
1004 
1005 #endif