CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
NTupleHelper.cxx
Go to the documentation of this file.
1
3#include <sstream>
4
5// ********************************************************************
6// HELPER FUNCTIONS
7// ********************************************************************
8
9NTupleHelper::NTupleHelper(NTuple::Tuple* Tree){
10 m_Tree = Tree;
11 m_bookingStage = true;
12
13 if( m_Tree == NULL )
14 cout << "ERROR: null tree pointer -- "
15 << "check for duplicate final states in configuration"
16 << endl;
17 assert( m_Tree != NULL );
18}
19
20
21void
23
24 for (map<string,double>::iterator mapItr = m_doubleMap.begin();
25 mapItr != m_doubleMap.end(); mapItr++){
26 m_ntupleDoubleMap[mapItr->first] = mapItr->second;
27 }
28
29 for (map<string,long>::iterator mapItr = m_longMap.begin();
30 mapItr != m_longMap.end(); mapItr++){
31 m_ntupleLongMap[mapItr->first] = mapItr->second;
32 }
33
34 for (map<string,double*>::iterator mapItr = m_arrayMap.begin();
35 mapItr != m_arrayMap.end(); mapItr++){
36 for(int i=0; i< 100; i++) {
37 m_ntupleArrayMap[mapItr->first][i] = *(mapItr->second + i);
38 }
39 }
40
41 for (map<string,long*>::iterator mapItr = m_arrayLongMap.begin();
42 mapItr != m_arrayLongMap.end(); mapItr++){
43 for(int i=0; i< 100; i++) {
44 m_ntupleArrayLongMap[mapItr->first][i] = *(mapItr->second + i);
45 }
46 }
47
48 for (map<string,int*>::iterator mapItr = m_arrayIntMap.begin();
49 mapItr != m_arrayIntMap.end(); mapItr++){
50 for(int i=0; i< 100; i++) {
51 m_ntupleArrayIntMap[mapItr->first][i] = *(mapItr->second + i);
52 }
53 }
54
55 m_Tree->write();
56
57 for (map<string,double*>::iterator mapItr = m_arrayMap.begin();
58 mapItr != m_arrayMap.end(); mapItr++){
59 delete mapItr->second;
60 }
61 for (map<string,long*>::iterator mapItr = m_arrayLongMap.begin();
62 mapItr != m_arrayLongMap.end(); mapItr++){
63 delete mapItr->second;
64 }
65 for (map<string,int*>::iterator mapItr = m_arrayIntMap.begin();
66 mapItr != m_arrayIntMap.end(); mapItr++){
67 delete mapItr->second;
68 }
69 m_bookingStage = false;
70 //cout<<mapItr->first<<" "<<sizeof(*(mapItr->second))<<endl;
71 //for(int i=0; i<m_ntupleLongMap["idx_mc"]; i++) {
72}
73
74
75void NTupleHelper::fillDouble(string name, double value){
76 if (m_bookingStage && !containsEntry(name)){
77 m_Tree->addItem(name,m_ntupleDoubleMap[name]);
78 }
79 if (!m_bookingStage && !containsEntry(name)){
80 cout << "NTUPLEHELPER: Variable " << name << " has not been booked." << endl;
81 exit(0);
82 }
83 m_doubleMap[name] = value;
84}
85
86void NTupleHelper::fillLong(string name, long value){
87 if (m_bookingStage && !containsEntry(name)){
88 m_Tree->addItem(name,m_ntupleLongMap[name]);
89 }
90 if (!m_bookingStage && !containsEntry(name)){
91 cout << "NTUPLEHELPER: Variable " << name << " has not been booked." << endl;
92 exit(0);
93 }
94 m_longMap[name] = value;
95}
96
97
98
99void NTupleHelper::fillArray(string name, string index_name, double* value, int size){
100
101 if (m_bookingStage && !containsEntry(index_name)){
102 m_Tree->addItem(index_name, m_ntupleLongMap[index_name], 0, 100);
103 }
104
105 m_longMap[index_name]=size;
106
107 if (m_bookingStage && !containsEntry(name)){
108 m_Tree->addIndexedItem(name, m_ntupleLongMap[index_name], m_ntupleArrayMap[name]);
109 }
110
111 if (!m_bookingStage && !containsEntry(name)){
112 cout << "NTUPLEHELPER: Variable " << name << " has not been booked." << endl;
113 exit(0);
114 }
115
116 if (!m_bookingStage && !containsEntry(index_name)){
117 cout << "NTUPLEHELPER: Variable " << index_name << " has not been booked." << endl;
118 exit(0);
119 }
120
121 m_arrayMap[name]= new double[100];
122 for(int i=0; i<size; i++){
123 //printf("value %2d = %10f\n", i, *(value+i));
124 m_arrayMap[name][i] = *(value+i);
125 }
126}
127
128void NTupleHelper::fillArrayLong(string name, string index_name, long* value, int size){
129
130 if (m_bookingStage && !containsEntry(index_name)){
131 m_Tree->addItem(index_name, m_ntupleLongMap[index_name], 0, 100);
132 }
133
134 m_longMap[index_name]=size;
135
136 if (m_bookingStage && !containsEntry(name)){
137 m_Tree->addIndexedItem(name, m_ntupleLongMap[index_name], m_ntupleArrayLongMap[name]);
138 }
139
140 if (!m_bookingStage && !containsEntry(name)){
141 cout << "NTUPLEHELPER: Variable " << name << " has not been booked." << endl;
142 exit(0);
143 }
144
145 if (!m_bookingStage && !containsEntry(index_name)){
146 cout << "NTUPLEHELPER: Variable " << index_name << " has not been booked." << endl;
147 exit(0);
148 }
149
150 m_arrayLongMap[name]= new long[100];
151 for(int i=0; i<size; i++){
152 //printf("value %2d = %10f\n", i, *(value+i));
153 m_arrayLongMap[name][i] = *(value+i);
154 }
155}
156
157void NTupleHelper::fillArrayInt(string name, string index_name, int* value, int size){
158
159 if (m_bookingStage && !containsEntry(index_name)){
160 m_Tree->addItem(index_name, m_ntupleLongMap[index_name], 0, 100);
161 }
162
163 m_longMap[index_name]=size;
164
165 if (m_bookingStage && !containsEntry(name)){
166 m_Tree->addIndexedItem(name, m_ntupleLongMap[index_name], m_ntupleArrayIntMap[name]);
167 }
168
169 if (!m_bookingStage && !containsEntry(name)){
170 cout << "NTUPLEHELPER: Variable " << name << " has not been booked." << endl;
171 exit(0);
172 }
173
174 if (!m_bookingStage && !containsEntry(index_name)){
175 cout << "NTUPLEHELPER: Variable " << index_name << " has not been booked." << endl;
176 exit(0);
177 }
178
179 m_arrayIntMap[name]= new int[100];
180 for(int i=0; i<size; i++){
181 //printf("value %2d = %10f\n", i, *(value+i));
182 m_arrayIntMap[name][i] = *(value+i);
183 }
184}
185
186
187
188bool
189NTupleHelper::containsEntry(string name){
190
191 map<string,double>::iterator mapItr1 = m_doubleMap.find(name);
192 if (mapItr1 != m_doubleMap.end()) return true;
193
194 map<string,long>::iterator mapItr2 = m_longMap.find(name);
195 if (mapItr2 != m_longMap.end()) return true;
196
197 map<string,double*>::iterator mapItr3 = m_arrayMap.find(name);
198 if (mapItr3 != m_arrayMap.end()) return true;
199
200 map<string,long*>::iterator mapItr4 = m_arrayLongMap.find(name);
201 if (mapItr4 != m_arrayLongMap.end()) return true;
202
203 map<string,int*>::iterator mapItr5 = m_arrayIntMap.find(name);
204 if (mapItr5 != m_arrayIntMap.end()) return true;
205
206 return false;
207}
208
209string
210NTupleHelper::concatName(string tag, string base, int index){
211 stringstream name;
212 name << tag;
213 name << base;
214 name << "P";
215 name << index;
216 return name.str();
217}
218
219string
220NTupleHelper::concatName(string tag, string base){
221 stringstream name;
222 name << tag;
223 name << base;
224 return name.str();
225}
void fillArrayLong(string name, string index_name, long *value, int size)
void fillLong(string name, long value)
void fillDouble(string name, double value)
void fillArrayInt(string name, string index_name, int *value, int size)
NTupleHelper(NTuple::Tuple *Tree)
void fillArray(string name, string index_name, double *value, int size)