g4tools  5.4.0
ntuple_booking
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_ntuple_booking
5 #define tools_ntuple_booking
6 
7 // a little class to capture booking parameters
8 // to create an ntuple.
9 
10 #include "cids"
11 
12 #include <ostream>
13 #include "forit"
14 
15 namespace tools {
16 
18 public:
19  column_booking(const std::string& a_name,cid a_cid,void* a_user_obj)
20  :m_name(a_name)
21  ,m_cid(a_cid)
22  ,m_user_obj(a_user_obj) //WARNING : not owner.
23  {}
24  virtual ~column_booking() {}
25 public:
27  :m_name(a_from.m_name)
28  ,m_cid(a_from.m_cid)
29  ,m_user_obj(a_from.m_user_obj)
30  {}
32  if(&a_from==this) return *this;
33  m_name = a_from.m_name;
34  m_cid = a_from.m_cid;
35  m_user_obj = a_from.m_user_obj;
36  return *this;
37  }
38 public:
39  const std::string& name() const {return m_name;}
40  cid cls_id() const {return m_cid;}
41  void* user_obj() const {return m_user_obj;}
42  void set_user_obj(void* a_obj) {m_user_obj = a_obj;}
43 protected:
44  std::string m_name;
46  void* m_user_obj;
47 };
48 
50 public:
51  ntuple_booking(const std::string& a_name = "",const std::string& a_title = "")
52  :m_name(a_name)
53  ,m_title(a_title)
54  {}
55  virtual ~ntuple_booking(){}
56 public:
58  :m_name(a_from.m_name)
59  ,m_title(a_from.m_title)
60  ,m_columns(a_from.m_columns)
61  {}
63  m_name = a_from.m_name;
64  m_title = a_from.m_title;
65  m_columns = a_from.m_columns;
66  return *this;
67  }
68 public:
69  template <class T>
70  void add_column(const std::string& a_name) {
71  m_columns.push_back(column_booking(a_name,_cid(T()),0));
72  }
73  template <class T>
74  void add_column(const std::string& a_name,T& a_user) {
75  m_columns.push_back(column_booking(a_name,_cid(T()),(void*)&a_user));
76  }
77 
78  template <class T>
79  void add_column_vec(const std::string& a_name) {
80  m_columns.push_back(column_booking(a_name,_cid_std_vector<T>(),0));
81  }
82  template <class T>
83  void add_column_vec(const std::string& a_name,std::vector<T>& a_user_vec) {
84  m_columns.push_back(column_booking(a_name,_cid_std_vector<T>(),(void*)&a_user_vec));
85  }
86  template <class T>
87  void add_column(const std::string& a_name,std::vector<T>& a_user_vec) {
88  m_columns.push_back(column_booking(a_name,_cid_std_vector<T>(),(void*)&a_user_vec));
89  }
90 
91  const std::string& name() const {return m_name;}
92  const std::string& title() const {return m_title;}
93  const std::vector<column_booking>& columns() const {return m_columns;}
94  std::vector<column_booking>& columns() {return m_columns;}
95 
96  void set_name(const std::string& a_s) {m_name = a_s;}
97  void set_title(const std::string& a_s) {m_title = a_s;}
98 
99  bool has_similar_layout(std::ostream& a_out,const ntuple_booking& a_nbk) {
100  if(m_columns.size()!=a_nbk.m_columns.size()) {
101  a_out << "tools::ntuple_booking::has_similar_layout :"
102  << " bookings have not the same number of columns."
103  << " (" << m_columns.size() << " != " << a_nbk.m_columns.size() << ")."
104  << std::endl;
105  return false;
106  }
107  std::vector<column_booking>::const_iterator ait = a_nbk.m_columns.begin();
109  if((*it).name()!=(*ait).name()) {
110  a_out << "tools::ntuple_booking::has_similar_layout :"
111  << " columns don't have same name."
112  << " (" << (*it).name() << " != " << (*ait).name() << ")."
113  << std::endl;
114  return false;
115  }
116  if((*it).cls_id()!=(*ait).cls_id()) {
117  a_out << "tools::ntuple_booking::has_similar_layout :"
118  << " columns don't have same class id."
119  << " (" << (*it).cls_id() << " != " << (*ait).cls_id() << ")."
120  << std::endl;
121  return false;
122  }
123 
124  ait++;
125  }
126  return true;
127  }
128 
129 protected:
130  std::string m_name;
131  std::string m_title;
132  std::vector<column_booking> m_columns;
133 };
134 
135 }
136 
137 #endif
tools::_cid
cid _cid(byte)
Definition: cids:14
tools::ntuple_booking::add_column_vec
void add_column_vec(const std::string &a_name)
Definition: ntuple_booking:79
tools::ntuple_booking::ntuple_booking
ntuple_booking(const ntuple_booking &a_from)
Definition: ntuple_booking:57
tools::column_booking
Definition: ntuple_booking:17
tools::column_booking::set_user_obj
void set_user_obj(void *a_obj)
Definition: ntuple_booking:42
tools::column_booking::column_booking
column_booking(const std::string &a_name, cid a_cid, void *a_user_obj)
Definition: ntuple_booking:19
tools::ntuple_booking::add_column
void add_column(const std::string &a_name)
Definition: ntuple_booking:70
tools::ntuple_booking::operator=
ntuple_booking & operator=(const ntuple_booking &a_from)
Definition: ntuple_booking:62
tools::column_booking::cls_id
cid cls_id() const
Definition: ntuple_booking:40
tools::ntuple_booking::add_column
void add_column(const std::string &a_name, T &a_user)
Definition: ntuple_booking:74
tools::column_booking::column_booking
column_booking(const column_booking &a_from)
Definition: ntuple_booking:26
tools::ntuple_booking::has_similar_layout
bool has_similar_layout(std::ostream &a_out, const ntuple_booking &a_nbk)
Definition: ntuple_booking:99
tools::column_booking::m_name
std::string m_name
Definition: ntuple_booking:44
tools::ntuple_booking::add_column_vec
void add_column_vec(const std::string &a_name, std::vector< T > &a_user_vec)
Definition: ntuple_booking:83
tools::ntuple_booking::m_columns
std::vector< column_booking > m_columns
Definition: ntuple_booking:132
tools::column_booking::~column_booking
virtual ~column_booking()
Definition: ntuple_booking:24
tools_vforit
#define tools_vforit(a__T, a__v, a__it)
Definition: forit:13
tools::ntuple_booking::columns
std::vector< column_booking > & columns()
Definition: ntuple_booking:94
tools::ntuple_booking::add_column
void add_column(const std::string &a_name, std::vector< T > &a_user_vec)
Definition: ntuple_booking:87
tools::ntuple_booking::columns
const std::vector< column_booking > & columns() const
Definition: ntuple_booking:93
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::ntuple_booking::m_title
std::string m_title
Definition: ntuple_booking:131
tools::column_booking::user_obj
void * user_obj() const
Definition: ntuple_booking:41
tools::column_booking::name
const std::string & name() const
Definition: ntuple_booking:39
tools::ntuple_booking::title
const std::string & title() const
Definition: ntuple_booking:92
tools::column_booking::operator=
column_booking & operator=(const column_booking &a_from)
Definition: ntuple_booking:31
tools::column_booking::m_cid
cid m_cid
Definition: ntuple_booking:45
tools::ntuple_booking::ntuple_booking
ntuple_booking(const std::string &a_name="", const std::string &a_title="")
Definition: ntuple_booking:51
forit
tools::ntuple_booking::~ntuple_booking
virtual ~ntuple_booking()
Definition: ntuple_booking:55
tools::ntuple_booking::m_name
std::string m_name
Definition: ntuple_booking:130
cids
tools::ntuple_booking::set_title
void set_title(const std::string &a_s)
Definition: ntuple_booking:97
tools::ntuple_booking::name
const std::string & name() const
Definition: ntuple_booking:91
tools::ntuple_booking
Definition: ntuple_booking:49
tools::column_booking::m_user_obj
void * m_user_obj
Definition: ntuple_booking:46
tools::ntuple_booking::set_name
void set_name(const std::string &a_s)
Definition: ntuple_booking:96
tools::cid
unsigned short cid
Definition: cid:9