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