]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDptrgCBAC.cxx
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / TRD / AliTRDptrgCBAC.cxx
index c5f8862ad09ca9e305c5f12116882277ca592bff..be1d722adbf0da3ed1fb8b8993c250e8e3df7fd7 100644 (file)
@@ -44,18 +44,22 @@ AliTRDptrgCBAC::AliTRDptrgCBAC(AliRunLoader *rl)
   fRunLoader(rl),
   fLUTArray(),
   fFEBArray(),
-  fPosition(kUnknown),
-  fOperatingMode(kDigits),
+  fPosition(AliTRDptrgParam::kUnknown),
+  fOperatingMode(AliTRDptrgParam::kDigits),
   fParam(0x0)
 {
+  //
   // ctor
+  //
+
   AliError("default ctor - usage not recommended");
+
 }
 
 //______________________________________________________________________________
 AliTRDptrgCBAC::AliTRDptrgCBAC(AliRunLoader *rl, 
-                               AliTRDptrgFEBPosition_t position,
-                               AliTRDptrgOperatingMode_t operatingMode,
+                               AliTRDptrgParam::AliTRDptrgFEBPosition_t position,
+                               AliTRDptrgParam::AliTRDptrgOperatingMode_t operatingMode,
                                AliTRDptrgParam *param) 
   : TObject(),
   fRunLoader(rl),
