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 5 #define tools_wroot_base_pntuple 6 7 // pntuple = for parallel ntupling. 8 9 #include "branch_element" 10 #include "icol" 11 12 #include "../vfind" 13 14 #ifdef TOOLS_MEM 15 #include "../mem" 16 #endif 17 18 namespace tools { 19 namespace wroot { 20 21 class base_pntuple { 22 #ifdef TOOLS_MEM 23 static const std::string& s_class() { 24 static const std::string s_v("tools::wroot::base_pntuple"); 25 return s_v; 26 } 27 #endif 28 public: 29 30 #include "columns.icc" 31 32 public: 33 base_pntuple(std::ostream& a_out,seek a_seek_directory,const std::string& a_name,const std::string& a_title) 34 :m_out(a_out) 35 ,m_seek_directory(a_seek_directory) 36 ,m_name(a_name) 37 ,m_title(a_title) 38 { 39 #ifdef TOOLS_MEM 40 mem::increment(s_class().c_str()); 41 #endif 42 } 43 44 virtual ~base_pntuple() { 45 safe_clear<icol>(m_cols); 46 #ifdef TOOLS_MEM 47 mem::decrement(s_class().c_str()); 48 #endif 49 } 50 protected: 51 base_pntuple(const base_pntuple& a_from):m_out(a_from.m_out){ 52 #ifdef TOOLS_MEM 53 mem::increment(s_class().c_str()); 54 #endif 55 } 56 base_pntuple& operator=(const base_pntuple&){return *this;} 57 public: 58 const std::vector<icol*>& columns() const {return m_cols;} 59 60 template <class T> 61 column_ref<T>* find_column_ref(const std::string& a_name) { 62 icol* col = find_named<icol>(m_cols,a_name); 63 if(!col) return 0; 64 return id_cast<icol, column_ref<T> >(*col); 65 } 66 67 template <class T> 68 column<T>* find_column(const std::string& a_name) { 69 icol* col = find_named<icol>(m_cols,a_name); 70 if(!col) return 0; 71 return id_cast<icol, column<T> >(*col); 72 } 73 74 column_string_ref* find_column_string_ref(const std::string& a_name) { 75 icol* col = find_named<icol>(m_cols,a_name); 76 if(!col) return 0; 77 return id_cast<icol, column_string_ref >(*col); 78 } 79 80 column_string* find_column_string(const std::string& a_name) { 81 icol* col = find_named<icol>(m_cols,a_name); 82 if(!col) return 0; 83 return id_cast<icol, column_string >(*col); 84 } 85 86 template <class T> 87 std_vector_column_ref<T>* find_column_vector_ref(const std::string& a_name) { 88 icol* col = find_named<icol>(m_cols,a_name); 89 if(!col) return 0; 90 return id_cast<icol, std_vector_column_ref<T> >(*col); 91 } 92 93 template <class T> 94 std_vector_column<T>* find_column_vector(const std::string& a_name) { 95 icol* col = find_named<icol>(m_cols,a_name); 96 if(!col) return 0; 97 return id_cast<icol, std_vector_column<T> >(*col); 98 } 99 100 column_vector_string_ref* find_column_vector_string_ref(const std::string& a_name) { 101 icol* col = find_named<icol>(m_cols,a_name); 102 if(!col) return 0; 103 return id_cast<icol, column_vector_string_ref >(*col); 104 } 105 106 column_vector_string* find_column_vector_string(const std::string& a_name) { 107 icol* col = find_named<icol>(m_cols,a_name); 108 if(!col) return 0; 109 return id_cast<icol, column_vector_string >(*col); 110 } 111 112 void print_columns(std::ostream& a_out) { 113 a_out << "for ntuple named " << sout(m_name) << ", number of columns " << m_cols.size() << " :" << std::endl; 114 tools_vforit(icol*,m_cols,it) { 115 a_out << " " << (*it)->name() << std::endl; 116 } 117 } 118 119 //void set_basket_size(uint32 a_size) {tools_vforit(icol*,m_cols,it) (*it)->set_basket_size(a_size);} 120 121 protected: 122 std::ostream& m_out; 123 seek m_seek_directory; 124 std::string m_name; 125 std::string m_title; 126 std::vector<icol*> m_cols; 127 }; 128 129 }} 130 131 #endif