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