source: pixelmap/PixelMap.cc@ 13

Last change on this file since 13 was 12, checked in by qweitzel, 17 years ago
update of pixelmap class, whitespaces now ignored in pixelname, initialization of default pixel constructor changed
File size: 6.8 KB
Line 
1#include "PixelMap.h"
2#include <iostream>
3#include <fstream>
4#include <cstring>
5#include <cstdlib>
6#include <cctype>
7
8PixelMap::PixelMap() {
9
10 pixelmap.clear();
11 ReadPixelMap(pixelmap, false);
12
13}
14
15PixelMap::~PixelMap() {
16
17 for( std::map<const std::string, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
18 delete ((*iter).second);
19 }
20
21}
22
23void PixelMap::ReadPixelMap(std::map<std::string, Pixel*>& pixelmap, bool verbose) {
24
25 std::string filename("PixelMap.txt");
26 std::ifstream infile(filename.c_str(), std::fstream::in);
27
28 std::cout<<"Reading mapping file: "<<filename<<std::endl<<std::endl;
29
30 if (!infile.good()) {
31 std::cerr<<"ERROR in PixelMap::ReadPixelMap: File "<<filename<<" cannot be found."<<std::endl;
32 }
33
34 while (infile.good()) {
35
36 char line[1024];
37
38 infile.getline(line, 1024);
39
40 if (line[0] == '#') {
41 if (verbose) {
42 std::cout << "Ignoring comment: " << line << std::endl;
43 }
44 }
45
46 else {
47
48 if (strlen(line)!=0) {
49
50 char delim[] = ":";
51 char *name = NULL; //unformated name before : tokens
52 char name2[256] = ""; //formated name without whitespaces
53 char *rest = NULL;
54
55 name = strtok(line, delim);
56
57 unsigned int count1 = 0; //count non-whitespace characters in name
58 unsigned int count2 = 0; //count number of - in name
59
60 for (unsigned int i = 0; i < strlen(name); i++) {
61
62 if ( !(isspace(name[i])) ) {
63
64 name2[count1] = name[i];
65 count1+=1;
66
67 if ( (name[i] == 45) ) {
68 count2+=1;
69 }
70
71 }
72
73 }
74
75 if (verbose) {
76 std::cout << "Formated pixel name: " << name2 << std::endl;
77 }
78
79 if( (count1 > 4) && (count1 < 7) && (count2 == 2) ) {
80
81 rest = strtok(NULL, delim);
82
83 if(rest != NULL) {
84
85 unsigned int DRSboard = (unsigned int)strtod(rest, &rest);
86 unsigned int DRSchip = (unsigned int)strtod(rest, &rest);
87 unsigned int DRSchannel = (unsigned int)strtod(rest, &rest);
88 unsigned int HVboard = (unsigned int)strtod(rest, &rest);
89 unsigned int HVchain = (unsigned int)strtod(rest, &rest);
90 unsigned int HVchannel = (unsigned int)strtod(rest, &rest);
91
92 pixelmap[name2] = new Pixel(DRSboard, DRSchip, DRSchannel,
93 HVboard, HVchain, HVchannel);
94
95 }
96
97 }
98
99 else {
100
101 std::cout << "ERROR in PixelMap::ReadPixelMap: Wrong pixel name: " << name2 << " -> pixel not initialized" << std::endl;
102
103 }
104
105 }
106
107 else {
108
109 if(verbose){
110
111 std::cout << "Skipping empty line" << std::endl;
112
113 }
114
115 }
116
117 }
118
119 }
120
121 if(verbose){
122 for( std::map<const std::string, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
123 std::cout << std::endl << (*iter).first << std::endl << "-----------" << std::endl << *((*iter).second);
124 }
125 }
126
127 std::cout << pixelmap.size() << " pixels found" << std::endl << std::endl;
128
129 infile.close();
130
131}
132
133void PixelMap::Print() {
134
135 std::cout << "Printing entries of pixelmap:" << std::endl << std::endl;
136
137 for( std::map<const std::string, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
138 std::cout << (*iter).first << std::endl << "------------" << std::endl << *((*iter).second) << std::endl;
139 }
140
141}
142
143std::string PixelMap::DRS_to_Pixel(unsigned int DRSboard, unsigned int DRSchip, unsigned int DRSchannel) {
144
145 std::string pixelname = "";
146
147 for( std::map<const std::string, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
148
149 if( ( ((*iter).second)->GetPixelDRSboard() == DRSboard ) &&
150 ( ((*iter).second)->GetPixelDRSchip() == DRSchip ) &&
151 ( ((*iter).second)->GetPixelDRSchannel() == DRSchannel ) ) {
152
153 pixelname = (*iter).first;
154
155 }
156
157 }
158
159 if(pixelname == ""){
160
161 std::cout << "ERROR in PixelMap::DRS_to_Pixel: No pixel with DRS board, chip, channel = "
162 << DRSboard << ", "
163 << DRSchip << ", "
164 << DRSchannel << " found in pixelmap" << std::endl;
165
166 }
167
168 return pixelname;
169
170}
171
172std::string PixelMap::HV_to_Pixel(unsigned int HVboard, unsigned int HVchain, unsigned int HVchannel) {
173
174 std::string pixelname = "";
175
176 for( std::map<const std::string, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
177
178 if( ( ((*iter).second)->GetPixelHVboard() == HVboard ) &&
179 ( ((*iter).second)->GetPixelHVchain() == HVchain ) &&
180 ( ((*iter).second)->GetPixelHVchannel() == HVchannel ) ) {
181
182 pixelname = (*iter).first;
183
184 }
185
186 }
187
188 if(pixelname == ""){
189
190 std::cout << "ERROR in PixelMap::HV_to_Pixel: No pixel with HV board, chain, channel = "
191 << HVboard << ", "
192 << HVchain << ", "
193 << HVchannel << " found in pixelmap" << std::endl;
194
195 }
196
197 return pixelname;
198
199}
200
201unsigned int PixelMap::Pixel_to_DRSboard(std::string pixelname) {
202
203 unsigned int DRSboard = 999999999;
204
205 if(pixelmap[pixelname] != NULL) {
206
207 DRSboard = pixelmap[pixelname]->GetPixelDRSboard();
208
209 }
210
211 else {
212
213 std::cout << "ERROR in PixelMap::Pixel_to_DRSboard: No pixel with name = "
214 << pixelname << " found in pixelmap" << std::endl;
215
216 }
217
218 return DRSboard;
219
220}
221
222unsigned int PixelMap::Pixel_to_DRSchip(std::string pixelname) {
223
224 unsigned int DRSchip = 999999999;
225
226 if(pixelmap[pixelname] != NULL) {
227
228 DRSchip = pixelmap[pixelname]->GetPixelDRSchip();
229
230 }
231
232 else {
233
234 std::cout << "ERROR in PixelMap::Pixel_to_DRSchip: No pixel with name = "
235 << pixelname << " found in pixelmap" << std::endl;
236
237 }
238
239 return DRSchip;
240
241}
242
243unsigned int PixelMap::Pixel_to_DRSchannel(std::string pixelname) {
244
245 unsigned int DRSchannel = 999999999;
246
247 if(pixelmap[pixelname] != NULL) {
248
249 DRSchannel = pixelmap[pixelname]->GetPixelDRSchannel();
250
251 }
252
253 else {
254
255 std::cout << "ERROR in PixelMap::Pixel_to_DRSchannel: No pixel with name = "
256 << pixelname << " found in pixelmap" << std::endl;
257
258 }
259
260 return DRSchannel;
261
262}
263
264unsigned int PixelMap::Pixel_to_HVboard(std::string pixelname) {
265
266 unsigned int HVboard = 999999999;
267
268 if(pixelmap[pixelname] != NULL) {
269
270 HVboard = pixelmap[pixelname]->GetPixelHVboard();
271
272 }
273
274 else {
275
276 std::cout << "ERROR in PixelMap::Pixel_to_HVboard: No pixel with name = "
277 << pixelname << " found in pixelmap" << std::endl;
278
279 }
280
281 return HVboard;
282
283}
284
285unsigned int PixelMap::Pixel_to_HVchain(std::string pixelname) {
286
287 unsigned int HVchain = 999999999;
288
289 if(pixelmap[pixelname] != NULL) {
290
291 HVchain = pixelmap[pixelname]->GetPixelHVchain();
292
293 }
294
295 else {
296
297 std::cout << "ERROR in PixelMap::Pixel_to_HVchain: No pixel with name = "
298 << pixelname << " found in pixelmap" << std::endl;
299
300 }
301
302 return HVchain;
303
304}
305
306unsigned int PixelMap::Pixel_to_HVchannel(std::string pixelname) {
307
308 unsigned int HVchannel = 999999999;
309
310 if(pixelmap[pixelname] != NULL) {
311
312 HVchannel = pixelmap[pixelname]->GetPixelHVchannel();
313
314 }
315
316 else {
317
318 std::cout << "ERROR in PixelMap::Pixel_to_HVchannel: No pixel with name = "
319 << pixelname << " found in pixelmap" << std::endl;
320
321 }
322
323 return HVchannel;
324
325}
Note: See TracBrowser for help on using the repository browser.