]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFRawStream.cxx
some coverity fixes
[u/mrichter/AliRoot.git] / TOF / AliTOFRawStream.cxx
index d8a6a1cc0bc110aa2e7df262645282e61e5aa9db..b46291de47047b98093c66336c7844e39ebed0a9 100644 (file)
 
 /*
 $Log$
+
+Added lookup tables for
+         TRM number 3 in the left crates (TOF OR signals)
+         and detector elements (A.Silenzi)
+
 Revision 1.19.1  2008/09/19  preghenella
   Decode method updated:
   it reads the CDH from the rawReader and sends it to the decoder;
@@ -121,6 +126,16 @@ Revision 0.01  2005/07/22 A. De Caro
 #include "AliRawEventHeaderBase.h"
 #include "AliRawDataHeader.h"
 
+#include "AliTOFDecoderV2.h"
+#include "AliTOFTDCHit.h"
+#include "AliTOFDecoderSummaryData.h"
+#include "AliTOFDRMSummaryData.h"
+#include "AliTOFLTMSummaryData.h"
+#include "AliTOFTRMSummaryData.h"
+#include "AliTOFChainSummaryData.h"
+#include "AliTOFTDCHitBuffer.h"
+#include "AliTOFTDCErrorBuffer.h"
+
 ClassImp(AliTOFRawStream)
 
 const Int_t AliTOFRawStream::fgkddlBCshift[72] = 
@@ -145,12 +160,81 @@ const Int_t AliTOFRawStream::fgkddlBCshift[72] =
   0, 0, 0, 0
 };
 
+const Int_t AliTOFRawStream::fgkStrip0MapCrate0[]=
+  {1,3,5,7,9,11,13,15,17,0,2,4,6,8,10,12,14,16,18,1,3,5,7,-1};
+const Int_t AliTOFRawStream::fgkStrip1MapCrate0[]=
+  {0,2,4,6,8,10,12,14,16,18,1,3,5,7,9,11,13,15,17,0,2,4,6,-1};
+const Int_t AliTOFRawStream::fgkStrip0MapCrate1[]=
+  {1,3,5,7,9,11,13,15,17,0,2,4,6,8,10,12,14,16,18,1,3,5,7,-1};
+const Int_t AliTOFRawStream::fgkStrip1MapCrate1[]=
+  {0,2,4,6,8,10,12,14,16,18,1,3,5,7,9,11,13,15,17,0,2,4,6,-1};
+const Int_t AliTOFRawStream::fgkStrip0MapCrate2[]=
+  {17,15,13,11, 9,7,5,3,1,18,16,14,12,10,8,6,4,2, 0,13,11, 9,7,-1};
+const Int_t AliTOFRawStream::fgkStrip1MapCrate2[]=
+  {18,16,14,12,10,8,6,4,2, 0,17,15,13,11,9,7,5,3, 1,14,12,10,8,-1};
+const Int_t AliTOFRawStream::fgkStrip0MapCrate3[]=
+  {17,15,13,11, 9,7,5,3,1,18,16,14,12,10,8,6,4,2, 0,13,11, 9,7,-1};
+const Int_t AliTOFRawStream::fgkStrip1MapCrate3[]=
+  {18,16,14,12,10,8,6,4,2, 0,17,15,13,11,9,7,5,3, 1,14,12,10,8,-1};
+
+
+const Int_t AliTOFRawStream::fgkModule0MapCrate0[]=
+  {0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,2,-1};
+const Int_t AliTOFRawStream::fgkModule1MapCrate0[]=
+  {0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,-1};
+const Int_t AliTOFRawStream::fgkModule0MapCrate1[]=
+  {0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,2,-1};
+const Int_t AliTOFRawStream::fgkModule1MapCrate1[]=
+  {0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,-1};
+
+const Int_t AliTOFRawStream::fgkModule0MapCrate2[]=
+  {4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,2,2,2,2,-1};
+const Int_t AliTOFRawStream::fgkModule1MapCrate2[]=
+  {4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,2,2,2,2,-1};
+const Int_t AliTOFRawStream::fgkModule0MapCrate3[]=
+  {4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,2,2,2,2,-1};
+const Int_t AliTOFRawStream::fgkModule1MapCrate3[]=
+  {4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,2,2,2,2,-1};
+
+const Int_t AliTOFRawStream::fgkChannelMap0[5][19]=
+  {{0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9},
+   {9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18},
+   {19,19,20,20,21,21,22,22,22,21,21,20,20,19,19,-1,-1,-1,-1},
+   {18,18,17,17,16,16,15,15,14,14,13,13,12,12,11,11,10,10,9},
+   {9,8,8,7,7,6,6,5,5,4,4,3,3,2,2,1,1,0,0}
+  };
+
+const Int_t AliTOFRawStream::fgkChainMap0[5][19]=
+  {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+   {0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,-1,-1,-1,-1},
+   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
+   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
+  };
+
+const Int_t AliTOFRawStream::fgkChannelMap24[5][19]=
+  {{0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9},
+   {9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18},
+   {19,19,20,20,21,21,22,22,22,21,21,20,20,19,19,-1,-1,-1,-1},
+   {18,18,17,17,16,16,15,15,14,14,13,13,12,12,11,11,10,10,9},
+   {9,8,8,7,7,6,6,5,5,4,4,3,3,2,2,1,1,0,0}
+  };
+
+const Int_t AliTOFRawStream::fgkChainMap24[5][19]=
+  {{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
+   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
+   {1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,-1,-1,-1,-1},
+   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
+  };
+
 Bool_t AliTOFRawStream::fgApplyBCCorrections = kTRUE;
 //_____________________________________________________________________________
 AliTOFRawStream::AliTOFRawStream(AliRawReader* rawReader):
   fRawReader(rawReader),
   fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
   fDecoder(new AliTOFDecoder()),
+  fDecoderV2(new AliTOFDecoderV2()),
   fDDL(-1),
   fTRM(-1),
   fTRMchain(-1),
@@ -218,6 +302,7 @@ AliTOFRawStream::AliTOFRawStream():
   fRawReader(0x0),
   fTOFrawData(new TClonesArray("AliTOFrawData",1000)),
   fDecoder(new AliTOFDecoder()),
+  fDecoderV2(new AliTOFDecoderV2()),
   fDDL(-1),
   fTRM(-1),
   fTRMchain(-1),
@@ -282,6 +367,7 @@ AliTOFRawStream::AliTOFRawStream(const AliTOFRawStream& stream) :
   fRawReader(stream.fRawReader),
   fTOFrawData(stream.fTOFrawData),
   fDecoder(new AliTOFDecoder()),
+  fDecoderV2(new AliTOFDecoderV2()),
   fDDL(stream.fDDL),
   fTRM(stream.fTRM),
   fTRMchain(stream.fTRMchain),
@@ -385,7 +471,7 @@ AliTOFRawStream& AliTOFRawStream::operator = (const AliTOFRawStream& stream)
   fInsideLTM = stream.fInsideLTM;
   fInsideTRMchain0 = stream.fInsideTRMchain0;
   fInsideTRMchain1 = stream.fInsideTRMchain1;
-  
+
   for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){ 
     fDataBuffer[i] = stream.fDataBuffer[i];
     fPackedDataBuffer[i] = stream.fPackedDataBuffer[i];
@@ -415,14 +501,16 @@ AliTOFRawStream& AliTOFRawStream::operator = (const AliTOFRawStream& stream)
 //_____________________________________________________________________________
 AliTOFRawStream::~AliTOFRawStream()
 {
-// destructor
+  // destructor
 
   fPackedDigits = 0;
-
   delete fDecoder;
-
-  fTOFrawData->Clear();
-  delete fTOFrawData;
+  delete fDecoderV2;
+  
+  if (fTOFrawData) {
+    fTOFrawData->Clear("C");
+    delete fTOFrawData;
+  }
 
   //delete fCableLengthMap;
 
@@ -446,8 +534,8 @@ void AliTOFRawStream::LoadRawData(Int_t indexDDL)
   fPackedDigits = 0;
 
   // create raw data map
-  AliTOFRawMap *rawMap = new AliTOFRawMap(fTOFrawData);
-  rawMap->Clear();
+  AliTOFRawMap rawMap(fTOFrawData);
+  rawMap.Clear();
 
   Int_t slot[4] = {-1, -1, -1, -1};
 
@@ -479,9 +567,9 @@ void AliTOFRawStream::LoadRawData(Int_t indexDDL)
       slot[2] = fTDC;
       slot[3] = fTDCchannel;
 
-      if (rawMap->TestHit(slot) != kEmpty) {
+      if (rawMap.TestHit(slot) != kEmpty) {
 
-       rawDigit = static_cast<AliTOFrawData*>(rawMap->GetHit(slot));
+       rawDigit = static_cast<AliTOFrawData*>(rawMap.GetHit(slot));
 
        if (rawDigit->GetLeading()!=-1 && rawDigit->GetTrailing()==-1 &&
            fLeadingEdge==-1 && fTrailingEdge!=-1) {
@@ -496,7 +584,7 @@ void AliTOFRawStream::LoadRawData(Int_t indexDDL)
 
            new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
 
-           rawMap->SetHit(slot);
+           rawMap.SetHit(slot);
 
          }
 
@@ -506,16 +594,14 @@ void AliTOFRawStream::LoadRawData(Int_t indexDDL)
 
        new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(fTRM, fTRMchain, fTDC, fTDCchannel, fTime, fToT, fLeadingEdge, fTrailingEdge, fPSbit, fACQ, fErrorFlag);
 
-       rawMap->SetHit(slot);
+       rawMap.SetHit(slot);
 
-      } // else if (rawMap->TestHit(slot) == kEmpty)
+      } // else if (rawMap.TestHit(slot) == kEmpty)
 
     } // if (signal)
 
   } // closed -> while (Next())
 
-  rawMap->Delete();
-
 }
 
 //_____________________________________________________________________________
@@ -545,6 +631,11 @@ Bool_t AliTOFRawStream::Next()
   }
 
   fDDL  = fRawReader->GetDDLID();
+  if (fDDL==-1) {
+    fRawReader->AddMajorErrorLog(kDDLdataReading);
+    AliWarning("Error when load DDL. Go to next DDL");
+    return kFALSE;
+  }
 
   fWordType = GetField(data,WORD_TYPE_MASK,WORD_TYPE_POSITION);
 
@@ -938,7 +1029,7 @@ void AliTOFRawStream::SetPadX()
 Int_t AliTOFRawStream::GetField(UInt_t word, Int_t fieldMask, Int_t fieldPosition) const
 {
   // 
-  // 
+  // Returns 'word' masked by 'fieldMask' and shifted by 'fieldPosition'
   // 
 
   return ((word & fieldMask) >> fieldPosition);
@@ -1160,7 +1251,7 @@ Int_t AliTOFRawStream::Equip2VolNpad(Int_t iDDL, Int_t iChain, Int_t nTDC,
 
   if (((iDDL==1 || iDDL==2) && iPadAlongTheStrip< AliTOFGeometry::NpadX()) ||
       ((iDDL==0 || iDDL==3) && iPadAlongTheStrip>=AliTOFGeometry::NpadX())) {
-    std::cerr << "Warning -> AliTOFRawStream::Equip2VolNpad: Problems with the padX number!" << endl;
+    std::cerr << "Warning -> AliTOFRawStream::Equip2VolNpad: Problems with the padX number!\n";
     //AliWarning("Problems with the padX number!");
   }
   return iPadAlongTheStrip;
@@ -1240,8 +1331,8 @@ void AliTOFRawStream::EquipmentId2VolumeId(AliTOFHitData *hitData, Int_t *volume
 }
 //----------------------------------------------------------------------------
 void AliTOFRawStream::EquipmentId2VolumeId(Int_t nDDL, Int_t nTRM, Int_t iChain,
-                                       Int_t nTDC, Int_t iCH,
-                                       Int_t *volume)
+                                          Int_t nTDC, Int_t iCH,
+                                          Int_t *volume)
 {
   //
   // To convert:
@@ -1274,24 +1365,24 @@ void AliTOFRawStream::EquipmentId2VolumeId(Int_t nDDL, Int_t nTRM, Int_t iChain,
   if (iPlate==-1) {
     /*if (fRawReader)
       fRawReader->AddMajorErrorLog(kPlateError,"plate = -1");*/
