]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
major revision of HLTTPCDigitReaders
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 30 Sep 2008 14:04:30 +0000 (14:04 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 30 Sep 2008 14:04:30 +0000 (14:04 +0000)
- corrections in the interface functions added in rev. 29023 to
  get the RCU trailer -> now passing by reference
- speedup of DigitReaderPacked by using a singleton of the AltroRawStream
  and thus avoiding of multiple allocations of TPCMapping aso
- speedup of DigitReaderPacked in sorted mode by using correct array bounds
- corrected implementation of bulk read mode in DigitReaderPacked
- code cleanup in DigitReaderPacked

HLT/TPCLib/AliHLTTPCDigitReader.cxx
HLT/TPCLib/AliHLTTPCDigitReader.h
HLT/TPCLib/AliHLTTPCDigitReaderDecoder.cxx
HLT/TPCLib/AliHLTTPCDigitReaderDecoder.h
HLT/TPCLib/AliHLTTPCDigitReaderPacked.cxx
HLT/TPCLib/AliHLTTPCDigitReaderPacked.h

index 6e6538a73b77b2e500321d41fc8a9760941e0bbe..9a41c2e85d463aab7842e511273917b8432de4c2 100644 (file)
@@ -107,21 +107,27 @@ bool AliHLTTPCDigitReader::Next(int /*type*/)
 bool AliHLTTPCDigitReader::NextChannel()
 {
   // see header file for class documentation
-  PrintMissingFastAccessWarning();
+  PrintWarningOnce(kWarnMissFastAccess,"\n"
+                  "      !!! This digit reader does not implement the methods for       !!!\n"
+                  "      !!! fast data access on channel/bunch basis. Data is discarded !!!");
   return false;
 }
 
 int AliHLTTPCDigitReader::NextBunch()
 {
   // see header file for class documentation
-  PrintMissingFastAccessWarning();
+  PrintWarningOnce(kWarnMissFastAccess,"\n"
+                  "      !!! This digit reader does not implement the methods for       !!!\n"
+                  "      !!! fast data access on channel/bunch basis. Data is discarded !!!");
   return false;
 }
 
 const UInt_t* AliHLTTPCDigitReader::GetSignals()
 {
   // see header file for class documentation
-  PrintMissingFastAccessWarning();
+  PrintWarningOnce(kWarnMissFastAccess,"\n"
+                  "      !!! This digit reader does not implement the methods for       !!!\n"
+                  "      !!! fast data access on channel/bunch basis. Data is discarded !!!");
   return 0;
 }
 
@@ -176,7 +182,9 @@ int AliHLTTPCDigitReader::RewindToPrevChannel()
 int AliHLTTPCDigitReader::GetBunchSize()
 {
   // see header file for class documentation
-  PrintMissingFastAccessWarning();
+  PrintWarningOnce(kWarnMissFastAccess,"\n"
+                  "      !!! This digit reader does not implement the methods for       !!!\n"
+                  "      !!! fast data access on channel/bunch basis. Data is discarded !!!");
   return 0;
 }
 
@@ -201,25 +209,28 @@ AliHLTUInt32_t AliHLTTPCDigitReader::GetAltroBlockHWaddr(Int_t /*row*/, Int_t /*
 int AliHLTTPCDigitReader::GetRCUTrailerSize()
 {
   // see header file for class documentation
-  PrintMissingFastAccessWarning();
+  PrintWarningOnce(kWarnMissTrailerGetters,"\n"
+                  "      !!! This digit reader does not implement the Getters       !!!\n"
+                  "      !!! for RCU trailer. Ignoring call.                        !!!");
   return 0;
 }
 
-bool AliHLTTPCDigitReader::GetRCUTrailerData(UChar_t *trData)
+bool AliHLTTPCDigitReader::GetRCUTrailerData(UChar_t*& trData)
 {
   // see header file for class documentation
-  PrintMissingFastAccessWarning();
+  PrintWarningOnce(kWarnMissTrailerGetters,"\n"
+                  "      !!! This digit reader does not implement the Getters       !!!\n"
+                  "      !!! for RCU trailer. Ignoring call.                        !!!");
+  if (trData) trData=NULL;
   return 0;
 }
 
 
-void AliHLTTPCDigitReader::PrintMissingFastAccessWarning()
+void AliHLTTPCDigitReader::PrintWarningOnce(int type, const char* message)
 {
   // see header file for class documentation
-  if (CheckFlag(kWarnMissFastAccess)) return;
-  SetFlag(kWarnMissFastAccess);
-  HLTWarning("\n"
-            "      !!! This digit reader does not implement the methods for       !!!\n"
-            "      !!! fast data access on channel/bunch basis. Data is discarded !!!");
+  if (CheckFlag(type)) return;
+  SetFlag(type);
+  HLTWarning(message);
 }
 
index 898a70dac8c661e14479609115f907cd7f8895a5..6be7ba1b7283b1bb721e2cc4b22ea098c14566e5 100644 (file)
@@ -193,17 +193,15 @@ public:
    */  
   virtual int GetRowOffset() const;
 
-   /**
-   * Returns the trailer size. used by zerosuppression component. 
+  /**
+   * Returns the trailer size.
    */
   virtual int GetRCUTrailerSize();
 
   /**
-   * Returns the trailer data. used by zerosuppression component. 
+   * Returns the trailer data.
    */
-  virtual bool GetRCUTrailerData(UChar_t *trData);
-
-
+  virtual bool GetRCUTrailerData(UChar_t*& trData);
 
   /**
    * Access operator to the data of a specific time bin.
@@ -235,6 +233,8 @@ public:
     kNoRewind = 0x4,
     /** warning missing fast access methods */
     kWarnMissFastAccess = 0x8,
+    /** warning on missing RCU trailer getters */
+    kWarnMissTrailerGetters = 0x10,
     /** channel caching enabled */
     kChannelCaching = 0x100
   };
@@ -275,10 +275,10 @@ protected:
 
 private:
   /**
-   * Print a warning on the missing fast access methods.
+   * Print a warning once for missing functionality.
    * Set corresponding flag to avoid repetitive warnings.
    */
-  void PrintMissingFastAccessWarning();
+  void PrintWarningOnce(int type, const char* message);
 
   /** pad/channel is locked */
   unsigned int fFlags;                                    //!transient
index e6acd1ec3b177fb936ffd062c7b2511c9f2605b2..badf9ee2ba299051b1d62e273725c4479eef607f 100644 (file)
@@ -95,6 +95,12 @@ int AliHLTTPCDigitReaderDecoder::InitBlock(void* ptr,unsigned long size, Int_t p
 int AliHLTTPCDigitReaderDecoder::Reset()
 {
   // see header file for class documentation
+  fAltroData.Reset();
+  fAltroData.SetIsComplete(false);
+  if (fAltroBunch) {
+    fAltroBunch->SetBunchSize(0);
+    fAltroBunch->SetData(NULL);
+  }
   if (fAltroDecoder) ReleaseDecoderInstance(fAltroDecoder);
   fAltroDecoder=NULL;
   return 0;
@@ -225,15 +231,18 @@ AliHLTUInt32_t AliHLTTPCDigitReaderDecoder::GetAltroBlockHWaddr(Int_t row, Int_t
   }
 }
 
-
-int AliHLTTPCDigitReaderDecoder::GetRCUTrailerSize(){
+int AliHLTTPCDigitReaderDecoder::GetRCUTrailerSize()
+{
+  // see header file for class documentation
   if(fAltroDecoder){
     return fAltroDecoder->GetRCUTrailerSize();
   }
   return 0;
 }
 
-bool AliHLTTPCDigitReaderDecoder::GetRCUTrailerData(UChar_t *trData){
+bool AliHLTTPCDigitReaderDecoder::GetRCUTrailerData(UChar_t*& trData)
+{
+  // see header file for class documentation
   if(fAltroDecoder){
     return fAltroDecoder->GetRCUTrailerData(trData);
   }
index 5be613c9ed015c5a70f9c716b7cdebaaf2722536..671d6974facccb5719026211e94495b85b6834e2 100644 (file)
@@ -51,7 +51,7 @@ public:
   AliHLTUInt32_t GetAltroBlockHWaddr() const;
   AliHLTUInt32_t GetAltroBlockHWaddr(Int_t row, Int_t pad) const;
   int GetRCUTrailerSize();
-  bool GetRCUTrailerData(UChar_t *trData);  
+  bool GetRCUTrailerData(UChar_t*& trData);
 
 protected:
   bool NextSignal();
index 13b2c01b3987d425fcdb6f5da310d3684abec632..26425b6a8a256905afff4fcf9d4ec139f1b97a70 100644 (file)
@@ -21,7 +21,8 @@
 /** @file   AliHLTTPCDigitReaderPacked.cxx
     @author Timm Steinbeck, Jochen Thaeder, Matthias Richter, Kenneth Aamodt
     @date   
-    @brief  A digit reader implementation for simulated, packed TPC 'raw' data.
+    @brief  A digit reader implementation for raw data, using the offline
+            AliAltroRawStream/AliTPCRawStream.
 */
 
 #if __GNUC__>= 3
@@ -34,47 +35,49 @@ using namespace std;
 #include "AliRawReaderMemory.h"
 #include "AliRawDataHeader.h"
 
-//#if ENABLE_PAD_SORTING
 #include "AliHLTTPCTransform.h"
-//#endif // ENABLE_PAD_SORTING
 #include "AliHLTStdIncludes.h"
 
 ClassImp(AliHLTTPCDigitReaderPacked)
 
 AliHLTTPCDigitReaderPacked::AliHLTTPCDigitReaderPacked()
   :
-  fRawMemoryReader(NULL),
   fTPCRawStream(NULL),
-  //#if ENABLE_PAD_SORTING
   fCurrentRow(0),
   fCurrentPad(0),
   fCurrentBin(-1),
   fRowOffset(0),
   fNRows(0),
+  fNPads(0),
   fData(NULL),
-  //#endif // ENABLE_PAD_SORTING  
   fUnsorted(kFALSE),
   fDataBunch(),
-  fNextChannelFlag(kFALSE),
+  fCurrentChannel(-1),
+  fbHaveData(false),
   fCurrentPatch(0)
 {
-  fRawMemoryReader = new AliRawReaderMemory;
-  
-  fTPCRawStream = new AliTPCRawStream( fRawMemoryReader );
+  // see header file for class documentation
+  // or
+  // refer to README to build package
+  // or
+  // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
 
-  //#if ENABLE_PAD_SORTING
 
   // Matthias Sep 2008: the pad sorting functionality needs a deep
   // revision of the code
-  // I just stumbled over a few awkward realizations
+  // I just stumbled over a few awkward implementation
   // - each instance allocates the buffer for sorted data, this is
   //   approx. 8 MByte each
-  // - each instance to loops to extract the buffer size
+  // - each instance loops to extract the buffer size
+  // - the AliTPCRawStream reads the Altro mapping for each instance
+  //
+  // There is now an instance handling of the buffer and the buffer size
+  // is only calculated once The sorting of pads is going to be a common
+  // functionality of the DigitReader base class in the future.
   //
-  // quick reaction: there is now an instance handling of the buffer
-  // and the buffer size is only calculated once
-  // The sorting of pads is going to be a common functionality of the
-  // DigitReader base class
+  // Same applies to the instance of the AliRawReaderMemory and
+  // AliTPCRawStream. Since processing of multiple instances is always
+  // sequential, one instance can be used for all readers.
 
   // get max number of rows
   if (fNMaxRows<0) {
@@ -95,32 +98,44 @@ AliHLTTPCDigitReaderPacked::AliHLTTPCDigitReaderPacked()
   fNTimeBins = AliHLTTPCTransform::GetNTimeBins();
   }
 
-  //#endif // ENABLE_PAD_SORTING
+  fgObjectCount++;
 }
 
 Int_t AliHLTTPCDigitReaderPacked::fNMaxRows=-1;
 Int_t AliHLTTPCDigitReaderPacked::fNMaxPads=-1;
 Int_t AliHLTTPCDigitReaderPacked::fNTimeBins=-1;
-Int_t* AliHLTTPCDigitReaderPacked::fgpFreeInstance=NULL;
-Int_t* AliHLTTPCDigitReaderPacked::fgpIssuedInstance=NULL;
+Int_t* AliHLTTPCDigitReaderPacked::fgpFreeBufferInstance=NULL;
+Int_t* AliHLTTPCDigitReaderPacked::fgpIssuedBufferInstance=NULL;
+AliHLTTPCDigitReaderPacked::AliHLTTPCRawStream* AliHLTTPCDigitReaderPacked::fgpFreeStreamInstance=NULL;
+AliHLTTPCDigitReaderPacked::AliHLTTPCRawStream* AliHLTTPCDigitReaderPacked::fgpIssuedStreamInstance=NULL;
+Int_t AliHLTTPCDigitReaderPacked::fgObjectCount=0;
 
 AliHLTTPCDigitReaderPacked::~AliHLTTPCDigitReaderPacked()
 {
-  if (fData)
-    ReleaseBufferInstance(fData);
+  // see header file for class documentation
+  if (fData) ReleaseBufferInstance(fData);
+  fData=NULL;
 
-  if ( fRawMemoryReader )
-    delete fRawMemoryReader;
-  fRawMemoryReader = NULL;
-  if ( fTPCRawStream )
-      delete fTPCRawStream;
-  fTPCRawStream = NULL;
+  if (fTPCRawStream) ReleaseRawStreamInstance(fTPCRawStream);
+  fTPCRawStream=NULL;
+
+  if (--fgObjectCount==0) {
+    if (fgpFreeBufferInstance) delete fgpFreeBufferInstance;
+    fgpFreeBufferInstance=NULL;
+    if (fgpIssuedBufferInstance) delete fgpIssuedBufferInstance;
+    fgpIssuedBufferInstance=NULL;
+    if (fgpFreeStreamInstance) delete fgpFreeStreamInstance;
+    fgpFreeStreamInstance=NULL;
+    if (fgpIssuedStreamInstance) delete fgpIssuedStreamInstance;
+    fgpIssuedStreamInstance=NULL;
+  }
 }
 
 Int_t AliHLTTPCDigitReaderPacked::InitBlock(void* ptr,ULong_t size, Int_t patch, Int_t slice)
 {
-
-  fRawMemoryReader->SetMemory( reinterpret_cast<UChar_t*>( ptr ), size );
+  // see header file for class documentation
+  fTPCRawStream=GetRawStreamInstance();
+  if (!fTPCRawStream) return -ENODEV;
 
   fCurrentPatch=patch;
   
@@ -131,14 +146,13 @@ Int_t AliHLTTPCDigitReaderPacked::InitBlock(void* ptr,ULong_t size, Int_t patch,
   else 
     DDLid = 840 + 4*slice + patch-2;
 
-  fRawMemoryReader->SetEquipmentID(DDLid);
-  //fRawMemoryReader->SetEquipmentID(1);
-  fRawMemoryReader->RewindEvents();
-  fRawMemoryReader->NextEvent();
-
-  if(!fUnsorted){
-  //#if ENABLE_PAD_SORTING
+  fTPCRawStream->SetMemory(DDLid, reinterpret_cast<UChar_t*>( ptr ), size );
 
+  // fCurrentRow always is the row number within a partition, whereas the TPCRawStream
+  // counts rows within the inner and outer sector, i.e. 0 to 62 for the inner and
+  // 63 to 158 for the outer sector
+  // fRowOffset is the offset of the first row of the current partition with respect
+  // to inner or outer sector.
   fCurrentRow = 0;
   fCurrentPad = 0;
   fCurrentBin = -1;
@@ -146,6 +160,10 @@ Int_t AliHLTTPCDigitReaderPacked::InitBlock(void* ptr,ULong_t size, Int_t patch,
   Int_t firstrow=AliHLTTPCTransform::GetFirstRow(patch);
   Int_t lastrow=AliHLTTPCTransform::GetLastRow(patch);
   fNRows = lastrow - firstrow + 1;
+  for (Int_t ii=firstrow; ii <= lastrow;ii++ ) {
+    if (AliHLTTPCTransform::GetNPads(ii) > fNPads) 
+      fNPads = AliHLTTPCTransform::GetNPads(ii);
+  }
 
   Int_t offset=0;
   if (patch > 1) offset =  AliHLTTPCTransform::GetFirstRow( 2 );
@@ -154,6 +172,10 @@ Int_t AliHLTTPCDigitReaderPacked::InitBlock(void* ptr,ULong_t size, Int_t patch,
   firstrow -= offset;
   lastrow  -= offset;
 
+  fbHaveData=false;
+
+  if(!fUnsorted){
+
   // get the global instance of the array
   fData=GetBufferInstance();
   if (!fData) return -ENOMEM;
@@ -187,7 +209,6 @@ Int_t AliHLTTPCDigitReaderPacked::InitBlock(void* ptr,ULong_t size, Int_t patch,
          }
       }
   }
-  //#endif // ENABLE_PAD_SORTING
   }
   return 0;
 }
@@ -197,26 +218,29 @@ int AliHLTTPCDigitReaderPacked::Reset()
   // see header file for class documentation
   if (fData) ReleaseBufferInstance(fData);
   fData=NULL;
+  if (fTPCRawStream) ReleaseRawStreamInstance(fTPCRawStream);
+  fTPCRawStream=NULL;
   return 0;
 }
 
-Bool_t AliHLTTPCDigitReaderPacked::NextSignal(){
+Bool_t AliHLTTPCDigitReaderPacked::NextSignal()
+{
+  // see header file for class documentation
   Bool_t readvalue = kTRUE;
 
-  if(!fUnsorted){//added for test
+  if(!fUnsorted) {
     if (!fData) return false;
-    //#if ENABLE_PAD_SORTING
     while (1) {
       fCurrentBin++;
       if (fCurrentBin >= fNTimeBins){
          fCurrentBin = 0;
          fCurrentPad++;
      
-         if (fCurrentPad >=fNMaxPads){
+         if (fCurrentPad >=fNPads){
              fCurrentPad = 0;
              fCurrentRow++;
              
-             if (fCurrentRow >= fNMaxRows){
+             if (fCurrentRow >= fNRows){
                  readvalue = kFALSE;
                  break;
              }
@@ -231,43 +255,30 @@ Bool_t AliHLTTPCDigitReaderPacked::NextSignal(){
 
       if (fData[ fCurrentRow*fNMaxPads*fNTimeBins + fCurrentPad*fNTimeBins + fCurrentBin  ] != -1) break;
     }
-  }// added for test
-  else{//added for test
-    //#else // !ENABLE_PAD_SORTING
-    readvalue = fTPCRawStream->Next();
-  }//added for test
-  //#endif // ENABLE_PAD_SORTING
+  } else{
+    if (readvalue = fTPCRawStream->Next()) {
+      fCurrentBin=fTPCRawStream->GetTime();
+    }
+  }
 
+  fbHaveData=readvalue;
   return readvalue;
 }
 
-Int_t AliHLTTPCDigitReaderPacked::GetRow(){
-  /*#if ENABLE_PAD_SORTING
-  return (fCurrentRow + fRowOffset);
-#else // !ENABLE_PAD_SORTING
-  return (Int_t) fTPCRawStream->GetRow();
-#endif // ENABLE_PAD_SORTING
-  */
+Int_t AliHLTTPCDigitReaderPacked::GetRow()
+{
+  // see header file for class documentation
   if(!fUnsorted){
   return (fCurrentRow + fRowOffset);
   }
   else{
-    if(fCurrentPatch>1){
-      return (Int_t) fTPCRawStream->GetRow()-AliHLTTPCTransform::GetFirstRow(fCurrentPatch)+AliHLTTPCTransform::GetFirstRow(2);
-    }
-    else{
-      return (Int_t) fTPCRawStream->GetRow()-AliHLTTPCTransform::GetFirstRow(fCurrentPatch);
-    }
+    return (Int_t) fTPCRawStream->GetRow()-fRowOffset;
   }
 }
 
-int AliHLTTPCDigitReaderPacked::GetPad(){
-  /*#if ENABLE_PAD_SORTING
-    return fCurrentPad;
-    #else // !ENABLE_PAD_SORTING
-    return fTPCRawStream->GetPad();
-    #endif // ENABLE_PAD_SORTING
-  */
+int AliHLTTPCDigitReaderPacked::GetPad()
+{
+  // see header file for class documentation
   if(!fUnsorted){
     return fCurrentPad;
   }
@@ -278,17 +289,31 @@ int AliHLTTPCDigitReaderPacked::GetPad(){
 
 AliHLTUInt32_t AliHLTTPCDigitReaderPacked::GetAltroBlockHWaddr() const
 {
+  // see header file for class documentation
   return fTPCRawStream->GetHWAddress();
 }
 
-Int_t AliHLTTPCDigitReaderPacked::GetSignal(){ 
-  /*
-    #if ENABLE_PAD_SORTING
-    return fData[ fCurrentRow*fNMaxPads*fNTimeBins+ fCurrentPad*fNTimeBins + fCurrentBin ];
-    #else // !ENABLE_PAD_SORTING
-    return fTPCRawStream->GetSignal();
-    #endif // ENABLE_PAD_SORTING
-  */
+int AliHLTTPCDigitReaderPacked::GetRCUTrailerSize()
+{
+  // see header file for class documentation
+  if(fTPCRawStream){
+    return fTPCRawStream->GetRCUTrailerSize();
+  }
+  return 0;
+}
+
+bool AliHLTTPCDigitReaderPacked::GetRCUTrailerData(UChar_t*& trData)
+{
+  // see header file for class documentation
+  if(fTPCRawStream){
+    return fTPCRawStream->GetRCUTrailerData(trData);
+  }
+  return false;
+}
+
+Int_t AliHLTTPCDigitReaderPacked::GetSignal()
+{ 
+  // see header file for class documentation
   if(!fUnsorted){
     // check for validity of fData is in NextSignal, no check at here
     return fData[ fCurrentRow*fNMaxPads*fNTimeBins+ fCurrentPad*fNTimeBins + fCurrentBin ];
@@ -298,89 +323,73 @@ Int_t AliHLTTPCDigitReaderPacked::GetSignal(){
   }
 }
 
-Int_t AliHLTTPCDigitReaderPacked::GetTime(){
-  /*
-    #if ENABLE_PAD_SORTING
-    return fCurrentBin;
-    #else // !ENABLE_PAD_SORTING
-    return fTPCRawStream->GetTime();
-    #endif // ENABLE_PAD_SORTING
-  */
-  if(!fUnsorted){
-    return fCurrentBin;
-  }
-  else{
-    if((Int_t)(fTPCRawStream->GetTime()-fDataBunch.size()+1)>0 &&(Int_t)(fTPCRawStream->GetTime()-fDataBunch.size()+1)<=AliHLTTPCTransform::GetNTimeBins()){
-      return fTPCRawStream->GetTime()-fDataBunch.size()+1;
-    }
-    else{
-      HLTDebug("Timebin is out of range: %d",fTPCRawStream->GetTime()-fDataBunch.size()+1);
-      return 0;
-    }
-  }
+Int_t AliHLTTPCDigitReaderPacked::GetTime()
+{
+  // see header file for class documentation
+  return fCurrentBin;
 }
 
 Int_t AliHLTTPCDigitReaderPacked::GetTimeOfUnsortedSignal(){
   return fTPCRawStream->GetTime();
 }
 
-bool AliHLTTPCDigitReaderPacked::NextChannel(){
-  bool iResult=false;
-  if(fNextChannelFlag==kFALSE){
-    if(!NextSignal()){//if there are no more signals
-      iResult=false;
-    }
-    else{
-      iResult=true;
-    }
-  }
-  else{
-    iResult=true;
+bool AliHLTTPCDigitReaderPacked::NextChannel()
+{
+  // see header file for class documentation
+
+  // return true if a channel is available. This is true if
+  // 1. the current row position >=0 : a signal has already been read in the stream
+  //    but it was not part of the previous bunch
+  // 2. the current row position <0 : this is the first invocation at all, read
+  //    signal and send result according to the availability
+  if(fbHaveData || // data available from the last NextSignal call?
+     NextSignal()) { // there is data
+    fCurrentChannel=GetAltroBlockHWaddr();
+    return true;
   }
-  return iResult;
+  return false;
 }
 
-int AliHLTTPCDigitReaderPacked::NextBunch(){
-  
+int AliHLTTPCDigitReaderPacked::NextBunch()
+{  
+  // see header file for class documentation
+  if (fCurrentChannel<0) return 0;
+
   fDataBunch.clear();
   //adding the first signal (will always be the leftover from either NextChannel call or Previous bunch)
   fDataBunch.push_back(GetSignal());
 
-  int iResult=1;
-  Bool_t continueLoop=kTRUE;
-  AliHLTUInt32_t prevHWAddress=GetAltroBlockHWaddr();
   Int_t prevTime=GetTimeOfUnsortedSignal();
   do{
     if(NextSignal()){
-      if(GetAltroBlockHWaddr()==prevHWAddress){//check if there is a change in channel(new row and pad)
+      if((int)GetAltroBlockHWaddr()==fCurrentChannel){//check if there is a change in channel(new row and pad)
        if(prevTime==GetTimeOfUnsortedSignal()+1){//if true means that we have consecutive signals
          prevTime=GetTimeOfUnsortedSignal();
-         fDataBunch.push_back(GetSignal());
+         fDataBunch.insert(fDataBunch.begin(), GetSignal());
        }
        else{//end of bunch but not of channel
-         continueLoop=kFALSE;
+         break;
        }
       }
       else{
-       iResult=0;//end of bunch
-       continueLoop=kFALSE;
-       fNextChannelFlag=kTRUE;
+       fCurrentChannel=-1;
+       break;
       }
     }
     else{
-      continueLoop=kFALSE;
-      fNextChannelFlag=kFALSE;
-      if(fDataBunch.size()>0){//we reached end of data in total, but we still have a bunch
-       iResult = 0;
-      }
+      // end of data, but there is one bunch to be completed
+      fCurrentChannel=-1;
+      break;
     }
-  }while(continueLoop);
+  }while(1);
 
-  return iResult;
+  fCurrentBin=prevTime;
+  return fDataBunch.size();
 
 }
 
 int AliHLTTPCDigitReaderPacked::GetBunchSize(){
+  // see header file for class documentation
   return fDataBunch.size();
 }
 
@@ -401,39 +410,152 @@ Int_t* AliHLTTPCDigitReaderPacked::GetBufferInstance()
   // This is just a poor man's solution, no synchronization for the
   // moment
   AliHLTLogging log;
-  if (fgpIssuedInstance) {
+  if (fgpIssuedBufferInstance) {
     log.LoggingVarargs(kHLTLogError, "AliHLTTPCDigitReaderPacked", "GetBufferInstance" , __FILE__ , __LINE__ ,
                       "instance of sorted buffer has not been released or multiple instances requested. Only available as global singleton for DigitReaderPacked");
     return NULL;
   }
 
-  if (!fgpFreeInstance) {
+  if (!fgpFreeBufferInstance) {
     if (fNMaxRows<0 || fNMaxPads<0 || fNTimeBins<0) {
       log.LoggingVarargs(kHLTLogError, "AliHLTTPCDigitReaderPacked", "GetBufferInstance" , __FILE__ , __LINE__ ,
                         "can not determine size of buffer for sorted data");
       return NULL;
     }
-    fgpFreeInstance=new Int_t[ fNMaxRows*fNMaxPads*fNTimeBins ];
+    fgpFreeBufferInstance=new Int_t[ fNMaxRows*fNMaxPads*fNTimeBins ];
     log.LoggingVarargs(kHLTLogDebug, "AliHLTTPCDigitReaderPacked", "GetBufferInstance" , __FILE__ , __LINE__ , 
                       "Array Borders  ||| MAXPAD=%d ||| MAXROW=%d ||| MAXBIN=%d ||| MAXMUL=%d", 
                       fNMaxPads, fNMaxRows, fNTimeBins, fNTimeBins*fNMaxRows*fNMaxPads);
   }
 
-  fgpIssuedInstance=fgpFreeInstance;
-  fgpFreeInstance=NULL;
-  return fgpIssuedInstance;
+  fgpIssuedBufferInstance=fgpFreeBufferInstance;
+  fgpFreeBufferInstance=NULL;
+  return fgpIssuedBufferInstance;
 }
 
 void AliHLTTPCDigitReaderPacked::ReleaseBufferInstance(Int_t* pInstance)
 {
   // see header file for class documentation
   if (!pInstance) return;
-  if (pInstance!=fgpIssuedInstance) {
+  if (pInstance!=fgpIssuedBufferInstance) {
     AliHLTLogging log;
     log.LoggingVarargs(kHLTLogError, "AliHLTTPCDigitReaderPacked", "ReleaseBufferInstance" , __FILE__ , __LINE__ ,
-                      "wrong instance %p, expecting %p", pInstance, fgpIssuedInstance);
+                      "wrong instance %p, expecting %p", pInstance, fgpIssuedBufferInstance);
+    return;
+  }
+  fgpFreeBufferInstance=fgpIssuedBufferInstance;
+  fgpIssuedBufferInstance=NULL;
+}
+
+AliHLTTPCDigitReaderPacked::AliHLTTPCRawStream* AliHLTTPCDigitReaderPacked::GetRawStreamInstance()
+{
+  // see header file for class documentation
+  if (fgpIssuedStreamInstance) {
+    HLTError("instance of TPCRawStream has not been released or multiple instances requested. Only available as global singleton for DigitReaderPacked");
+    return NULL;
+  }
+
+  if (!fgpFreeStreamInstance) {
+    fgpFreeStreamInstance=new AliHLTTPCDigitReaderPacked::AliHLTTPCRawStream;
+  }
+
+  fgpIssuedStreamInstance=fgpFreeStreamInstance;
+  fgpFreeStreamInstance=NULL;
+  return fgpIssuedStreamInstance;
+}
+
+void AliHLTTPCDigitReaderPacked::ReleaseRawStreamInstance(AliHLTTPCDigitReaderPacked::AliHLTTPCRawStream* pInstance)
+{
+  // see header file for class documentation
+  if (!pInstance) return;
+  if (pInstance!=fgpIssuedStreamInstance) {
+    HLTError("wrong instance %p, expecting %p", pInstance, fgpIssuedStreamInstance);
     return;
   }
-  fgpFreeInstance=fgpIssuedInstance;
-  fgpIssuedInstance=NULL;
+  fgpFreeStreamInstance=fgpIssuedStreamInstance;
+  fgpIssuedStreamInstance=NULL;
+}
+
+AliHLTTPCDigitReaderPacked::AliHLTTPCRawStream::AliHLTTPCRawStream()
+  :
+  fRawMemoryReader(new AliRawReaderMemory),
+  fTPCRawStream(new AliTPCRawStream(fRawMemoryReader))
+{
+  // see header file for class documentation
+}
+
+AliHLTTPCDigitReaderPacked::AliHLTTPCRawStream::~AliHLTTPCRawStream()
+{
+  // see header file for class documentation
+  if (fRawMemoryReader) delete fRawMemoryReader;
+  fRawMemoryReader=NULL;
+  if (fTPCRawStream) delete fTPCRawStream;
+  fTPCRawStream=NULL;
+}
+
+Bool_t AliHLTTPCDigitReaderPacked::AliHLTTPCRawStream::SetMemory(Int_t ddlId, UChar_t* memory, ULong_t size )
+{
+  // see header file for class documentation
+  if (!fRawMemoryReader) return false;
+  Bool_t result=fRawMemoryReader->SetMemory(memory, size );
+  fRawMemoryReader->SetEquipmentID(ddlId);
+  fRawMemoryReader->RewindEvents();
+  fRawMemoryReader->NextEvent();
+  return result;
+}
+
+bool AliHLTTPCDigitReaderPacked::AliHLTTPCRawStream::Next()
+{
+  // see header file for class documentation
+  if (!fTPCRawStream) return -1;
+  return fTPCRawStream->Next();
+}
+
+Int_t AliHLTTPCDigitReaderPacked::AliHLTTPCRawStream::GetRow() const
+{
+  // see header file for class documentation
+  if (!fTPCRawStream) return -1;
+  return fTPCRawStream->GetRow();
+}
+
+Int_t AliHLTTPCDigitReaderPacked::AliHLTTPCRawStream::GetPad() const
+{
+  // see header file for class documentation
+  if (!fTPCRawStream) return -1;
+  return fTPCRawStream->GetPad();
+}
+
+Int_t AliHLTTPCDigitReaderPacked::AliHLTTPCRawStream::GetTime() const
+{
+  // see header file for class documentation
+  if (!fTPCRawStream) return -1;
+  return fTPCRawStream->GetTime();
+}
+
+Int_t AliHLTTPCDigitReaderPacked::AliHLTTPCRawStream::GetSignal() const
+{
+  // see header file for class documentation
+  if (!fTPCRawStream) return -1;
+  return fTPCRawStream->GetSignal();
+}
+
+Int_t AliHLTTPCDigitReaderPacked::AliHLTTPCRawStream::GetHWAddress() const
+{
+  // see header file for class documentation
+  if (!fTPCRawStream) return -1;
+  return fTPCRawStream->GetHWAddress();
+}
+
+Bool_t  AliHLTTPCDigitReaderPacked::AliHLTTPCRawStream::GetRCUTrailerData(UChar_t*& data) const
+{
+  // see header file for class documentation
+  if (!fTPCRawStream) return -1;
+  return fTPCRawStream->GetRCUTrailerData(data);
+}
+
+Int_t   AliHLTTPCDigitReaderPacked::AliHLTTPCRawStream::GetRCUTrailerSize() const
+{
+  // see header file for class documentation
+  if (!fTPCRawStream) return -1;
+  return fTPCRawStream->GetRCUTrailerSize();
 }
index 57069f4f012968e4bd00a07171e192a28a5f94bf..4cb1641e1898cd820e1e2d7a2dff815566bc17eb 100644 (file)
@@ -14,8 +14,6 @@
     @brief  A digit reader implementation for simulated, packed TPC 'raw' data.
 */
 
-//#define ENABLE_PAD_SORTING 1
-
 #include "AliHLTTPCDigitReader.h"
 #include <vector>
 
@@ -58,10 +56,41 @@ public:
   bool NextChannel();
   int NextBunch();
   AliHLTUInt32_t GetAltroBlockHWaddr() const;
+  int GetRCUTrailerSize();
+  bool GetRCUTrailerData(UChar_t*& trData);
   int GetBunchSize();
   const UInt_t* GetSignals();
   Int_t GetTimeOfUnsortedSignal();    
-    
+
+  /**
+   * Compound to hold both the AliTPCRawStreamInstance and the RawReader
+   */
+  class AliHLTTPCRawStream {
+  public:
+    AliHLTTPCRawStream();
+    ~AliHLTTPCRawStream();
+
+    Bool_t SetMemory(Int_t ddlId, UChar_t* memory, ULong_t size );
+
+    bool Next();
+
+    Int_t GetRow() const;
+    Int_t GetPad() const;
+    Int_t GetTime() const;
+    Int_t GetSignal() const;
+    Int_t GetHWAddress() const;
+    Bool_t  GetRCUTrailerData(UChar_t*& data) const;
+    Int_t   GetRCUTrailerSize() const;
+
+  private:
+    /** copy constructor prohibited */
+    AliHLTTPCRawStream(const AliHLTTPCRawStream&);
+    /** assignment operator prohibited */
+    AliHLTTPCRawStream& operator=(const AliHLTTPCRawStream&);
+
+    AliRawReaderMemory *fRawMemoryReader; //!transient
+    AliTPCRawStream *fTPCRawStream; //!transient
+  };
 protected:
     
 private:
@@ -80,38 +109,64 @@ private:
   static Int_t* GetBufferInstance();
 
   /**
-   * Release an instance of the decoder.
+   * Release an instance of the buffer.
    */
   static void ReleaseBufferInstance(Int_t* pInstance);
 
-  // Initialize AliROOT TPC raw stream parsing class
-  AliRawReaderMemory *fRawMemoryReader; //!transient
+  /**
+   * Instance handling of the TPCRawStream.
+   * In order to keep memory consumption small, one global instance of the
+   * TPCRawStream will be used to read data.
+   * This can actually be extended in order to support more than one global
+   * instance provided by a scheduler, but thats overkill for the moment.
+   */
+  AliHLTTPCRawStream* GetRawStreamInstance();
+
+  /**
+   * Release an instance of the TPCRawStream.
+   */
+  void ReleaseRawStreamInstance(AliHLTTPCRawStream* pInstance);
+
+  AliHLTTPCRawStream* fTPCRawStream; //!transient
 
-  AliTPCRawStream *fTPCRawStream; //!transient
-    
-  //#if ENABLE_PAD_SORTING 
   Int_t fCurrentRow; //!transient
   Int_t fCurrentPad; //!transient
   Int_t fCurrentBin; //!transient
  
   Int_t fRowOffset; //!transient
   Int_t fNRows; //!transient
+  Int_t fNPads; //!transient
 
   static Int_t fNMaxRows; //!transient
   static Int_t fNMaxPads; //!transient
   static Int_t fNTimeBins; //!transient
 
   Int_t *fData; //!transient
-  //#endif // ENABLE_PAD_SORTING
 
   Bool_t fUnsorted; //!transient
 
+  /** array to hold bunch data */
   vector<UInt_t> fDataBunch;                             //! transient
-  Bool_t fNextChannelFlag;                               //! transient
+  /** the current channel for bulk read mode */
+  Int_t fCurrentChannel;                                 //! transient
+  /** last NextSignal returned data */
+  Int_t fbHaveData;                                      //! transient
+
+  /** partition the reader is initialized for */
   Int_t fCurrentPatch;                                   //! transient
 
-  static Int_t* fgpFreeInstance;                         //! transient
-  static Int_t* fgpIssuedInstance;                       //! transient
+  /** the global free instance of sorted data buffer */
+  static Int_t* fgpFreeBufferInstance;                   //! transient
+  /** occupied instance */
+  static Int_t* fgpIssuedBufferInstance;                 //! transient
+
+  /** the global free instance of the TPCRawStream */
+  static AliHLTTPCRawStream* fgpFreeStreamInstance;      //! transient
+  /** occupied instance of the TPCRawStream */
+  static AliHLTTPCRawStream* fgpIssuedStreamInstance;    //! transient
+
+  /** counter for instances of the reader */
+  static Int_t fgObjectCount;                            //! transient
 
   ClassDef(AliHLTTPCDigitReaderPacked, 4)