]>
Commit | Line | Data |
---|---|---|
1 | /************************************************************************** | |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | ***************************************************************************/ | |
15 | ||
16 | /* | |
17 | * author: Roberto Preghenella (R+), Roberto.Preghenella@bo.infn.it | |
18 | */ | |
19 | ||
20 | ////////////////////////////////////////////////////////////////////// | |
21 | // // | |
22 | // // | |
23 | // This class provides the TOF FEE reader. // | |
24 | // // | |
25 | // // | |
26 | ////////////////////////////////////////////////////////////////////// | |
27 | ||
28 | #include <TSystem.h> | |
29 | #include "AliTOFFEEReader.h" | |
30 | #include "AliTOFFEEConfig.h" | |
31 | #include "AliTOFFEElightConfig.h" | |
32 | #include "AliTOFRawStream.h" | |
33 | #include "AliTOFGeometry.h" | |
34 | #include "AliTOFcalibHisto.h" | |
35 | #include "AliLog.h" | |
36 | #include <fstream> | |
37 | ||
38 | ClassImp(AliTOFFEEReader) | |
39 | ||
40 | //_______________________________________________________________ | |
41 | ||
42 | AliTOFFEEReader::AliTOFFEEReader() : | |
43 | TObject(), | |
44 | fFEEConfig(new AliTOFFEEConfig()), | |
45 | fFEElightConfig(new AliTOFFEElightConfig()), | |
46 | fChannelEnabled(), | |
47 | fMatchingWindow(), | |
48 | fLatencyWindow() | |
49 | { | |
50 | /* | |
51 | * | |
52 | * default constructor | |
53 | * | |
54 | */ | |
55 | ||
56 | Reset(); | |
57 | } | |
58 | ||
59 | //_______________________________________________________________ | |
60 | ||
61 | AliTOFFEEReader::AliTOFFEEReader(const AliTOFFEEReader &source) : | |
62 | TObject(source), | |
63 | fFEEConfig(new AliTOFFEEConfig()), | |
64 | fFEElightConfig(new AliTOFFEElightConfig()) | |
65 | { | |
66 | /* | |
67 | * | |
68 | * copy constructor | |
69 | * | |
70 | */ | |
71 | ||
72 | Reset(); | |
73 | memcpy(fFEEConfig, source.fFEEConfig, sizeof(AliTOFFEEConfig)); | |
74 | memcpy(fFEElightConfig, source.fFEElightConfig, sizeof(AliTOFFEElightConfig)); | |
75 | } | |
76 | ||
77 | //_______________________________________________________________ | |
78 | ||
79 | AliTOFFEEReader & | |
80 | AliTOFFEEReader::operator=(const AliTOFFEEReader &source) | |
81 | { | |
82 | /* | |
83 | * | |
84 | * operator = | |
85 | * | |
86 | */ | |
87 | ||
88 | TObject::operator=(source); | |
89 | memcpy(fFEEConfig, source.fFEEConfig, sizeof(AliTOFFEEConfig)); | |
90 | memcpy(fFEElightConfig, source.fFEElightConfig, sizeof(AliTOFFEElightConfig)); | |
91 | return *this; | |
92 | } | |
93 | ||
94 | //_______________________________________________________________ | |
95 | ||
96 | AliTOFFEEReader::~AliTOFFEEReader() | |
97 | { | |
98 | /* | |
99 | * | |
100 | * default destructor | |
101 | * | |
102 | */ | |
103 | ||
104 | delete fFEEConfig; | |
105 | delete fFEElightConfig; | |
106 | } | |
107 | ||
108 | //_______________________________________________________________ | |
109 | ||
110 | void | |
111 | AliTOFFEEReader::ResetChannelEnabledArray() | |
112 | { | |
113 | /* | |
114 | * | |
115 | * reset channel enabled array | |
116 | * | |
117 | */ | |
118 | ||
119 | for (Int_t iIndex = 0; iIndex < GetNumberOfIndexes(); iIndex++) | |
120 | fChannelEnabled[iIndex] = kFALSE; | |
121 | } | |
122 | ||
123 | //_______________________________________________________________ | |
124 | ||
125 | void | |
126 | AliTOFFEEReader::ResetTriggerMaskArray() | |
127 | { | |
128 | /* | |
129 | * | |
130 | * reset trigger mask array | |
131 | * | |
132 | */ | |
133 | ||
134 | for (Int_t iddl = 0; iddl < GetNumberOfDDLs(); iddl++) | |
135 | fTriggerMask[iddl] = 0x0; | |
136 | } | |
137 | ||
138 | //_______________________________________________________________ | |
139 | ||
140 | void | |
141 | AliTOFFEEReader::Reset() | |
142 | { | |
143 | /* | |
144 | * | |
145 | * reset | |
146 | * | |
147 | */ | |
148 | ||
149 | for (Int_t iIndex = 0; iIndex < GetNumberOfIndexes(); iIndex++) { | |
150 | fChannelEnabled[iIndex] = kFALSE; | |
151 | fMatchingWindow[iIndex] = 0; | |
152 | fLatencyWindow[iIndex] = 0; | |
153 | } | |
154 | ||
155 | for (Int_t iddl = 0; iddl < GetNumberOfDDLs(); iddl++) | |
156 | fTriggerMask[iddl] = 0x0; | |
157 | } | |
158 | ||
159 | //_______________________________________________________________ | |
160 | ||
161 | void | |
162 | AliTOFFEEReader::LoadFEEConfig(const Char_t *FileName) const | |
163 | { | |
164 | /* | |
165 | * | |
166 | * load FEE config | |
167 | * | |
168 | */ | |
169 | ||
170 | Char_t *expandedFileName = gSystem->ExpandPathName(FileName); | |
171 | std::ifstream is; | |
172 | is.open(expandedFileName, std::ios::binary); | |
173 | is.read((Char_t *)fFEEConfig, sizeof(AliTOFFEEConfig)); | |
174 | is.close(); | |
175 | } | |
176 | ||
177 | //_______________________________________________________________ | |
178 | ||
179 | void | |
180 | AliTOFFEEReader::LoadFEElightConfig(const Char_t *FileName) const | |
181 | { | |
182 | /* | |
183 | * | |
184 | * load FEElight config | |
185 | * | |
186 | */ | |
187 | ||
188 | Char_t *expandedFileName = gSystem->ExpandPathName(FileName); | |
189 | std::ifstream is; | |
190 | is.open(expandedFileName, std::ios::binary); | |
191 | is.read((Char_t *)fFEElightConfig, sizeof(AliTOFFEElightConfig)); | |
192 | is.close(); | |
193 | } | |
194 | ||
195 | //_______________________________________________________________ | |
196 | ||
197 | Int_t | |
198 | AliTOFFEEReader::ParseFEEConfig() | |
199 | { | |
200 | /* | |
201 | * | |
202 | * parse FEE config | |
203 | * | |
204 | * loops over all FEE channels, checks whether they are enabled | |
205 | * and sets channel enabled | |
206 | * | |
207 | */ | |
208 | ||
209 | AliInfo("parsing TOF FEE config"); | |
210 | ||
211 | AliTOFRawStream rawStream; | |
212 | Int_t nEnabled = 0; | |
213 | Int_t volume[5], index; | |
214 | Int_t temp; | |
215 | ||
216 | Reset(); | |
217 | ||
218 | /* loop over all FEE channels */ | |
219 | for (Int_t iDDL = 0; iDDL < GetNumberOfDDLs(); iDDL++) | |
220 | for (Int_t iTRM = 0; iTRM < GetNumberOfTRMs(); iTRM++) | |
221 | for (Int_t iChain = 0; iChain < GetNumberOfChains(); iChain++) | |
222 | for (Int_t iTDC = 0; iTDC < GetNumberOfTDCs(); iTDC++) | |
223 | for (Int_t iChannel = 0; iChannel < GetNumberOfChannels(); iChannel++) | |
224 | /* check whether FEE channel is enabled */ | |
225 | if (IsChannelEnabled(iDDL, iTRM + 3, iChain, iTDC, iChannel)) { | |
226 | /* convert FEE channel indexes into detector indexes */ | |
227 | rawStream.EquipmentId2VolumeId(iDDL, iTRM + 3, iChain, iTDC, iChannel, volume); | |
228 | /* swap padx and padz to fit AliTOFGeometry::GetIndex behaviour */ | |
229 | temp = volume[4]; volume[4] = volume[3]; volume[3] = temp; | |
230 | /* check if index is ok */ | |
231 | if (volume[0] < 0 || volume[0] > 17 || | |
232 | volume[1] < 0 || volume[1] > 4 || | |
233 | volume[2] < 0 || volume[2] > 18 || | |
234 | volume[3] < 0 || volume[3] > 1 || | |
235 | volume[4] < 0 || volume[4] > 47) | |
236 | continue; | |
237 | /* convert detector indexes into calibration index */ | |
238 | index = AliTOFGeometry::GetIndex(volume); | |
239 | /* check calibration index */ | |
240 | if (index != -1 && index < GetNumberOfIndexes()) { | |
241 | /* set calibration channel enabled */ | |
242 | fChannelEnabled[index] = kTRUE; | |
243 | fMatchingWindow[index] = GetMatchingWindow(iDDL, iTRM + 3, iChain, iTDC, iChannel); | |
244 | nEnabled++; | |
245 | } | |
246 | } | |
247 | return nEnabled; | |
248 | } | |
249 | ||
250 | //_______________________________________________________________ | |
251 | ||
252 | Int_t | |
253 | AliTOFFEEReader::ParseFEElightConfig() | |
254 | { | |
255 | /* | |
256 | * | |
257 | * parse FEElight config | |
258 | * | |
259 | * loops over all FEE channels, checks whether they are enabled | |
260 | * and sets channel enabled | |
261 | * | |
262 | */ | |
263 | ||
264 | AliInfo("parsing TOF FEElight config"); | |
265 | ||
266 | Reset(); | |
267 | ||
268 | AliTOFcalibHisto calibHisto; | |
269 | calibHisto.LoadCalibHisto(); | |
270 | ||
271 | Int_t nEnabled = 0, index; | |
272 | AliTOFFEEchannelConfig *channelConfig = NULL; | |
273 | for (Int_t i = 0; i < GetNumberOfIndexesEO(); i++) { | |
274 | channelConfig = fFEElightConfig->GetChannelConfig(i); | |
275 | if (!channelConfig->IsEnabled()) continue; | |
276 | /* get index DO from index EO */ | |
277 | index = (Int_t)calibHisto.GetCalibMap(AliTOFcalibHisto::kIndex, i); | |
278 | if (index == -1) continue; | |
279 | nEnabled++; | |
280 | fChannelEnabled[index] = channelConfig->IsEnabled(); | |
281 | fMatchingWindow[index] = channelConfig->GetMatchingWindow(); | |
282 | fLatencyWindow[index] = channelConfig->GetLatencyWindow(); | |
283 | } | |
284 | ||
285 | AliTOFFEEtriggerConfig *triggerConfig = NULL; | |
286 | for (Int_t iddl = 0; iddl < GetNumberOfDDLs(); iddl++) { | |
287 | triggerConfig = fFEElightConfig->GetTriggerConfig(iddl); | |
288 | fTriggerMask[iddl] = triggerConfig->GetStatusMap(); | |
289 | } | |
290 | ||
291 | return nEnabled; | |
292 | } | |
293 | ||
294 | //_______________________________________________________________ | |
295 | ||
296 | Bool_t | |
297 | AliTOFFEEReader::IsChannelEnabled(Int_t iDDL, Int_t iTRM, Int_t iChain, Int_t iTDC, Int_t iChannel) const | |
298 | { | |
299 | /* | |
300 | * | |
301 | * is channel enabled | |
302 | * | |
303 | * checks whether a FEE channel is enabled using the | |
304 | * TOF FEE config object. | |
305 | * | |
306 | */ | |
307 | ||
308 | AliTOFFEEConfig *feeConfig; | |
309 | AliTOFCrateConfig *crateConfig; | |
310 | AliTOFTRMConfig *trmConfig; | |
311 | Int_t maskPB, maskTDC, activeChip; | |
312 | ||
313 | /* get and check fee config */ | |
314 | if (!(feeConfig = GetFEEConfig())) | |
315 | return kFALSE; | |
316 | ||
317 | /* get and check crate config */ | |
318 | if (!(crateConfig = feeConfig->GetCrateConfig(iDDL))) | |
319 | return kFALSE; | |
320 | ||
321 | /* get and check TRM config */ | |
322 | if (!(trmConfig = crateConfig->GetTRMConfig(iTRM - 3))) | |
323 | return kFALSE; | |
324 | ||
325 | /* check DRM enabled */ | |
326 | if (!crateConfig->IsDRMEnabled()) | |
327 | return kFALSE; | |
328 | ||
329 | /* check TRM enabled */ | |
330 | if (!crateConfig->IsTRMEnabled(iTRM - 3)) | |
331 | return kFALSE; | |
332 | ||
333 | /* switch chain */ | |
334 | switch (iChain) { | |
335 | /* chain A */ | |
336 | case 0: | |
337 | /* check chain enabled */ | |
338 | if (trmConfig->GetChainAFlag() != 1) | |
339 | return kFALSE; | |
340 | /* get active chip mask */ | |
341 | activeChip = trmConfig->GetActiveChipA(); | |
342 | /* switch TDC */ | |
343 | switch (iTDC) { | |
344 | case 0: case 1: case 2: | |
345 | maskPB = trmConfig->GetMaskPB0(); | |
346 | break; | |
347 | case 3: case 4: case 5: | |
348 | maskPB = trmConfig->GetMaskPB1(); | |
349 | break; | |
350 | case 6: case 7: case 8: | |
351 | maskPB = trmConfig->GetMaskPB2(); | |
352 | break; | |
353 | case 9: case 10: case 11: | |
354 | maskPB = trmConfig->GetMaskPB3(); | |
355 | break; | |
356 | case 12: case 13: case 14: | |
357 | maskPB = trmConfig->GetMaskPB4(); | |
358 | break; | |
359 | default: | |
360 | return kFALSE; | |
361 | break; | |
362 | } /* switch TDC */ | |
363 | break; /* chain A */ | |
364 | /* chain B */ | |
365 | case 1: | |
366 | /* check chain enabled */ | |
367 | if (trmConfig->GetChainBFlag() != 1) | |
368 | return kFALSE; | |
369 | /* get active chip mask */ | |
370 | activeChip = trmConfig->GetActiveChipB(); | |
371 | /* switch TDC */ | |
372 | switch (iTDC) { | |
373 | case 0: case 1: case 2: | |
374 | maskPB = trmConfig->GetMaskPB5(); | |
375 | break; | |
376 | case 3: case 4: case 5: | |
377 | maskPB = trmConfig->GetMaskPB6(); | |
378 | break; | |
379 | case 6: case 7: case 8: | |
380 | maskPB = trmConfig->GetMaskPB7(); | |
381 | break; | |
382 | case 9: case 10: case 11: | |
383 | maskPB = trmConfig->GetMaskPB8(); | |
384 | break; | |
385 | case 12: case 13: case 14: | |
386 | maskPB = trmConfig->GetMaskPB9(); | |
387 | break; | |
388 | default: | |
389 | return kFALSE; | |
390 | break; | |
391 | } /* switch TDC */ | |
392 | break; /* chain B */ | |
393 | default: | |
394 | return kFALSE; | |
395 | break; | |
396 | } /* switch chain */ | |
397 | ||
398 | /* check chip enabled */ | |
399 | if (!(activeChip & (0x1 << iTDC))) | |
400 | return kFALSE; | |
401 | ||
402 | /* check channel enabled */ | |
403 | maskTDC = (maskPB & (0xFF << ((iTDC % 3) * 8))) >> ((iTDC % 3) * 8); | |
404 | if (maskTDC & (0x1 << iChannel)) | |
405 | return kTRUE; | |
406 | else | |
407 | return kFALSE; | |
408 | ||
409 | } | |
410 | ||
411 | //_______________________________________________________________ | |
412 | ||
413 | Int_t | |
414 | AliTOFFEEReader::GetMatchingWindow(Int_t iDDL, Int_t iTRM, Int_t, Int_t, Int_t) const | |
415 | { | |
416 | /* | |
417 | * | |
418 | * get matching window | |
419 | * | |
420 | * checks whether a FEE channel is enabled using the | |
421 | * TOF FEE config object and return the associated | |
422 | * matching window | |
423 | * | |
424 | */ | |
425 | ||
426 | AliTOFFEEConfig *feeConfig; | |
427 | AliTOFCrateConfig *crateConfig; | |
428 | AliTOFTRMConfig *trmConfig; | |
429 | ||
430 | /* get and check fee config */ | |
431 | if (!(feeConfig = GetFEEConfig())) | |
432 | return 0; | |
433 | ||
434 | /* get and check crate config */ | |
435 | if (!(crateConfig = feeConfig->GetCrateConfig(iDDL))) | |
436 | return 0; | |
437 | ||
438 | /* get and check TRM config */ | |
439 | if (!(trmConfig = crateConfig->GetTRMConfig(iTRM - 3))) | |
440 | return 0; | |
441 | ||
442 | /* check DRM enabled */ | |
443 | if (!crateConfig->IsDRMEnabled()) | |
444 | return 0; | |
445 | ||
446 | /* check TRM enabled */ | |
447 | if (!crateConfig->IsTRMEnabled(iTRM - 3)) | |
448 | return 0; | |
449 | ||
450 | return trmConfig->GetMatchingWindow(); | |
451 | } | |
452 | ||
453 | ||
454 | void | |
455 | AliTOFFEEReader::DumpFEEConfig() | |
456 | { | |
457 | /* | |
458 | * | |
459 | * dump FEE config | |
460 | * | |
461 | */ | |
462 | ||
463 | AliTOFFEEConfig *feeConfig = GetFEEConfig(); | |
464 | AliTOFCrateConfig *crateConfig; | |
465 | AliTOFDRMConfig *drmConfig; | |
466 | AliTOFLTMConfig *ltmConfig; | |
467 | AliTOFTRMConfig *trmConfig; | |
468 | ||
469 | AliInfo("-------------------------------------"); | |
470 | AliInfo("dumping TOF FEE config"); | |
471 | AliInfo("-------------------------------------"); | |
472 | AliInfo(Form("version: %d", feeConfig->GetVersion())); | |
473 | AliInfo(Form("dump time: %d", (Int_t)feeConfig->GetDumpTime())); | |
474 | AliInfo(Form("run number: %d", feeConfig->GetRunNumber())); | |
475 | AliInfo(Form("run type: %d", feeConfig->GetRunType())); | |
476 | AliInfo("-------------------------------------"); | |
477 | ||
478 | /* loop over crates */ | |
479 | for (Int_t iCrate = 0; iCrate < AliTOFFEEConfig::GetNumberOfCrates(); iCrate++) { | |
480 | crateConfig = feeConfig->GetCrateConfig(iCrate); | |
481 | ||
482 | /* check crate config */ | |
483 | if (!crateConfig) | |
484 | continue; | |
485 | ||
486 | /* check DRM enabled */ | |
487 | if (!crateConfig->IsDRMEnabled()) | |
488 | continue; | |
489 | ||
490 | AliInfo(Form("crate id: %02d", iCrate)); | |
491 | ||
492 | /* dump DRM config */ | |
493 | drmConfig = crateConfig->GetDRMConfig(); | |
494 | AliInfo(Form("DRM is enabled: drmId=%d, slotMask=%03x", drmConfig->GetDRMId(), drmConfig->GetSlotMask())); | |
495 | ||
496 | /* dump LTM config if enabled */ | |
497 | if (crateConfig->IsLTMEnabled()) { | |
498 | ltmConfig = crateConfig->GetLTMConfig(); | |
499 | AliInfo(Form("LTM is enabled: threshold=%d", ltmConfig->GetThreshold())); | |
500 | } | |
501 | ||
502 | /* dump CPDM config if enabled */ | |
503 | if (crateConfig->IsCPDMEnabled()) { | |
504 | AliInfo(Form("CPDM is enabled")); | |
505 | } | |
506 | ||
507 | /* loop over TRMs */ | |
508 | for (Int_t iTRM = 0; iTRM < AliTOFCrateConfig::GetNumberOfTRMs(); iTRM++) { | |
509 | ||
510 | trmConfig = crateConfig->GetTRMConfig(iTRM); | |
511 | ||
512 | /* check TRM config */ | |
513 | if (!trmConfig) | |
514 | continue; | |
515 | ||
516 | /* check TRM enabled */ | |
517 | if (!crateConfig->IsTRMEnabled(iTRM)) | |
518 | continue; | |
519 | ||
520 | /* dump TRM config */ | |
521 | AliInfo(Form("TRM%02d is enabled: matchWin=%d, latWin=%d, packFlag=%d", iTRM + 3, trmConfig->GetMatchingWindow(), trmConfig->GetLatencyWindow(), trmConfig->GetPackingFlag())); | |
522 | ||
523 | /* check TRM chain A flag */ | |
524 | if (trmConfig->GetChainAFlag() == 1) { | |
525 | AliInfo(Form("TRM%02d chainA is enabled: activeChip=%04X, PB0=%06X, PB1=%06X, PB2=%06X, PB3=%06X, PB4=%06X", iTRM + 3, trmConfig->GetActiveChipA(), trmConfig->GetMaskPB0(), trmConfig->GetMaskPB1(), trmConfig->GetMaskPB2(), trmConfig->GetMaskPB3(), trmConfig->GetMaskPB4())); | |
526 | } | |
527 | ||
528 | /* check TRM chain B flag */ | |
529 | if (trmConfig->GetChainBFlag() == 1) { | |
530 | AliInfo(Form("TRM%02d chainB is enabled: activeChip=%04X, PB5=%06X, PB6=%06X, PB7=%06X, PB8=%06X, PB9=%06X", iTRM + 3, trmConfig->GetActiveChipB(), trmConfig->GetMaskPB5(), trmConfig->GetMaskPB6(), trmConfig->GetMaskPB7(), trmConfig->GetMaskPB8(), trmConfig->GetMaskPB9())); | |
531 | } | |
532 | ||
533 | ||
534 | ||
535 | } /* loop over TRMs */ | |
536 | AliInfo("-------------------------------------"); | |
537 | } /* loop over crates */ | |
538 | } | |
539 | ||
540 | //_______________________________________________________________ | |
541 | ||
542 | void | |
543 | AliTOFFEEReader::CreateFEElightConfig(const Char_t *filename) | |
544 | { | |
545 | /* | |
546 | * | |
547 | * create FEElight config | |
548 | * | |
549 | */ | |
550 | ||
551 | AliTOFFEElightConfig lightConfig; | |
552 | ||
553 | for (Int_t i = 0; i < GetNumberOfIndexes(); i++) { | |
554 | if (fChannelEnabled[i]) { | |
555 | lightConfig.GetChannelConfig(i)->SetStatus(AliTOFFEEchannelConfig::kStatusEnabled); | |
556 | lightConfig.GetChannelConfig(i)->SetMatchingWindow(fMatchingWindow[i]); | |
557 | lightConfig.GetChannelConfig(i)->SetLatencyWindow(fLatencyWindow[i]); | |
558 | } | |
559 | else { | |
560 | lightConfig.GetChannelConfig(i)->SetStatus(0x0); | |
561 | lightConfig.GetChannelConfig(i)->SetMatchingWindow(0); | |
562 | lightConfig.GetChannelConfig(i)->SetLatencyWindow(0); | |
563 | } | |
564 | } | |
565 | ||
566 | Char_t *expandedFileName = gSystem->ExpandPathName(filename); | |
567 | std::ofstream os; | |
568 | os.open(expandedFileName, std::ios::binary); | |
569 | os.write((Char_t *)&lightConfig, sizeof(AliTOFFEElightConfig)); | |
570 | os.close(); | |
571 | ||
572 | } |