-    printf("Warning -> AliTOFRawStream::EquipmentId2VolumeId: Problems with the plate number (%2d %2d %2d)!\n",
-          nDDL, nTRM, nTDC);
+    AliWarningGeneral("AliTOFRawStream", Form("Warning -> AliTOFRawStream::EquipmentId2VolumeId: Problems with the plate number (%2d %2d %2d)!\n",
+                        nDDL, nTRM, nTDC));
   }
 
   Int_t iStrip = Equip2VolNstrip(iDDL, nTRM, nTDC);
   if (iStrip==-1) {
     /*if (fRawReader)
       fRawReader->AddMajorErrorLog(kStripError,"strip = -1");*/
-    printf("Warning -> AliTOFRawStream::EquipmentId2VolumeId: Problems with the strip number (%2d %2d %2d)!\n",
-          nDDL, nTRM, nTDC);
+    AliWarningGeneral("AliTOFRawStream", Form("Warning -> AliTOFRawStream::EquipmentId2VolumeId: Problems with the strip number (%2d %2d %2d)!\n",
+                        nDDL, nTRM, nTDC));
   }
 
   Int_t iPadAlongTheStrip  = Equip2VolNpad(iDDL, iChain, nTDC, iCH);
   if (iPadAlongTheStrip==-1) {
     /*if (fRawReader)
       fRawReader->AddMajorErrorLog(kPadAlongStripError,"pad = -1");*/
-    printf("Warning -> AliTOFRawStream::EquipmentId2VolumeId: Problems with the pad number along the strip (%2d %1d %2d %1d)!\n",
-          nDDL, iChain, nTDC, iCH);
+    AliWarningGeneral("AliTOFRawStream", Form("Warning -> AliTOFRawStream::EquipmentId2VolumeId: Problems with the pad number along the strip (%2d %1d %2d %1d)!\n",
+                        nDDL, iChain, nTDC, iCH));
   }
   
   Int_t iPadX  = (Int_t)(iPadAlongTheStrip/(Float_t(AliTOFGeometry::NpadZ())));
