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