source: pixelmap/PixelMap.cc@ 10

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