@@ -1329,6 +1420,7 @@ Bool_t AliTOFRawStream::DecodeDDL(Int_t nDDLMin, Int_t nDDLMax, Int_t verbose =
   }  
 
   //select required DDLs
+  fRawReader->Reset();
   fRawReader->Select("TOF", nDDLMin, nDDLMax);
 
   if (verbose)
@@ -1352,13 +1444,17 @@ Bool_t AliTOFRawStream::Decode(Int_t verbose = 0) {
   //loop and read DDL headers 
   while(fRawReader->ReadHeader()){
 
-    //memory leak prevention (actually data should be always 0x0 here)
-    if (data != 0x0)
-      delete [] data;
-
     //get equipment infos
     currentEquipment = fRawReader->GetEquipmentId();
+
     currentDDL = fRawReader->GetDDLID();
+    if (currentDDL==-1) {
+      fRawReader->AddMajorErrorLog(kDDLdataReading);
+      if (verbose)
+       AliWarning("Error when load DDL. Go to next DDL");
+      continue;
+    }
+
     currentCDH = fRawReader->GetDataHeader();
     const Int_t kDataSize = fRawReader->GetDataSize();
     const Int_t kDataWords = kDataSize / 4;
@@ -1393,7 +1489,9 @@ Bool_t AliTOFRawStream::Decode(Int_t verbose = 0) {
     //start decoding
     if (fDecoder->Decode((UInt_t *)data, kDataWords, currentCDH) == kTRUE) {
       fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",currentDDL));
-      AliWarning(Form("Error while decoding DDL # %d: decoder returned with errors", currentDDL));
+      if (verbose) AliWarning(Form("Error while decoding DDL # %d: decoder returned with errors", currentDDL));
+      ResetDataBuffer(currentDDL);
+      ResetPackedDataBuffer(currentDDL);
     }
     
     delete [] data;
@@ -1408,6 +1506,68 @@ Bool_t AliTOFRawStream::Decode(Int_t verbose = 0) {
     
   return kFALSE;
   
+}
+//-----------------------------------------------------------------------------
+Bool_t AliTOFRawStream::DecodeV2(Int_t verbose = 0) {
+  //
+  // Enhanced decoder method
+  //
+
+  Int_t currentEquipment;
+  Int_t currentDDL;
+  //const AliRawDataHeader *currentCDH;
+
+  //pointers
+  UChar_t *data = 0x0;
+  
+  // read header
+  if (!fRawReader->ReadHeader()) return kTRUE;
+  
+  //get equipment infos
+  currentEquipment = fRawReader->GetEquipmentId();
+  currentDDL = fRawReader->GetDDLID();
+  //currentCDH = fRawReader->GetDataHeader();
+  const Int_t kDataSize = fRawReader->GetDataSize();
+  const Int_t kDataWords = kDataSize / 4;
+  data = new UChar_t[kDataSize];
+  
+  if (verbose)
+    AliInfo(Form("Found equipment # %d header (DDL # %d): %d bytes (%d words)", currentEquipment, currentDDL, kDataSize, kDataWords));
+  
+  if (verbose)
+    AliInfo(Form("Reading equipment #%d (DDL # %d) data...", currentEquipment, currentDDL));
+  
+  //read equipment payload
+  if (!fRawReader->ReadNext(data, kDataSize))
+    {
+      fRawReader->AddMajorErrorLog(kDDLdataReading);
+      if (verbose)
+       AliWarning("Error while reading DDL data. Go to next equipment");
+      delete [] data;
+      data = 0x0;
+      return kTRUE;
+    }
+  
+  if (verbose)
+    AliInfo(Form("Equipment # %d (DDL # %d) data has been read", currentEquipment, currentDDL));
+  
+  
+  //set up the decoder
+  fDecoderV2->SetVerbose(verbose);
+  
+  //start decoding
+  if (fDecoderV2->Decode((UInt_t *)data, kDataWords) == kTRUE) {
+    fRawReader->AddMajorErrorLog(kDDLDecoder,Form("DDL # = %d",currentDDL));
+    if (verbose) AliWarning(Form("Error while decoding DDL # %d: decoder returned with errors", currentDDL));
+  }
+  
+  delete [] data;
+  
+  if (verbose)
+    AliInfo("All done");
+    
+  return kFALSE;
+  
 }
 //---------------------------------------------------------------------------
 void
@@ -1468,20 +1628,15 @@ AliTOFRawStream::LoadRawDataBuffers(Int_t indexDDL, Int_t verbose)
     Int_t   hitChan = hitData->GetChan();
     Int_t   hitTimeBin = hitData->GetTimeBin();
     Int_t   hitTOTBin = hitData->GetTOTBin();
-
-    if (fgApplyBCCorrections) {
-      /* DDL BC shift time correction */
-      hitTimeBin += 1024 * fgkddlBCshift[indexDDL];
-      /* deltaBC shift time correction */
-      hitTimeBin += 1024 * hitData->GetDeltaBunchID();
-    }
+    Int_t   hitDeltaBC = hitData->GetDeltaBunchID();
+    Int_t   hitL0L1Latency = hitData->GetL0L1Latency();
 
     Int_t hitLeading = hitData->GetTimeBin();
     Int_t hitTrailing = -1;
     Int_t hitError = -1;
     
     TClonesArray &arrayTofRawData =  *fTOFrawData;
-    new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(hitSlotID, hitChain, hitTDC, hitChan, hitTimeBin, hitTOTBin, hitLeading, hitTrailing, hitPS, hitACQ, hitError);
+    new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(hitSlotID, hitChain, hitTDC, hitChan, hitTimeBin, hitTOTBin, hitLeading, hitTrailing, hitPS, hitACQ, hitError, hitDeltaBC, hitL0L1Latency);
   }
 
   if (verbose > 0)
@@ -1499,6 +1654,186 @@ AliTOFRawStream::LoadRawDataBuffers(Int_t indexDDL, Int_t verbose)
   return kFALSE;
 }
 
+//---------------------------------------------------------------------------
+Bool_t
+AliTOFRawStream::LoadRawDataBuffersV2(Int_t indexDDL, Int_t verbose)
+{
+  //
+  // To load the buffers
+  //
+
+  /*
+   * decode raw data and fill output array with TOF hits.
+   * decode algorithm may return with errors due to inconsistent
+   * raw data format detected during decoding process.
+   * decoder algorithm has internal recover procedure to deal with
+   * errors in a safe condition.
+   * 
+   * the following conditions will cause total hit rejection from
+   * specific boards where the condition is detected:
+   *
+   * --- within DRM payload (full DRM skipped) ---
+   * - no header/trailer detected
+   *
+   * --- within TRM payload (full TRM skippped) ---
+   * - no header/trailer detected
+   * - empty event inserted
+   * - bad event counter
+   * - bad CRC
+   * - ACQ mode off
+   *
+   * --- within chain payload (full chain skipped) ---
+   * - no header/trailer detected
+   * - bad status
+   * - bad event counter
+   *
+   * --- HPTDC (ful TDC skipped) ---
+   * - error detected
+   *
+   */
+
+  fTOFrawData->Clear();
+  fPackedDigits = 0;
+  
+  if (verbose > 0)
+    AliInfo(Form("Decoding raw data for DDL # %d ...", indexDDL));
+
+  //check and fix valid DDL range
+  if (indexDDL < 0){
+    indexDDL = 0;
+    fRawReader->AddMinorErrorLog(kDDLMinError);
+    AliWarning("Wrong DDL range: setting first DDL ID to 0");
+  }
+  if (indexDDL > 71){
+    indexDDL = 71;
+    fRawReader->AddMinorErrorLog(kDDLMaxError);
+    AliWarning("Wrong DDL range: setting last DDL ID to 71");
+  }  
+
+  //select required DDLs
+  fRawReader->Reset();
+  fRawReader->Select("TOF", indexDDL, indexDDL);
+
+  /* decode */
+  if (DecodeV2(verbose)) return kTRUE;
+
+  /* read and check CDH info */
+  const AliRawDataHeader *currentCDH = fRawReader->GetDataHeader();
+  Int_t currentMiniEventID = currentCDH->GetMiniEventID();
+  Int_t currentEventID1 = currentCDH->GetEventID1();
+
+  /* read decoder summary data */
+  AliTOFDecoderSummaryData *decodersd;
+  AliTOFDRMSummaryData *drmsd;
+  //  AliTOFLTMSummaryData *ltmsd;
+  AliTOFTRMSummaryData *trmsd;  
+  AliTOFChainSummaryData *chainsd;
+  AliTOFTDCHitBuffer *hitBuffer;
+  AliTOFTDCHit *hit;
+  AliTOFTDCErrorBuffer *errorBuffer;
+  AliTOFTDCError *error;
+  Bool_t tdcErrorFlag[15];
+  decodersd = fDecoderV2->GetDecoderSummaryData();
+
+  /* check error detected/recovered */
+  if (decodersd->GetErrorDetected()) {
+      AliDebug(2, Form("Error detected while decoding DDL %d (errorSlotID mask = %04x)", indexDDL, decodersd->GetErrorSlotID()));
+    if (decodersd->GetRecoveringError()) {
+      AliDebug(2, "Couldn't recover from error");
+    }
+    else {
+      AliDebug(2, "Error recovered, anyway something is probably lost");
+    }
+  }
+  /* check DRM header/trailer */
+  drmsd = decodersd->GetDRMSummaryData();
+  if (!drmsd->GetHeader() || !drmsd->GetTrailer()) {
+    AliWarning("DRM header/trailer missing, skip DDL");
+    return kTRUE;
+  }
+  /* check partecipating mask */
+  if (drmsd->GetPartecipatingSlotID() != drmsd->GetDecoderSlotEnableMask()) {
+      AliDebug(2, Form("DRM slot enable mask differs from decoder slot enable mask (%08x != %08x) in DDL %d", drmsd->GetSlotEnableMask(), drmsd->GetDecoderSlotEnableMask(), indexDDL));
+    for (Int_t ibit = 0; ibit < 11; ibit++)
+      if ((drmsd->GetPartecipatingSlotID() & (0x1 << ibit)) && !(drmsd->GetDecoderSlotEnableMask() & (0x1 << ibit)))
+        AliDebug(2, Form("readout slot %d data is missing in decoder", ibit + 2));
+  }
+  
+  /* get DRM data */
+  Int_t currentL0BCID = drmsd->GetL0BCID();
+
+  /* loop over TRM to get hits */
+  Int_t hitACQ, hitPS, hitSlotID, hitChain, hitTDC, hitChan, hitTimeBin, hitTOTBin, hitDeltaBC, hitL0L1Latency, hitLeading, hitTrailing, hitError;
+  Int_t currentBunchID;
+
+  /* loop over TRMs */
+  for (Int_t itrm = 0; itrm < 10; itrm++) {
+    trmsd = drmsd->GetTRMSummaryData(itrm);
+    /* check header/trailer */
+    if (!trmsd->GetHeader() || !trmsd->GetTrailer()) continue;
+    /* skip if TRM empty event detected */
+    if (trmsd->GetEBit() != 0) continue;
+    /* skip if bad TRM event counter detected */
+    if (trmsd->GetEventCounter() != drmsd->GetLocalEventCounter()) continue;
+    /* skip if bad TRM CRC detected */
+    AliDebug(2,Form("~~~~~~ %02d %02d --- TRM CRC: as written in raw data =%d and as computed =%d ~~~~~~",indexDDL,itrm,trmsd->GetEventCRC(), trmsd->GetDecoderCRC()));
+    if (trmsd->GetEventCRC() != trmsd->GetDecoderCRC()) continue;
+
+    /* loop over chains */
+    for (Int_t ichain = 0; ichain < 2; ichain++) {
+      chainsd = trmsd->GetChainSummaryData(ichain);
+    /* check header/trailer */
+      if (!chainsd->GetHeader() || !chainsd->GetTrailer()) continue;
+      /* skip if chain bad status detected */
+      if (chainsd->GetStatus() != 0) continue;
+      /* skip if bad chain event counter detected */
+      if (chainsd->GetEventCounter() != drmsd->GetLocalEventCounter()) continue;
+
+      currentBunchID = chainsd->GetBunchID();
+      hitBuffer = chainsd->GetTDCPackedHitBuffer();
+      errorBuffer = chainsd->GetTDCErrorBuffer();
+
+      /* check TDC errors and set TDC error flag */
+      for (Int_t itdc = 0; itdc < 15; itdc++) tdcErrorFlag[itdc] = kFALSE;
+      for (Int_t ierr = 0; ierr < errorBuffer->GetEntries(); ierr++) {
+       error = errorBuffer->GetError(ierr);
+       tdcErrorFlag[error->GetTDCID()] = kTRUE;
+      }
+
+      /* loop over hits */
+      for (Int_t ihit = 0; ihit < hitBuffer->GetEntries(); ihit++) {
+
+       /* get hit */
+       hit = hitBuffer->GetHit(ihit);
+       /* skip hit if coming from a TDC with error detected */
+       if (tdcErrorFlag[hit->GetTDCID()]) continue;
+
+       /* set info */
+       hitACQ = trmsd->GetACQBits();
+       hitPS = hit->GetPSBits();
+       hitSlotID = trmsd->GetSlotID();
+       hitChain = chainsd->GetChain();
+       hitTDC = hit->GetTDCID();
+       hitChan = hit->GetChan();
+       hitTimeBin = hit->GetHitTime();
+       hitTOTBin = hit->GetTOTWidth();
+       hitDeltaBC = currentBunchID - currentEventID1;
+       hitL0L1Latency = currentMiniEventID - currentL0BCID;
+       
+       hitLeading = hitTimeBin;
+       hitTrailing = -1;
+       hitError = -1;
+       
+       /* add hit */
+       TClonesArray &arrayTofRawData =  *fTOFrawData;
+       new (arrayTofRawData[fPackedDigits++]) AliTOFrawData(hitSlotID, hitChain, hitTDC, hitChan, hitTimeBin, hitTOTBin, hitLeading, hitTrailing, hitPS, hitACQ, hitError, hitDeltaBC, hitL0L1Latency);
+      }
+    }
+  }
+
+  return kFALSE;
+}
+
 //---------------------------------------------------------------------------
 void AliTOFRawStream::Geant2EquipmentId(Int_t vol[], Int_t eqId[])
 {
@@ -1971,7 +2306,7 @@ Int_t AliTOFRawStream::Geant2Channel(Int_t vol[])
 }
 
 //____________________________________________________________________________
-void AliTOFRawStream::Raw2Digits(AliRawReader* rawReader, TClonesArray* digitsArray)
+void AliTOFRawStream::Raw2Digits(AliRawReader* rawReader, TClonesArray * const digitsArray)
 {
   //
   // Converts raw data to digits for TOF
@@ -2108,7 +2443,7 @@ void AliTOFRawStream::Raw2Digits(AliRawReader* rawReader, TClonesArray* digitsAr
 }
 
 //____________________________________________________________________________
-void AliTOFRawStream::Raw2SDigits(AliRawReader* rawReader, TClonesArray* sdigitsArray)
+void AliTOFRawStream::Raw2SDigits(AliRawReader* rawReader, TClonesArray * const sdigitsArray)
 {
   //
   // Converts raw data to sdigits for TOF
@@ -2213,10 +2548,10 @@ void AliTOFRawStream::Raw2SDigits(AliRawReader* rawReader, TClonesArray* sdigits
        else ftxt << "   " << digit[3] << endl;
       }
       */
-      AliDebug(2, Form(" Raw data reading %2d -> %2d %1d %2d %1d %2d (%d, %d, %d)",
+      AliDebug(2, Form(" Raw data reading %2d -> %2d %1d %2d %1d %2d (%d, %d)",
                       last,
                       detectorIndex[0], detectorIndex[1], detectorIndex[2], detectorIndex[4], detectorIndex[3],
-                      digit[0], digit[1], digit[3]));
+                      digit[0], digit[1]));
 
       tofRawDatum = 0;
     } // while loop
@@ -2235,3 +2570,127 @@ void AliTOFRawStream::Raw2SDigits(AliRawReader* rawReader, TClonesArray* sdigits
                   stopwatch.RealTime(),stopwatch.CpuTime()));
 
 }
