Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/ntuple_binding 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_ntuple_binding
0005 #define tools_ntuple_binding
0006 
0007 // a little class to capture column binding parameters
0008 // when reading an ntuple.
0009 
0010 #include <string>
0011 #include <vector>
0012 #include "forit"
0013 #include "cids"
0014 
0015 namespace tools {
0016 
0017 class column_binding {
0018 public:
0019   column_binding(const std::string& a_name,cid a_cid,void* a_user_obj)
0020   :m_name(a_name)
0021   ,m_cid(a_cid)
0022   ,m_user_obj(a_user_obj) //WARNING : not owner.
0023   {}
0024   virtual ~column_binding() {}
0025 public:
0026   column_binding(const column_binding& a_from)
0027   :m_name(a_from.m_name)
0028   ,m_cid(a_from.m_cid)
0029   ,m_user_obj(a_from.m_user_obj)
0030   {}
0031   column_binding& operator=(const column_binding& a_from) {
0032     if(&a_from==this) return *this;
0033     m_name = a_from.m_name;
0034     m_cid = a_from.m_cid;
0035     m_user_obj = a_from.m_user_obj;
0036     return *this;
0037   }
0038 public:
0039   const std::string& name() const {return m_name;}
0040   cid get_cid() const {return m_cid;}
0041   void* user_obj() const {return m_user_obj;}
0042 protected:
0043   std::string m_name;
0044   cid m_cid;
0045   void* m_user_obj;
0046 };
0047 
0048 class ntuple_binding {
0049 public:
0050   ntuple_binding()
0051   {}
0052   virtual ~ntuple_binding(){}
0053 public:
0054   ntuple_binding(const ntuple_binding& a_from)
0055   :m_columns(a_from.m_columns)
0056   {}
0057   ntuple_binding& operator=(const ntuple_binding& a_from){
0058     m_columns = a_from.m_columns;
0059     return *this;
0060   }
0061 public:
0062   template <class T>
0063   void add_column(const std::string& a_name,T& a_user_var) {
0064     m_columns.push_back(column_binding(a_name,_cid(T()),(void*)&a_user_var));
0065   }
0066 
0067   template <class T>
0068   void add_column(const std::string& a_name,std::vector<T>& a_user_var) {
0069     m_columns.push_back(column_binding(a_name,_cid_std_vector<T>(),(void*)&a_user_var));
0070   }
0071 
0072   // to have consistent naming than in ntuple_booking :
0073   template <class T>
0074   void add_column_vec(const std::string& a_name,std::vector<T>& a_user_var) {
0075     m_columns.push_back(column_binding(a_name,_cid_std_vector<T>(),(void*)&a_user_var));
0076   }
0077 
0078   template <class T>
0079   void add_column_cid(const std::string& a_name,T& a_user_var) {
0080     m_columns.push_back(column_binding(a_name,T::id_class(),(void*)&a_user_var));
0081   }
0082 
0083   void add_column_no_var(const std::string& a_name) { //used in rcsv_ntuple.
0084     m_columns.push_back(column_binding(a_name,0,0));
0085   }
0086 
0087   const std::vector<column_binding>& columns() const {return m_columns;}
0088 
0089   bool find_user_obj(const std::string& a_name,cid& a_cid,void*& a_obj) const {
0090     tools_vforcit(column_binding,m_columns,it) {
0091       if((*it).name()==a_name) {
0092         a_cid = (*it).get_cid();
0093         a_obj = (*it).user_obj();
0094         return true;
0095       }
0096     }
0097     a_cid = 0;
0098     a_obj = 0;
0099     return false;
0100   }
0101 
0102   template <class T>
0103   T* find_variable(const std::string& a_name) const {
0104     tools_vforcit(column_binding,m_columns,it) {
0105       if((*it).name()==a_name) {
0106         // we should check cid. If so, take care of T=aida::ntuple.
0107         return (T*)((*it).user_obj());
0108       }
0109     }
0110     return 0;
0111   }
0112 
0113   template <class T>
0114   std::vector<T>* find_vector_variable(const std::string& a_name) const {
0115     tools_vforcit(column_binding,m_columns,it) {
0116       if((*it).name()==a_name) {
0117         if((*it).get_cid()!=_cid_std_vector<T>()) return 0;
0118         return (std::vector<T>*)((*it).user_obj());
0119       }
0120     }
0121     return 0;
0122   }
0123 protected:
0124   std::vector<column_binding> m_columns;
0125 };
0126 
0127 }
0128 
0129 #endif