Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/wroot/base_pntuple_column_wise is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_wroot_base_pntuple_column_wise
0005 #define tools_wroot_base_pntuple_column_wise
0006 
0007 // pntuple = for parallel ntupling.
0008 
0009 #include "base_pntuple"
0010 
0011 #include "../ntuple_booking"
0012 
0013 namespace tools {
0014 namespace wroot {
0015 
0016 class base_pntuple_column_wise : public base_pntuple {
0017   typedef base_pntuple parent;
0018 public:
0019   class file {
0020   public:
0021     file(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,bool a_verbose)
0022     :m_out(a_out)
0023     ,m_byte_swap(a_byte_swap),m_compression(a_compression),m_verbose(a_verbose)
0024     {}
0025     virtual ~file(){}
0026   public:
0027     file(const file& a_from)
0028     :m_out(a_from.m_out)
0029     ,m_byte_swap(a_from.m_byte_swap),m_compression(a_from.m_compression),m_verbose(a_from.m_verbose)
0030     {}
0031     file& operator=(const file& a_from) {
0032       m_byte_swap = a_from.m_byte_swap;
0033       m_verbose = a_from.m_verbose;
0034       return *this;
0035     }
0036   public:
0037     bool verbose() const {return m_verbose;}
0038     std::ostream& out() const {return m_out;}
0039     bool byte_swap() const {return m_byte_swap;}
0040     uint32 compression() const {return m_compression;}
0041   protected:
0042     std::ostream& m_out;
0043     bool m_byte_swap;
0044     uint32 m_compression;
0045     bool m_verbose;
0046   };
0047 
0048 public:
0049   base_pntuple_column_wise(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,seek a_seek_directory,
0050                            const std::string& a_name,const std::string& a_title,bool a_verbose)
0051   :parent(a_out,a_seek_directory,a_name,a_title)
0052   ,m_file(a_out,a_byte_swap,a_compression,a_verbose)
0053   {}
0054   base_pntuple_column_wise(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,seek a_seek_directory,
0055                            const std::vector<uint32>& a_basket_sizes,
0056                            const ntuple_booking& a_bkg,bool a_verbose)
0057   :parent(a_out,a_seek_directory,a_bkg.name(),a_bkg.title())
0058   ,m_file(a_out,a_byte_swap,a_compression,a_verbose)
0059   {
0060     const std::vector<column_booking>& cols = a_bkg.columns();
0061 
0062     if(a_basket_sizes.size()!=cols.size()) {
0063       a_out << "tools::wroot::base_pntuple_column_wise :"
0064             << " a_basket_sizes.size() (" << a_basket_sizes.size() << ") != "
0065             << "a_bkg.columns().size() (" << a_bkg.columns().size() << ")."
0066             << std::endl;
0067       return;
0068     }
0069     std::vector<uint32>::const_iterator itb = a_basket_sizes.begin();
0070 
0071     tools_vforcit(column_booking,cols,it){
0072 
0073 #define TOOLS_WROOT_PNTUPLE_CREATE_COL(a__type) \
0074       if((*it).cls_id()==_cid(a__type())) {\
0075         a__type* user = (a__type*)(*it).user_obj();\
0076         if(user) {\
0077           if(!create_column_ref<a__type>(*itb,(*it).name(),*user)) {\
0078             a_out << "tools::wroot::base_pntuple_column_wise : create_column_ref(" << (*it).name() << ") failed." << std::endl;\
0079             safe_clear<icol>(m_cols);\
0080             safe_clear<branch>(m_branches);\
0081             return;\
0082           }\
0083           itb++;\
0084         } else {\
0085           if(!create_column<a__type>(*itb,(*it).name())) {\
0086             a_out << "tools::wroot::base_pntuple_column_wise : create_column(" << (*it).name() << ") failed." << std::endl;\
0087             safe_clear<icol>(m_cols);\
0088             safe_clear<branch>(m_branches);\
0089             return;\
0090           }\
0091           itb++;\
0092         }\
0093       }
0094 
0095 #define TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(a__type) \
0096       if((*it).cls_id()==_cid_std_vector<a__type>()) {\
0097         std::vector<a__type>* vec = (std::vector<a__type>*)(*it).user_obj();\
0098         if(vec) {\
0099           if(!create_column_vector_ref<a__type>(*itb,(*it).name(),*vec)) {\
0100             a_out << "tools::wroot::base_pntuple_column_wise :"\
0101                   << " create_column failed for std::vector column_ref " << sout((*it).name()) << "."\
0102                   << std::endl;\
0103             safe_clear<icol>(m_cols);\
0104             safe_clear<branch>(m_branches);\
0105             return;\
0106           }\
0107           itb++;\
0108         } else {\
0109           if(!create_column_vector<a__type>(*itb,(*it).name())) {\
0110             a_out << "tools::wroot::base_pntuple_column_wise :"\
0111                   << " create_column failed for std::vector column " << sout((*it).name()) << "."\
0112                   << std::endl;\
0113             safe_clear<icol>(m_cols);\
0114             safe_clear<branch>(m_branches);\
0115             return;\
0116           }\
0117           itb++;\
0118         }\
0119       }
0120 
0121            TOOLS_WROOT_PNTUPLE_CREATE_COL(char)
0122       else TOOLS_WROOT_PNTUPLE_CREATE_COL(short)
0123       else TOOLS_WROOT_PNTUPLE_CREATE_COL(int)
0124       else TOOLS_WROOT_PNTUPLE_CREATE_COL(float)
0125       else TOOLS_WROOT_PNTUPLE_CREATE_COL(double)
0126 
0127       else if((*it).cls_id()==_cid(std::string())) {
0128         std::string* user = (std::string*)(*it).user_obj();
0129         if(user) {
0130           if(!create_column_string_ref(*itb,(*it).name(),*user)) {
0131             a_out << "tools::wroot::base_pntuple_column_wise : create_column_string_ref(" << (*it).name() << ") failed."
0132                   << std::endl;
0133             safe_clear<icol>(m_cols);
0134             safe_clear<branch>(m_branches);
0135             return;
0136           }
0137           itb++;
0138         } else {
0139           if(!create_column_string(*itb,(*it).name())) {
0140             a_out << "tools::wroot::base_pntuple_column_wise : create_column_string(" << (*it).name() << ") failed." << std::endl;
0141             safe_clear<icol>(m_cols);
0142             safe_clear<branch>(m_branches);
0143             return;
0144           }
0145           itb++;
0146         }
0147       }
0148 
0149       else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(char)
0150       else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(short)
0151       else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(int)
0152       else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(float)
0153       else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(double)
0154 
0155       else if((*it).cls_id()==_cid_std_vector<std::string>()) {\
0156         std::vector<std::string>* user = (std::vector<std::string>*)(*it).user_obj();
0157         char sep = '\n';
0158         if(user) {
0159           if(!create_column_vector_string_ref(*itb,(*it).name(),*user,sep)) {
0160             a_out << "tools::wroot::base_pntuple_column_wise :"
0161                   << " create_column_vector_string_ref(" << (*it).name() << ") failed." << std::endl;
0162             safe_clear<icol>(m_cols);
0163             safe_clear<branch>(m_branches);
0164             return;
0165           }
0166           itb++;
0167         } else {
0168           if(!create_column_vector_string(*itb,(*it).name(),std::vector<std::string>(),sep)) {
0169             a_out << "tools::wroot::base_pntuple_column_wise :"
0170                   << " create_column_vector_string(" << (*it).name() << ") failed." << std::endl;
0171             safe_clear<icol>(m_cols);
0172             safe_clear<branch>(m_branches);
0173             return;
0174           }
0175           itb++;
0176         }
0177       }
0178 
0179       // no leaf_store_class() defined for the other types.
0180 
0181       else {
0182         a_out << "tools::wroot::base_pntuple_column_wise :"
0183               << " for column " << sout((*it).name())
0184               << ", type with cid " << (*it).cls_id() << " not yet handled."
0185               << std::endl;
0186         //throw
0187         safe_clear<icol>(m_cols);
0188         safe_clear<branch>(m_branches);
0189         return;
0190       }
0191 
0192 #undef TOOLS_WROOT_PNTUPLE_CREATE_COL
0193 #undef TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL
0194 
0195     }
0196   }
0197 
0198   virtual ~base_pntuple_column_wise() {safe_clear<branch>(m_branches);}
0199 protected:
0200   base_pntuple_column_wise(const base_pntuple_column_wise& a_from):parent(a_from),m_file(a_from.m_file){}
0201   base_pntuple_column_wise& operator=(const base_pntuple_column_wise&){return *this;}
0202 public:
0203   template <class T>
0204   column_ref<T>* create_column_ref(uint32 a_basket_size,const std::string& a_name,const T& a_ref) {
0205     if(find_named<icol>(m_cols,a_name)) return 0;
0206     branch* _branch = new branch(m_file.out(),m_file.byte_swap(),m_file.compression(),
0207                                  m_seek_directory,a_name,m_name,m_file.verbose());
0208     _branch->set_basket_size(a_basket_size);
0209     column_ref<T>* col = new column_ref<T>(*_branch,a_name,a_ref);
0210     if(!col) {delete _branch;return 0;}
0211     m_branches.push_back(_branch);
0212     m_cols.push_back(col);
0213     return col;
0214   }
0215 
0216   template <class T>
0217   column<T>* create_column(uint32 a_basket_size,const std::string& a_name,const T& a_def = T()) {
0218     if(find_named<icol>(m_cols,a_name)) return 0;
0219     branch*  _branch = new branch(m_file.out(),m_file.byte_swap(),m_file.compression(),
0220                                   m_seek_directory,a_name,m_name,m_file.verbose());
0221     _branch->set_basket_size(a_basket_size);
0222     column<T>* col = new column<T>(*_branch,a_name,a_def);
0223     if(!col) {delete _branch;return 0;}
0224     m_branches.push_back(_branch);
0225     m_cols.push_back(col);
0226     return col;
0227   }
0228 
0229   column_string_ref* create_column_string_ref(uint32 a_basket_size,const std::string& a_name,const std::string& a_ref) {
0230     if(find_named<icol>(m_cols,a_name)) return 0;
0231     branch* _branch = new branch(m_file.out(),m_file.byte_swap(),m_file.compression(),
0232                                  m_seek_directory,a_name,m_name,m_file.verbose());
0233     _branch->set_basket_size(a_basket_size);
0234     column_string_ref* col = new column_string_ref(*_branch,a_name,a_ref);
0235     if(!col) {delete _branch;return 0;}
0236     m_branches.push_back(_branch);
0237     m_cols.push_back(col);
0238     return col;
0239   }
0240 
0241   column_string* create_column_string(uint32 a_basket_size,
0242                                       const std::string& a_name,
0243                                       const std::string& a_def = std::string()) {
0244     if(find_named<icol>(m_cols,a_name)) return 0;
0245     branch* _branch = new branch(m_file.out(),m_file.byte_swap(),m_file.compression(),
0246                                  m_seek_directory,a_name,m_name,m_file.verbose());
0247     _branch->set_basket_size(a_basket_size);
0248     column_string* col = new column_string(*_branch,a_name,a_def);
0249     if(!col) {delete _branch;return 0;}
0250     m_branches.push_back(_branch);
0251     m_cols.push_back(col);
0252     return col;
0253   }
0254 
0255   column_vector_string_ref* create_column_vector_string_ref(uint32 a_basket_size,const std::string& a_name,
0256                                                             const std::vector<std::string>& a_ref,char a_sep) {
0257     if(find_named<icol>(m_cols,a_name)) return 0;
0258     branch* _branch = new branch(m_file.out(),m_file.byte_swap(),m_file.compression(),
0259                                  m_seek_directory,a_name,m_name,m_file.verbose());
0260     _branch->set_basket_size(a_basket_size);
0261     column_vector_string_ref* col = new column_vector_string_ref(*_branch,a_name,a_ref,a_sep);
0262     if(!col) {delete _branch;return 0;}
0263     m_branches.push_back(_branch);
0264     m_cols.push_back(col);
0265     return col;
0266   }
0267 
0268   column_vector_string* create_column_vector_string(uint32 a_basket_size,
0269                                                     const std::string& a_name,
0270                                                     const std::vector<std::string>& a_def,char a_sep) {
0271     if(find_named<icol>(m_cols,a_name)) return 0;
0272     branch* _branch = new branch(m_file.out(),m_file.byte_swap(),m_file.compression(),
0273                                  m_seek_directory,a_name,m_name,m_file.verbose());
0274     _branch->set_basket_size(a_basket_size);
0275     column_vector_string* col = new column_vector_string(*_branch,a_name,a_def,a_sep);
0276     if(!col) {delete _branch;return 0;}
0277     m_branches.push_back(_branch);
0278     m_cols.push_back(col);
0279     return col;
0280   }
0281 
0282   template <class T>
0283   std_vector_column_ref<T>* create_column_vector_ref(uint32 a_basket_size,const std::string& a_name,const std::vector<T>& a_ref) {
0284     if(find_named<icol>(m_cols,a_name)) return 0;
0285     std_vector_be_ref<T>* _branch = new std_vector_be_ref<T>(m_file.out(),m_file.byte_swap(),m_file.compression(),
0286                                                              m_seek_directory,a_name,m_name,a_ref,m_file.verbose());
0287     _branch->set_basket_size(a_basket_size);
0288     std_vector_column_ref<T>* col = new std_vector_column_ref<T>(*_branch,a_name,a_ref);
0289     if(!col) {delete _branch;return 0;}
0290     m_branches.push_back(_branch);
0291     m_cols.push_back(col);
0292     return col;
0293   }
0294 
0295   template <class T>
0296   std_vector_column<T>* create_column_vector(uint32 a_basket_size,const std::string& a_name,const std::vector<T>& a_def = std::vector<T>()) {
0297     if(find_named<icol>(m_cols,a_name)) return 0;
0298     std_vector_be_pointer<T>* _branch = new std_vector_be_pointer<T>(m_file.out(),m_file.byte_swap(),m_file.compression(),
0299                                                                      m_seek_directory,a_name,m_name,0,m_file.verbose());
0300     _branch->set_basket_size(a_basket_size);
0301     std_vector_column<T>* col = new std_vector_column<T>(*_branch,a_name,a_def);
0302     if(!col) {delete _branch;return 0;}
0303     _branch->set_pointer(&(col->variable()));
0304     m_branches.push_back(_branch);
0305     m_cols.push_back(col);
0306     return col;
0307   }
0308 protected:
0309   file m_file;
0310   std::vector<branch*> m_branches;
0311 };
0312 
0313 }}
0314 
0315 #endif