File indexing completed on 2025-01-18 09:57:48
0001
0002
0003
0004
0005
0006 template <class T>
0007 class column_ref : public virtual icol {
0008 #ifdef TOOLS_MEM
0009 static const std::string& s_class() {
0010 static const std::string s_v("tools::wroot::ntuple::column_ref<"+stype(T())+">");
0011 return s_v;
0012 }
0013 #endif
0014 public:
0015 static cid id_class() {
0016 static const T s_v = T();
0017 return _cid(s_v)+10000;
0018 }
0019 virtual void* cast(cid a_class) const {
0020 if(void* p = cmp_cast<column_ref>(this,a_class)) {return p;}
0021 else return 0;
0022 }
0023 virtual cid id_cls() const {return id_class();}
0024 public:
0025 virtual void add() {}
0026 virtual void set_def() {}
0027 virtual const std::string& name() const {return m_leaf->name();}
0028 virtual void set_basket_size(uint32 a_size) {m_branch.set_basket_size(a_size);}
0029 virtual branch& get_branch() const {return m_branch;}
0030 virtual base_leaf* get_leaf() const {return m_leaf;}
0031 public:
0032 column_ref(branch& a_branch,const std::string& a_name,const T& a_ref)
0033 :m_branch(a_branch),m_leaf(0)
0034 {
0035 #ifdef TOOLS_MEM
0036 mem::increment(s_class().c_str());
0037 #endif
0038 m_leaf = m_branch.create_leaf_ref<T>(a_name,a_ref);
0039 }
0040 virtual ~column_ref(){
0041 #ifdef TOOLS_MEM
0042 mem::decrement(s_class().c_str());
0043 #endif
0044 }
0045 protected:
0046 column_ref(const column_ref& a_from)
0047 :icol(a_from)
0048 ,m_branch(a_from.m_branch)
0049 ,m_leaf(0)
0050 {}
0051 column_ref& operator=(const column_ref& a_from){
0052 if(&a_from==this) return *this;
0053 m_leaf = 0;
0054 return *this;
0055 }
0056 public:
0057 const T& variable() const {return m_leaf->variable();}
0058 T& variable() {return m_leaf->variable();}
0059 protected:
0060 branch& m_branch;
0061 leaf_ref<T>* m_leaf;
0062 };
0063
0064 template <class T>
0065 class column : public column_ref<T> {
0066 typedef column_ref<T> parent;
0067 #ifdef TOOLS_MEM
0068 static const std::string& s_class() {
0069 static const std::string s_v("tools::wroot::ntuple::column<"+stype(T())+">");
0070 return s_v;
0071 }
0072 #endif
0073 public:
0074 static cid id_class() {
0075 static const T s_v = T();
0076 return _cid(s_v);
0077 }
0078 virtual void* cast(cid a_class) const {
0079 if(void* p = cmp_cast<column>(this,a_class)) {return p;}
0080 else return 0;
0081 }
0082 virtual cid id_cls() const {return id_class();}
0083 public:
0084 virtual void set_def() {m_value = m_def;}
0085 public:
0086 column(branch& a_branch,const std::string& a_name,const T& a_def)
0087 :parent(a_branch,a_name,m_value)
0088 ,m_def(a_def),m_value(a_def)
0089 {
0090 #ifdef TOOLS_MEM
0091 mem::increment(s_class().c_str());
0092 #endif
0093 }
0094 virtual ~column(){
0095 #ifdef TOOLS_MEM
0096 mem::decrement(s_class().c_str());
0097 #endif
0098 }
0099 protected:
0100 column(const column& a_from)
0101 :icol(a_from)
0102 ,parent(a_from)
0103 ,m_def(a_from.m_def)
0104 ,m_value(a_from.m_value)
0105 {}
0106 column& operator=(const column& a_from){
0107 if(&a_from==this) return *this;
0108 parent::operator=(a_from);
0109 m_def = a_from.m_def;
0110 m_value = a_from.m_value;
0111 return *this;
0112 }
0113 public:
0114 column& operator=(const T& a_value){m_value = a_value;return *this;}
0115 bool fill(const T& a_value) {m_value = a_value;return true;}
0116 protected:
0117 T m_def;
0118 T m_value;
0119 };
0120
0121 class column_string_ref : public virtual icol {
0122 #ifdef TOOLS_MEM
0123 static const std::string& s_class() {
0124 static const std::string s_v("tools::wroot::ntuple::column_string_ref");
0125 return s_v;
0126 }
0127 #endif
0128 public:
0129 static cid id_class() {
0130 static const std::string s_v;
0131 return _cid(s_v)+10000;
0132 }
0133 virtual void* cast(cid a_class) const {
0134 if(void* p = cmp_cast<column_string_ref>(this,a_class)) {return p;}
0135 else return 0;
0136 }
0137 virtual cid id_cls() const {return id_class();}
0138 public:
0139 virtual void add() {}
0140 virtual void set_def() {}
0141 virtual const std::string& name() const {return m_leaf->name();}
0142 virtual void set_basket_size(uint32 a_size) {m_branch.set_basket_size(a_size);}
0143 virtual branch& get_branch() const {return m_branch;}
0144 virtual base_leaf* get_leaf() const {return m_leaf;}
0145 public:
0146 column_string_ref(branch& a_branch,const std::string& a_name,const std::string& a_ref)
0147 :m_branch(a_branch),m_leaf(0)
0148 {
0149 #ifdef TOOLS_MEM
0150 mem::increment(s_class().c_str());
0151 #endif
0152 m_leaf = m_branch.create_leaf_string_ref(a_name,a_ref);
0153 }
0154 virtual ~column_string_ref(){
0155 #ifdef TOOLS_MEM
0156 mem::decrement(s_class().c_str());
0157 #endif
0158 }
0159 protected:
0160 column_string_ref(const column_string_ref& a_from)
0161 :icol(a_from)
0162 ,m_branch(a_from.m_branch)
0163 ,m_leaf(0)
0164 {}
0165 column_string_ref& operator=(const column_string_ref& a_from){
0166 if(&a_from==this) return *this;
0167 m_leaf = 0;
0168 return *this;
0169 }
0170 public:
0171 const std::string& variable() const {return m_leaf->variable();}
0172 std::string& variable() {return m_leaf->variable();}
0173 protected:
0174 branch& m_branch;
0175 leaf_string_ref* m_leaf;
0176 };
0177
0178 class column_string : public column_string_ref {
0179 typedef column_string_ref parent;
0180 #ifdef TOOLS_MEM
0181 static const std::string& s_class() {
0182 static const std::string s_v("tools::wroot::ntuple::column_string");
0183 return s_v;
0184 }
0185 #endif
0186 public:
0187 static cid id_class() {
0188 static const std::string s_v;
0189 return _cid(s_v);
0190 }
0191 virtual void* cast(cid a_class) const {
0192 if(void* p = cmp_cast<column_string>(this,a_class)) {return p;}
0193 else return 0;
0194 }
0195 virtual cid id_cls() const {return id_class();}
0196 public:
0197 virtual void set_def() {m_value = m_def;}
0198 public:
0199 column_string(branch& a_branch,const std::string& a_name,const std::string& a_def)
0200 :parent(a_branch,a_name,m_value)
0201 ,m_def(a_def),m_value(a_def)
0202 {
0203 #ifdef TOOLS_MEM
0204 mem::increment(s_class().c_str());
0205 #endif
0206 }
0207 virtual ~column_string(){
0208 #ifdef TOOLS_MEM
0209 mem::decrement(s_class().c_str());
0210 #endif
0211 }
0212 protected:
0213 column_string(const column_string& a_from)
0214 :icol(a_from)
0215 ,parent(a_from)
0216 ,m_def(a_from.m_def)
0217 ,m_value(a_from.m_value)
0218 {}
0219 column_string& operator=(const column_string& a_from){
0220 if(&a_from==this) return *this;
0221 parent::operator=(a_from);
0222 m_def = a_from.m_def;
0223 m_value = a_from.m_value;
0224 return *this;
0225 }
0226 public:
0227 column_string& operator=(const std::string& a_value){m_value = a_value;return *this;}
0228 bool fill(const std::string& a_value) {m_value = a_value;return true;}
0229 protected:
0230 std::string m_def;
0231 std::string m_value;
0232 };
0233
0234 class column_vector_string_ref : public column_string_ref {
0235 typedef column_string_ref parent;
0236 #ifdef TOOLS_MEM
0237 static const std::string& s_class() {
0238 static const std::string s_v("tools::wroot::ntuple::column_vector_string_ref");
0239 return s_v;
0240 }
0241 #endif
0242 public:
0243 static cid id_class() {return _cid_std_vector<std::string>()+10000;}
0244 virtual void* cast(cid a_class) const {
0245 if(void* p = cmp_cast<column_vector_string_ref>(this,a_class)) {return p;}
0246 else return 0;
0247 }
0248 virtual cid id_cls() const {return id_class();}
0249 public:
0250 virtual void add() {
0251 m_string.clear();
0252 tools_vforcit(std::string,m_ref,it) {
0253 if(it!=m_ref.begin()) m_string += m_sep;
0254 m_string += *it;
0255 }
0256 parent::add();
0257 }
0258 public:
0259 column_vector_string_ref(branch& a_branch,const std::string& a_name,const std::vector<std::string>& a_ref,char a_sep)
0260 :parent(a_branch,a_name,m_string)
0261 ,m_ref(a_ref)
0262 ,m_sep(a_sep)
0263 {
0264 #ifdef TOOLS_MEM
0265 mem::increment(s_class().c_str());
0266 #endif
0267 }
0268 virtual ~column_vector_string_ref(){
0269 #ifdef TOOLS_MEM
0270 mem::decrement(s_class().c_str());
0271 #endif
0272 }
0273 protected:
0274 column_vector_string_ref(const column_vector_string_ref& a_from)
0275 :icol(a_from)
0276 ,parent(a_from)
0277 ,m_ref(a_from.m_ref)
0278 ,m_sep(a_from.m_sep)
0279 {}
0280 column_vector_string_ref& operator=(const column_vector_string_ref& a_from){
0281 if(&a_from==this) return *this;
0282 m_sep = a_from.m_sep;
0283 return *this;
0284 }
0285 public:
0286 const std::vector<std::string>& variable() const {return m_ref;}
0287 std::vector<std::string>& variable() {return const_cast< std::vector<std::string>& >(m_ref);}
0288 protected:
0289 const std::vector<std::string>& m_ref;
0290 char m_sep;
0291 std::string m_string;
0292 };
0293
0294 class column_vector_string : public column_vector_string_ref {
0295 typedef column_vector_string_ref parent;
0296 #ifdef TOOLS_MEM
0297 static const std::string& s_class() {
0298 static const std::string s_v("tools::wroot::ntuple::column_vector_string");
0299 return s_v;
0300 }
0301 #endif
0302 public:
0303 static cid id_class() {return _cid_std_vector<std::string>();}
0304 virtual void* cast(cid a_class) const {
0305 if(void* p = cmp_cast<column_vector_string>(this,a_class)) {return p;}
0306 else return 0;
0307 }
0308 virtual cid id_cls() const {return id_class();}
0309 public:
0310 virtual void set_def() {m_value = m_def;}
0311 public:
0312 column_vector_string(branch& a_branch,const std::string& a_name,const std::vector<std::string>& a_def,char a_sep)
0313 :parent(a_branch,a_name,m_value,a_sep)
0314 ,m_def(a_def),m_value(a_def)
0315 {
0316 #ifdef TOOLS_MEM
0317 mem::increment(s_class().c_str());
0318 #endif
0319 }
0320 virtual ~column_vector_string(){
0321 #ifdef TOOLS_MEM
0322 mem::decrement(s_class().c_str());
0323 #endif
0324 }
0325 protected:
0326 column_vector_string(const column_vector_string& a_from)
0327 :icol(a_from)
0328 ,parent(a_from)
0329 ,m_def(a_from.m_def)
0330 ,m_value(a_from.m_value)
0331 {}
0332 column_vector_string& operator=(const column_vector_string& a_from){
0333 if(&a_from==this) return *this;
0334 parent::operator=(a_from);
0335 m_def = a_from.m_def;
0336 m_value = a_from.m_value;
0337 return *this;
0338 }
0339 public:
0340 column_vector_string& operator=(const std::vector<std::string>& a_value){m_value = a_value;return *this;}
0341 bool fill(const std::vector<std::string>& a_value) {m_value = a_value;return true;}
0342 protected:
0343 std::vector<std::string> m_def;
0344 std::vector<std::string> m_value;
0345 };
0346
0347 template <class T>
0348 class std_vector_column_ref : public virtual icol {
0349 #ifdef TOOLS_MEM
0350 static const std::string& s_class() {
0351 static const std::string s_v("tools::wroot::ntuple::std_vector_column_ref<"+stype(T())+">");
0352 return s_v;
0353 }
0354 #endif
0355 public:
0356 static cid id_class() {return _cid_std_vector<T>()+10000;}
0357 virtual void* cast(cid a_class) const {
0358 if(void* p = cmp_cast<std_vector_column_ref>(this,a_class)) {return p;}
0359 else return 0;
0360 }
0361 virtual cid id_cls() const {return id_class();}
0362 public:
0363 virtual void add() {
0364 if(m_leaf_count) m_leaf_count->fill((int)m_ref.size());
0365 }
0366 virtual void set_def() {}
0367 virtual const std::string& name() const {return m_leaf->name();}
0368 virtual void set_basket_size(uint32 a_size) {m_branch.set_basket_size(a_size);}
0369 virtual branch& get_branch() const {return m_branch;}
0370 virtual base_leaf* get_leaf() const {return m_leaf;}
0371 public:
0372 std_vector_column_ref(branch& a_branch,const std::string& a_name,const std::vector<T>& a_ref)
0373 :m_branch(a_branch)
0374 ,m_ref(a_ref)
0375 ,m_leaf(0)
0376 ,m_leaf_count(0)
0377 {
0378 #ifdef TOOLS_MEM
0379 mem::increment(s_class().c_str());
0380 #endif
0381 if(a_branch.store_cls()==branch_element_store_class()) {
0382
0383 int id = -1;
0384 int type = 0;
0385 m_leaf = m_branch.create_leaf_element(a_name,id,type);
0386 } else {
0387
0388 std::string leaf_count_name = a_name+"_count";
0389 m_leaf_count = m_branch.create_leaf<int>(leaf_count_name);
0390 m_leaf = m_branch.create_leaf_std_vector_ref<T>(a_name,*m_leaf_count,a_ref);
0391 m_leaf->set_title(a_name+"["+leaf_count_name+"]");
0392 }
0393 }
0394 virtual ~std_vector_column_ref(){
0395 #ifdef TOOLS_MEM
0396 mem::decrement(s_class().c_str());
0397 #endif
0398 }
0399 protected:
0400 std_vector_column_ref(const std_vector_column_ref& a_from)
0401 :icol(a_from)
0402 ,m_branch(a_from.m_barnch)
0403 ,m_ref(a_from.m_ref)
0404 ,m_leaf(0)
0405 ,m_leaf_count(0)
0406 {}
0407 std_vector_column_ref& operator=(const std_vector_column_ref& a_from){
0408 if(&a_from==this) return *this;
0409 m_leaf = 0;
0410 m_leaf_count = 0;
0411 return *this;
0412 }
0413 public:
0414 const std::vector<T>& variable() const {return m_ref;}
0415 std::vector<T>& variable() {return const_cast< std::vector<T>& >(m_ref);}
0416 protected:
0417 branch& m_branch;
0418 const std::vector<T>& m_ref;
0419 base_leaf* m_leaf;
0420 leaf<int>* m_leaf_count;
0421 };
0422
0423 template <class T>
0424 class std_vector_column : public std_vector_column_ref<T> {
0425 typedef std_vector_column_ref<T> parent;
0426 #ifdef TOOLS_MEM
0427 static const std::string& s_class() {
0428 static const std::string s_v("tools::wroot::ntuple::std_vector_column<"+stype(T())+">");
0429 return s_v;
0430 }
0431 #endif
0432 public:
0433 static cid id_class() {return _cid_std_vector<T>();}
0434 virtual void* cast(cid a_class) const {
0435 if(void* p = cmp_cast<std_vector_column>(this,a_class)) {return p;}
0436 else return 0;
0437 }
0438 virtual cid id_cls() const {return id_class();}
0439 public:
0440 virtual void set_def() {m_value = m_def;}
0441 public:
0442 std_vector_column(branch& a_branch,const std::string& a_name,const std::vector<T>& a_def)
0443 :parent(a_branch,a_name,m_value)
0444 ,m_def(a_def),m_value(a_def)
0445 {
0446 #ifdef TOOLS_MEM
0447 mem::increment(s_class().c_str());
0448 #endif
0449 }
0450 virtual ~std_vector_column(){
0451 #ifdef TOOLS_MEM
0452 mem::decrement(s_class().c_str());
0453 #endif
0454 }
0455 protected:
0456 std_vector_column(const std_vector_column& a_from)
0457 :icol(a_from)
0458 ,parent(a_from)
0459 ,m_def(a_from.m_def)
0460 ,m_value(a_from.m_value)
0461 {}
0462 std_vector_column& operator=(const std_vector_column& a_from){
0463 if(&a_from==this) return *this;
0464 parent::operator=(a_from);
0465 m_def = a_from.m_def;
0466 m_value = a_from.m_value;
0467 return *this;
0468 }
0469 public:
0470 std_vector_column& operator=(const std::vector<T>& a_value){m_value = a_value;return *this;}
0471 bool fill(const std::vector<T>& a_value) {m_value = a_value;return true;}
0472 protected:
0473 std::vector<T> m_def;
0474 std::vector<T> m_value;
0475 };