Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/wroot/base_pntuple_row_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_row_wise
0005 #define tools_wroot_base_pntuple_row_wise
0006 
0007 // pntuple = for parallel ntupling.
0008 
0009 #include "base_pntuple"
0010 
0011 #include "../ntuple_booking"
0012 
0013 #ifdef TOOLS_MEM
0014 #include "../mem"
0015 #endif
0016 
0017 namespace tools {
0018 namespace wroot {
0019 
0020 class base_pntuple_row_wise : public base_pntuple {
0021   typedef base_pntuple parent;
0022 public:
0023   base_pntuple_row_wise(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,seek a_seek_directory,
0024                         const std::string& a_name,const std::string& a_title,
0025                         uint32 a_basket_size,bool a_verbose)
0026   :parent(a_out,a_seek_directory,a_name,a_title)
0027   ,m_row_wise_branch(a_out,a_byte_swap,a_compression,a_seek_directory,"row_wise_branch","row_wise_branch",a_verbose)
0028   {
0029     m_row_wise_branch.set_basket_size(a_basket_size);
0030   }
0031 
0032   base_pntuple_row_wise(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,seek a_seek_directory,
0033                         uint32 a_basket_size,
0034                         const ntuple_booking& a_bkg,bool a_verbose)
0035   :parent(a_out,a_seek_directory,a_bkg.name(),a_bkg.title())
0036   ,m_row_wise_branch(a_out,a_byte_swap,a_compression,a_seek_directory,"row_wise_branch","row_wise_branch",a_verbose)
0037   {
0038     m_row_wise_branch.set_basket_size(a_basket_size);
0039 
0040     const std::vector<column_booking>& cols = a_bkg.columns();
0041 
0042     tools_vforcit(column_booking,cols,it){
0043 
0044 #define TOOLS_WROOT_PNTUPLE_CREATE_COL(a__type) \
0045       if((*it).cls_id()==_cid(a__type())) {\
0046         a__type* user = (a__type*)(*it).user_obj();\
0047         if(user) {\
0048           if(!create_column_ref<a__type>((*it).name(),*user)) {\
0049             a_out << "tools::wroot::base_pntuple_row_wise : create_column_ref(" << (*it).name() << ") failed." << std::endl;\
0050             safe_clear<icol>(m_cols);\
0051             return;\
0052           }\
0053         } else {\
0054           if(!create_column<a__type>((*it).name())) {\
0055             a_out << "tools::wroot::base_pntuple_row_wise : create_column(" << (*it).name() << ") failed." << std::endl;\
0056             safe_clear<icol>(m_cols);\
0057             return;\
0058           }\
0059         }\
0060       }
0061 
0062 #define TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(a__type) \
0063       if((*it).cls_id()==_cid_std_vector<a__type>()) {\
0064         std::vector<a__type>* vec = (std::vector<a__type>*)(*it).user_obj();\
0065         if(vec) {\
0066           if(!create_column_vector_ref<a__type>((*it).name(),*vec)) {\
0067             a_out << "tools::wroot::base_pntuple_row_wise :"\
0068                   << " create_column_vector_ref failed for std::vector column " << sout((*it).name()) << "."\
0069                   << std::endl;\
0070             safe_clear<icol>(m_cols);\
0071             return;\
0072           }\
0073         } else {\
0074           if(!create_column_vector<a__type>((*it).name())) {\
0075             a_out << "tools::wroot::base_pntuple_row_wise :"\
0076                   << " create_column_vector failed for std::vector column " << sout((*it).name()) << "."\
0077                   << std::endl;\
0078             safe_clear<icol>(m_cols);\
0079             return;\
0080           }\
0081         }\
0082       }
0083 
0084            TOOLS_WROOT_PNTUPLE_CREATE_COL(char)
0085       else TOOLS_WROOT_PNTUPLE_CREATE_COL(short)
0086       else TOOLS_WROOT_PNTUPLE_CREATE_COL(int)
0087       else TOOLS_WROOT_PNTUPLE_CREATE_COL(float)
0088       else TOOLS_WROOT_PNTUPLE_CREATE_COL(double)
0089 
0090       else if((*it).cls_id()==_cid(std::string())) {
0091         std::string* user = (std::string*)(*it).user_obj();
0092         if(user) {
0093           if(!create_column_string_ref((*it).name(),*user)) {
0094             a_out << "tools::wroot::base_pntuple_row_wise : create_column_string_ref(" << (*it).name() << ") failed." << std::endl;
0095             safe_clear<icol>(m_cols);
0096             return;
0097           }
0098         } else {
0099           if(!create_column_string((*it).name())) {
0100             a_out << "tools::wroot::base_pntuple_row_wise : create_column_string(" << (*it).name() << ") failed." << std::endl;
0101             safe_clear<icol>(m_cols);
0102             return;
0103           }
0104         }
0105       }
0106 
0107       else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(char)
0108       else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(short)
0109       else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(int)
0110       else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(float)
0111       else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(double)
0112 
0113       else if((*it).cls_id()==_cid_std_vector<std::string>()) {\
0114         std::vector<std::string>* user = (std::vector<std::string>*)(*it).user_obj();
0115         char sep = '\n';
0116         if(user) {
0117           if(!create_column_vector_string_ref((*it).name(),*user,sep)) {
0118             a_out << "tools::wroot::base_pntuple_row_wise :"
0119                   << " create_column_vector_string_ref(" << (*it).name() << ") failed." << std::endl;
0120             safe_clear<icol>(m_cols);
0121             return;
0122           }
0123         } else {
0124           if(!create_column_vector_string((*it).name(),std::vector<std::string>(),sep)) {
0125             a_out << "tools::wroot::base_pntuple_row_wise :"
0126                   << " create_column_vector_string(" << (*it).name() << ") failed." << std::endl;
0127             safe_clear<icol>(m_cols);
0128             return;
0129           }
0130         }
0131       }
0132 
0133       // no leaf_store_class() defined for the other types.
0134 
0135       else {
0136         a_out << "tools::wroot::base_pntuple_row_wise :"
0137               << " for column " << sout((*it).name())
0138               << ", type with cid " << (*it).cls_id() << " not yet handled."
0139               << std::endl;
0140         //throw
0141         safe_clear<icol>(m_cols);
0142         return;
0143       }
0144 
0145 #undef TOOLS_WROOT_PNTUPLE_CREATE_COL
0146 #undef TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL
0147     }
0148   }
0149 
0150   virtual ~base_pntuple_row_wise() {}
0151 protected:
0152   base_pntuple_row_wise(const base_pntuple_row_wise& a_from)
0153   :parent(a_from)
0154   ,m_row_wise_branch(m_out,false,0,0,"row_wise_branch","row_wise_branch",false)
0155   {}
0156   base_pntuple_row_wise& operator=(const base_pntuple_row_wise&){return *this;}
0157 public:
0158   template <class T>
0159   column_ref<T>* create_column_ref(const std::string& a_name,const T& a_ref) {
0160     if(find_named<icol>(m_cols,a_name)) return 0;
0161     column_ref<T>* col = new column_ref<T>(m_row_wise_branch,a_name,a_ref);
0162     if(!col) return 0;
0163     m_cols.push_back(col);
0164     return col;
0165   }
0166 
0167   template <class T>
0168   column<T>* create_column(const std::string& a_name,const T& a_def = T()) {
0169     if(find_named<icol>(m_cols,a_name)) return 0;
0170     column<T>* col = new column<T>(m_row_wise_branch,a_name,a_def);
0171     if(!col) return 0;
0172     m_cols.push_back(col);
0173     return col;
0174   }
0175 
0176   column_string_ref* create_column_string_ref(const std::string& a_name,const std::string& a_ref) {
0177     if(find_named<icol>(m_cols,a_name)) return 0;
0178     column_string_ref* col = new column_string_ref(m_row_wise_branch,a_name,a_ref);
0179     if(!col) return 0;
0180     m_cols.push_back(col);
0181     return col;
0182   }
0183 
0184   column_string* create_column_string(const std::string& a_name,const std::string& a_def = std::string()) {
0185     if(find_named<icol>(m_cols,a_name)) return 0;
0186     column_string* col = new column_string(m_row_wise_branch,a_name,a_def);
0187     if(!col) return 0;
0188     m_cols.push_back(col);
0189     return col;
0190   }
0191 
0192   column_vector_string_ref* create_column_vector_string_ref(const std::string& a_name,
0193                                                             const std::vector<std::string>& a_ref,char a_sep) {
0194     if(find_named<icol>(m_cols,a_name)) return 0;
0195     column_vector_string_ref* col = new column_vector_string_ref(m_row_wise_branch,a_name,a_ref,a_sep);
0196     if(!col) return 0;
0197     m_cols.push_back(col);
0198     return col;
0199   }
0200 
0201   column_vector_string* create_column_vector_string(const std::string& a_name,const std::vector<std::string>& a_def,char a_sep) {
0202     if(find_named<icol>(m_cols,a_name)) return 0;
0203     column_vector_string* col = new column_vector_string(m_row_wise_branch,a_name,a_def,a_sep);
0204     if(!col) return 0;
0205     m_cols.push_back(col);
0206     return col;
0207   }
0208 
0209   template <class T>
0210   std_vector_column_ref<T>* create_column_vector_ref(const std::string& a_name,const std::vector<T>& a_ref) {
0211     if(find_named<icol>(m_cols,a_name)) return 0;
0212     std_vector_column_ref<T>* col = new std_vector_column_ref<T>(m_row_wise_branch,a_name,a_ref);
0213     if(!col) return 0;
0214     m_cols.push_back(col);
0215     return col;
0216   }
0217 
0218   template <class T>
0219   std_vector_column<T>* create_column_vector(const std::string& a_name,const std::vector<T>& a_def = std::vector<T>()) {
0220     if(find_named<icol>(m_cols,a_name)) return 0;
0221     std_vector_column<T>* col = new std_vector_column<T>(m_row_wise_branch,a_name,a_def);
0222     if(!col) return 0;
0223     m_cols.push_back(col);
0224     return col;
0225   }
0226 
0227 protected:
0228   branch m_row_wise_branch;
0229 };
0230 
0231 }}
0232 
0233 #endif