g4tools  5.4.0
cids
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_cids
5 #define tools_cids
6 
7 #include "cid"
8 
9 #include <string>
10 #include "typedefs" //byte
11 
12 namespace tools {
13 
14 inline cid _cid(byte) {return 1;}
15 inline cid _cid(char) {return 2;}
16 inline cid _cid(unsigned short) {return 3;}
17 inline cid _cid(short) {return 4;}
18 inline cid _cid(unsigned int) {return 5;}
19 inline cid _cid(int) {return 6;}
20 inline cid _cid(float) {return 7;}
21 inline cid _cid(double) {return 8;}
22 inline cid _cid(bool) {return 9;}
23 
24 // not compiler types :
25 inline cid _cid(uint64) {return 10;}
26 inline cid _cid(int64) {return 11;}
27 inline cid _cid(const std::string&) {return 12;}
28 inline cid _cid(fits_bit) {return 13;}
29 inline cid _cid(csv_time) {return 14;}
30 
31 //NOTE : avoid time_t which is defined in general as a long
32 // and is then ambiguous relative to int/int64.
33 
34 //NOTE : if adding some, it must not exceed 20. Else, you have to change
35 // the below for std::vector.
36 
37 }
38 
39 #include <vector>
40 
41 namespace tools {
42 
43 // For rntuple and rroot::ntuple::column_element.
44 // The read::icolumn<T> needs a _cid(T) with T :
45 // std::vector< [basic_type, std::vector<basic_type>] >
46 
47 template <class T>
48 inline cid _cid(const std::vector<T>&) {return 20+_cid(T());}
49 
50 template <class T>
51 inline cid _cid_std_vector() {
52  static const T s_v = T(); //do that for T = std::string.
53  return 20+_cid(s_v);
54 }
55 
56 // Then : cid for std::vector< std::vector<T> > is going to be :
57 // 20+_cid(std::vector<T>) = 2*20+_cid(T)
58 
59 //WARNING : rroot/cids start at 100.
60 //WARNING : rroot/geo_cids start at 1000.
61 
62 }
63 
64 namespace tools {
65 
66 inline bool cid2s(cid a_id,std::string& a_s) {
67  // NOTE : the returned string must not contain space.
68 
69  if(a_id==_cid(char(0))) {a_s = "char";return true;}
70  else if(a_id==_cid(short(0))) {a_s = "short";return true;}
71  else if(a_id==_cid(int(0))) {a_s = "int";return true;}
72  else if(a_id==_cid(float(0))) {a_s = "float";return true;}
73  else if(a_id==_cid(double(0))) {a_s = "double";return true;}
74  else if(a_id==_cid(std::string())) {a_s = "string";return true;}
75 
76  // NOTE : the below do not follow the AIDA convention.
77  else if(a_id==_cid((unsigned char)0)) {a_s = "uchar";return true;} //AIDA=byte
78  else if(a_id==_cid((unsigned short)0)) {a_s = "ushort";return true;} //AIDA not defined
79  else if(a_id==_cid((unsigned int)0)) {a_s = "uint";return true;} //AIDA not defined
80  else if(a_id==_cid(bool(true))) {a_s = "bool";return true;} //AIDA=boolean
81  else if(a_id==_cid(int64(0))) {a_s = "int64";return true;} //AIDA=long
82  else if(a_id==_cid(uint64(0))) {a_s = "uint64";return true;} //AIDA=not defined
83 
84  else if(a_id==_cid_std_vector<char>()) {a_s = "char[]";return true;}
85  else if(a_id==_cid_std_vector<short>()) {a_s = "short[]";return true;}
86  else if(a_id==_cid_std_vector<int>()) {a_s = "int[]";return true;}
87  else if(a_id==_cid_std_vector<float>()) {a_s = "float[]";return true;}
88  else if(a_id==_cid_std_vector<double>()) {a_s = "double[]";return true;}
89  else if(a_id==_cid_std_vector<std::string>()) {a_s = "string[]";return true;}
90 
91  else if(a_id==_cid_std_vector<unsigned char>()) {a_s = "uchar[]";return true;}
92  else if(a_id==_cid_std_vector<unsigned short>()) {a_s = "ushort[]";return true;}
93  else if(a_id==_cid_std_vector<unsigned int>()) {a_s = "uint[]";return true;}
94  else if(a_id==_cid_std_vector<bool>()) {a_s = "bool[]";return true;}
95  else if(a_id==_cid_std_vector<int64>()) {a_s = "int64[]";return true;}
96  else if(a_id==_cid_std_vector<uint64>()) {a_s = "uint64[]";return true;}
97 
98  a_s.clear();
99  return false;
100 }
101 
102 }
103 
104 #endif
tools::uint64
unsigned long long uint64
Definition: typedefs:72
tools::int64
long long int64
Definition: typedefs:67
tools::_cid
cid _cid(byte)
Definition: cids:14
typedefs
tools::csv_time
Definition: typedefs:108
tools::cid2s
bool cid2s(cid a_id, std::string &a_s)
Definition: cids:66
tools::fits_bit
Definition: typedefs:107
tools::_cid_std_vector
cid _cid_std_vector()
Definition: cids:51
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
cid
tools::cid
unsigned short cid
Definition: cid:9