Be sure to load mapping when needed
[u/mrichter/AliRoot.git] / TRD / AliTRDtrapConfig.h
1 #ifndef ALITRDTRAPCONFIG_H
2 #define ALITRDTRAPCONFIG_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 //
7 // Class holding the configuration of the tracklet processor
8 // in the TRD FEE
9 //
10
11
12 #include <TObject.h>
13 #include <TString.h>
14 #include <fstream>
15
16 class AliTRDtrapConfig : public TObject
17 {
18  public:
19   ~AliTRDtrapConfig();
20
21   static AliTRDtrapConfig* Instance();
22
23   enum TrapReg_t { kSML0,
24                   kSML1,
25                   kSML2,
26                   kSMMODE,
27                   kNITM0,
28                   kNITM1,
29                   kNITM2,
30                   kNIP4D,
31                   kCPU0CLK,
32                   kCPU1CLK,
33                   kCPU2CLK,
34                   kCPU3CLK,
35                   kNICLK,
36                   kFILCLK,
37                   kPRECLK,
38                   kADCEN,
39                   kNIODE,
40                   kNIOCE,
41                   kNIIDE,
42                   kNIICE,
43                   kARBTIM,
44                   kIA0IRQ0,
45                   kIA0IRQ1,
46                   kIA0IRQ2,
47                   kIA0IRQ3,
48                   kIA0IRQ4,
49                   kIA0IRQ5,
50                   kIA0IRQ6,
51                   kIA0IRQ7,
52                   kIA0IRQ8,
53                   kIA0IRQ9,
54                   kIA0IRQA,
55                   kIA0IRQB,
56                   kIA0IRQC,
57                   kIRQSW0,
58                   kIRQHW0,
59                   kIRQHL0,
60                   kIA1IRQ0,
61                   kIA1IRQ1,
62                   kIA1IRQ2,
63                   kIA1IRQ3,
64                   kIA1IRQ4,
65                   kIA1IRQ5,
66                   kIA1IRQ6,
67                   kIA1IRQ7,
68                   kIA1IRQ8,
69                   kIA1IRQ9,
70                   kIA1IRQA,
71                   kIA1IRQB,
72                   kIA1IRQC,
73                   kIRQSW1,
74                   kIRQHW1,
75                   kIRQHL1,
76                   kIA2IRQ0,
77                   kIA2IRQ1,
78                   kIA2IRQ2,
79                   kIA2IRQ3,
80                   kIA2IRQ4,
81                   kIA2IRQ5,
82                   kIA2IRQ6,
83                   kIA2IRQ7,
84                   kIA2IRQ8,
85                   kIA2IRQ9,
86                   kIA2IRQA,
87                   kIA2IRQB,
88                   kIA2IRQC,
89                   kIRQSW2,
90                   kIRQHW2,
91                   kIRQHL2,
92                   kIA3IRQ0,
93                   kIA3IRQ1,
94                   kIA3IRQ2,
95                   kIA3IRQ3,
96                   kIA3IRQ4,
97                   kIA3IRQ5,
98                   kIA3IRQ6,
99                   kIA3IRQ7,
100                   kIA3IRQ8,
101                   kIA3IRQ9,
102                   kIA3IRQA,
103                   kIA3IRQB,
104                   kIA3IRQC,
105                   kIRQSW3,
106                   kIRQHW3,
107                   kIRQHL3,
108                   kCTGDINI,
109                   kCTGCTRL,
110                   kC08CPU0,
111                   kC09CPU0,
112                   kC10CPU0,
113                   kC11CPU0,
114                   kC12CPUA,
115                   kC13CPUA,
116                   kC14CPUA,
117                   kC15CPUA,
118                   kC08CPU1,
119                   kC09CPU1,
120                   kC10CPU1,
121                   kC11CPU1,
122                   kC08CPU2,
123                   kC09CPU2,
124                   kC10CPU2,
125                   kC11CPU2,
126                   kC08CPU3,
127                   kC09CPU3,
128                   kC10CPU3,
129                   kC11CPU3,
130                   kNMOD,
131                   kNDLY,
132                   kNED,
133                   kNTRO,
134                   kNRRO,
135                   kNES,
136                   kNTP,
137                   kNBND,
138                   kNP0,
139                   kNP1,
140                   kNP2,
141                   kNP3,
142                   kNCUT,
143                   kTPPT0,
144                   kTPFS,
145                   kTPFE,
146                   kTPPGR,
147                   kTPPAE,
148                   kTPQS0,
149                   kTPQE0,
150                   kTPQS1,
151                   kTPQE1,
152                   kEBD,
153                   kEBAQA,
154                   kEBSIA,
155                   kEBSF,
156                   kEBSIM,
157                   kEBPP,
158                   kEBPC,
159                   kEBIS,
160                   kEBIT,
161                   kEBIL,
162                   kEBIN,
163                   kFLBY,
164                   kFPBY,
165                   kFGBY,
166                   kFTBY,
167                   kFCBY,
168                   kFPTC,
169                   kFPNP,
170                   kFPCL,
171                   kFGTA,
172                   kFGTB,
173                   kFGCL,
174                   kFTAL,
175                   kFTLL,
176                   kFTLS,
177                   kFCW1,
178                   kFCW2,
179                   kFCW3,
180                   kFCW4,
181                   kFCW5,
182                   kTPFP,
183                   kTPHT,
184                   kTPVT,
185                   kTPVBY,
186                   kTPCT,
187                   kTPCL,
188                   kTPCBY,
189                   kTPD,
190                   kTPCI0,
191                   kTPCI1,
192                   kTPCI2,
193                   kTPCI3,
194                   kADCMSK,
195                   kADCINB,
196                   kADCDAC,
197                   kADCPAR,
198                   kADCTST,
199                   kSADCAZ,
200                   kFGF0,
201                   kFGF1,
202                   kFGF2,
203                   kFGF3,
204                   kFGF4,
205                   kFGF5,
206                   kFGF6,
207                   kFGF7,
208                   kFGF8,
209                   kFGF9,
210                   kFGF10,
211                   kFGF11,
212                   kFGF12,
213                   kFGF13,
214                   kFGF14,
215                   kFGF15,
216                   kFGF16,
217                   kFGF17,
218                   kFGF18,
219                   kFGF19,
220                   kFGF20,
221                   kFGA0,
222                   kFGA1,
223                   kFGA2,
224                   kFGA3,
225                   kFGA4,
226                   kFGA5,
227                   kFGA6,
228                   kFGA7,
229                   kFGA8,
230                   kFGA9,
231                   kFGA10,
232                   kFGA11,
233                   kFGA12,
234                   kFGA13,
235                   kFGA14,
236                   kFGA15,
237                   kFGA16,
238                   kFGA17,
239                   kFGA18,
240                   kFGA19,
241                   kFGA20,
242                   kFLL00,
243                   kFLL01,
244                   kFLL02,
245                   kFLL03,
246                   kFLL04,
247                   kFLL05,
248                   kFLL06,
249                   kFLL07,
250                   kFLL08,
251                   kFLL09,
252                   kFLL0A,
253                   kFLL0B,
254                   kFLL0C,
255                   kFLL0D,
256                   kFLL0E,
257                   kFLL0F,
258                   kFLL10,
259                   kFLL11,
260                   kFLL12,
261                   kFLL13,
262                   kFLL14,
263                   kFLL15,
264                   kFLL16,
265                   kFLL17,
266                   kFLL18,
267                   kFLL19,
268                   kFLL1A,
269                   kFLL1B,
270                   kFLL1C,
271                   kFLL1D,
272                   kFLL1E,
273                   kFLL1F,
274                   kFLL20,
275                   kFLL21,
276                   kFLL22,
277                   kFLL23,
278                   kFLL24,
279                   kFLL25,
280                   kFLL26,
281                   kFLL27,
282                   kFLL28,
283                   kFLL29,
284                   kFLL2A,
285                   kFLL2B,
286                   kFLL2C,
287                   kFLL2D,
288                   kFLL2E,
289                   kFLL2F,
290                   kFLL30,
291                   kFLL31,
292                   kFLL32,
293                   kFLL33,
294                   kFLL34,
295                   kFLL35,
296                   kFLL36,
297                   kFLL37,
298                   kFLL38,
299                   kFLL39,
300                   kFLL3A,
301                   kFLL3B,
302                   kFLL3C,
303                   kFLL3D,
304                   kFLL3E,
305                   kFLL3F,
306                   kPASADEL,
307                   kPASAPHA,
308                   kPASAPRA,
309                   kPASADAC,
310                   kPASACHM,
311                   kPASASTL,
312                   kPASAPR1,
313                   kPASAPR0,
314                   kSADCTRG,
315                   kSADCRUN,
316                   kSADCPWR,
317                   kL0TSIM,
318                   kSADCEC,
319                   kSADCMC,
320                   kSADCOC,
321                   kSADCGTB,
322                   kSEBDEN,
323                   kSEBDOU,
324                   kTPL00,
325                   kTPL01,
326                   kTPL02,
327                   kTPL03,
328                   kTPL04,
329                   kTPL05,
330                   kTPL06,
331                   kTPL07,
332                   kTPL08,
333                   kTPL09,
334                   kTPL0A,
335                   kTPL0B,
336                   kTPL0C,
337                   kTPL0D,
338                   kTPL0E,
339                   kTPL0F,
340                   kTPL10,
341                   kTPL11,
342                   kTPL12,
343                   kTPL13,
344                   kTPL14,
345                   kTPL15,
346                   kTPL16,
347                   kTPL17,
348                   kTPL18,
349                   kTPL19,
350                   kTPL1A,
351                   kTPL1B,
352                   kTPL1C,
353                   kTPL1D,
354                   kTPL1E,
355                   kTPL1F,
356                   kTPL20,
357                   kTPL21,
358                   kTPL22,
359                   kTPL23,
360                   kTPL24,
361                   kTPL25,
362                   kTPL26,
363                   kTPL27,
364                   kTPL28,
365                   kTPL29,
366                   kTPL2A,
367                   kTPL2B,
368                   kTPL2C,
369                   kTPL2D,
370                   kTPL2E,
371                   kTPL2F,
372                   kTPL30,
373                   kTPL31,
374                   kTPL32,
375                   kTPL33,
376                   kTPL34,
377                   kTPL35,
378                   kTPL36,
379                   kTPL37,
380                   kTPL38,
381                   kTPL39,
382                   kTPL3A,
383                   kTPL3B,
384                   kTPL3C,
385                   kTPL3D,
386                   kTPL3E,
387                   kTPL3F,
388                   kTPL40,
389                   kTPL41,
390                   kTPL42,
391                   kTPL43,
392                   kTPL44,
393                   kTPL45,
394                   kTPL46,
395                   kTPL47,
396                   kTPL48,
397                   kTPL49,
398                   kTPL4A,
399                   kTPL4B,
400                   kTPL4C,
401                   kTPL4D,
402                   kTPL4E,
403                   kTPL4F,
404                   kTPL50,
405                   kTPL51,
406                   kTPL52,
407                   kTPL53,
408                   kTPL54,
409                   kTPL55,
410                   kTPL56,
411                   kTPL57,
412                   kTPL58,
413                   kTPL59,
414                   kTPL5A,
415                   kTPL5B,
416                   kTPL5C,
417                   kTPL5D,
418                   kTPL5E,
419                   kTPL5F,
420                   kTPL60,
421                   kTPL61,
422                   kTPL62,
423                   kTPL63,
424                   kTPL64,
425                   kTPL65,
426                   kTPL66,
427                   kTPL67,
428                   kTPL68,
429                   kTPL69,
430                   kTPL6A,
431                   kTPL6B,
432                   kTPL6C,
433                   kTPL6D,
434                   kTPL6E,
435                   kTPL6F,
436                   kTPL70,
437                   kTPL71,
438                   kTPL72,
439                   kTPL73,
440                   kTPL74,
441                   kTPL75,
442                   kTPL76,
443                   kTPL77,
444                   kTPL78,
445                   kTPL79,
446                   kTPL7A,
447                   kTPL7B,
448                   kTPL7C,
449                   kTPL7D,
450                   kTPL7E,
451                   kTPL7F,
452                   kMEMRW,
453                   kMEMCOR,
454                   kDMDELA,
455                   kDMDELS,
456                   kLastReg };   // enum of all TRAP registers, to be used for access to them
457
458   const char* GetRegName(TrapReg_t reg)       const { return reg >= 0 && reg < kLastReg ? fRegs[reg].fName.Data() : ""; }
459   UShort_t    GetRegAddress(TrapReg_t reg)    const { return reg >= 0 && reg < kLastReg ? fRegs[reg].fAddr : 0; }
460   UShort_t    GetRegNBits(TrapReg_t reg)      const { return reg >= 0 && reg < kLastReg ? fRegs[reg].fNbits : 0; }
461   UInt_t      GetRegResetValue(TrapReg_t reg) const { return reg >= 0 && reg < kLastReg ? fRegs[reg].fResetValue : 0; }
462
463   TrapReg_t          GetRegByAddress(Int_t address) const;
464
465   Int_t  GetTrapReg(TrapReg_t reg, Int_t det = -1, Int_t rob = -1, Int_t mcm = -1) const;
466   Bool_t PrintTrapReg(TrapReg_t reg, Int_t det = -1, Int_t rob = -1, Int_t mcm = -1) const;
467   Bool_t PrintTrapAddr(Int_t addr, Int_t det = -1, Int_t rob = -1, Int_t mcm = -1) const;
468
469   Bool_t SetTrapReg(TrapReg_t reg, Int_t value);
470   Bool_t SetTrapReg(TrapReg_t reg, Int_t value, Int_t det);
471   Bool_t SetTrapReg(TrapReg_t reg, Int_t value, Int_t det, Int_t rob, Int_t mcm);
472
473   UInt_t Peek(Int_t addr, Int_t det, Int_t rob, Int_t mcm) const;
474   Bool_t Poke(Int_t addr, UInt_t value, Int_t det, Int_t rob, Int_t mcm);
475
476   void InitRegs();
477   void ResetRegs();
478   void ResetDmem();
479
480   // DMEM
481   Bool_t SetDmem(Int_t addr, UInt_t value);
482   //  Bool_t SetDmem(Int_t addr, UInt_t value, Int_t det);
483   Bool_t SetDmem(Int_t addr, UInt_t value, Int_t det, Int_t rob, Int_t mcm);
484   Bool_t SetDmem(Int_t addr, Int_t value) { return SetDmem(addr, (UInt_t) value); }
485   //  Bool_t SetDmem(Int_t addr, Int_t value, Int_t det) { return SetDmem(addr, (UInt_t) value, det); }
486   Bool_t SetDmem(Int_t addr, Int_t value, Int_t det, Int_t rob, Int_t mcm) { return SetDmem(addr, (UInt_t) value, det, rob, mcm); }
487
488   UInt_t GetDmemUnsigned(Int_t addr) const;
489   UInt_t GetDmemUnsigned(Int_t addr, Int_t det, Int_t rob, Int_t mcm) const;
490
491   void PrintMemDatx(ostream &os, Int_t addr) const;
492   void PrintMemDatx(ostream &os, Int_t addr, Int_t det, Int_t rob, Int_t mcm) const;
493   void PrintMemDatx(ostream &os, TrapReg_t reg) const;
494   void PrintMemDatx(ostream &os, TrapReg_t reg, Int_t det, Int_t rob, Int_t mcm) const;
495   void PrintDatx(ostream &os, UInt_t addr, UInt_t data, Int_t rob, Int_t mcm) const;
496
497   // configuration handling
498   Bool_t ReadPackedConfig(Int_t det, UInt_t *data, Int_t size);
499
500   Bool_t AddValues(UInt_t det, UInt_t cmd, UInt_t extali, Int_t addr, UInt_t data);
501
502   // DMEM addresses
503   static const Int_t fgkDmemAddrLUTcor0       = 0xC02A;
504   static const Int_t fgkDmemAddrLUTcor1       = 0xC028;
505   static const Int_t fgkDmemAddrLUTnbins      = 0xC029;
506
507   static const Int_t fgkDmemAddrLUTStart      = 0xC100; // LUT start address
508   static const Int_t fgkDmemAddrLUTEnd        = 0xC3FF; // maximum possible end address for the LUT table
509   static const Int_t fgkDmemAddrLUTLength     = 0xC02B; // address where real size of the LUT table is stored
510
511   static const Int_t fgkDmemAddrTrackletStart = 0xC0E0; // Storage area for tracklets, start address
512   static const Int_t fgkDmemAddrTrackletEnd   = 0xC0E3; // Storage area for tracklets, end address
513
514   static const Int_t fgkDmemAddrDeflCorr      = 0xc022; // DMEM address of deflection correction
515   static const Int_t fgkDmemAddrNdrift        = 0xc025; // DMEM address of Ndrift
516   static const Int_t fgkDmemAddrDeflCutStart  = 0xc030; // DMEM start address of deflection cut
517   static const Int_t fgkDmemAddrDeflCutEnd    = 0xc055; // DMEM end address of deflection cut
518
519   // DMEM memory in simulation;
520   static const Int_t fgkDmemStartAddress;           // start address in TRAP GIO
521   static const Int_t fgkDmemWords = 0xc400;         // number of words in DMEM
522
523  protected:
524   static AliTRDtrapConfig *fgInstance;  // pointer to instance (singleton)
525
526   struct SimpleReg_t {
527     TString   fName;       // Name of the register
528     UShort_t  fAddr;       // Address in GIO of TRAP
529     UShort_t  fNbits;      // Number of bits, from 1 to 32
530     UInt_t    fResetValue; // reset value
531     SimpleReg_t(const char *nnn = 0, UShort_t a = 0, UShort_t n = 0, UInt_t r = 0) :
532       fName(nnn), fAddr(a), fNbits(n), fResetValue(r) {}
533   };
534
535   struct RegValue_t {
536     enum {
537       kInvalid = 0,
538       kGlobal,
539       kIndividual
540     } state; // mode of storage (global or per MCM)
541     union {
542       Int_t globalValue;
543       Int_t *individualValue;
544     };
545   };
546
547   // configuration registers
548   SimpleReg_t fRegs[kLastReg];          // array of TRAP registers
549   RegValue_t fRegisterValue[kLastReg];  // array of TRAP register values in use
550
551   static const UInt_t fgkScsnCmdWrite=10;  // Command number for the write command
552   static const Int_t fgkMaxLinkPairs=4;    // number of linkpairs used during configuration
553   static const Int_t fgkMaxMcm;            // max. no. of MCMs to be treated
554   static const Int_t fgkMcmlistSize=256;     // list of MCMs to which a value has to be written
555
556   // DMEM
557   UInt_t* fDmem[fgkDmemWords]; // DMEM storage
558   Int_t fDmemDepth[fgkDmemWords]; // memory space indicator for fDmem
559
560   static const Int_t fgkDmemSizeEmpty=0;
561   static const   Int_t fgkDmemSizeUniform = 1;
562   static const   Int_t fgkDmemSizeSmIndividual = 30*8*16;   // storage for each MCM within one supermodule
563   static const   Int_t fgkDmemSizeTotalIndividual = 540*6*8*16;  // one individual value for each and every MCM in the TRD
564   static const   Int_t fgkDmemSizeSmRocIndividual = 540; // one individual value for each chamber in TRD
565
566   // Online PID
567   Double_t fScaleQ0;  // scaling factor for the x-axis of the PID table
568   Double_t fScaleQ1;  // scaling factor for the y-axis of the PID table
569
570   AliTRDtrapConfig(); // private constructor due to singleton implementation
571
572 /* not yet used
573   struct BlockDescr_t {
574     UShort_t addr;
575     UShort_t nregs;
576     UShort_t nbits;
577     UShort_t step;
578   };
579
580   struct CmdReg_t {
581     char *name;
582     UShort_t addr;
583   };
584
585   enum DbankProp_t { kDBankEmpty = 0,
586                     kDBankHeader,
587                     kDBankData,
588                     kDBankNoB,
589                     kDBankCRC,
590                     kDBankEHeader,
591                     kDBankSCSNData };
592 */
593
594
595  private:
596   AliTRDtrapConfig& operator=(const AliTRDtrapConfig &rhs); // not implemented
597   AliTRDtrapConfig(const AliTRDtrapConfig& cfg); // not implemented
598
599   ClassDef(AliTRDtrapConfig, 2);
600 };
601
602 #endif
603