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