]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDptrgParam.cxx
Fix Coverity defects
[u/mrichter/AliRoot.git] / TRD / AliTRDptrgParam.cxx
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 /* $Id$ */
17
18 ////////////////////////////////////////////////////////////////////////////
19 //                                                                        
20 //  Parameters for Pre-Trigger Simulation                                 
21 //                                                                        
22 //  Author: F. Reidt (Felix.Reidt@cern.ch)                                
23 //               
24 //  This class controls the parameters used by the pretrigger simulation.
25 //  A configuration file ca be loaded by calling LoadConfigurationFromFile()
26 //  The generation of look up tables is also done in this class and has to
27 //  be done only once after a configuration file was loaded.
28 //  If no configuration file was loaded, the standard
29 //  configuration in LoadStandardConfiguration() would be used.
30 //                                                        
31 ////////////////////////////////////////////////////////////////////////////
32 #include "TArrayI.h"
33 #include "TObjString.h"
34 #include "TString.h"
35
36 #include <fstream>
37
38 #include "AliLog.h"
39
40 #include "AliTRDptrgParam.h"
41
42 ClassImp(AliTRDptrgParam)
43
44 AliTRDptrgParam *AliTRDptrgParam::fgInstance = 0;
45
46
47 //______________________________________________________________________________
48 AliTRDptrgParam::AliTRDptrgParam()
49   : TObject(),
50     fTLMUInputStretch(0),
51     fTLMUcmatrices(0x0),
52     fTLMUmultiplicity(0x0), 
53     fTLMUoutput(0x0),
54     fFEBT0Thresholds(0x0),
55     fFEBT0Multiplicities(0x0),
56     fFEBT0LUTs(0x0),
57     fFEBV0Thresholds(0x0),
58     fFEBV0Multiplicities(0x0),
59     fFEBV0LUTs(0x0),
60     fCBLUTs(0x0),
61     fPTmasks(AliTRDptrgPTmasks())
62 {
63   // ctor
64   
65   // initialize coincidence matrices
66   this->fTLMUcmatrices = new UInt_t*[3];
67   for (UInt_t iMatrix = 0; iMatrix < 3; iMatrix++) {
68     this->fTLMUcmatrices[iMatrix] = new UInt_t[18];
69     for (UInt_t iSlice = 0; iSlice < 18; iSlice++) {
70       this->fTLMUcmatrices[iMatrix][iSlice] = 0;
71     }
72   }
73   
74   // initialize multiplicity slices
75   this->fTLMUmultiplicity = new UInt_t*[9];
76   for (UInt_t iSlice = 0; iSlice < 9; iSlice++) {
77     this->fTLMUmultiplicity[iSlice] = new UInt_t[2];
78     this->fTLMUmultiplicity[iSlice][0] = 577; // disabled
79     this->fTLMUmultiplicity[iSlice][1] = 0;
80   }
81   
82   // initialize output muxer
83   this->fTLMUoutput = new Int_t*[8];
84   for (UInt_t iBit = 0; iBit < 8; iBit++) {
85     this->fTLMUoutput[iBit] = new Int_t[2];
86     this->fTLMUoutput[iBit][0] = -1; // cmatrix disabled
87     this->fTLMUoutput[iBit][1] = -1; // multslice disabled
88   }
89   
90   // initialize T0 FEB thresholds
91   this->fFEBT0Thresholds = new UInt_t*[2];
92   this->fFEBT0Thresholds[0] = new UInt_t[12];
93   this->fFEBT0Thresholds[1] = new UInt_t[12];
94   for (Int_t iChan = 0; iChan < 12; iChan++) {
95     this->fFEBT0Thresholds[0][iChan] = 4294967295U; 
96     this->fFEBT0Thresholds[1][iChan] = 4294967295U;
97     // writing 2^32-1 disables the input because all used adcs have 
98     // less than 32 bits
99   }
100   
101   // initialize T0 Multiplicity
102   this->fFEBT0Multiplicities = new UInt_t**[2];
103   this->fFEBT0Multiplicities[0] = new UInt_t*[2];
104   this->fFEBT0Multiplicities[1] = new UInt_t*[2];
105   this->fFEBT0Multiplicities[0][0] = new UInt_t[2];
106   this->fFEBT0Multiplicities[0][1] = new UInt_t[2];
107   this->fFEBT0Multiplicities[1][0] = new UInt_t[2];
108   this->fFEBT0Multiplicities[1][1] = new UInt_t[2];
109   this->fFEBT0Multiplicities[0][0][0] = 4294967295U;
110   this->fFEBT0Multiplicities[0][0][1] = 4294967295U;
111   this->fFEBT0Multiplicities[0][1][0] = 4294967295U;
112   this->fFEBT0Multiplicities[0][1][1] = 4294967295U;
113   this->fFEBT0Multiplicities[1][0][0] = 4294967295U;
114   this->fFEBT0Multiplicities[1][0][1] = 4294967295U;
115   this->fFEBT0Multiplicities[1][1][0] = 4294967295U;
116   this->fFEBT0Multiplicities[1][1][1] = 4294967295U;
117   // writing 2^32-1 disables the input because all used adcs have 
118   // less than 32 bits
119
120   // initialize T0 LUTs
121   // this->fFEBT0LUTs = 0x0; (done in member initialization list)
122   // further initialization is done in AliTRDptrgParam::GenerateLUTs()
123   
124
125   // initialize V0 FEB Thresholds
126   this->fFEBV0Thresholds = new UInt_t**[2];
127   for (UInt_t iPosition = 0; iPosition < 2; iPosition++) {
128     this->fFEBV0Thresholds[iPosition] = new UInt_t*[4];
129     for (UInt_t iCard = 0; iCard < 4; iCard++) {
130       this->fFEBV0Thresholds[iPosition][iCard] = new UInt_t[8];
131       for (UInt_t iChannel = 0; iChannel < 8; iChannel++) {
132         this->fFEBV0Thresholds[iPosition][iCard][iChannel] = 4294967295U;
133       }
134     }
135   }
136  
137   // initialize V0 Multiplicities
138   this->fFEBV0Multiplicities = new UInt_t***[2];
139   for (UInt_t iPosition = 0; iPosition < 2; iPosition++) {
140     this->fFEBV0Multiplicities[iPosition] = new UInt_t**[4];
141     for (UInt_t iCard = 0; iCard < 4; iCard++) {
142       this->fFEBV0Multiplicities[iPosition][iCard] = new UInt_t*[2];
143       for (UInt_t iLUT = 0; iLUT < 2; iLUT++) {
144         this->fFEBV0Multiplicities[iPosition][iCard][iLUT] = new UInt_t[2];
145         this->fFEBV0Multiplicities[iPosition][iCard][iLUT][0] = 4294967295U;
146         this->fFEBV0Multiplicities[iPosition][iCard][iLUT][1] = 0x0;      
147       }
148     }
149   }
150   
151   // initialize V0 LUTs
152   //  this->fFEBV0LUTs = 0x0; (done in member initialization list)
153   // further initialization is done in AliTRDptrgParam::GenerateLUTs()
154
155   // initialize CB LUTs
156   // this->fCBLUTs = 0x0; (done in member initialization list)
157   // further initialization is done in AliTRDptrgParam::GenerateLUTs()
158
159   this->LoadStandardConfiguration(); // load standard configuration
160 }
161
162 //______________________________________________________________________________
163 AliTRDptrgParam::~AliTRDptrgParam() 
164 {
165   // dtor
166   
167   // delete coincidence matrices
168   if (this->fTLMUcmatrices != 0x0) {
169     for (UInt_t iMatrix = 0; iMatrix < 3; iMatrix++) {
170       if (this->fTLMUcmatrices[iMatrix] != 0x0) {
171         delete[] this->fTLMUcmatrices[iMatrix];
172         this->fTLMUcmatrices[iMatrix] = 0x0;
173       }
174     }
175     delete[] this->fTLMUcmatrices;
176     this->fTLMUcmatrices = 0x0;
177   }
178   
179   // delete multiplicity slices
180   if (this->fTLMUmultiplicity != 0x0) {
181     for (UInt_t iSlice = 0; iSlice < 9; iSlice++) {
182       if (this->fTLMUmultiplicity[iSlice] != 0x0) {
183         delete[] this->fTLMUmultiplicity[iSlice];
184         this->fTLMUmultiplicity[iSlice] = 0x0;
185       }
186     }
187     delete[] this->fTLMUmultiplicity;
188     this->fTLMUmultiplicity = 0x0;
189   }
190
191   // delete output mux
192   if (this->fTLMUoutput != 0x0) {
193     for (UInt_t iBit = 0; iBit < 8; iBit++) {
194       if (this->fTLMUoutput[iBit] != 0x0) {
195         delete[] this->fTLMUoutput[iBit];
196         this->fTLMUoutput[iBit] = 0x0;
197       }
198     }
199     delete[] this->fTLMUoutput;
200     this->fTLMUoutput = 0x0;
201   }
202
203   // delete T0 FEB thresholds
204   if (this->fFEBT0Thresholds != 0x0) {
205     if (this->fFEBT0Thresholds[0] != 0x0) {
206       delete[] this->fFEBT0Thresholds[0];
207       this->fFEBT0Thresholds[0] = 0x0;
208     }
209     if (this->fFEBT0Thresholds[1] != 0x0) {
210       delete[] this->fFEBT0Thresholds[1];
211       this->fFEBT0Thresholds[1] = 0x0;
212     }
213     delete[] this->fFEBT0Thresholds;
214     this->fFEBT0Thresholds = 0x0;
215   }
216  
217   // delete T0 multiplicities
218   if (this->fFEBT0Multiplicities != 0x0) {
219     for (UInt_t iPosition = 0; iPosition < 2; iPosition++) {
220       if (this->fFEBT0Multiplicities[iPosition] != 0x0) {
221         for (UInt_t iLUT = 0; iLUT < 2; iLUT++) {
222           if (this->fFEBT0Multiplicities[iPosition][iLUT] != 0x0) {
223             delete[] this->fFEBT0Multiplicities[iPosition][iLUT];
224             this->fFEBT0Multiplicities[iPosition][iLUT] = 0x0;
225           }
226         }
227         delete[] this->fFEBT0Multiplicities[iPosition];
228         this->fFEBT0Multiplicities[iPosition] = 0x0;
229       }
230     }
231     delete[] this->fFEBT0Multiplicities;
232     this->fFEBT0Multiplicities = 0x0;
233   }  
234
235   // delete T0 LUTs
236   if (this->fFEBT0LUTs != 0x0) {
237     for (UInt_t iPosition = 0; iPosition < 2; iPosition++) {
238       if (this->fFEBT0LUTs[iPosition] != 0x0) {
239         for (UInt_t iLUT = 0; iLUT < 2; iLUT++) {
240           if (this->fFEBT0LUTs[iPosition][iLUT] != 0x0) {
241             delete[] this->fFEBT0LUTs[iPosition][iLUT];
242             this->fFEBT0LUTs[iPosition][iLUT] = 0x0;
243           }
244         }
245         delete[] this->fFEBT0LUTs[iPosition];
246         this->fFEBT0LUTs[iPosition] = 0x0;
247       }
248     }
249     delete[] this->fFEBT0LUTs;
250     this->fFEBT0LUTs = 0x0;
251   }  
252
253   // delete V0 FEB thresholds
254   if (this->fFEBV0Thresholds != 0x0) {
255     for (UInt_t iPosition = 0; iPosition < 2; iPosition++) {
256       if (this->fFEBV0Thresholds[iPosition] != 0x0) {
257         for (UInt_t iCard = 0; iCard < 4; iCard++) {
258           if (this->fFEBV0Thresholds[iPosition][iCard] != 0x0) {
259             delete[] this->fFEBV0Thresholds[iPosition][iCard];
260             this->fFEBV0Thresholds[iPosition][iCard] = 0x0;
261           }
262         }
263         delete[] this->fFEBV0Thresholds[iPosition]; 
264         this->fFEBV0Thresholds[iPosition] = 0x0;
265       }
266     }
267     delete[] this->fFEBV0Thresholds;
268     this->fFEBV0Thresholds = 0x0;
269   }
270
271   // delete V0 multiplicities
272   if (this->fFEBV0Multiplicities != 0x0) {
273     for (UInt_t iPosition = 0; iPosition < 2; iPosition++) {
274       if (this->fFEBV0Multiplicities[iPosition] != 0x0) {
275         for (UInt_t iCard = 0; iCard < 4; iCard++) {
276           if (this->fFEBV0Multiplicities[iPosition][iCard] != 0x0) {
277             for (UInt_t iLUT = 0; iLUT < 2; iLUT++) {
278               if (this->fFEBV0Multiplicities[iPosition][iCard][iLUT] != 0x0) {
279                 delete[] this->fFEBV0Multiplicities[iPosition][iCard][iLUT];
280                 this->fFEBV0Multiplicities[iPosition][iCard][iLUT] = 0x0;
281               }
282             }
283             delete[] this->fFEBV0Multiplicities[iPosition][iCard];
284             this->fFEBV0Multiplicities[iPosition][iCard] = 0x0;
285           }
286         }
287         delete[] this->fFEBV0Multiplicities[iPosition]; 
288         this->fFEBV0Multiplicities[iPosition] = 0x0;
289       }
290     }
291     delete[] this->fFEBV0Multiplicities;
292     this->fFEBV0Multiplicities = 0x0;
293   } 
294
295   // delete V0 LUTs
296   if (this->fFEBV0LUTs != 0x0) {
297     for (UInt_t iPosition = 0; iPosition < 2; iPosition++) {
298       if (this->fFEBV0LUTs[iPosition] != 0x0) {
299         for (UInt_t iCard = 0; iCard < 4; iCard++) {
300           if (this->fFEBV0LUTs[iPosition][iCard] != 0x0) {
301             for (UInt_t iLUT = 0; iLUT < 2; iLUT++) {
302               if (this->fFEBV0LUTs[iPosition][iCard][iLUT] != 0x0) {
303                 delete[] this->fFEBV0LUTs[iPosition][iCard][iLUT];
304                 this->fFEBV0LUTs[iPosition][iCard][iLUT] = 0x0;
305               }
306             }
307             delete[] this->fFEBV0LUTs[iPosition][iCard];
308             this->fFEBV0LUTs[iPosition][iCard] = 0x0;
309           }
310         }
311         delete[] this->fFEBV0LUTs[iPosition]; 
312         this->fFEBV0LUTs[iPosition] = 0x0;
313       }
314     }
315     delete[] this->fFEBV0LUTs;
316     this->fFEBV0LUTs = 0x0;
317   } 
318
319   // delete CB LUTs
320   if (this->fCBLUTs != 0x0) {
321     for (UInt_t iCB = 0; iCB < 3; iCB++) {
322       if (this->fCBLUTs[iCB] != 0x0) {
323         for (UInt_t iLUT = 0; iLUT < 2; iLUT++) {
324           if (this->fCBLUTs[iCB][iLUT] != 0x0) {
325             delete[] this->fCBLUTs[iCB][iLUT];
326             this->fCBLUTs[iCB][iLUT] = 0x0;
327           }
328         }
329         if (iCB == kB) {
330           // CB-B has 3 LUTs!
331           if (this->fCBLUTs[iCB][2] != 0x0) {
332             delete[] this->fCBLUTs[iCB][2];
333             this->fCBLUTs[iCB][2] = 0x0;
334           }
335         }
336         delete[] this->fCBLUTs[iCB];
337         this->fCBLUTs[iCB] = 0x0;
338       }
339     }
340     delete[] this->fCBLUTs;
341     this->fCBLUTs = 0x0;
342   }  
343 }
344
345 //______________________________________________________________________________
346 Int_t AliTRDptrgParam::CheckVariables() const
347 {
348   // checks whether variables are deleted early enough
349  
350   // check coincidence matrices
351   if (this->fTLMUcmatrices != 0x0) {
352     for (UInt_t iMatrix = 0; iMatrix < 3; iMatrix++) {
353       if (this->fTLMUcmatrices[iMatrix] == 0x0) {
354         return -1;
355       }
356     }
357   }
358   else {
359     return -2;
360   }
361   
362   // check multiplicity slices
363   if (this->fTLMUmultiplicity != 0x0) {
364     for (UInt_t iSlice = 0; iSlice < 9; iSlice++) {
365       if (this->fTLMUmultiplicity[iSlice] == 0x0) {
366         return -3;
367       }
368     }
369   }
370   else {
371     return -4;
372   }
373
374   // check output mux
375   if (this->fTLMUoutput != 0x0) {
376     for (UInt_t iBit = 0; iBit < 8; iBit++) {
377       if (this->fTLMUoutput[iBit] == 0x0) {
378         return -5;
379       }
380     }
381   }
382   else {
383     return -6;
384   }
385
386   // check T0 FEB thresholds
387   if (this->fFEBT0Thresholds != 0x0) {
388     if (this->fFEBT0Thresholds[0] == 0x0) {
389       return -7;
390     }
391     if (this->fFEBT0Thresholds[1] == 0x0) {
392       return -8;
393     }
394   }
395   else {
396     return -9;
397   }
398
399   // check T0 multiplicities
400   if (this->fFEBT0Multiplicities != 0x0) {
401     for (UInt_t iPosition = 0; iPosition < 2; iPosition++) {
402       if (this->fFEBT0Multiplicities[iPosition] != 0x0) {
403         for (UInt_t iLUT = 0; iLUT < 2; iLUT++) {
404           if (this->fFEBT0Multiplicities[iPosition][iLUT] == 0x0) {
405             return -10;
406           }
407         }
408       }
409       else {
410         return -11;
411       }
412     }
413   }
414   else {
415     return -12;
416   }
417   
418
419   // check T0 LUTs
420   if (this->fFEBT0LUTs != 0x0) {
421     for (UInt_t iPosition = 0; iPosition < 2; iPosition++) {
422       if (this->fFEBT0LUTs[iPosition] != 0x0) {
423         for (UInt_t iLUT = 0; iLUT < 2; iLUT++) {
424           if (this->fFEBT0LUTs[iPosition][iLUT] == 0x0) {
425             return -13;
426           }
427         }
428       }
429       else {
430         return -14;
431       }
432     }
433   }  
434   else {
435     return -15;
436   }
437
438   // check V0 FEB thresholds
439   if (this->fFEBV0Thresholds != 0x0) {
440     for (UInt_t iPosition = 0; iPosition < 2; iPosition++) {
441       if (this->fFEBV0Thresholds[iPosition] != 0x0) {
442         for (UInt_t iCard = 0; iCard < 4; iCard++) {
443           if (this->fFEBV0Thresholds[iPosition][iCard] == 0x0) {
444             return -16;
445           }
446         }
447       }
448       else {
449         return -17;
450       }
451     }
452   }
453   else {
454     return -18;
455   }
456
457   // check V0 multiplicities
458   if (this->fFEBV0Multiplicities != 0x0) {
459     for (UInt_t iPosition = 0; iPosition < 2; iPosition++) {
460       if (this->fFEBV0Multiplicities[iPosition] != 0x0) {
461         for (UInt_t iCard = 0; iCard < 4; iCard++) {
462           if (this->fFEBV0Multiplicities[iPosition][iCard] != 0x0) {
463             for (UInt_t iLUT = 0; iLUT < 2; iLUT++) {
464               if (this->fFEBV0Multiplicities[iPosition][iCard][iLUT] == 0x0) {
465                 return -19;
466               }
467             }
468           }
469           else {
470             return -20;
471           }
472         }
473       }
474       else {
475         return -21;
476       }
477     }
478   } 
479   else {
480     return -22;
481   }
482
483   // check V0 LUTs
484   if (this->fFEBV0LUTs != 0x0) {
485     for (UInt_t iPosition = 0; iPosition < 2; iPosition++) {
486       if (this->fFEBV0LUTs[iPosition] != 0x0) {
487         for (UInt_t iCard = 0; iCard < 4; iCard++) {
488           if (this->fFEBV0LUTs[iPosition][iCard] != 0x0) {
489             for (UInt_t iLUT = 0; iLUT < 2; iLUT++) {
490               if (this->fFEBV0LUTs[iPosition][iCard][iLUT] == 0x0) {
491                 return -23;
492               }
493             }
494           }
495           else {
496             return -24;
497           }
498         }
499       }
500       else {
501         return -25;
502       }
503     }
504   } 
505   else {
506     return -26;
507   }
508
509   // check CB LUTs
510   if (this->fCBLUTs != 0x0) {
511     for (UInt_t iCB = 0; iCB < 3; iCB++) {
512       if (this->fCBLUTs[iCB] != 0x0) {
513         for (UInt_t iLUT = 0; iLUT < 2; iLUT++) {
514           if (this->fCBLUTs[iCB][iLUT] == 0x0) {
515             return -27;
516           }
517         }
518         if (iCB == kB) {
519           if (this->fCBLUTs[iCB][2] == 0x0) {
520             return -28;
521           }
522         }
523       }
524       else {
525         return -29;
526       }
527     }
528   }  
529   else {
530     return -30;
531   }
532   return 0;
533 }
534
535 //______________________________________________________________________________
536 AliTRDptrgParam* AliTRDptrgParam::Instance() 
537 {
538   // get (or create) the single instance
539
540   if (fgInstance == 0) 
541     fgInstance = new AliTRDptrgParam();
542
543   return fgInstance;
544 }
545
546 //______________________________________________________________________________
547 void AliTRDptrgParam::Terminate() 
548 {
549   // destruct the instance
550
551   if (fgInstance != 0) {
552     delete fgInstance;
553     fgInstance = 0x0;
554   }
555 }
556
557 //______________________________________________________________________________
558 void AliTRDptrgParam::LoadStandardConfiguration() {
559   // loads a standard configuration parameters for testing 
560
561   // TLMU Input Masks
562   for (UInt_t iSM = 0; iSM < 18; iSM++) {
563     this->fTLMUInputMask[iSM] = 0xFFFFFFFF; // enable all input bits
564   }
565  
566   // TLMU Input Stretch
567   this->fTLMUInputStretch = 0; // not used in simulation
568
569   // TLMU Coincidence Matrices
570   //
571   // Matrix 0: Back-To-Back
572   // Matrix 1: Back-To-Back +/-1
573   // Matrix 2: Back-To-Back +/-2
574   for (UInt_t iMatrix = 0; iMatrix < 3; iMatrix++) {
575     for (UInt_t iSlice = 0; iSlice < 18; iSlice++) {
576       if (iMatrix == 0) {
577         if (iSlice < 9) {
578           this->fTLMUcmatrices[iMatrix][iSlice] = 0x201 << iSlice; 
579           // Back-To-Back 
580           AliDebug(5, Form("fTLMUcmatrices[%d][%d]=0x%x",iMatrix,iSlice,
581                            this->fTLMUcmatrices[iMatrix][iSlice]));
582         }
583         // because of symmetrie the other slices are not necessary
584       } 
585       else if (iMatrix == 1)  {
586         // Back-To-Back +/- 1
587         if (iSlice < 8) {
588           this->fTLMUcmatrices[iMatrix][iSlice] = 0x381 << iSlice;
589         }
590         else if (iSlice == 8) {
591           this->fTLMUcmatrices[iMatrix][iSlice] = 0x30101;
592         }
593         else if (iSlice == 9) {
594           this->fTLMUcmatrices[iMatrix][iSlice] = 0x20203;
595         }
596         else {
597           this->fTLMUcmatrices[iMatrix][iSlice] = 0x407 << (iSlice - 10);
598         } 
599         AliDebug(5, Form("fTLMUcmatrices[%d][%d]=0x%x",iMatrix,iSlice,
600                          this->fTLMUcmatrices[iMatrix][iSlice])); 
601       }
602       else if (iMatrix == 2) {
603         // Back-To-Back +/-2
604         if (iSlice < 7 ) {
605           this->fTLMUcmatrices[iMatrix][iSlice] = 0xF81 << iSlice;
606         }
607         else if (iSlice == 7) {
608           this->fTLMUcmatrices[iMatrix][iSlice] = 0x3C081;
609         }
610         else if (iSlice == 8) {
611           this->fTLMUcmatrices[iMatrix][iSlice] = 0x38103;
612         }
613         else if (iSlice == 9) {
614           this->fTLMUcmatrices[iMatrix][iSlice] = 0x30207;
615         }
616         else if (iSlice == 10) {
617           this->fTLMUcmatrices[iMatrix][iSlice] = 0x2040F;
618         }
619         else {
620           this->fTLMUcmatrices[iMatrix][iSlice] = 0x81F << (iSlice - 11);
621         } 
622         AliDebug(5, Form("fTLMUcmatrices[%d][%d]=0x%x",iMatrix,iSlice,
623                          this->fTLMUcmatrices[iMatrix][iSlice]));     
624       }
625     } 
626   }
627
628   // TLMU Mulitplicity
629   this->fTLMUmultiplicity[0][0] = 0;
630   this->fTLMUmultiplicity[0][1] = 10;
631   this->fTLMUmultiplicity[1][0] = 10;
632   this->fTLMUmultiplicity[1][1] = 25;
633   this->fTLMUmultiplicity[2][0] = 25;
634   this->fTLMUmultiplicity[2][1] = 50;
635   this->fTLMUmultiplicity[3][0] = 50;
636   this->fTLMUmultiplicity[3][1] = 100;
637   this->fTLMUmultiplicity[4][0] = 100;
638   this->fTLMUmultiplicity[4][1] = 200;
639   this->fTLMUmultiplicity[5][0] = 200;
640   this->fTLMUmultiplicity[5][1] = 350;
641   this->fTLMUmultiplicity[6][0] = 350;
642   this->fTLMUmultiplicity[6][1] = 400;
643   this->fTLMUmultiplicity[7][0] = 400;
644   this->fTLMUmultiplicity[7][1] = 576;
645   this->fTLMUmultiplicity[8][0] = 1;
646   this->fTLMUmultiplicity[8][1] = 576;
647  
648   // TLMU output
649   this->fTLMUoutput[0][0] = 0;
650   this->fTLMUoutput[1][0] = 1;
651   this->fTLMUoutput[2][0] = 2;
652   this->fTLMUoutput[3][1] = 0;
653   this->fTLMUoutput[4][1] = 1;
654   this->fTLMUoutput[5][1] = 2;
655   this->fTLMUoutput[6][1] = 3;
656   this->fTLMUoutput[7][1] = 8;
657
658   // T0 FEB Thresholds
659   for (UInt_t iChannel = 0; iChannel < 12; iChannel++) {
660     this->fFEBT0Thresholds[0][iChannel] = 10;
661     this->fFEBT0Thresholds[1][iChannel] = 10;
662   }
663
664   // T0 Multiplicities
665   for (UInt_t iPosition = 0; iPosition < 2; iPosition++) {
666     for (UInt_t iLUT = 0; iLUT < 2; iLUT++) {
667       if (iLUT == 0) {
668         this->fFEBT0Multiplicities[iPosition][iLUT][0] = 0;
669       }
670       else {
671         this->fFEBT0Multiplicities[iPosition][iLUT][0] = 5;
672       }
673       this->fFEBT0Multiplicities[iPosition][iLUT][1] = 0xFFF;
674     }
675   }
676
677   // V0 FEB Thresholds
678   for (UInt_t iPosition = 0; iPosition < 2; iPosition++) {
679     for (UInt_t iCard = 0; iCard < 4; iCard++) {
680       for (UInt_t iChannel = 0; iChannel < 8; iChannel++) {
681         this->fFEBV0Thresholds[iPosition][iCard][iChannel] = 10;
682       }
683     }
684   }
685
686   // V0 Multiplicities
687   for (UInt_t iPosition = 0; iPosition < 2; iPosition++) {
688     for (UInt_t iCard = 0; iCard < 4; iCard++) {
689       for (UInt_t iLUT = 0; iLUT < 2; iLUT++) {
690         if (iLUT == 0) {
691           this->fFEBV0Multiplicities[iPosition][iCard][iLUT][0] = 0;
692         }
693         else {
694           this->fFEBV0Multiplicities[iPosition][iCard][iLUT][0] = 3;
695         }
696         this->fFEBV0Multiplicities[iPosition][iCard][iLUT][1] = 0xFF;
697       }
698     }
699   }
700
701   // CB-A LUT equations
702   this->fCBALUTequ[0] = "T0_0 || (V0-0_0 || V0-1_0 || V0-2_0 || V0-3_0)";
703   this->fCBALUTequ[1] = "!T0_1 && !V0-0_1 && !V0-1_1 && !V0-2_1 && !V0-3_1";
704
705   // CB-C LUT equations
706   this->fCBCLUTequ[0] = "T0_0 || ( V0-0_0 || V0-1_0 || V0-2_0 || V0-3_0 )";
707   this->fCBCLUTequ[1] = "!T0_1 && !V0-0_1 && !V0-1_1 && !V0-2_1 && !V0-3_1";
708
709   // CB-B LUT equations
710   this->fCBBLUTequ[0] = "CB-A_1 && !CB-C_1 && TLMU_7";
711   this->fCBBLUTequ[1] = "!CB-A_1 && CB-C_1 && TLMU_7";
712   this->fCBBLUTequ[2] = "CB-A_1 && CB-C_1 && TLMU_7";
713
714   // PT output mask
715   this->fPTmasks.fLUTs[0] = kTRUE;
716   this->fPTmasks.fLUTs[1] = kTRUE;
717   this->fPTmasks.fLUTs[2] = kTRUE;
718   this->fPTmasks.fCBA[0] = kTRUE;
719   this->fPTmasks.fCBC[0] = kTRUE;
720   for (Int_t i = 1; i < 7; i++) {
721     this->fPTmasks.fTLMU[i] = kTRUE;
722   }
723
724   return;  
725 }
726
727 //______________________________________________________________________________
728 Bool_t AliTRDptrgParam::LoadConfigurationFromFile(TString filename) {
729   // Reads pretrigger configuration file and forwards identifiers and values
730   // to the corresponding parser functions
731   // This method is only checking for certain keywords at the beginning of a
732   // line in the config file
733
734   ifstream inputFile;
735   inputFile.open(filename.Data());
736   TString line;
737   TString identifier;
738   TString value;
739   std::string str;
740
741
742   if (inputFile.is_open())
743   {
744     AliDebug(5, "---- Reading configuration file ----");
745     while (getline(inputFile, str)) {
746       line = str;
747    
748       AliDebug(5, Form("line: %s\n", line.Data()));
749       if (line.Index("TLMU") == 0) {
750         this->PrepareLine(line, identifier, value);
751         if (!this->ParseTLMU(identifier, value)) {
752           return kFALSE;
753         }
754       }
755       else if (line.Index("FEB") == 0) {
756         this->PrepareLine(line, identifier, value);
757         if (!this->ParseFEB(identifier, value)) {
758           return kFALSE;
759         }
760       }
761       else if (line.Index("CBB") == 0) {
762         this->PrepareLine(line, identifier, value);
763         if (!this->ParseCBB(identifier, value)) {
764           return kFALSE;
765         }
766       }
767       else if ((line.Index("CBA") == 0) ||
768                (line.Index("CBC") == 0)) {
769         this->PrepareLine(line, identifier, value);
770         if (!this->ParseCBAC(identifier, value)) {
771           return kFALSE;
772         }
773       }
774     }
775     AliDebug(5, "---- Finished reading configuration file ----");
776     inputFile.close();
777     return kTRUE;
778   }
779   else
780   {
781     AliDebug(5, "Error opening configuration file");
782     return kFALSE;
783   }
784   return kTRUE;
785 }
786
787
788 //______________________________________________________________________________
789 Int_t AliTRDptrgParam::GenerateLUTs() {
790   // generates all LUTs defined inside this object, this schould called only
791   // once, after configuration is loaded in order to save cpu time
792
793   // generation method:
794   // walk through address space
795   // mask address with input mask =>  get multiplicity of masked value
796   // if (multiplicity of masked value) > multiplicity condition
797   // write 1 in LUT
798   
799   // T0
800   this->fFEBT0LUTs = new Int_t**[2]; // 2 A + C side
801   for (UInt_t iPosition = 0; iPosition < 2; iPosition++) {
802     // iPosition = 0 -> A, iPosition = 1 -> C
803     this->fFEBT0LUTs[iPosition] = new Int_t*[2]; // 2 LUTs per side
804     for (UInt_t iLUT = 0; iLUT < 2; iLUT++) {
805       // LUT with 12 input channels 2^12=4096
806       this->fFEBT0LUTs[iPosition][iLUT] = new Int_t[4096];
807       AliDebug(5, Form("Generate FEBT0LUT[%d][%d]: (0x%x)>%d", iPosition, iLUT,
808                        this->fFEBT0Multiplicities[iPosition][iLUT][1],
809                        this->fFEBT0Multiplicities[iPosition][iLUT][0]));
810       for (UInt_t iEntry = 0; iEntry < 4096; iEntry++) {
811         // Check whether that entry belongs to a multiplicity exceeding the 
812         // threshold
813         if (this->GetMultiplicity(iEntry & 
814               this->fFEBT0Multiplicities[iPosition][iLUT][1]) > 
815             this->fFEBT0Multiplicities[iPosition][iLUT][0]) {
816           this->fFEBT0LUTs[iPosition][iLUT][iEntry] = 1;
817         }
818         else {
819           // initialize LUT (not done before !)
820           this->fFEBT0LUTs[iPosition][iLUT][iEntry] = 0;
821         }
822         AliDebug(10, Form("FEBT0LUTs[%d][%d][0x%x]=%d", iPosition, iLUT, iEntry,
823                          this->fFEBT0LUTs[iPosition][iLUT][iEntry])); 
824       }
825       AliDebug(5, Form("Generated FEBT0LUTs[%d][%d]", iPosition, iLUT));
826     }
827   }
828
829   // V0
830   this->fFEBV0LUTs = new Int_t***[2]; // 2 A + C side
831   for (UInt_t iPosition = 0; iPosition < 2; iPosition++) {
832     // iPosition = 0 -> A, iPosition = 1 -> C
833     this->fFEBV0LUTs[iPosition] = new Int_t**[4]; // 4 FEBs per side
834     for (UInt_t iFEB = 0; iFEB < 4; iFEB++) {
835       this->fFEBV0LUTs[iPosition][iFEB] = new Int_t*[2]; // 2 LUTs per FEB
836       for (UInt_t iLUT = 0; iLUT < 2; iLUT++) {
837       // LUT with 10 input channels 2^10=1024
838         this->fFEBV0LUTs[iPosition][iFEB][iLUT] = new Int_t[1024];
839         AliDebug(5, Form("Generate FEBV0LUT[%d][%d][%d]: (0x%x)>%d", iPosition, 
840                          iFEB, iLUT,
841                          this->fFEBV0Multiplicities[iPosition][iFEB][iLUT][1],
842                          this->fFEBV0Multiplicities[iPosition][iFEB][iLUT][0]));
843         for (UInt_t iEntry = 0; iEntry < 1024; iEntry++) {
844           // Check whether that entry belongs to a multiplicity exceeding the 
845           // threshold
846           if (this->GetMultiplicity(iEntry & 
847                 this->fFEBV0Multiplicities[iPosition][iFEB][iLUT][1]) > 
848               this->fFEBV0Multiplicities[iPosition][iFEB][iLUT][0]) {
849             this->fFEBV0LUTs[iPosition][iFEB][iLUT][iEntry] = 1;
850           }
851           else {
852             // initialize LUT (not done before !)
853             this->fFEBV0LUTs[iPosition][iFEB][iLUT][iEntry] = 0;
854           }
855           AliDebug(10, Form("FEBV0LUTs[%d][%d][%d][0x%x]=%d", iPosition, iFEB,
856                             iLUT, iEntry, 
857                             this->fFEBV0LUTs[iPosition][iFEB][iLUT][iEntry]));
858         }
859         AliDebug(5, Form("Generated FEBV0LUTs[%d][%d][%d]", iPosition, iFEB, 
860                          iLUT));
861       }
862     }
863   }
864
865   // ControlBoxes (CB-x)
866   // initialize LUTs
867   this->fCBLUTs = new Int_t**[3];
868   for (Int_t iCB = 0; iCB < 3; iCB++) {
869     if (iCB == kB) { // B
870       fCBLUTs[iCB] = new Int_t*[3];
871       this->fCBLUTs[iCB][0] = 0x0;
872       this->fCBLUTs[iCB][1] = 0x0;
873       this->fCBLUTs[iCB][2] = 0x0;
874     }
875     else { // A + C
876       fCBLUTs[iCB] = new Int_t*[2];
877       this->fCBLUTs[iCB][0] = 0x0;
878       this->fCBLUTs[iCB][1] = 0x0;
879     }
880   }
881   
882   // CB-A (CB = 1 / kA)
883   for (Int_t iLUT = 0; iLUT < 2; iLUT++) {
884     this->fCBLUTs[1][iLUT] = this->GenerateLUTbasedOnEq(this->fCBALUTequ[iLUT],
885                                                         10,1);
886     for (Int_t iEntry = 0; iEntry < 1024; iEntry++) {
887       AliDebug(10, Form("fCBLUTs[@A][%d][0x%x]=%d", iLUT, iEntry,
888                         this->fCBLUTs[1][iLUT][iEntry]));
889     }
890   }
891
892   // CB-C (CB = 2 / kC)
893   for (Int_t iLUT = 0; iLUT < 2; iLUT++) {
894     this->fCBLUTs[2][iLUT] = this->GenerateLUTbasedOnEq(this->fCBCLUTequ[iLUT],
895                                                         10,1);
896     for (Int_t iEntry = 0; iEntry < 1024; iEntry++) {
897       AliDebug(6, Form("fCBLUTs[@C][%d][0x%x]=%d", iLUT, iEntry,
898                        this->fCBLUTs[2][iLUT][iEntry]));
899     }
900   }  
901  
902   // CB-B (CB = 0 / kB)
903   for (Int_t iLUT = 0; iLUT < 3; iLUT++) {
904     this->fCBLUTs[0][iLUT] = this->GenerateLUTbasedOnEq(this->fCBBLUTequ[iLUT], 
905                                                         12,1);
906     for (Int_t iEntry = 0; iEntry < 4096; iEntry++) {
907       AliDebug(10, Form("fCBLUTs[@B][%d][0x%x]=%d", iLUT, iEntry,
908                         this->fCBLUTs[0][iLUT][iEntry]));
909     }
910   }
911
912   AliDebug(5, "LUTs were generated!");
913   return 0;
914 }
915
916 //______________________________________________________________________________
917 UInt_t AliTRDptrgParam::GetMultiplicity(UInt_t BitVector) const {
918   // returns the multiplicity of a given bit vector
919   
920   UInt_t result = 0;
921   UInt_t temp = 0x01;
922   for (UInt_t iBit = 0; iBit < 32; iBit++) {
923     if (BitVector & temp) {
924       result++;
925     }
926     temp <<= 1;
927   }
928
929   return result;
930 }
931
932 //______________________________________________________________________________
933 UInt_t AliTRDptrgParam::GetMultiplicity(Int_t BitVector) const {
934   // returns the multiplicity of a given bit vector
935   
936   UInt_t result = 0;
937   UInt_t temp = 0x01;
938   for (UInt_t iBit = 0; iBit < 32; iBit++) {
939     if (BitVector & temp) {
940       result++;
941     }
942     temp <<= 1;
943   }
944
945   return result;
946 }
947
948 //______________________________________________________________________________
949 //
950 //      Configuration file parsing (helper functions)
951 //______________________________________________________________________________
952
953 //______________________________________________________________________________
954 void AliTRDptrgParam::PrepareLine(TString line, TString& identifier, 
955                                   TString& value) {
956   // Prepares a line for parsing
957   // divide identifier and value 
958
959   // clear identifier and value
960   identifier.Clear();
961   value.Clear();  
962
963   Int_t iLetter = 0;
964   while ((line[iLetter] != ' ') && (line[iLetter] != '\t') && 
965          (line[iLetter] != '#') && (iLetter < line.Length())) {
966     // read identifier
967     identifier += line[iLetter];
968     iLetter++;
969   }
970   while (((line[iLetter] == ' ') || (line[iLetter] == '\t')) &&
971          (iLetter < line.Length()) && (line[iLetter] != '#')) {
972     // omit whitespaces and tabs in between
973     iLetter++;
974   }
975   while(iLetter < line.Length()) {
976     // read value or equation and remove white spaces and tabs
977     //if ((line[iLetter] != ' ') && (line[iLetter] != '\t') &&
978     //    (line[iLetter] != '#')) {
979     if (line[iLetter] != '#') {
980       value += line[iLetter];
981     }
982     iLetter++;
983   }
984 }
985
986 //______________________________________________________________________________
987 TString AliTRDptrgParam::CleanTString(TString string) {
988   // Removes white spaces and tabs
989
990   TString result;
991   result.Clear();
992   for (Int_t iLetter = 0; iLetter < string.Length(); iLetter++) {
993     if ((string[iLetter] != ' ') && (string[iLetter] != '\t')) {
994       result += string[iLetter];
995     }
996   } 
997   AliDebug(5, Form("Cleaned string: %s", result.Data()));  
998   return result;
999 }
1000
1001 //______________________________________________________________________________
1002 void AliTRDptrgParam::SplitUpValues(TString value, TObjArray& arr) {
1003   // splits up multiple values into a TObjArray
1004
1005   TString temp;
1006   temp.Clear();
1007   temp.Resize(0);
1008   for (Int_t iLetter = 0; iLetter < value.Length(); iLetter++) {
1009     if ((value[iLetter] != ' ') && (value[iLetter] != '\t')) {
1010       // add another letter
1011       temp += value[iLetter];
1012     }
1013     else {
1014       // seperator found: white space or tabs
1015       if (temp.Length()) {
1016         TObjString* t = new TObjString(temp.Data());
1017         arr.Add(t);      
1018         temp.Clear();
1019         temp.Resize(0);
1020       }
1021     }
1022   }
1023   if (temp.Length() != 0) {
1024     TObjString* t = new TObjString(temp.Data());
1025     arr.Add(t);         
1026   }
1027 }
1028
1029 //______________________________________________________________________________
1030 UInt_t AliTRDptrgParam::BinaryTStringToInt(TString number) const {
1031   // converts a binary TString to an integer
1032   UInt_t temp = 0x01;
1033   UInt_t result = 0x0;
1034   for (Int_t i = number.Length() - 1; i >= 0; i--) {
1035     if (number[i] == '1') {
1036       result |= temp;
1037       temp <<= 1;
1038     }
1039     else if (number[i] == '0')  {
1040       temp <<= 1;    
1041     }
1042   }
1043   return result;
1044 }
1045
1046 //______________________________________________________________________________
1047 Bool_t AliTRDptrgParam::ParseMultiplicityCondition(TString condition, 
1048                                                    UInt_t* threshold,
1049                                                    UInt_t* mask) {
1050   // converts a string formed like "M(1111_1111)>4" to a input mask and a
1051   // multiplicity threshold
1052
1053   // check whether condition is starting with "M(
1054   if ((condition[0] != 'M') || ( condition[1] != '(')) {
1055     return kFALSE;
1056   }
1057   
1058   TString maskStr = "";
1059   Int_t iLetter = 0;
1060   
1061   // extract input mask
1062   while (condition[iLetter] != ')') {
1063     maskStr += condition[iLetter++];
1064   }
1065   (*mask) = BinaryTStringToInt(maskStr);
1066   if ((*mask) == 0) { 
1067     AliDebug(5, Form("Invalid input mask: %s,[%s]", maskStr.Data(), 
1068                       condition.Data()));
1069     return kFALSE;
1070   }
1071   
1072   // ensure that ')' is followed by a '>'
1073   if (condition[++iLetter] != '>') {
1074     AliDebug(5, Form("multiplicity condition is incorrectly formed: %s", 
1075                      condition.Data()));
1076     return kFALSE;
1077   }
1078   iLetter++; // move on to the first digit
1079
1080   TString thresholdStr = "";
1081   // gain threshold string
1082   while (((condition[iLetter] != ' ') || (condition[iLetter] != '\t')) &&
1083          (iLetter < condition.Length())) {
1084     thresholdStr += condition[iLetter++];
1085   }
1086   (*threshold) = thresholdStr.Atoi(); // convert string to integer
1087   AliDebug(5, Form("mask: 0x%x, multiplicity threshold: %d", (*mask), 
1088                    (*threshold)));
1089   return kTRUE;
1090 }
1091
1092 //______________________________________________________________________________
1093 Bool_t AliTRDptrgParam::ParseFEB(TString identifier, TString value) {
1094   // Parse FEB configuration
1095
1096   //------------------------------------------
1097   if (identifier.Index("FEB/T0/A/THR") == 0) {
1098     // FEB T0 thresholds at A side
1099
1100     TObjArray arr;
1101     arr.Clear();
1102     SplitUpValues(value, arr);
1103     
1104     if (arr.GetEntries() != 12) {
1105       AliError("Wrong FEB T0 Threshold count, it must be 12 channels!");
1106       return kFALSE; 
1107     }
1108     for (Int_t iValue = 0; iValue < arr.GetEntries(); iValue++) {
1109       this->fFEBT0Thresholds[0][iValue] =  
1110         (dynamic_cast<TObjString*>(arr[iValue])->GetString()).Atoi();
1111       AliDebug(5, Form("FEB/T0/A/THR[%d]=%d", iValue, 
1112                        this->fFEBT0Thresholds[0][iValue])); 
1113     }
1114     return kTRUE;
1115   }
1116
1117   //-----------------------------------------------
1118   else if (identifier.Index("FEB/T0/C/THR") == 0) {
1119     // FEB T0 thresholds at c side
1120
1121     TObjArray arr;
1122     arr.Clear();
1123     SplitUpValues(value, arr);
1124     
1125     if (arr.GetEntries() != 12) {
1126       AliError("Wrong FEB T0 Threshold count, it must be 12 channels!");
1127       return kFALSE; 
1128     }
1129     for (Int_t iValue = 0; iValue < arr.GetEntries(); iValue++) {
1130       this->fFEBT0Thresholds[1][iValue] =  
1131         (dynamic_cast<TObjString*>(arr[iValue])->GetString()).Atoi();
1132       AliDebug(5, Form("FEB/T0/C/THR[%d]=%d", iValue, 
1133                        this->fFEBT0Thresholds[1][iValue])); 
1134     }
1135     return kTRUE;
1136   }
1137   
1138   //--------------------------------------------------
1139   else if ((identifier.Index("FEB/V0/A0/THR") == 0) ||
1140       (identifier.Index("FEB/V0/A1/THR") == 0) ||
1141       (identifier.Index("FEB/V0/A2/THR") == 0) ||
1142       (identifier.Index("FEB/V0/A3/THR") == 0)) {
1143     // FEB V0 thresholds at a side (cards 0,1,2,3)
1144    
1145     TString cardIDstr = identifier(8, 1);
1146     Int_t cardID = cardIDstr.Atoi();
1147  
1148     TObjArray arr;
1149     arr.Clear();
1150     SplitUpValues(value, arr);
1151     
1152     if (arr.GetEntries() != 8) {
1153       AliError("Wrong FEB V0 Threshold count, it must be 8 channels!");
1154       return kFALSE; 
1155     }
1156     for (Int_t iValue = 0; iValue < arr.GetEntries(); iValue++) {
1157       this->fFEBV0Thresholds[0][cardID][iValue] =  
1158         (dynamic_cast<TObjString*>(arr[iValue])->GetString()).Atoi();
1159       AliDebug(5, Form("FEB/V0/A%d/THR[%d]=%d", cardID, iValue, 
1160                        this->fFEBV0Thresholds[0][cardID][iValue])); 
1161     }
1162   }
1163
1164   //--------------------------------------------------
1165   else if ((identifier.Index("FEB/V0/C0/THR") == 0) ||
1166       (identifier.Index("FEB/V0/C1/THR") == 0) ||
1167       (identifier.Index("FEB/V0/C2/THR") == 0) ||
1168       (identifier.Index("FEB/V0/C3/THR") == 0)) {
1169     // FEB V0 thresholds at c side (cards 0,1,2,3)
1170    
1171     TString cardIDstr = identifier(8, 1);
1172     Int_t cardID = cardIDstr.Atoi();
1173  
1174     TObjArray arr;
1175     arr.Clear();
1176     SplitUpValues(value, arr);
1177     
1178     if (arr.GetEntries() != 8) {
1179       AliError("Wrong FEB V0 Threshold count, it must be 8 channels!");
1180       return kFALSE; 
1181     }
1182     for (Int_t iValue = 0; iValue < arr.GetEntries(); iValue++) {
1183       this->fFEBV0Thresholds[1][cardID][iValue] =  
1184         (dynamic_cast<TObjString*>(arr[iValue])->GetString()).Atoi();
1185       AliDebug(5, Form("FEB/V0/C%d/THR[%d]=%d", cardID, iValue, 
1186                        this->fFEBV0Thresholds[1][cardID][iValue])); 
1187     }
1188   }
1189   
1190   //-----------------------------------------------
1191   else if (identifier.Index("FEB/T0/A/LUT") == 0) {
1192     // FEB T0 look up tables at A side
1193
1194     TString lutIDstr = identifier(13, 1);
1195     Int_t lutID = lutIDstr.Atoi();
1196     
1197     UInt_t val = 0;
1198     UInt_t mask = 0;
1199     ParseMultiplicityCondition(value, &val, &mask);
1200     this->fFEBT0Multiplicities[0][lutID][0] = val;
1201     this->fFEBT0Multiplicities[0][lutID][1] = mask;
1202     AliDebug(5, Form("FEBT0Multiplicities[0/A][%d][val] = %d", lutID, val));
1203     AliDebug(5, Form("FEBT0Multiplicities[0/A][%d][mask] = %d", lutID, mask));
1204     
1205     return kTRUE;
1206   }
1207
1208   //-----------------------------------------------
1209   else if (identifier.Index("FEB/T0/C/LUT") == 0) {
1210     // FEB T0 look up tables at C side
1211
1212     TString lutIDstr = identifier(13, 1);
1213     Int_t lutID = lutIDstr.Atoi();
1214     
1215     UInt_t val = 0;
1216     UInt_t mask = 0;
1217     ParseMultiplicityCondition(value, &val, &mask);
1218     this->fFEBT0Multiplicities[1][lutID][0] = val;
1219     this->fFEBT0Multiplicities[1][lutID][1] = mask;
1220     AliDebug(5, Form("FEBT0Multiplicities[1/C][%d][val] = %d", lutID, val));
1221     AliDebug(5, Form("FEBT0Multiplicities[1/C][%d][mask] = %d", lutID, mask));
1222
1223     return kTRUE;
1224   }
1225
1226   //--------------------------------------------------
1227   else if ((identifier.Index("FEB/V0/A0/LUT") == 0) ||
1228            (identifier.Index("FEB/V0/A1/LUT") == 0) ||
1229            (identifier.Index("FEB/V0/A2/LUT") == 0) ||
1230            (identifier.Index("FEB/V0/A3/LUT") == 0)) {
1231     // FEB V0 look up tables at A side
1232
1233     TString cardIDstr = identifier(8, 1);
1234     Int_t cardID = cardIDstr.Atoi();
1235  
1236     TString lutIDstr = identifier(14, 1);
1237     Int_t lutID = lutIDstr.Atoi();
1238      
1239     UInt_t val = 0;
1240     UInt_t mask = 0;
1241     ParseMultiplicityCondition(value, &val, &mask);
1242     this->fFEBV0Multiplicities[0][cardID][lutID][0] = val;
1243     this->fFEBV0Multiplicities[0][cardID][lutID][1] = mask;
1244     AliDebug(5, Form("FEBV0Multiplicities[0/A][%d][%d][val] = %d", cardID, 
1245                      lutID, val));
1246     AliDebug(5, Form("FEBV0Multiplicities[0/A][%d][%d][mask] = %d", cardID, 
1247                      lutID, mask));
1248
1249     return kTRUE;
1250   }
1251    
1252   //--------------------------------------------------
1253   else if ((identifier.Index("FEB/V0/C0/LUT") == 0) ||
1254            (identifier.Index("FEB/V0/C1/LUT") == 0) ||
1255            (identifier.Index("FEB/V0/C2/LUT") == 0) ||
1256            (identifier.Index("FEB/V0/C3/LUT") == 0)) {
1257     // FEB V0 look up tables at C side
1258
1259     TString cardIDstr = identifier(8, 1);
1260     Int_t cardID = cardIDstr.Atoi();
1261  
1262     TString lutIDstr = identifier(14, 1);
1263     Int_t lutID = lutIDstr.Atoi();
1264      
1265     UInt_t val = 0;
1266     UInt_t mask = 0;
1267     ParseMultiplicityCondition(value, &val, &mask);
1268     this->fFEBV0Multiplicities[1][cardID][lutID][0] = val;
1269     this->fFEBV0Multiplicities[1][cardID][lutID][1] = mask;
1270     AliDebug(5, Form("FEBV0Multiplicities[1/C][%d][%d][val] = %d", cardID, 
1271                      lutID, val));
1272     AliDebug(5, Form("FEBV0Multiplicities[1/C][%d][%d][mask] = %d", cardID, 
1273                      lutID, mask));
1274
1275     return kTRUE;
1276   }
1277   return kTRUE;
1278 }
1279
1280 //______________________________________________________________________________
1281 Bool_t AliTRDptrgParam::ParseCBAC(TString identifier, TString value) {
1282   // Parse CB-A and CB-C configuration
1283  
1284   if (identifier.Index("CBA/LUT/") == 0) {
1285     // parse CB-A's logical equations
1286     
1287     TString eqIDstr = identifier(8, 1);
1288     Int_t eqID = eqIDstr.Atoi();
1289    
1290     if ((eqID == 0) || (eqID == 1)) {
1291       this->fCBALUTequ[eqID] = this->CleanTString(value);
1292       AliDebug(5, Form("fCBALUTequ[%d]=%s", eqID, this->fCBALUTequ[eqID].Data())); 
1293     }
1294     return kTRUE;    
1295   }
1296     
1297   else if (identifier.Index("CBC/LUT/") == 0) {
1298     // parse CB-C's logical equations
1299     
1300     TString eqIDstr = identifier(8, 1);
1301     Int_t eqID = eqIDstr.Atoi();
1302    
1303     if ((eqID == 0) || (eqID == 1)) {
1304       this->fCBCLUTequ[eqID] = this->CleanTString(value);
1305       AliDebug(5, Form("fCBCLUTequ[%d]=%s", eqID, this->fCBCLUTequ[eqID].Data()));
1306     }
1307     return kTRUE;
1308   }
1309
1310   return kTRUE;
1311 }
1312
1313 //______________________________________________________________________________
1314 Bool_t AliTRDptrgParam::ParseCBB(TString identifier, TString value) {
1315   // Parse CBB configuration
1316   
1317   if (identifier.Index("CBB/LUT/") == 0) {
1318     // parse CB-B's logical equations
1319     
1320     TString eqIDstr = identifier(8, 1);
1321     Int_t eqID = eqIDstr.Atoi();
1322    
1323     if ((eqID == 0) || (eqID == 1) || (eqID == 2)) {
1324       this->fCBBLUTequ[eqID] = this->CleanTString(value);
1325       AliDebug(5, Form("fCBBLUTequ[%d]=%s", eqID, this->fCBBLUTequ[eqID].Data()));
1326     }
1327     return kTRUE;
1328   }
1329   
1330   // PT masks 
1331   else if (identifier.Index("CBB/PT/MASK/CB-A_0") == 0) { // CB-A_0
1332     if (value.Index("YES") == 0) {
1333       this->fPTmasks.fCBA[0] = kTRUE;     
1334     }
1335     else {
1336       this->fPTmasks.fCBA[0] = kFALSE;
1337     }
1338     AliDebug(5, Form("CBB/PT/MASK/CB-A_0=%d", this->fPTmasks.fCBA[0]));
1339     return kTRUE;
1340   }
1341   else if (identifier.Index("CBB/PT/MASK/CB-A_1") == 0) { // CB-A_1
1342     if (value.Index("YES") == 0) {
1343       this->fPTmasks.fCBA[1] = kTRUE;     
1344     }
1345     else {
1346       this->fPTmasks.fCBA[1] = kFALSE;
1347     }
1348     AliDebug(5, Form("CBB/PT/MASK/CB-A_1=%d", this->fPTmasks.fCBA[1]));
1349     return kTRUE;
1350   } 
1351   else if (identifier.Index("CBB/PT/MASK/CB-C_0") == 0) { // CB-C_0
1352     if (value.Index("YES") == 0) {
1353       this->fPTmasks.fCBC[0] = kTRUE;     
1354     }
1355     else {
1356       this->fPTmasks.fCBC[0] = kFALSE;
1357     }
1358     AliDebug(5, Form("CBB/PT/MASK/CB-C_0=%d",this->fPTmasks.fCBC[0]));
1359     return kTRUE;
1360   }
1361   else if (identifier.Index("CBB/PT/MASK/CB-C_1") == 0) { // CB-C_1
1362     if (value.Index("YES") == 0) {
1363       this->fPTmasks.fCBC[1] = kTRUE;     
1364     }
1365     else {
1366       this->fPTmasks.fCBC[1] = kFALSE;
1367     }
1368     AliDebug(5, Form("CBB/PT/MASK/CB-C_1=%d", this->fPTmasks.fCBC[1]));
1369     return kTRUE;
1370   } 
1371   else if (identifier.Index("CBB/PT/MASK/CB-B_0") == 0) { // CB-B_0
1372     if (value.Index("YES") == 0) {
1373       this->fPTmasks.fLUTs[0] = kTRUE;     
1374     }
1375     else {
1376       this->fPTmasks.fLUTs[0] = kFALSE;
1377     }
1378     AliDebug(5, Form("CBB/PT/MASK/CB-B_0=%d",this->fPTmasks.fLUTs[0]));
1379     return kTRUE;
1380   }
1381   else if (identifier.Index("CBB/PT/MASK/CB-B_1") == 0) { // CB-B_1
1382     if (value.Index("YES") == 0) {
1383       this->fPTmasks.fLUTs[1] = kTRUE;     
1384     }
1385     else {
1386       this->fPTmasks.fLUTs[1] = kFALSE;
1387     }
1388     AliDebug(5, Form("CBB/PT/MASK/CB-B_1/=%d", this->fPTmasks.fLUTs[1]));
1389     return kTRUE;
1390   }
1391   else if (identifier.Index("CBB/PT/MASK/CB-B_2") == 0) { // CB-B_2
1392     if (value.Index("YES") == 0) {
1393       this->fPTmasks.fLUTs[2] = kTRUE;     
1394     }
1395     else {
1396       this->fPTmasks.fLUTs[2] = kFALSE;
1397     }
1398     AliDebug(5, Form("CBB/PT/MASK/CB-B_2/=%d", this->fPTmasks.fLUTs[2]));
1399     return kTRUE;
1400   }
1401   else if (identifier.Index("BB/PT/MASK/TLMU_") == 0) {
1402     TString indexStr = identifier(16, 1);
1403     Int_t index = indexStr.Atoi();
1404     if (value.Index("YES") == 0) {
1405       this->fPTmasks.fTLMU[index] = kTRUE;
1406     }
1407     else {
1408       this->fPTmasks.fTLMU[index] = kFALSE;
1409     }
1410     AliDebug(5, Form("CBB/PT/MASK/TLMU_%d=%d", index, 
1411                      this->fPTmasks.fTLMU[index]));
1412     return kTRUE;
1413   }
1414   return kTRUE;
1415 }
1416
1417 //______________________________________________________________________________
1418 Bool_t AliTRDptrgParam::ParseTLMU(TString identifier, TString value) {
1419   // Parse TLMU configuration
1420
1421   if (identifier.Index("TLMU/IMASK/SEC") == 0) {
1422     // TLMU input masks
1423     TString indexStr = identifier(14,2);
1424     Int_t index = indexStr.Atoi();
1425     if ((index < 0) || (index > 17)) {
1426       AliDebug(5, "Wrong section index in TLMU input mask");
1427       return kFALSE;
1428     }
1429     this->fTLMUInputMask[index] = BinaryTStringToInt(value);
1430     AliDebug(5, Form("%d %x\n", index, this->fTLMUInputMask[index]));
1431     return kTRUE;
1432   }
1433
1434   //-----------------------------------------------
1435   else if (identifier.Index("TLMU/CMATRIX") == 0) {
1436     // TLMU coincidence matrices
1437
1438     // matrix index
1439     TString matrixIndexStr = identifier(12,1);
1440     Int_t matrixIndex = matrixIndexStr.Atoi();
1441     // entry index
1442     TString indexStr = identifier(17,2);
1443     Int_t index = indexStr.Atoi();
1444     this->fTLMUcmatrices[matrixIndex][index] = BinaryTStringToInt(value);
1445     AliDebug(5, Form("%d 0x%x\n", matrixIndex, 
1446                      this->fTLMUcmatrices[matrixIndex][index]));
1447     return kTRUE;
1448   }
1449
1450   //---------------------------------------------
1451   else if (identifier.Index("TLMU/MCNTR") == 0) {
1452     // TLMU multiplicity counter setup
1453     
1454     TString indexStr = identifier(10,1);
1455     Int_t index = indexStr.Atoi();
1456     TObjArray arr;
1457
1458     SplitUpValues(value, arr);
1459     
1460     TString t0 = (dynamic_cast<TObjString*>(arr[0]))->GetString();
1461     TString t1 = (dynamic_cast<TObjString*>(arr[1]))->GetString();
1462   
1463     this->fTLMUmultiplicity[index][0] = t0.Atoi();
1464     this->fTLMUmultiplicity[index][1] = t1.Atoi();
1465  
1466     AliDebug(5, Form("%d: %d  %d", index, this->fTLMUmultiplicity[index][0], 
1467                      this->fTLMUmultiplicity[index][1]));      
1468
1469     return kTRUE;
1470   }
1471   
1472   //----------------------------------------------
1473   else if (identifier.Index("TLMU/OUTMUX") == 0) {
1474     // TLMU output signal assignment
1475     TObjArray arr;
1476     SplitUpValues(value, arr);
1477   
1478     if (arr.GetEntries() > 8) {
1479       AliError("Too many TLMU output signals assigned");
1480       return kFALSE;
1481     } 
1482   
1483     for (Int_t iEntry = 0; iEntry < arr.GetEntries(); iEntry++) {
1484       TString t = (dynamic_cast<TObjString*>(arr[iEntry]))->GetString(); 
1485       
1486       TString indexStr = t(2,1);
1487       if (t.Index("CM") == 0) { // coincidence matrix
1488         this->fTLMUoutput[iEntry][0] = indexStr.Atoi();
1489       }
1490       else if (t.Index("MC") == 0) { // multiplicity
1491         this->fTLMUoutput[iEntry][1] = indexStr.Atoi();
1492       }
1493       AliDebug(5, Form("TLMU output: cm = %d, mc = %d", 
1494                        this->fTLMUoutput[iEntry][0], 
1495                        this->fTLMUoutput[iEntry][1]));
1496     }
1497     return kTRUE;
1498   }
1499   return kTRUE;
1500 }
1501
1502 //______________________________________________________________________________
1503 //
1504 //       Logical Equation to LUT processing (helper functions)
1505 //______________________________________________________________________________
1506
1507 //______________________________________________________________________________
1508 Int_t AliTRDptrgParam::LookUp(TString* const identifier) const {
1509   // Transforms identifier into look up table address bit
1510   //
1511   // this function has to be extended/changed when different identifiers for
1512   // other equations and destination LUTs should be used
1513
1514   if (identifier->CompareTo("T0_0", TString::kIgnoreCase) == 0)  
1515     return 0x001;
1516   else if (identifier->CompareTo("T0_1", TString::kIgnoreCase) == 0) 
1517     return 0x002; 
1518   else if (identifier->CompareTo("V0-0_0", TString::kIgnoreCase) == 0) 
1519     return 0x004; 
1520   else if (identifier->CompareTo("V0-0_1", TString::kIgnoreCase) == 0) 
1521     return 0x008; 
1522   else if (identifier->CompareTo("V0-1_0", TString::kIgnoreCase) == 0) 
1523     return 0x010; 
1524   else if (identifier->CompareTo("V0-1_1", TString::kIgnoreCase) == 0) 
1525     return 0x020; 
1526   else if (identifier->CompareTo("V0-2_0", TString::kIgnoreCase) == 0) 
1527     return 0x040; 
1528   else if (identifier->CompareTo("V0-2_1", TString::kIgnoreCase) == 0) 
1529     return 0x080; 
1530   else if (identifier->CompareTo("V0-3_0", TString::kIgnoreCase) == 0) 
1531     return 0x100; 
1532   else if (identifier->CompareTo("V0-3_1", TString::kIgnoreCase) == 0) 
1533     return 0x200; 
1534   else if (identifier->CompareTo("CB-A_0", TString::kIgnoreCase) == 0) 
1535     return 0x001; 
1536   else if (identifier->CompareTo("CB-A_1", TString::kIgnoreCase) == 0) 
1537     return 0x002; 
1538   else if (identifier->CompareTo("CB-C_0", TString::kIgnoreCase) == 0) 
1539     return 0x004; 
1540   else if (identifier->CompareTo("CB-C_1", TString::kIgnoreCase) == 0) 
1541     return 0x008; 
1542   else if (identifier->CompareTo("TLMU_0", TString::kIgnoreCase) == 0)  
1543     return 0x010; 
1544   else if (identifier->CompareTo("TLMU_1", TString::kIgnoreCase) == 0) 
1545     return 0x020; 
1546   else if (identifier->CompareTo("TLMU_2", TString::kIgnoreCase) == 0) 
1547     return 0x040; 
1548   else if (identifier->CompareTo("TLMU_3", TString::kIgnoreCase) == 0) 
1549     return 0x080; 
1550   else if (identifier->CompareTo("TLMU_4", TString::kIgnoreCase) == 0) 
1551     return 0x100; 
1552   else if (identifier->CompareTo("TLMU_5", TString::kIgnoreCase) == 0) 
1553     return 0x200; 
1554   else if (identifier->CompareTo("TLMU_6", TString::kIgnoreCase) == 0) 
1555     return 0x400; 
1556   else if (identifier->CompareTo("TLMU_7", TString::kIgnoreCase) == 0) 
1557     return 0x800; 
1558   else return 0x0; // Error
1559 }
1560
1561 //______________________________________________________________________________
1562 void AliTRDptrgParam::MergeResults(TArrayI*& partResult1, TArrayI*& partResult2,
1563                                    TArrayI*& results,
1564                                    TArrayI*& signalsInvolved1, 
1565                                    TArrayI*& signalsInvolved2, 
1566                                    TArrayI*& signalsInvolved, 
1567                                    Bool_t useOR) {
1568   // merges result and signal involved arrays
1569   // uses logical OR (or=kTRUE) and AND (or==kFALSE) as merging function
1570   
1571   // check whether input data is valid
1572   if ((partResult1 == 0x0) || (partResult2 == 0x0) || 
1573       (signalsInvolved1 == 0x0) || (signalsInvolved2 == 0x0)) {
1574     AliError("fatal logical equation processing error!");
1575   }
1576  
1577   // allocate results and signalsInvolved 
1578   results = new TArrayI(0);    
1579   signalsInvolved = new TArrayI(0);
1580
1581   // merge arrays (necessary for OR and AND)
1582   for (Int_t i = 0; i < partResult1->GetSize(); i++) {
1583     for (Int_t j = 0; j < partResult2->GetSize(); j++) {
1584       results->Set(results->GetSize() + 1); // increment size
1585       (*results)[results->GetSize() - 1] =  // add combination
1586         (*partResult1)[i] | (*partResult2)[j];
1587  
1588       signalsInvolved->Set(signalsInvolved->GetSize() + 1);
1589       (*signalsInvolved)[signalsInvolved->GetSize() - 1] = 
1590          (*signalsInvolved1)[i] | (*signalsInvolved2)[j];
1591     }
1592   }
1593   
1594   if (useOR) { // only necessary for OR
1595     // add partResult1
1596     for (Int_t i = 0; i < partResult1->GetSize(); i++) {
1597       results->Set(results->GetSize() + 1);
1598       (*results)[results->GetSize() - 1] = (*partResult1)[i];
1599       
1600       signalsInvolved->Set(signalsInvolved->GetSize() + 1);
1601       (*signalsInvolved)[signalsInvolved->GetSize()-1] = (*signalsInvolved1)[i];
1602     }
1603     // add partResult2
1604     for (Int_t i = 0; i < partResult2->GetSize(); i++) {
1605       results->Set(results->GetSize() + 1);
1606       (*results)[results->GetSize() - 1] = (*partResult2)[i];
1607       
1608       signalsInvolved->Set(signalsInvolved->GetSize() + 1);
1609       (*signalsInvolved)[signalsInvolved->GetSize()-1] = (*signalsInvolved2)[i];
1610     }
1611   }
1612   
1613   // debug output
1614   AliDebug(5, "merging results: ");
1615   for (Int_t i = 0; i < results->GetSize(); i++) {
1616     AliDebug(5, Form("0x%x 0x%x", (*results)[i], (*signalsInvolved)[i]));
1617   }
1618
1619   // free memory
1620   delete partResult1;
1621   partResult1 = 0x0;
1622   delete partResult2;
1623   partResult2 = 0x0; 
1624 }
1625
1626 //______________________________________________________________________________
1627 void AliTRDptrgParam::ConvertLogicalEqToBitVectors(TString eq, 
1628                                                    TArrayI*& results,
1629                                                    TArrayI*& signalsInvolved) {
1630   // converts a logical equation to a LUT
1631   //
1632   // input string must not contain white spaces or tabs
1633   // only identifiers, ||, &&, (, ) and ! are allowed
1634   //
1635   // neglected signals are assumed to be zero in this function
1636   // this problem is solved by "void CheckSignalsInvolved(...)"
1637
1638   AliDebug(5, Form("eq: %s", eq.Data()));
1639
1640   // temporary variables used before/while merging
1641   TArrayI* partResult1 = 0x0;
1642   TArrayI* partResult2 = 0x0;
1643   TArrayI* partResult3 = 0x0;
1644   TArrayI* partResult4 = 0x0;
1645   TArrayI* signalsInvolved1 = 0x0;
1646   TArrayI* signalsInvolved2 = 0x0;
1647   TArrayI* signalsInvolved3 = 0x0;
1648   TArrayI* signalsInvolved4 = 0x0;
1649  
1650   Int_t iChar = 0; // counter variable
1651   
1652   // variables needed for correct operator order (&& before ||!)
1653   Int_t foundORbefore = -1; // found an || in that string (-1 = not found)
1654   Int_t foundAND = -1; // found an &&
1655   Int_t foundORafter = -1; // found a second OR after &&
1656
1657   // variables needed for correct bracket processing
1658   Int_t enteredBrackets = 0; // indicates in which bracket layer the parser is
1659   Int_t bracketLevelAtZero = -1; // when enteredBrackets = 0 was reached first
1660   // after it ascended  
1661
1662   while ((iChar < eq.Length())) { //--------------------------------------------
1663     // walk through string
1664
1665     // operators ---------------------------------------------------------------
1666     if ((enteredBrackets == 0 ) && (eq[iChar] != '(') && (eq[iChar] != ')'))  {
1667       // '|'
1668       if (eq[iChar] == '|') {
1669         if (eq[iChar + 1] == '|') { // ||
1670           iChar++; // jump to the next charakter
1671           if (foundAND == -1) {
1672             foundORbefore = iChar;
1673           }
1674           else if ((foundORafter == -1) && (foundAND != -1)) {
1675             foundORafter = iChar;
1676           }
1677         }
1678         else { // bit-wise and not supported
1679           AliError(Form("LogicalEquation incorrect: %s", eq.Data()));
1680           AliError("bit-wise AND (&) not supported for now");
1681           return;
1682         }
1683       }
1684       // '&' 
1685       else if (eq[iChar] == '&') {
1686         if (eq[iChar] == '&') { // ||
1687           iChar++; // jump to the next charakter
1688           if (foundAND == -1) {
1689             foundAND = iChar;
1690           }
1691         }
1692         else { // bit-wise or not supported
1693           AliError(Form("LogicalEquation incorrect: %s", eq.Data()));
1694           AliError("bit-wise OR (|) not supported for now");
1695           return;
1696         }
1697       }
1698     }
1699     // brackets ----------------------------------------------------------------
1700     // '(' 
1701     if (eq[iChar] == '(') {
1702       enteredBrackets++;      
1703     }
1704     // ')' 
1705     else if (eq[iChar] == ')') {
1706       enteredBrackets--;
1707       if (enteredBrackets < 0) {        
1708         AliError(Form("LogicalEquation incorrect: %s", eq.Data()));     
1709         AliError("Too many )s");
1710       }
1711       if ((enteredBrackets == 0) && (bracketLevelAtZero == -1) &&
1712           (foundAND == -1) && (foundORbefore == -1)) {
1713         // needed to detected equations encapsulated in brackets: (...)
1714         bracketLevelAtZero = iChar;
1715       }
1716     }      
1717     iChar++; // go on to the next letter/char
1718   } //--------------------------------------------------------------------------
1719
1720   if (bracketLevelAtZero == (eq.Length() - 1)) { // strip ( ) and process again
1721     ConvertLogicalEqToBitVectors(eq(1, eq.Length() -2), results, 
1722                                  signalsInvolved);
1723     return;     
1724   }
1725   else if (foundAND == -1) { // no AND
1726     if (foundORbefore != -1) { // only OR / || found and no AND
1727       ConvertLogicalEqToBitVectors(eq(0, foundORbefore-1), partResult1, 
1728                                    signalsInvolved1); 
1729       ConvertLogicalEqToBitVectors(eq(foundORbefore+1, 
1730                                       eq.Length()-foundORbefore-1),
1731                                    partResult2, signalsInvolved2);
1732       
1733       MergeResults(partResult1, partResult2, results, signalsInvolved1,
1734                    signalsInvolved2, signalsInvolved, kTRUE);
1735       return;
1736     } 
1737     else { // only identifier remained!
1738       results = new TArrayI(1);
1739       signalsInvolved = new TArrayI(1);
1740       if (eq[0] != '!') { // identifier without negation
1741         (*results)[0] = LookUp(&eq); 
1742         (*signalsInvolved)[0] = (*results)[0];
1743       }
1744       else { // identifier with negation
1745         (*results)[0] = 0;
1746         TString eqNegated = eq(1, eq.Length()-1);
1747         (*signalsInvolved)[0] = LookUp(&eqNegated);
1748       } 
1749       return;
1750     }
1751   }
1752   // found single or multiple AND / && 
1753   else if ((foundORafter != -1) && (foundORbefore != -1)) { 
1754     // found: ...||...&&...||...   
1755     ConvertLogicalEqToBitVectors(eq(0, foundORbefore-1), partResult1, 
1756                                  signalsInvolved1);
1757     ConvertLogicalEqToBitVectors(eq(foundORbefore+1, 
1758                                     foundORafter-foundORbefore-2),
1759                                  partResult2, signalsInvolved2);
1760     ConvertLogicalEqToBitVectors(eq(foundORafter+1, eq.Length()-foundORafter-1),
1761                                  partResult3, signalsInvolved3);
1762
1763     // merge: 4 = 1 || 2 
1764     MergeResults(partResult1, partResult2, partResult4, signalsInvolved1,
1765                  signalsInvolved2, signalsInvolved4, kTRUE);
1766     // merge results = 3 || 4
1767     MergeResults(partResult3, partResult4, results, signalsInvolved3,
1768                  signalsInvolved4, signalsInvolved, kTRUE);
1769     return;
1770   } 
1771   else if (foundORbefore != -1) { 
1772     // found ...||...&&...
1773     ConvertLogicalEqToBitVectors(eq(0, foundORbefore - 1), partResult1, 
1774                                  signalsInvolved1); 
1775     ConvertLogicalEqToBitVectors(eq(foundORbefore+1, 
1776                                     eq.Length()-foundORbefore-1),
1777                                  partResult2, signalsInvolved2);
1778    
1779     MergeResults(partResult1, partResult2, results, signalsInvolved1,
1780                  signalsInvolved2, signalsInvolved, kTRUE);
1781     return;
1782   }
1783   else if (foundORafter != -1) {
1784     // found  ...&&...||...
1785     ConvertLogicalEqToBitVectors(eq(0, foundORafter - 1), partResult1, 
1786                                  signalsInvolved1); 
1787     ConvertLogicalEqToBitVectors(eq(foundORafter+1, 
1788                                     eq.Length()-foundORafter-1),
1789                                  partResult2, signalsInvolved2);
1790    
1791     MergeResults(partResult1, partResult2, results, signalsInvolved1,
1792                  signalsInvolved2, signalsInvolved, kTRUE);
1793     return;
1794   }
1795   else /* if (foundAND != -1)*/ { // found ...&&...
1796     ConvertLogicalEqToBitVectors(eq(0, foundAND-1), partResult1, 
1797                                  signalsInvolved1); 
1798     ConvertLogicalEqToBitVectors(eq(foundAND+1, eq.Length()-foundAND-1), 
1799                                  partResult2, signalsInvolved2); 
1800
1801     MergeResults(partResult1, partResult2, results, signalsInvolved1,
1802                  signalsInvolved2, signalsInvolved, kFALSE);    
1803     return;
1804   }
1805   
1806   AliError("Logical equation parser error!");
1807   return;
1808 }
1809
1810 //______________________________________________________________________________
1811 void AliTRDptrgParam::CheckSignalsInvolved(TArrayI*& results, 
1812                                            TArrayI*& signalsInvolved,
1813                                            Int_t inputWidth) {
1814   // checks whether all input signals are taken into account
1815   //
1816   // this function is needed to be able to write equations which contain not all
1817   // possible signals and which are not mentioned in the equation do not effect
1818   // the result
1819   // X=B&&C=(A||!A)&&B&&C
1820
1821   // this routine is quite inefficient but working O((2^inputWidth)^3)
1822
1823   // generate mask:
1824   Int_t temp = 0x1;
1825   Int_t mask = 0x0;
1826   for (Int_t iSignal = 0; iSignal < inputWidth; iSignal++) {
1827     mask |= temp;
1828     temp <<= 1; // move temp to the next bit 
1829   }
1830   
1831   for (Int_t iResult = 0; iResult < results->GetSize(); iResult++) {
1832     // tricky: size of results increases while loop is iterating
1833     // that is needed to generate all valid input signal combinations
1834     if (mask != (*signalsInvolved)[iResult]) {
1835       // not all input signals are taken into account
1836       Int_t inputSignal = 0x1;
1837       for (Int_t iSignal = 0; iSignal < inputWidth; iSignal++) {
1838         if (!(inputSignal & (*signalsInvolved)[iResult])) {
1839           Int_t newInvolvedSignalCombination = 
1840             (*signalsInvolved)[iResult] | inputSignal;
1841           Int_t newResult = inputSignal | (*results)[iResult];
1842           Bool_t signalCombinationAlreadyEnlisted = kFALSE;
1843           for (Int_t iEntry = 0; iEntry < signalsInvolved->GetSize(); iEntry++){
1844             // this loop is needed to reduce the amount of equal entries in 
1845             // signalsInvolved
1846             // maybe a table with all possible input values could reduce the
1847             // computional effort, but this would consume a lot of ram
1848             if ((signalsInvolved->At(iEntry) == newInvolvedSignalCombination) &&
1849                 (results->At(iEntry) == newResult)) {
1850               signalCombinationAlreadyEnlisted = kTRUE;
1851               break;
1852             }
1853           }
1854           if (!signalCombinationAlreadyEnlisted) {
1855             results->Set(results->GetSize() + 1);
1856             (*results)[results->GetSize() - 1] = inputSignal | 
1857                                                  (*results)[iResult];
1858             // add variant with active bit, variant with inactive signal
1859             // is already containt in the results array
1860
1861             // update signalsInvolved:
1862             signalsInvolved->Set(signalsInvolved->GetSize() + 1);
1863             (*signalsInvolved)[signalsInvolved->GetSize() - 1] =
1864               (*signalsInvolved)[iResult] | inputSignal;
1865           }
1866         }
1867         inputSignal <<= 1; // move temp to the next input signal      
1868       }      
1869     }
1870   }
1871   return;
1872 }
1873
1874 //______________________________________________________________________________
1875 Int_t* AliTRDptrgParam::GenerateLUTbasedOnEq(TString eq, Int_t inputWidth, 
1876                                              Int_t initValue) {
1877   // Processes the conversion of a logical equation to a look up table
1878   
1879   TArrayI* results = 0x0;
1880   TArrayI* signalsInvolved = 0x0;
1881  
1882   ConvertLogicalEqToBitVectors(eq, results, signalsInvolved);
1883   // generate bit vectors
1884
1885   CheckSignalsInvolved(results, signalsInvolved, inputWidth);
1886   // add bit vectors for signals which are not taken into account
1887
1888   Int_t lutSize =  0x1 << inputWidth; // 2^inputwidth elements
1889   Int_t* resultingLUT = new Int_t[lutSize]; // create LUT
1890   for (Int_t iLUTentry = 0; iLUTentry < lutSize; iLUTentry++) { // init LUT
1891     resultingLUT[iLUTentry] = 0;
1892   }
1893   for (Int_t iEntry = 0; iEntry < results->GetSize(); iEntry++) {
1894     resultingLUT[(*results)[iEntry]] = initValue;
1895   }
1896   
1897   if (results != 0x0) {
1898     delete results;
1899     results = 0x0;
1900   }
1901   if (signalsInvolved != 0x0) {
1902     delete signalsInvolved;
1903     signalsInvolved = 0x0;
1904   }
1905   
1906   return resultingLUT;
1907 }
1908
1909 //______________________________________________________________________________
1910 //___ GETTER FUNCTIONS__________________________________________________________
1911 //______________________________________________________________________________
1912 UInt_t* AliTRDptrgParam::GetFEBT0Thresholds(AliTRDptrgFEBPosition_t FEBposition)
1913   const
1914 {
1915   // get T0 FEB Thresholds
1916   return this->fFEBT0Thresholds[FEBposition - 1];
1917   // 0 kB, 1= kA, 2, kC => -1 because T0FEBs are only in position kA and kC
1918 }
1919
1920 //_____________________________________________________________________________
1921 Int_t* AliTRDptrgParam::GetFEBT0LUT(AliTRDptrgFEBPosition_t FEBposition, 
1922                                     Int_t iLUT) {
1923   // get T0 FEB LUTs
1924   if (this->fFEBT0LUTs == 0x0) {
1925     this->GenerateLUTs();
1926   }
1927   return this->fFEBT0LUTs[FEBposition - 1][iLUT]; 
1928   // 0 kB, 1= kA, 2, kC => -1 because T0FEBs are only in position kA and kC
1929
1930
1931 //______________________________________________________________________________
1932 UInt_t* AliTRDptrgParam::GetFEBV0Thresholds(AliTRDptrgFEBPosition_t FEBposition,
1933                                            Int_t iCard) const {
1934   // get V0 FEB Thresholds
1935   return this->fFEBV0Thresholds[FEBposition - 1][iCard];
1936   // 0 kB, 1= kA, 2, kC => -1 because T0FEBs are only in position kA and kC
1937 }
1938
1939 //______________________________________________________________________________
1940 Int_t* AliTRDptrgParam::GetFEBV0LUT(AliTRDptrgFEBPosition_t FEBposition, 
1941                                     Int_t iCard, Int_t iLUT) {
1942   // get V0 FEB LUTs
1943   if (this->fFEBV0LUTs == 0x0) {
1944     this->GenerateLUTs();
1945   }
1946   return this->fFEBV0LUTs[FEBposition - 1][iCard][iLUT];
1947   // 0 kB, 1= kA, 2, kC => -1 because T0FEBs are only in position kA and kC
1948 }
1949
1950 //______________________________________________________________________________
1951 Int_t* AliTRDptrgParam::GetCBLUT(UInt_t iCB, Int_t LUTid) {
1952   // return control box LUT
1953   // iCB: 0 = B, 1 = A, 2 = C
1954   if (this->fCBLUTs == 0x0) {
1955     this->GenerateLUTs();
1956   }
1957   return this->fCBLUTs[iCB][LUTid];
1958 }
1959