]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/TPCLib/HWCFemulator/AliHLTTPCHWCFSupport.cxx
ALIROOT-5433 Transition to CDHv3 in HLT
[u/mrichter/AliRoot.git] / HLT / TPCLib / HWCFemulator / AliHLTTPCHWCFSupport.cxx
index 1cd5077c6a1560165eb69720b903ea849c02f4b0..7264d1e00e6ed48562a1b9d3e95fe68e6d050a5e 100644 (file)
 #include "AliHLTTPCDigitReaderUnpacked.h"
 #include "AliHLTTPCTransform.h"
 #include "AliHLTTPCDefinitions.h"
-#include "AliRawDataHeader.h"
+#include "AliHLTCDHWrapper.h"
 #include "AliHLTTPCHWCFEmulator.h"
 #include "AliTPCcalibDB.h"
 #include "AliTPCCalPad.h"
 #include "AliTPCCalROC.h"
 #include "TMath.h"
 
-#if __GNUC__>= 3
-using namespace std;
-#endif
-
 #include <cstdlib>
 #include <algorithm>
 #include <cerrno>
 #include <sys/time.h>
 
+using namespace std;
 
 AliHLTTPCHWCFSupport::AliHLTTPCHWCFSupport()
   : 
@@ -65,8 +62,7 @@ AliHLTTPCHWCFSupport::~AliHLTTPCHWCFSupport()
   // see header file for class documentation
   for( int i=0; i<fgkNSlices; i++ )
     for( int j=0; j<fgkNPatches; j++ ) delete[] fMapping[i][j];
-  delete[] fEventMemory;
-  delete[] fEventMCMemory;
+  ReleaseEventMemory(); 
 }
 
 AliHLTTPCHWCFSupport::AliHLTTPCHWCFSupport(const AliHLTTPCHWCFSupport&)
@@ -84,6 +80,16 @@ AliHLTTPCHWCFSupport& AliHLTTPCHWCFSupport::operator=(const AliHLTTPCHWCFSupport
 }
 
 
+void AliHLTTPCHWCFSupport::ReleaseEventMemory()
+{
+  // clean up 
+  if( fEventMemory ) delete[] fEventMemory;
+  if( fEventMCMemory )delete[] fEventMCMemory;
+  fEventMemory = 0;
+  fEventMCMemory = 0;
+}
+
+
 const AliHLTUInt32_t *AliHLTTPCHWCFSupport::GetMapping( int slice, int patch )
 { 
   // see header file for class documentation
@@ -311,8 +317,7 @@ int AliHLTTPCHWCFSupport::CreateRawEvent
   // MC labels are provided if possible  
   //
 
-  delete[] fEventMemory;
-  delete[] fEventMCMemory;
+  ReleaseEventMemory();
   
   rawEvent = 0;
   rawEventSize32 = 0;
@@ -335,15 +340,14 @@ int AliHLTTPCHWCFSupport::CreateRawEvent
       // already raw format -> only set the pointers and estimate the size
 
       // read CDH header, estimate size of the data 
-      
-      AliHLTUInt64_t headerSize = sizeof(AliRawDataHeader);                  
+      AliHLTCDHWrapper cdhHeader(block->fPtr);
+
+      AliHLTUInt64_t headerSize = cdhHeader.GetHeaderSize();
  
-      AliRawDataHeader *cdhHeader = reinterpret_cast<AliRawDataHeader*>(block->fPtr);
-      
       AliHLTUInt64_t blockSize = block->fSize; // size of the raw data in bytes      
 
-      if( cdhHeader->fSize!=0xFFFFFFFF ){ // use size information from the header
-       blockSize = cdhHeader->fSize;
+      if( cdhHeader.GetDataSize()!=0xFFFFFFFF ){ // use size information from the header
+       blockSize = cdhHeader.GetDataSize();
        if( blockSize > block->fSize ){
          HLTWarning("%s Could not find a valid DDL header!",str);
          return 0;
@@ -408,6 +412,7 @@ int AliHLTTPCHWCFSupport::CreateRawEvent
       if( !fEventMCMemory ){
        HLTWarning("Not enougth memory: can not allocate %d bytes",totalNMC*sizeof(AliHLTTPCClusterMCLabel));
        delete[] fEventMemory;
+       fEventMemory = 0;
        return 0;
       }
 
@@ -550,10 +555,12 @@ int AliHLTTPCHWCFSupport::CheckRawData( const AliHLTUInt32_t *buffer,
   // The procedure checks consistency of the data
   //
 
-  const unsigned int headerSize32 = 8;
 
   if (!buffer) return 0;
 
+  AliHLTCDHWrapper cdh((void*)buffer);
+  const unsigned int headerSize32 = cdh.GetHeaderSize()/4;
+
   const char *str=Form("slice %d patch %d:", slice, patch);
   
   if( bufferSize32 < headerSize32 ){