Line data Source code
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 26 : ClassImp(AliTOFFEEReader)
39 :
40 : //_______________________________________________________________
41 :
42 : AliTOFFEEReader::AliTOFFEEReader() :
43 0 : TObject(),
44 0 : fFEEConfig(new AliTOFFEEConfig()),
45 0 : fFEElightConfig(new AliTOFFEElightConfig()),
46 0 : fChannelEnabled(),
47 0 : fMatchingWindow(),
48 0 : fLatencyWindow()
49 0 : {
50 : /*
51 : *
52 : * default constructor
53 : *
54 : */
55 :
56 0 : Reset();
57 0 : }
58 :
59 : //_______________________________________________________________
60 :
61 : AliTOFFEEReader::AliTOFFEEReader(const AliTOFFEEReader &source) :
62 0 : TObject(source),
63 0 : fFEEConfig(new AliTOFFEEConfig()),
64 0 : fFEElightConfig(new AliTOFFEElightConfig())
65 0 : {
66 : /*
67 : *
68 : * copy constructor
69 : *
70 : */
71 :
72 0 : Reset();
73 0 : memcpy(fFEEConfig, source.fFEEConfig, sizeof(AliTOFFEEConfig));
74 0 : memcpy(fFEElightConfig, source.fFEElightConfig, sizeof(AliTOFFEElightConfig));
75 0 : }
76 :
77 : //_______________________________________________________________
78 :
79 : AliTOFFEEReader &
80 : AliTOFFEEReader::operator=(const AliTOFFEEReader &source)
81 : {
82 : /*
83 : *
84 : * operator =
85 : *
86 : */
87 :
88 0 : TObject::operator=(source);
89 0 : memcpy(fFEEConfig, source.fFEEConfig, sizeof(AliTOFFEEConfig));
90 0 : memcpy(fFEElightConfig, source.fFEElightConfig, sizeof(AliTOFFEElightConfig));
91 0 : return *this;
92 : }
93 :
94 : //_______________________________________________________________
95 :
96 : AliTOFFEEReader::~AliTOFFEEReader()
97 0 : {
98 : /*
99 : *
100 : * default destructor
101 : *
102 : */
103 :
104 0 : delete fFEEConfig;
105 0 : delete fFEElightConfig;
106 0 : }
107 :
108 : //_______________________________________________________________
109 :
110 : void
111 : AliTOFFEEReader::ResetChannelEnabledArray()
112 : {
113 : /*
114 : *
115 : * reset channel enabled array
116 : *
117 : */
118 :
119 0 : for (Int_t iIndex = 0; iIndex < GetNumberOfIndexes(); iIndex++)
120 0 : fChannelEnabled[iIndex] = kFALSE;
121 0 : }
122 :
123 : //_______________________________________________________________
124 :
125 : void
126 : AliTOFFEEReader::ResetTriggerMaskArray()
127 : {
128 : /*
129 : *
130 : * reset trigger mask array
131 : *
132 : */
133 :
134 0 : for (Int_t iddl = 0; iddl < GetNumberOfDDLs(); iddl++)
135 0 : fTriggerMask[iddl] = 0x0;
136 0 : }
137 :
138 : //_______________________________________________________________
139 :
140 : void
141 : AliTOFFEEReader::Reset()
142 : {
143 : /*
144 : *
145 : * reset
146 : *
147 : */
148 :
149 0 : for (Int_t iIndex = 0; iIndex < GetNumberOfIndexes(); iIndex++) {
150 0 : fChannelEnabled[iIndex] = kFALSE;
151 0 : fMatchingWindow[iIndex] = 0;
152 0 : fLatencyWindow[iIndex] = 0;
153 : }
154 :
155 0 : for (Int_t iddl = 0; iddl < GetNumberOfDDLs(); iddl++)
156 0 : fTriggerMask[iddl] = 0x0;
157 0 : }
158 :
159 : //_______________________________________________________________
160 :
161 : void
162 : AliTOFFEEReader::LoadFEEConfig(const Char_t *FileName) const
163 : {
164 : /*
165 : *
166 : * load FEE config
167 : *
168 : */
169 :
170 0 : Char_t *expandedFileName = gSystem->ExpandPathName(FileName);
171 0 : std::ifstream is;
172 0 : is.open(expandedFileName, std::ios::binary);
173 0 : is.read((Char_t *)fFEEConfig, sizeof(AliTOFFEEConfig));
174 0 : is.close();
175 0 : }
176 :
177 : //_______________________________________________________________
178 :
179 : void
180 : AliTOFFEEReader::LoadFEElightConfig(const Char_t *FileName) const
181 : {
182 : /*
183 : *
184 : * load FEElight config
185 : *
186 : */
187 :
188 0 : Char_t *expandedFileName = gSystem->ExpandPathName(FileName);
189 0 : std::ifstream is;
190 0 : is.open(expandedFileName, std::ios::binary);
191 0 : is.read((Char_t *)fFEElightConfig, sizeof(AliTOFFEElightConfig));
192 0 : is.close();
193 0 : }
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 0 : AliInfo("parsing TOF FEE config");
210 :
211 0 : AliTOFRawStream rawStream;
212 : Int_t nEnabled = 0;
213 0 : Int_t volume[5], index;
214 : Int_t temp;
215 :
216 0 : Reset();
217 :
218 : /* loop over all FEE channels */
219 0 : for (Int_t iDDL = 0; iDDL < GetNumberOfDDLs(); iDDL++)
220 0 : for (Int_t iTRM = 0; iTRM < GetNumberOfTRMs(); iTRM++)
221 0 : for (Int_t iChain = 0; iChain < GetNumberOfChains(); iChain++)
222 0 : for (Int_t iTDC = 0; iTDC < GetNumberOfTDCs(); iTDC++)
223 0 : for (Int_t iChannel = 0; iChannel < GetNumberOfChannels(); iChannel++)
224 : /* check whether FEE channel is enabled */
225 0 : if (IsChannelEnabled(iDDL, iTRM + 3, iChain, iTDC, iChannel)) {
226 : /* convert FEE channel indexes into detector indexes */
227 0 : rawStream.EquipmentId2VolumeId(iDDL, iTRM + 3, iChain, iTDC, iChannel, volume);
228 : /* swap padx and padz to fit AliTOFGeometry::GetIndex behaviour */
229 0 : temp = volume[4]; volume[4] = volume[3]; volume[3] = temp;
230 : /* check if index is ok */
231 0 : if (volume[0] < 0 || volume[0] > 17 ||
232 0 : volume[1] < 0 || volume[1] > 4 ||
233 0 : volume[2] < 0 || volume[2] > 18 ||
234 0 : volume[3] < 0 || volume[3] > 1 ||
235 0 : volume[4] < 0 || volume[4] > 47)
236 : continue;
237 : /* convert detector indexes into calibration index */
238 0 : index = AliTOFGeometry::GetIndex(volume);
239 : /* check calibration index */
240 0 : if (index != -1 && index < GetNumberOfIndexes()) {
241 : /* set calibration channel enabled */
242 0 : fChannelEnabled[index] = kTRUE;
243 0 : fMatchingWindow[index] = GetMatchingWindow(iDDL, iTRM + 3, iChain, iTDC, iChannel);
244 0 : nEnabled++;
245 0 : }
246 : }
247 : return nEnabled;
248 0 : }
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 0 : AliInfo("parsing TOF FEElight config");
265 :
266 0 : Reset();
267 :
268 0 : AliTOFcalibHisto calibHisto;
269 0 : calibHisto.LoadCalibHisto();
270 :
271 : Int_t nEnabled = 0, index;
272 : AliTOFFEEchannelConfig *channelConfig = NULL;
273 0 : for (Int_t i = 0; i < GetNumberOfIndexesEO(); i++) {
274 0 : channelConfig = fFEElightConfig->GetChannelConfig(i);
275 0 : if (!channelConfig->IsEnabled()) continue;
276 : /* get index DO from index EO */
277 0 : index = (Int_t)calibHisto.GetCalibMap(AliTOFcalibHisto::kIndex, i);
278 0 : if (index == -1) continue;
279 0 : nEnabled++;
280 0 : fChannelEnabled[index] = channelConfig->IsEnabled();
281 0 : fMatchingWindow[index] = channelConfig->GetMatchingWindow();
282 0 : fLatencyWindow[index] = channelConfig->GetLatencyWindow();
283 0 : }
284 :
285 : AliTOFFEEtriggerConfig *triggerConfig = NULL;
286 0 : for (Int_t iddl = 0; iddl < GetNumberOfDDLs(); iddl++) {
287 0 : triggerConfig = fFEElightConfig->GetTriggerConfig(iddl);
288 0 : fTriggerMask[iddl] = triggerConfig->GetStatusMap();
289 : }
290 :
291 : return nEnabled;
292 0 : }
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 0 : if (!(feeConfig = GetFEEConfig()))
315 0 : return kFALSE;
316 :
317 : /* get and check crate config */
318 0 : if (!(crateConfig = feeConfig->GetCrateConfig(iDDL)))
319 0 : return kFALSE;
320 :
321 : /* get and check TRM config */
322 0 : if (!(trmConfig = crateConfig->GetTRMConfig(iTRM - 3)))
323 0 : return kFALSE;
324 :
325 : /* check DRM enabled */
326 0 : if (!crateConfig->IsDRMEnabled())
327 0 : return kFALSE;
328 :
329 : /* check TRM enabled */
330 0 : if (!crateConfig->IsTRMEnabled(iTRM - 3))
331 0 : return kFALSE;
332 :
333 : /* switch chain */
334 0 : switch (iChain) {
335 : /* chain A */
336 : case 0:
337 : /* check chain enabled */
338 0 : if (trmConfig->GetChainAFlag() != 1)
339 0 : return kFALSE;
340 : /* get active chip mask */
341 0 : activeChip = trmConfig->GetActiveChipA();
342 : /* switch TDC */
343 0 : switch (iTDC) {
344 : case 0: case 1: case 2:
345 0 : maskPB = trmConfig->GetMaskPB0();
346 0 : break;
347 : case 3: case 4: case 5:
348 0 : maskPB = trmConfig->GetMaskPB1();
349 0 : break;
350 : case 6: case 7: case 8:
351 0 : maskPB = trmConfig->GetMaskPB2();
352 0 : break;
353 : case 9: case 10: case 11:
354 0 : maskPB = trmConfig->GetMaskPB3();
355 0 : break;
356 : case 12: case 13: case 14:
357 0 : maskPB = trmConfig->GetMaskPB4();
358 0 : break;
359 : default:
360 0 : return kFALSE;
361 : break;
362 : } /* switch TDC */
363 : break; /* chain A */
364 : /* chain B */
365 : case 1:
366 : /* check chain enabled */
367 0 : if (trmConfig->GetChainBFlag() != 1)
368 0 : return kFALSE;
369 : /* get active chip mask */
370 0 : activeChip = trmConfig->GetActiveChipB();
371 : /* switch TDC */
372 0 : switch (iTDC) {
373 : case 0: case 1: case 2:
374 0 : maskPB = trmConfig->GetMaskPB5();
375 0 : break;
376 : case 3: case 4: case 5:
377 0 : maskPB = trmConfig->GetMaskPB6();
378 0 : break;
379 : case 6: case 7: case 8:
380 0 : maskPB = trmConfig->GetMaskPB7();
381 0 : break;
382 : case 9: case 10: case 11:
383 0 : maskPB = trmConfig->GetMaskPB8();
384 0 : break;
385 : case 12: case 13: case 14:
386 0 : maskPB = trmConfig->GetMaskPB9();
387 0 : break;
388 : default:
389 0 : return kFALSE;
390 : break;
391 : } /* switch TDC */
392 : break; /* chain B */
393 : default:
394 0 : return kFALSE;
395 : break;
396 : } /* switch chain */
397 :
398 : /* check chip enabled */
399 0 : if (!(activeChip & (0x1 << iTDC)))
400 0 : return kFALSE;
401 :
402 : /* check channel enabled */
403 0 : maskTDC = (maskPB & (0xFF << ((iTDC % 3) * 8))) >> ((iTDC % 3) * 8);
404 0 : if (maskTDC & (0x1 << iChannel))
405 0 : return kTRUE;
406 : else
407 0 : return kFALSE;
408 :
409 0 : }
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 0 : if (!(feeConfig = GetFEEConfig()))
432 0 : return 0;
433 :
434 : /* get and check crate config */
435 0 : if (!(crateConfig = feeConfig->GetCrateConfig(iDDL)))
436 0 : return 0;
437 :
438 : /* get and check TRM config */
439 0 : if (!(trmConfig = crateConfig->GetTRMConfig(iTRM - 3)))
440 0 : return 0;
441 :
442 : /* check DRM enabled */
443 0 : if (!crateConfig->IsDRMEnabled())
444 0 : return 0;
445 :
446 : /* check TRM enabled */
447 0 : if (!crateConfig->IsTRMEnabled(iTRM - 3))
448 0 : return 0;
449 :
450 0 : return trmConfig->GetMatchingWindow();
451 0 : }
452 :
453 :
454 : void
455 : AliTOFFEEReader::DumpFEEConfig()
456 : {
457 : /*
458 : *
459 : * dump FEE config
460 : *
461 : */
462 :
463 0 : AliTOFFEEConfig *feeConfig = GetFEEConfig();
464 : AliTOFCrateConfig *crateConfig;
465 : AliTOFDRMConfig *drmConfig;
466 : AliTOFLTMConfig *ltmConfig;
467 : AliTOFTRMConfig *trmConfig;
468 :
469 0 : AliInfo("-------------------------------------");
470 0 : AliInfo("dumping TOF FEE config");
471 0 : AliInfo("-------------------------------------");
472 0 : AliInfo(Form("version: %d", feeConfig->GetVersion()));
473 0 : AliInfo(Form("dump time: %d", (Int_t)feeConfig->GetDumpTime()));
474 0 : AliInfo(Form("run number: %d", feeConfig->GetRunNumber()));
475 0 : AliInfo(Form("run type: %d", feeConfig->GetRunType()));
476 0 : AliInfo("-------------------------------------");
477 :
478 : /* loop over crates */
479 0 : for (Int_t iCrate = 0; iCrate < AliTOFFEEConfig::GetNumberOfCrates(); iCrate++) {
480 0 : crateConfig = feeConfig->GetCrateConfig(iCrate);
481 :
482 : /* check crate config */
483 0 : if (!crateConfig)
484 : continue;
485 :
486 : /* check DRM enabled */
487 0 : if (!crateConfig->IsDRMEnabled())
488 : continue;
489 :
490 0 : AliInfo(Form("crate id: %02d", iCrate));
491 :
492 : /* dump DRM config */
493 0 : drmConfig = crateConfig->GetDRMConfig();
494 0 : AliInfo(Form("DRM is enabled: drmId=%d, slotMask=%03x", drmConfig->GetDRMId(), drmConfig->GetSlotMask()));
495 :
496 : /* dump LTM config if enabled */
497 0 : if (crateConfig->IsLTMEnabled()) {
498 0 : ltmConfig = crateConfig->GetLTMConfig();
499 0 : AliInfo(Form("LTM is enabled: threshold=%d", ltmConfig->GetThreshold()));
500 0 : }
501 :
502 : /* dump CPDM config if enabled */
503 0 : if (crateConfig->IsCPDMEnabled()) {
504 0 : AliInfo(Form("CPDM is enabled"));
505 0 : }
506 :
507 : /* loop over TRMs */
508 0 : for (Int_t iTRM = 0; iTRM < AliTOFCrateConfig::GetNumberOfTRMs(); iTRM++) {
509 :
510 0 : trmConfig = crateConfig->GetTRMConfig(iTRM);
511 :
512 : /* check TRM config */
513 0 : if (!trmConfig)
514 : continue;
515 :
516 : /* check TRM enabled */
517 0 : if (!crateConfig->IsTRMEnabled(iTRM))
518 : continue;
519 :
520 : /* dump TRM config */
521 0 : 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 0 : if (trmConfig->GetChainAFlag() == 1) {
525 0 : 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 0 : }
527 :
528 : /* check TRM chain B flag */
529 0 : if (trmConfig->GetChainBFlag() == 1) {
530 0 : 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 0 : }
532 :
533 :
534 :
535 : } /* loop over TRMs */
536 0 : AliInfo("-------------------------------------");
537 0 : } /* loop over crates */
538 0 : }
539 :
540 : //_______________________________________________________________
541 :
542 : void
543 : AliTOFFEEReader::CreateFEElightConfig(const Char_t *filename)
544 : {
545 : /*
546 : *
547 : * create FEElight config
548 : *
549 : */
550 :
551 0 : AliTOFFEElightConfig lightConfig;
552 :
553 0 : for (Int_t i = 0; i < GetNumberOfIndexes(); i++) {
554 0 : if (fChannelEnabled[i]) {
555 0 : lightConfig.GetChannelConfig(i)->SetStatus(AliTOFFEEchannelConfig::kStatusEnabled);
556 0 : lightConfig.GetChannelConfig(i)->SetMatchingWindow(fMatchingWindow[i]);
557 0 : lightConfig.GetChannelConfig(i)->SetLatencyWindow(fLatencyWindow[i]);
558 0 : }
559 : else {
560 0 : lightConfig.GetChannelConfig(i)->SetStatus(0x0);
561 0 : lightConfig.GetChannelConfig(i)->SetMatchingWindow(0);
562 0 : lightConfig.GetChannelConfig(i)->SetLatencyWindow(0);
563 : }
564 : }
565 :
566 0 : Char_t *expandedFileName = gSystem->ExpandPathName(filename);
567 0 : std::ofstream os;
568 0 : os.open(expandedFileName, std::ios::binary);
569 0 : os.write((Char_t *)&lightConfig, sizeof(AliTOFFEElightConfig));
570 0 : os.close();
571 :
572 0 : }
|