Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 3 4 #ifndef tools_wroot_base_pntuple_row_wise 5 #define tools_wroot_base_pntuple_row_wise 6 7 // pntuple = for parallel ntupling. 8 9 #include "base_pntuple" 10 11 #include "../ntuple_booking" 12 13 #ifdef TOOLS_MEM 14 #include "../mem" 15 #endif 16 17 namespace tools { 18 namespace wroot { 19 20 class base_pntuple_row_wise : public base_pntuple { 21 typedef base_pntuple parent; 22 public: 23 base_pntuple_row_wise(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,seek a_seek_directory, 24 const std::string& a_name,const std::string& a_title, 25 uint32 a_basket_size,bool a_verbose) 26 :parent(a_out,a_seek_directory,a_name,a_title) 27 ,m_row_wise_branch(a_out,a_byte_swap,a_compression,a_seek_directory,"row_wise_branch","row_wise_branch",a_verbose) 28 { 29 m_row_wise_branch.set_basket_size(a_basket_size); 30 } 31 32 base_pntuple_row_wise(std::ostream& a_out,bool a_byte_swap,uint32 a_compression,seek a_seek_directory, 33 uint32 a_basket_size, 34 const ntuple_booking& a_bkg,bool a_verbose) 35 :parent(a_out,a_seek_directory,a_bkg.name(),a_bkg.title()) 36 ,m_row_wise_branch(a_out,a_byte_swap,a_compression,a_seek_directory,"row_wise_branch","row_wise_branch",a_verbose) 37 { 38 m_row_wise_branch.set_basket_size(a_basket_size); 39 40 const std::vector<column_booking>& cols = a_bkg.columns(); 41 42 tools_vforcit(column_booking,cols,it){ 43 44 #define TOOLS_WROOT_PNTUPLE_CREATE_COL(a__type) \ 45 if((*it).cls_id()==_cid(a__type())) {\ 46 a__type* user = (a__type*)(*it).user_obj();\ 47 if(user) {\ 48 if(!create_column_ref<a__type>((*it).name(),*user)) {\ 49 a_out << "tools::wroot::base_pntuple_row_wise : create_column_ref(" << (*it).name() << ") failed." << std::endl;\ 50 safe_clear<icol>(m_cols);\ 51 return;\ 52 }\ 53 } else {\ 54 if(!create_column<a__type>((*it).name())) {\ 55 a_out << "tools::wroot::base_pntuple_row_wise : create_column(" << (*it).name() << ") failed." << std::endl;\ 56 safe_clear<icol>(m_cols);\ 57 return;\ 58 }\ 59 }\ 60 } 61 62 #define TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(a__type) \ 63 if((*it).cls_id()==_cid_std_vector<a__type>()) {\ 64 std::vector<a__type>* vec = (std::vector<a__type>*)(*it).user_obj();\ 65 if(vec) {\ 66 if(!create_column_vector_ref<a__type>((*it).name(),*vec)) {\ 67 a_out << "tools::wroot::base_pntuple_row_wise :"\ 68 << " create_column_vector_ref failed for std::vector column " << sout((*it).name()) << "."\ 69 << std::endl;\ 70 safe_clear<icol>(m_cols);\ 71 return;\ 72 }\ 73 } else {\ 74 if(!create_column_vector<a__type>((*it).name())) {\ 75 a_out << "tools::wroot::base_pntuple_row_wise :"\ 76 << " create_column_vector failed for std::vector column " << sout((*it).name()) << "."\ 77 << std::endl;\ 78 safe_clear<icol>(m_cols);\ 79 return;\ 80 }\ 81 }\ 82 } 83 84 TOOLS_WROOT_PNTUPLE_CREATE_COL(char) 85 else TOOLS_WROOT_PNTUPLE_CREATE_COL(short) 86 else TOOLS_WROOT_PNTUPLE_CREATE_COL(int) 87 else TOOLS_WROOT_PNTUPLE_CREATE_COL(float) 88 else TOOLS_WROOT_PNTUPLE_CREATE_COL(double) 89 90 else if((*it).cls_id()==_cid(std::string())) { 91 std::string* user = (std::string*)(*it).user_obj(); 92 if(user) { 93 if(!create_column_string_ref((*it).name(),*user)) { 94 a_out << "tools::wroot::base_pntuple_row_wise : create_column_string_ref(" << (*it).name() << ") failed." << std::endl; 95 safe_clear<icol>(m_cols); 96 return; 97 } 98 } else { 99 if(!create_column_string((*it).name())) { 100 a_out << "tools::wroot::base_pntuple_row_wise : create_column_string(" << (*it).name() << ") failed." << std::endl; 101 safe_clear<icol>(m_cols); 102 return; 103 } 104 } 105 } 106 107 else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(char) 108 else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(short) 109 else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(int) 110 else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(float) 111 else TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL(double) 112 113 else if((*it).cls_id()==_cid_std_vector<std::string>()) {\ 114 std::vector<std::string>* user = (std::vector<std::string>*)(*it).user_obj(); 115 char sep = '\n'; 116 if(user) { 117 if(!create_column_vector_string_ref((*it).name(),*user,sep)) { 118 a_out << "tools::wroot::base_pntuple_row_wise :" 119 << " create_column_vector_string_ref(" << (*it).name() << ") failed." << std::endl; 120 safe_clear<icol>(m_cols); 121 return; 122 } 123 } else { 124 if(!create_column_vector_string((*it).name(),std::vector<std::string>(),sep)) { 125 a_out << "tools::wroot::base_pntuple_row_wise :" 126 << " create_column_vector_string(" << (*it).name() << ") failed." << std::endl; 127 safe_clear<icol>(m_cols); 128 return; 129 } 130 } 131 } 132 133 // no leaf_store_class() defined for the other types. 134 135 else { 136 a_out << "tools::wroot::base_pntuple_row_wise :" 137 << " for column " << sout((*it).name()) 138 << ", type with cid " << (*it).cls_id() << " not yet handled." 139 << std::endl; 140 //throw 141 safe_clear<icol>(m_cols); 142 return; 143 } 144 145 #undef TOOLS_WROOT_PNTUPLE_CREATE_COL 146 #undef TOOLS_WROOT_PNTUPLE_CREATE_VEC_COL 147 } 148 } 149 150 virtual ~base_pntuple_row_wise() {} 151 protected: 152 base_pntuple_row_wise(const base_pntuple_row_wise& a_from) 153 :parent(a_from) 154 ,m_row_wise_branch(m_out,false,0,0,"row_wise_branch","row_wise_branch",false) 155 {} 156 base_pntuple_row_wise& operator=(const base_pntuple_row_wise&){return *this;} 157 public: 158 template <class T> 159 column_ref<T>* create_column_ref(const std::string& a_name,const T& a_ref) { 160 if(find_named<icol>(m_cols,a_name)) return 0; 161 column_ref<T>* col = new column_ref<T>(m_row_wise_branch,a_name,a_ref); 162 if(!col) return 0; 163 m_cols.push_back(col); 164 return col; 165 } 166 167 template <class T> 168 column<T>* create_column(const std::string& a_name,const T& a_def = T()) { 169 if(find_named<icol>(m_cols,a_name)) return 0; 170 column<T>* col = new column<T>(m_row_wise_branch,a_name,a_def); 171 if(!col) return 0; 172 m_cols.push_back(col); 173 return col; 174 } 175 176 column_string_ref* create_column_string_ref(const std::string& a_name,const std::string& a_ref) { 177 if(find_named<icol>(m_cols,a_name)) return 0; 178 column_string_ref* col = new column_string_ref(m_row_wise_branch,a_name,a_ref); 179 if(!col) return 0; 180 m_cols.push_back(col); 181 return col; 182 } 183 184 column_string* create_column_string(const std::string& a_name,const std::string& a_def = std::string()) { 185 if(find_named<icol>(m_cols,a_name)) return 0; 186 column_string* col = new column_string(m_row_wise_branch,a_name,a_def); 187 if(!col) return 0; 188 m_cols.push_back(col); 189 return col; 190 } 191 192 column_vector_string_ref* create_column_vector_string_ref(const std::string& a_name, 193 const std::vector<std::string>& a_ref,char a_sep) { 194 if(find_named<icol>(m_cols,a_name)) return 0; 195 column_vector_string_ref* col = new column_vector_string_ref(m_row_wise_branch,a_name,a_ref,a_sep); 196 if(!col) return 0; 197 m_cols.push_back(col); 198 return col; 199 } 200 201 column_vector_string* create_column_vector_string(const std::string& a_name,const std::vector<std::string>& a_def,char a_sep) { 202 if(find_named<icol>(m_cols,a_name)) return 0; 203 column_vector_string* col = new column_vector_string(m_row_wise_branch,a_name,a_def,a_sep); 204 if(!col) return 0; 205 m_cols.push_back(col); 206 return col; 207 } 208 209 template <class T> 210 std_vector_column_ref<T>* create_column_vector_ref(const std::string& a_name,const std::vector<T>& a_ref) { 211 if(find_named<icol>(m_cols,a_name)) return 0; 212 std_vector_column_ref<T>* col = new std_vector_column_ref<T>(m_row_wise_branch,a_name,a_ref); 213 if(!col) return 0; 214 m_cols.push_back(col); 215 return col; 216 } 217 218 template <class T> 219 std_vector_column<T>* create_column_vector(const std::string& a_name,const std::vector<T>& a_def = std::vector<T>()) { 220 if(find_named<icol>(m_cols,a_name)) return 0; 221 std_vector_column<T>* col = new std_vector_column<T>(m_row_wise_branch,a_name,a_def); 222 if(!col) return 0; 223 m_cols.push_back(col); 224 return col; 225 } 226 227 protected: 228 branch m_row_wise_branch; 229 }; 230 231 }} 232 233 #endif