]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFRawStream.cxx
first version of a bash utilities lib
[u/mrichter/AliRoot.git] / TOF / AliTOFRawStream.cxx
index 36c414269d5b7bd1ce7ea0f4b45ac57db7d1b9ee..9109fce54aaa64fd56b64fa135d4287abfadf8d4 100644 (file)
@@ -125,6 +125,7 @@ Revision 0.01  2005/07/22 A. De Caro
 
 #include "AliRawEventHeaderBase.h"
 #include "AliRawDataHeader.h"
+#include "AliRawDataHeaderV3.h"
 
 #include "AliTOFDecoderV2.h"
 #include "AliTOFTDCHit.h"
@@ -504,12 +505,13 @@ AliTOFRawStream::~AliTOFRawStream()
   // destructor
 
   fPackedDigits = 0;
-
   delete fDecoder;
   delete fDecoderV2;
   
-  fTOFrawData->Clear();
-  delete fTOFrawData;
+  if (fTOFrawData) {
+    fTOFrawData->Clear("C");
+    delete fTOFrawData;
+  }
 
   //delete fCableLengthMap;
 
@@ -630,6 +632,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);
 
@@ -1430,7 +1437,8 @@ Bool_t AliTOFRawStream::Decode(Int_t verbose = 0) {
 
   Int_t currentEquipment;
   Int_t currentDDL;
-  const AliRawDataHeader *currentCDH;
+  const AliRawDataHeader *currentCDH = 0x0;
+  const AliRawDataHeaderV3 *currentCDHV3 = 0x0;
 
   //pointers
   UChar_t *data = 0x0;
@@ -1438,14 +1446,19 @@ 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();
+    if (!currentCDH) currentCDHV3 = fRawReader->GetDataHeaderV3();
     const Int_t kDataSize = fRawReader->GetDataSize();
     const Int_t kDataWords = kDataSize / 4;
     data = new UChar_t[kDataSize];
@@ -1477,9 +1490,9 @@ Bool_t AliTOFRawStream::Decode(Int_t verbose = 0) {
     fDecoder->SetPackedDataBuffer(&fPackedDataBuffer[currentDDL]);
     
     //start decoding
-    if (fDecoder->Decode((UInt_t *)data, kDataWords, currentCDH) == kTRUE) {
+    if (fDecoder->Decode((UInt_t *)data, kDataWords, currentCDH, currentCDHV3) == 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);
     }
@@ -1505,7 +1518,7 @@ Bool_t AliTOFRawStream::DecodeV2(Int_t verbose = 0) {
 
   Int_t currentEquipment;
   Int_t currentDDL;
-  const AliRawDataHeader *currentCDH;
+  //const AliRawDataHeader *currentCDH;
 
   //pointers
   UChar_t *data = 0x0;
@@ -1516,7 +1529,7 @@ Bool_t AliTOFRawStream::DecodeV2(Int_t verbose = 0) {
   //get equipment infos
   currentEquipment = fRawReader->GetEquipmentId();
   currentDDL = fRawReader->GetDDLID();
-  currentCDH = fRawReader->GetDataHeader();
+  //currentCDH = fRawReader->GetDataHeader();
   const Int_t kDataSize = fRawReader->GetDataSize();
   const Int_t kDataWords = kDataSize / 4;
   data = new UChar_t[kDataSize];
@@ -1548,7 +1561,7 @@ Bool_t AliTOFRawStream::DecodeV2(Int_t verbose = 0) {
   //start decoding
   if (fDecoderV2->Decode((UInt_t *)data, kDataWords) == 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));
   }
   
   delete [] data;
@@ -1709,8 +1722,11 @@ AliTOFRawStream::LoadRawDataBuffersV2(Int_t indexDDL, Int_t verbose)
 
   /* read and check CDH info */
   const AliRawDataHeader *currentCDH = fRawReader->GetDataHeader();
-  Int_t currentMiniEventID = currentCDH->GetMiniEventID();
-  Int_t currentEventID1 = currentCDH->GetEventID1();
+  const AliRawDataHeaderV3 *currentCDHV3 = fRawReader->GetDataHeaderV3();
+  Int_t currentMiniEventID = currentCDH ? currentCDH->GetMiniEventID(): -1;
+  currentMiniEventID = currentCDHV3 ? currentCDHV3->GetMiniEventID(): currentMiniEventID;
+  Int_t currentEventID1 = currentCDH? currentCDH->GetEventID1() : -1;
+  currentEventID1 = currentCDHV3? currentCDHV3->GetEventID1() : currentEventID1;
 
   /* read decoder summary data */
   AliTOFDecoderSummaryData *decodersd;
@@ -1727,12 +1743,12 @@ AliTOFRawStream::LoadRawDataBuffersV2(Int_t indexDDL, Int_t verbose)
 
   /* check error detected/recovered */
   if (decodersd->GetErrorDetected()) {
-    AliWarning(Form("Error detected while decoding DDL %d (errorSlotID mask = %04x)", indexDDL, decodersd->GetErrorSlotID()));
+      AliDebug(2, Form("Error detected while decoding DDL %d (errorSlotID mask = %04x)", indexDDL, decodersd->GetErrorSlotID()));
     if (decodersd->GetRecoveringError()) {
-      AliWarning("Couldn't recover from error");
+      AliDebug(2, "Couldn't recover from error");
     }
     else {
-      AliWarning("Error recovered, anyway something is probably lost");
+      AliDebug(2, "Error recovered, anyway something is probably lost");
     }
   }
   /* check DRM header/trailer */
@@ -1743,10 +1759,10 @@ AliTOFRawStream::LoadRawDataBuffersV2(Int_t indexDDL, Int_t verbose)
   }
   /* check partecipating mask */
   if (drmsd->GetPartecipatingSlotID() != drmsd->GetDecoderSlotEnableMask()) {
-    AliWarning(Form("DRM slot enable mask differs from decoder slot enable mask (%08x != %08x) in DDL %d", drmsd->GetSlotEnableMask(), drmsd->GetDecoderSlotEnableMask(), indexDDL));
+      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)))
-       AliWarning(Form("readout slot %d data is missing in decoder", ibit + 2));
+        AliDebug(2, Form("readout slot %d data is missing in decoder", ibit + 2));
   }
   
   /* get DRM data */
@@ -1766,6 +1782,7 @@ AliTOFRawStream::LoadRawDataBuffersV2(Int_t indexDDL, Int_t verbose)
     /* 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 */
@@ -2537,10 +2554,10 @@ void AliTOFRawStream::Raw2SDigits(AliRawReader* rawReader, TClonesArray * const
        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
@@ -2561,11 +2578,11 @@ void AliTOFRawStream::Raw2SDigits(AliRawReader* rawReader, TClonesArray * const
 }
 
 void AliTOFRawStream::VolumeID2LTM(Int_t detind[],
-                                  Int_t iDDL,
-                                  Int_t iTRM,
-                                  Int_t iChain,
-                                  Int_t iTDC,
-                                  Int_t iChannel) const {
+                                  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)