@@ -65,32 +69,35 @@ AliTRDptrgCBAC::AliTRDptrgCBAC(AliRunLoader *rl,
   fOperatingMode(operatingMode),
   fParam(param)
 {
+  //
   // ctor  
+  //
+
   this->LoadParams(); // load parameters
  
   // T0
-  AliTRDptrgFEB *FEB = new AliTRDptrgFEB(this->fRunLoader, kTZERO, 
+  AliTRDptrgFEB *FEB = new AliTRDptrgFEB(this->fRunLoader, AliTRDptrgParam::kTZERO, 
                                          this->fOperatingMode, this->fPosition,
                                          0, this->fParam);
   this->fFEBArray.AddLast(FEB);
 
   // V0-1
-  FEB = new AliTRDptrgFEB(this->fRunLoader, kVZERO, this->fOperatingMode, 
+  FEB = new AliTRDptrgFEB(this->fRunLoader, AliTRDptrgParam::kVZERO, this->fOperatingMode, 
                           this->fPosition, 1, this->fParam);
   this->fFEBArray.AddLast(FEB);
 
   // V0-2
-  FEB = new AliTRDptrgFEB(this->fRunLoader, kVZERO, this->fOperatingMode, 
+  FEB = new AliTRDptrgFEB(this->fRunLoader, AliTRDptrgParam::kVZERO, this->fOperatingMode, 
                           this->fPosition, 2, this->fParam);
   this->fFEBArray.AddLast(FEB);
 
   // V0-3
-  FEB = new AliTRDptrgFEB(this->fRunLoader, kVZERO, this->fOperatingMode, 
+  FEB = new AliTRDptrgFEB(this->fRunLoader, AliTRDptrgParam::kVZERO, this->fOperatingMode, 
                           this->fPosition, 3, this->fParam);
   this->fFEBArray.AddLast(FEB);
 
   // V0-4
-  FEB = new AliTRDptrgFEB(this->fRunLoader, kVZERO, this->fOperatingMode, 
+  FEB = new AliTRDptrgFEB(this->fRunLoader, AliTRDptrgParam::kVZERO, this->fOperatingMode, 
                           this->fPosition, 4, this->fParam);
   this->fFEBArray.AddLast(FEB);
 
@@ -99,59 +106,73 @@ AliTRDptrgCBAC::AliTRDptrgCBAC(AliRunLoader *rl,
 //______________________________________________________________________________
 Bool_t AliTRDptrgCBAC::LoadParams() 
 {
-  // load configuration parameters
+  //
+  // Load configuration parameters
+  //
 
   if (this->fParam != 0x0) {
     // read AliTRDptrgParam
 
     // get LUTs
-    AliTRDptrgLUT* LUT = new AliTRDptrgLUT();
+    AliTRDptrgLUT* lut = 0x0;
     // 0
-    LUT = new AliTRDptrgLUT();
-    LUT->InitTable(10, 10, this->fParam->GetCBLUT(this->fPosition, 0), kFALSE); 
+    lut = new AliTRDptrgLUT();
+    lut->InitTable(10, 10, this->fParam->GetCBLUT(this->fPosition, 0), kFALSE); 
     // do not copy table data 
-    this->fLUTArray.AddLast(LUT);
+    this->fLUTArray.AddLast(lut);
     // 1
-    LUT = new AliTRDptrgLUT();
-    LUT->InitTable(10, 10, this->fParam->GetCBLUT(this->fPosition, 1), kFALSE); 
-    // do not copy table data // TODO 0x0
-    this->fLUTArray.AddLast(LUT);
+    lut = new AliTRDptrgLUT();
+    lut->InitTable(10, 10, this->fParam->GetCBLUT(this->fPosition, 1), kFALSE); 
+    // do not copy table data 
+    this->fLUTArray.AddLast(lut);
   }
   else {
     // load default parameters 
-    AliTRDptrgLUT* LUT = new AliTRDptrgLUT();
-    this->fLUTArray.AddLast(LUT);
-    LUT = new AliTRDptrgLUT();
-    this->fLUTArray.AddLast(LUT);
-               // the following lines are only needed for test reasons
-    LUT = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(0));
-    Int_t* initData = new Int_t[1024]; // 2^10
-    for (Int_t i = 0; i < 1024; i++ ) {
-      initData[i] = i;
-    }
-    LUT->InitTable(10, 10, initData, kTRUE); // copy initData
-    LUT = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(1));
-    for (Int_t i = 1023; i >= 0; i--) {
-      initData[31 - i] = i;  // inverse ramp
+    AliTRDptrgLUT* lut = new AliTRDptrgLUT();
+    this->fLUTArray.AddLast(lut);
+    lut = new AliTRDptrgLUT();
+    this->fLUTArray.AddLast(lut);
+    // the following lines are only needed for test reasons
+    lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(0));
+    if (lut) {
+      Int_t* initData = new Int_t[1024]; // 2^10
+      for (Int_t i = 0; i < 1024; i++ ) {
+        initData[i] = i;
+      }
+      lut->InitTable(10, 10, initData, kTRUE); // copy initData
+      lut = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray.At(1));
+      if (lut) {
+        for (Int_t i = 1023; i >= 0; i--) {
+          initData[31 - i] = i;  // inverse ramp
+        }
+        lut->InitTable(10, 10, initData, kTRUE); // copy initData
+      }
     }
-    LUT->InitTable(10, 10, initData, kTRUE); // copy initData
   }  
+
   return false;
+
 }
 
 //______________________________________________________________________________
 AliTRDptrgCBAC::~AliTRDptrgCBAC() 
 {
-  // destructor
+  //
+  // Destructor
+  //
 
   this->fLUTArray.Delete();
   this->fFEBArray.Delete();
+
 }
 
 //______________________________________________________________________________
 Int_t* AliTRDptrgCBAC::Simulate()
-{ // TODO check new/delete
+{ 
+  //
   // Simulate the CBAC behavior of event
+  //
+
   Int_t nFEBs = this->fFEBArray.GetEntries();
   Int_t nLUTs = this->fLUTArray.GetEntries();
 
@@ -160,10 +181,11 @@ Int_t* AliTRDptrgCBAC::Simulate()
   Int_t** partResults = 0x0;  
   partResults = new Int_t* [nFEBs];
 
-
   for (Int_t iFEB = 0; iFEB < nFEBs; iFEB++) {
-    partResults[iFEB] = 
-      dynamic_cast<AliTRDptrgFEB*>(this->fFEBArray.At(iFEB))->Simulate();
+    AliTRDptrgFEB *feb = 0x0;
+    if ((feb = dynamic_cast<AliTRDptrgFEB*>(this->fFEBArray.At(iFEB)))) {
+      partResults[iFEB] = feb->Simulate();
+    }
   }
   
   // combine partResults and create inputVector  
@@ -171,19 +193,21 @@ Int_t* AliTRDptrgCBAC::Simulate()
   Int_t mask = 0x1;
   for (Int_t iFEB = 0; iFEB < nFEBs ; iFEB++) {
     for (Int_t j = 1; j <= partResults[iFEB][0]; j++) {
-      if ((iBit++ >
-           dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray[0])->GetInputWidth()) 
-          || (iBit++ >
-           dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray[0])->GetInputWidth())) {
-        AliError("FEB result width does not match CB-A/C input with!");
+      AliTRDptrgLUT *lut0 = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray[0]);
+      AliTRDptrgLUT *lut1 = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray[1]);
+      if (lut0 && lut1) {
+        if ((iBit > lut0->GetInputWidth()) 
+         || (iBit > lut1->GetInputWidth())) {
+          AliError("FEB result width does not match CB-A/C input with!");
+       }
       }
+      iBit++;
       if (partResults[iFEB][j] > 0) {
         inputVector |= mask; // Add bit to the corresponding inputVector
         mask <<= 1;
       } 
     }
   }
-  
 
   AliDebug(5, Form("Inputvector: 0x%x", inputVector));
     
@@ -192,13 +216,18 @@ Int_t* AliTRDptrgCBAC::Simulate()
   result[0] = nLUTs; // storage array length in the first array value
   for (Int_t iLUT = 0; iLUT < nLUTs; iLUT++) { 
     // process the return value for each LUT and store the result in the array
-    result[iLUT + 1] = 
-      dynamic_cast<AliTRDptrgLUT*>(
-        this->fLUTArray[iLUT])->LookUp(inputVector);
+    AliTRDptrgLUT *lutTmp = 0x0;
+    if ((lutTmp = dynamic_cast<AliTRDptrgLUT*>(this->fLUTArray[iLUT]))) {
+      result[iLUT + 1] = lutTmp->LookUp(inputVector);
+    }
     AliDebug(4, Form("CBAC result[%d] = 0x%x",(iLUT + 1),result[iLUT + 1])); 
   }
 
+  // Clean up
+  delete [] partResults;
+
   return result;
+
 }