Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/ntuple_booking 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_booking
0005 #define tools_ntuple_booking
0006 
0007 // a little class to capture booking parameters
0008 // to create an ntuple.
0009 
0010 #include "cids"
0011 
0012 #include <ostream>
0013 #include "forit"
0014 
0015 namespace tools {
0016 
0017 class column_booking {
0018 public:
0019   column_booking(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_booking() {}
0025 public:
0026   column_booking(const column_booking& 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_booking& operator=(const column_booking& 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 cls_id() const {return m_cid;}
0041   void* user_obj() const {return m_user_obj;}
0042   void set_user_obj(void* a_obj) {m_user_obj = a_obj;}
0043 protected:
0044   std::string m_name;
0045   cid m_cid;
0046   void* m_user_obj;
0047 };
0048 
0049 class ntuple_booking {
0050 public:
0051   ntuple_booking(const std::string& a_name = "",const std::string& a_title = "")
0052   :m_name(a_name)
0053   ,m_title(a_title)
0054   {}
0055   virtual ~ntuple_booking(){}
0056 public:
0057   ntuple_booking(const ntuple_booking& a_from)
0058   :m_name(a_from.m_name)
0059   ,m_title(a_from.m_title)
0060   ,m_columns(a_from.m_columns)
0061   {}
0062   ntuple_booking& operator=(const ntuple_booking& a_from){
0063     m_name = a_from.m_name;
0064     m_title = a_from.m_title;
0065     m_columns = a_from.m_columns;
0066     return *this;
0067   }
0068 public:
0069   template <class T>
0070   void add_column(const std::string& a_name) {
0071     m_columns.push_back(column_booking(a_name,_cid(T()),0));
0072   }
0073   template <class T>
0074   void add_column(const std::string& a_name,T& a_user) {
0075     m_columns.push_back(column_booking(a_name,_cid(T()),(void*)&a_user));
0076   }
0077 
0078   template <class T>
0079   void add_column_vec(const std::string& a_name) {
0080     m_columns.push_back(column_booking(a_name,_cid_std_vector<T>(),0));
0081   }
0082   template <class T>
0083   void add_column_vec(const std::string& a_name,std::vector<T>& a_user_vec) {
0084     m_columns.push_back(column_booking(a_name,_cid_std_vector<T>(),(void*)&a_user_vec));
0085   }
0086   template <class T>
0087   void add_column(const std::string& a_name,std::vector<T>& a_user_vec) {
0088     m_columns.push_back(column_booking(a_name,_cid_std_vector<T>(),(void*)&a_user_vec));
0089   }
0090 
0091   const std::string& name() const {return m_name;}
0092   const std::string& title() const {return m_title;}
0093   const std::vector<column_booking>& columns() const {return m_columns;}
0094   std::vector<column_booking>& columns() {return m_columns;}
0095 
0096   void set_name(const std::string& a_s) {m_name = a_s;}
0097   void set_title(const std::string& a_s) {m_title = a_s;}
0098 
0099   bool has_similar_layout(std::ostream& a_out,const ntuple_booking& a_nbk) {
0100     if(m_columns.size()!=a_nbk.m_columns.size()) {
0101       a_out << "tools::ntuple_booking::has_similar_layout :"
0102             << " bookings have not the same number of columns."
0103             << " (" << m_columns.size() << " != " << a_nbk.m_columns.size() << ")."
0104             << std::endl;
0105       return false;
0106     }
0107     std::vector<column_booking>::const_iterator ait = a_nbk.m_columns.begin();
0108     tools_vforit(tools::column_booking,m_columns,it) {
0109       if((*it).name()!=(*ait).name()) {
0110         a_out << "tools::ntuple_booking::has_similar_layout :"
0111               << " columns don't have same name."
0112               << " (" << (*it).name() << " != " << (*ait).name() << ")."
0113               << std::endl;
0114         return false;
0115       }
0116       if((*it).cls_id()!=(*ait).cls_id()) {
0117         a_out << "tools::ntuple_booking::has_similar_layout :"
0118               << " columns don't have same class id."
0119               << " (" << (*it).cls_id() << " != " << (*ait).cls_id() << ")."
0120               << std::endl;
0121         return false;
0122       }
0123 
0124       ait++;
0125     }
0126     return true;
0127   }
0128 
0129 protected:
0130   std::string m_name;
0131   std::string m_title;
0132   std::vector<column_booking> m_columns;
0133 };
0134 
0135 }
0136 
0137 #endif