+
+void AliTOFRawStream::VolumeID2LTM(Int_t detind[],
+                                  Int_t &iDDL,
+                                  Int_t &iTRM,
+                                  Int_t &iChain,
+                                  Int_t &iTDC,
+                                  Int_t &iChannel) const {
+  //
+  // To convert the TOF trigger macropad ID (i.e. detind)
+  // into TOF OR signals equipment ID (i.e. iDDL, iTRM, iChain, iTDC, iChannel)
+  //
+
+  const Int_t kFirstTDCnumber = 12;
+
+  iDDL=-1, iTRM = 3 , iChain=-1, iTDC=-1, iChannel=-1;
+  if (detind[1]==0 || detind[1]==1 || (detind[1]==2 && detind[2]<=7)) {
+    if (detind[4]<24)
+      iDDL = detind[0]*4;
+    else
+      iDDL = detind[0]*4;
+  }
+  else {
+    if (detind[4]<24)
+      iDDL = detind[0]*4+2;
+    else
+      iDDL = detind[0]*4+2;
+  }
+
+  iChain=fgkChainMap24[detind[1]][detind[2]];
+  iTDC=(Int_t)(fgkChannelMap24[detind[1]][detind[2]]/8)+kFirstTDCnumber;
+  iChannel=fgkChannelMap24[detind[1]][detind[2]]%8;
+  
+}
+
+void AliTOFRawStream::LTM2VolumeID(Int_t iDDL,
+                                  Int_t iTRM,
+                                  Int_t iChain,
+                                  Int_t iTDC,
+                                  Int_t iChannel,
+                                  Int_t detind0[], Int_t detind1[]) const {
+  //
+  // To convert the TOF OR signals equipment ID (i.e. iDDL, iTRM, iChain, iTDC, iChannel)
+  // into TOF trigger macropad IDs (i.e. detind0 and detind1).
+  // In general, a couple of neighbouring TOF semi-strip represents a TOF trigger macropad.
+  //
+
+  const Int_t kFirstTDCnumber = 12;
+
+  Int_t iSector0=-1, iModule0=-1, iStrip0=-1, iPadX0=-1; // Le variabili del Volume ID
+  Int_t iSector1=-1, iModule1=-1, iStrip1=-1, iPadX1=-1; // Le variabili del Volume ID
+
+  if( iDDL%2==1 && iTRM==3 && iTDC-kFirstTDCnumber>=0 && iTDC-kFirstTDCnumber<3 ) {
+    iSector0 = (Int_t)(iDDL/4);
+    iSector1 = (Int_t)(iDDL/4);
+    Int_t iChan= iChannel+(iTDC-kFirstTDCnumber)*8;
+    if( iDDL%4 == 1 ){
+      if(iChain==0){      //CRATE 0
+        iPadX0=0;
+        iPadX1=0;
+        iStrip0=fgkStrip0MapCrate0[iChan];
+        iStrip1=fgkStrip1MapCrate0[iChan];
+        iModule0=fgkModule0MapCrate0[iChan];
+        iModule1=fgkModule1MapCrate0[iChan];
+      }
+      if(iChain==1){// CRATE 1
+        iPadX0=24;
+        iPadX1=24;
+        iStrip0=fgkStrip0MapCrate1[iChan];
+        iStrip1=fgkStrip1MapCrate1[iChan];
+        iModule0=fgkModule0MapCrate1[iChan];
+        iModule1=fgkModule1MapCrate1[iChan];
+      }
+
+    }
+    if( iDDL%4 == 3 ){
+      if(iChain==1){// CRATE 3
+        iPadX0=0;
+        iPadX1=0;
+        iStrip0=fgkStrip0MapCrate3[iChan];
+        iStrip1=fgkStrip1MapCrate3[iChan];
+        iModule0=fgkModule0MapCrate3[iChan];
+        iModule1=fgkModule1MapCrate3[iChan];
+      }
+      if(iChain==0){// CRATE 2
+        iPadX0=24;
+        iPadX1=24;
+        iStrip0=fgkStrip0MapCrate2[iChan];
+        iStrip1=fgkStrip1MapCrate2[iChan];
+        iModule0=fgkModule0MapCrate2[iChan];
+        iModule1=fgkModule1MapCrate2[iChan];
+      }
+    }
+  }
+
+  if(iStrip1==-1 || iModule1==-1){
+    detind1[0]=-1;
+    detind1[1]=-1;
+    detind1[2]=-1;
+    detind1[3]=-1;
+    detind1[4]=-1;
+  }
+  else{
+    detind1[0]=iSector1;
+    detind1[1]=iModule1;
+    detind1[2]=iStrip1;
+    detind1[3]=iPadX1;
+    detind1[4]=0;
+  }
+
+  if(iStrip0==-1 || iModule0==-1){
+    detind0[0]=-1;
+    detind0[1]=-1;
+    detind0[2]=-1;
+    detind0[3]=-1;
+    detind0[4]=-1;
+  }
+  else{
+    detind0[0]=iSector0;
+    detind0[1]=iModule0;
+    detind0[2]=iStrip0;
+    detind0[3]=iPadX0;
+    detind0[4]=0;
+  }
+}