source: fact/pixelmap/PixelMap.cc@ 15063

Last change on this file since 15063 was 10116, checked in by weitzel, 14 years ago
new version of pixelmap class
File size: 11.0 KB
Line 
1#include "PixelMap.h"
2#include <iostream>
3#include <fstream>
4#include <cstring>
5#include <cstdlib>
6#include <cctype>
7
8const unsigned int PixelMap::PM_ERROR_CODE;
9
10PixelMap::PixelMap(std::string data, bool verbose) {
11
12 pixelmap.clear();
13 ReadPixelMap(pixelmap, data, verbose);
14
15}
16
17PixelMap::~PixelMap() {
18
19 for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
20 delete ((*iter).second);
21 }
22
23}
24
25void PixelMap::ReadPixelMap(std::map<unsigned int, Pixel*>& pixelmap, std::string data, bool verbose) {
26
27 if (verbose) {
28 std::cout<<"Creating pixelmap table"<<std::endl;
29 if (strlen(data.c_str()) == 0) {
30 std::cerr<<"WARNING in PixelMap::ReadPixelMap: input table is empty"<<std::endl;
31 }
32 }
33
34 std::string::size_type Next, EndNext = 0;
35
36 while (EndNext != std::string::npos) {
37
38 Next = data.find_first_not_of(";", EndNext);
39 EndNext = data.find_first_of(";", Next);
40
41 // Stop if end of string reached
42 if (Next == std::string::npos) break;
43
44 std::string tokens = data.substr(Next, EndNext - Next);
45
46 if (tokens.find(":") != std::string::npos) {
47
48 char* ctokens = new char[tokens.size()+1];
49 strcpy (ctokens, tokens.c_str());
50
51 char delim[] = ":";
52 char *name = NULL; //unformated name before : tokens
53 char name2[256] = ""; //formated name without whitespaces
54 char *rest = NULL;
55
56 name = strtok(ctokens, delim);
57
58 unsigned int count1 = 0; //count non-whitespace characters in name
59
60 for (unsigned int i = 0; i < strlen(name); i++) {
61
62 if ( !(isspace(name[i])) ) {
63 name2[count1] = name[i];
64 count1+=1;
65 }
66
67 }
68
69 if( (count1 > 0) && (count1 < 5) ) {
70
71 unsigned int pixelID = (unsigned int)atoi(name2);
72 std::map<const unsigned int, Pixel*>::iterator found = pixelmap.find(pixelID);
73
74 if( found == pixelmap.end() ) {//pixelID already existing?
75
76 rest = strtok(NULL, delim);
77
78 if(rest != NULL) {
79
80 unsigned int FPAcrate = (unsigned int)strtod(rest, &rest);
81 unsigned int FPAboard = (unsigned int)strtod(rest, &rest);
82 unsigned int FPApatch = (unsigned int)strtod(rest, &rest);
83 unsigned int FPApixel = (unsigned int)strtod(rest, &rest);
84 unsigned int HVcrate = (unsigned int)strtod(rest, &rest);
85 unsigned int HVboard = (unsigned int)strtod(rest, &rest);
86 unsigned int HVchannel = (unsigned int)strtod(rest, &rest);
87 int POSx = (int)strtod(rest, &rest);
88 int POSy = (int)strtod(rest, &rest);
89
90 pixelmap[pixelID] = new Pixel(FPAcrate, FPAboard, FPApatch, FPApixel,
91 HVcrate, HVboard, HVchannel,
92 POSx, POSy);
93 }
94
95 else {
96
97 pixelmap[pixelID] = new Pixel();
98
99 }
100
101 }
102
103 else {
104
105 if (verbose) {
106 std::cout << "ERROR in PixelMap::ReadPixelMap: pixel ID already existing: " << pixelID << " -> pixel not initialized again" << std::endl;
107 }
108
109 }
110
111 }
112
113 else {
114
115 if (verbose) {
116 std::cout << "ERROR in PixelMap::ReadPixelMap: wrong pixel ID: " << name2 << " -> pixel not initialized" << std::endl;
117 }
118
119 }
120
121 delete[] ctokens;
122
123 }
124
125 else {
126
127 if(verbose){
128 std::cout << "ERROR in PixelMap::ReadPixelMap: entry without pixel ID: " << tokens << " -> pixel not initialized" << std::endl;
129 }
130
131 }
132
133 }
134
135 if (verbose) {
136 std::cout << std::endl << pixelmap.size() << " pixels found" << std::endl << std::endl;
137 }
138
139}
140
141void PixelMap::Print() {
142
143 std::cout << "Printing entries of pixelmap:" << std::endl << std::endl;
144
145 for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
146 std::cout << (*iter).first << std::endl << "------------" << std::endl << *((*iter).second) << std::endl;
147 }
148
149}
150
151unsigned int PixelMap::FPA_to_Pixel(unsigned int FPAcrate, unsigned int FPAboard, unsigned int FPApatch, unsigned int FPApixel, bool verbose) {
152
153 unsigned int pixelID = PM_ERROR_CODE;
154
155 for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
156
157 if( ( ((*iter).second)->GetPixelFPAcrate() == FPAcrate ) &&
158 ( ((*iter).second)->GetPixelFPAboard() == FPAboard ) &&
159 ( ((*iter).second)->GetPixelFPApatch() == FPApatch ) &&
160 ( ((*iter).second)->GetPixelFPApixel() == FPApixel ) ) {
161
162 pixelID = (*iter).first;
163
164 }
165
166 }
167
168 if(pixelID == PM_ERROR_CODE){
169
170 if (verbose) {
171 std::cout << "ERROR in PixelMap::FPA_to_Pixel: No pixel with FPA crate, board, patch, pixel = "
172 << FPAcrate << ", "
173 << FPAboard << ", "
174 << FPApatch << ", "
175 << FPApixel << " found in pixelmap" << std::endl;
176 }
177
178 }
179
180 return pixelID;
181
182}
183
184std::vector<unsigned int> PixelMap::HV_to_Pixel(unsigned int HVcrate, unsigned int HVboard, unsigned int HVchannel, bool verbose) {
185
186 unsigned int last_pixelID = PM_ERROR_CODE;
187
188 std::vector<unsigned int> PixelIDs;
189
190 for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
191
192 if( ( ((*iter).second)->GetPixelHVcrate() == HVcrate ) &&
193 ( ((*iter).second)->GetPixelHVboard() == HVboard ) &&
194 ( ((*iter).second)->GetPixelHVchannel() == HVchannel ) ) {
195
196 last_pixelID = (*iter).first;
197 PixelIDs.push_back(last_pixelID);
198
199 }
200
201 }
202
203 if(last_pixelID == PM_ERROR_CODE){
204
205 if (verbose) {
206 std::cout << "ERROR in PixelMap::HV_to_Pixel: No pixel with HV crate, board, channel = "
207 << HVcrate << ", "
208 << HVboard << ", "
209 << HVchannel << " found in pixelmap" << std::endl;
210 }
211
212 }
213
214 return PixelIDs;
215
216}
217
218unsigned int PixelMap::POS_to_Pixel(int POSx, int POSy, bool verbose) {
219
220 unsigned int pixelID = PM_ERROR_CODE;
221
222 for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
223
224 if( ( ((*iter).second)->GetPixelPOSx() == POSx ) &&
225 ( ((*iter).second)->GetPixelPOSy() == POSy ) ) {
226
227 pixelID = (*iter).first;
228
229 }
230
231 }
232
233 if(pixelID == PM_ERROR_CODE){
234
235 if (verbose) {
236 std::cout << "ERROR in PixelMap::POS_to_Pixel: No pixel with position x, y = "
237 << POSx << ", "
238 << POSy << " found in pixelmap" << std::endl;
239 }
240
241 }
242
243 return pixelID;
244
245}
246
247unsigned int PixelMap::Pixel_to_FPAcrate(unsigned int pixelID, bool verbose) {
248
249 unsigned int FPAcrate = PM_ERROR_CODE;
250
251 for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
252
253 if( ((*iter).first) == pixelID ){
254 FPAcrate = ((*iter).second)->GetPixelFPAcrate();
255 }
256
257 }
258
259 if (FPAcrate == PM_ERROR_CODE) {
260
261 if (verbose) {
262 std::cout << "ERROR in PixelMap::Pixel_to_FPAcrate: No pixel with ID = "
263 << pixelID << " found in pixelmap" << std::endl;
264 }
265
266 }
267
268 return FPAcrate;
269
270}
271
272unsigned int PixelMap::Pixel_to_FPAboard(unsigned int pixelID, bool verbose) {
273
274 unsigned int FPAboard = PM_ERROR_CODE;
275
276 for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
277
278 if( ((*iter).first) == pixelID ){
279 FPAboard = ((*iter).second)->GetPixelFPAboard();
280 }
281
282 }
283
284 if (FPAboard == PM_ERROR_CODE) {
285
286 if (verbose) {
287 std::cout << "ERROR in PixelMap::Pixel_to_FPAboard: No pixel with ID = "
288 << pixelID << " found in pixelmap" << std::endl;
289 }
290
291 }
292
293 return FPAboard;
294
295}
296
297unsigned int PixelMap::Pixel_to_FPApatch(unsigned int pixelID, bool verbose) {
298
299 unsigned int FPApatch = PM_ERROR_CODE;
300
301 for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
302
303 if( ((*iter).first) == pixelID ){
304 FPApatch = ((*iter).second)->GetPixelFPApatch();
305 }
306
307 }
308
309 if (FPApatch == PM_ERROR_CODE) {
310
311 if (verbose) {
312 std::cout << "ERROR in PixelMap::Pixel_to_FPApatch: No pixel with ID = "
313 << pixelID << " found in pixelmap" << std::endl;
314 }
315
316 }
317
318 return FPApatch;
319
320}
321
322unsigned int PixelMap::Pixel_to_FPApixel(unsigned int pixelID, bool verbose) {
323
324 unsigned int FPApixel = PM_ERROR_CODE;
325
326 for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
327
328 if( ((*iter).first) == pixelID ){
329 FPApixel = ((*iter).second)->GetPixelFPApixel();
330 }
331
332 }
333
334 if (FPApixel == PM_ERROR_CODE) {
335
336 if (verbose) {
337 std::cout << "ERROR in PixelMap::Pixel_to_FPApixel: No pixel with ID = "
338 << pixelID << " found in pixelmap" << std::endl;
339 }
340
341 }
342
343 return FPApixel;
344
345}
346
347unsigned int PixelMap::Pixel_to_HVcrate(unsigned int pixelID, bool verbose) {
348
349 unsigned int HVcrate = PM_ERROR_CODE;
350
351 for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
352
353 if( ((*iter).first) == pixelID ){
354 HVcrate = ((*iter).second)->GetPixelHVcrate();
355 }
356
357 }
358
359 if (HVcrate == PM_ERROR_CODE) {
360
361 if (verbose) {
362 std::cout << "ERROR in PixelMap::Pixel_to_HVcrate: No pixel with ID = "
363 << pixelID << " found in pixelmap" << std::endl;
364 }
365
366 }
367
368 return HVcrate;
369
370}
371
372unsigned int PixelMap::Pixel_to_HVboard(unsigned int pixelID, bool verbose) {
373
374 unsigned int HVboard = PM_ERROR_CODE;
375
376 for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
377
378 if( ((*iter).first) == pixelID ){
379 HVboard = ((*iter).second)->GetPixelHVboard();
380 }
381
382 }
383
384 if (HVboard == PM_ERROR_CODE) {
385
386 if (verbose) {
387 std::cout << "ERROR in PixelMap::Pixel_to_HVboard: No pixel with ID = "
388 << pixelID << " found in pixelmap" << std::endl;
389 }
390
391 }
392
393 return HVboard;
394
395}
396
397unsigned int PixelMap::Pixel_to_HVchannel(unsigned int pixelID, bool verbose) {
398
399 unsigned int HVchannel = PM_ERROR_CODE;
400
401 for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
402
403 if( ((*iter).first) == pixelID ){
404 HVchannel = ((*iter).second)->GetPixelHVchannel();
405 }
406
407 }
408
409 if (HVchannel == PM_ERROR_CODE) {
410
411 if (verbose) {
412 std::cout << "ERROR in PixelMap::Pixel_to_HVchannel: No pixel with ID = "
413 << pixelID << " found in pixelmap" << std::endl;
414 }
415
416 }
417
418 return HVchannel;
419
420}
421
422int PixelMap::Pixel_to_POSx(unsigned int pixelID, bool verbose) {
423
424 int POSx = PM_ERROR_CODE;
425
426 for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
427
428 if( ((*iter).first) == pixelID ){
429 POSx = ((*iter).second)->GetPixelPOSx();
430 }
431
432 }
433
434 if (POSx == (int)PM_ERROR_CODE) {
435
436 if (verbose) {
437 std::cout << "ERROR in PixelMap::Pixel_to_POSx: No pixel with ID = "
438 << pixelID << " found in pixelmap" << std::endl;
439 }
440
441 }
442
443 return POSx;
444
445}
446
447int PixelMap::Pixel_to_POSy(unsigned int pixelID, bool verbose) {
448
449 int POSy = PM_ERROR_CODE;
450
451 for( std::map<const unsigned int, Pixel*>::iterator iter = pixelmap.begin(); iter != pixelmap.end(); ++iter ) {
452
453 if( ((*iter).first) == pixelID ){
454 POSy = ((*iter).second)->GetPixelPOSy();
455 }
456
457 }
458
459 if (POSy == (int)PM_ERROR_CODE) {
460
461 if (verbose) {
462 std::cout << "ERROR in PixelMap::Pixel_to_POSy: No pixel with ID = "
463 << pixelID << " found in pixelmap" << std::endl;
464 }
465
466 }
467
468 return POSy;
469
470}
Note: See TracBrowser for help on using the repository browser.