Fixes in order to treat correctly event and sub-event header extensions.
authorcvetan <cvetan@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 5 Feb 2008 16:41:45 +0000 (16:41 +0000)
committercvetan <cvetan@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 5 Feb 2008 16:41:45 +0000 (16:41 +0000)
MONITOR/root2date.cxx
RAW/AliRawEventHeaderBase.cxx
RAW/AliRawEventHeaderBase.h

index e5eff02..0371553 100644 (file)
@@ -21,6 +21,8 @@ int Root2Date(AliRawEvent *gdcRootEvent, unsigned char *gdcDateEvent, char *ddlD
  p+=chunkSize;
  memcpy(p, aliHeader->HeaderBegin(), chunkSize=aliHeader->HeaderSize()); // Write DATE GDC header
  p+=chunkSize;
+ memcpy(p, aliHeader->GetExtendedData(), chunkSize=aliHeader->GetExtendedDataSize());
+ p+=chunkSize;
  for(ldcCounter=0; ldcCounter<gdcRootEvent->GetNSubEvents(); ldcCounter++) {
   ldcRootEvent=gdcRootEvent->GetSubEvent(ldcCounter);
   aliHeader=ldcRootEvent->GetHeader();
@@ -28,6 +30,8 @@ int Root2Date(AliRawEvent *gdcRootEvent, unsigned char *gdcDateEvent, char *ddlD
   p+=chunkSize;
   memcpy(p, aliHeader->HeaderBegin(), chunkSize=aliHeader->HeaderSize()); // Write DATE LDC header
   p+=chunkSize;
+  memcpy(p, aliHeader->GetExtendedData(), chunkSize=aliHeader->GetExtendedDataSize());
+  p+=chunkSize;
   for(equipmentCounter=0; equipmentCounter<ldcRootEvent->GetNEquipments(); equipmentCounter++) {
    aliEquipment=ldcRootEvent->GetEquipment(equipmentCounter);
    aliEquipmentHeader=aliEquipment->GetEquipmentHeader();
index 37a7847..742d062 100644 (file)
@@ -47,6 +47,7 @@ fMagic(0),
 fHeadSize(0),
 fVersion(0),
 fExtendedDataSize(0),
+fExtendedAllocSize(0),
 fExtendedData(NULL),
 fIsSwapped(kFALSE)
 {
@@ -247,10 +248,7 @@ AliRawEventHeaderBase* AliRawEventHeaderBase::Create(char*& data)
   }
   else {
     if (extsize > 0) {
-      hdr->SetExtendedDataSize(extsize);
-      char *extdata = new char[extsize];
-      memset(extdata,0,extsize);
-      hdr->SetExtendedData(extdata);
+      hdr->AllocateExtendedData(extsize);
     }
   }
 
@@ -282,26 +280,63 @@ Int_t AliRawEventHeaderBase::ReadHeader(char*& data)
     data += HeaderBaseSize();
     SwapData(data, HeaderBegin(), HeaderSize());
     data += HeaderSize();
-    if(GetExtendedDataSize()>0) {
-      SwapData(data, GetExtendedData(), GetExtendedDataSize());
-      data += GetExtendedDataSize();
-    }
   }
   else {
     memcpy(HeaderBaseBegin(), data, HeaderBaseSize());
     data += HeaderBaseSize();
     memcpy(HeaderBegin(), data, HeaderSize());
     data += HeaderSize();
-    if(GetExtendedDataSize()>0) {
-      memcpy(GetExtendedData(), data, GetExtendedDataSize());
-      data += GetExtendedDataSize();
-    }
   }
+  data += ReadExtendedData(data);
 
   return (Int_t)((Long_t)data - start);
 }
 
 //______________________________________________________________________________
+void AliRawEventHeaderBase::AllocateExtendedData(Int_t extsize)
+{
+  // Allocate the space for the header
+  // extended data
+  if (fExtendedData) delete [] fExtendedData;
+  
+  fExtendedDataSize = fExtendedAllocSize = extsize;
+  fExtendedData = new char[fExtendedAllocSize];
+  memset(fExtendedData,0,fExtendedAllocSize);
+}
+
+//______________________________________________________________________________
+Int_t AliRawEventHeaderBase::ReadExtendedData(char*& data)
+{
+  // Read extended header data
+  // Reallocates memory if the present
+  // buffer is insufficient
+  Int_t extsize = (Int_t)GetHeadSize() - (HeaderBaseSize() + HeaderSize());
+
+  if (extsize == 0) {
+    fExtendedDataSize = 0;
+    return 0;
+  }
+
+  if (extsize < 0) {
+    AliFatal(Form("Invalid header size (%d < %d +%d)!",
+                 GetHeadSize(),HeaderBaseSize(),HeaderSize()));
+    // try recovery... how?
+    return 0;
+  }
+
+  fExtendedDataSize = extsize;
+  if (fExtendedDataSize > fExtendedAllocSize)
+    AllocateExtendedData(fExtendedDataSize);
+
+  if (DataIsSwapped())
+    SwapData(data, fExtendedData, fExtendedDataSize);
+  else
+    memcpy(fExtendedData, data, fExtendedDataSize);
+
+  return fExtendedDataSize;
+}
+
+//______________________________________________________________________________
 UInt_t AliRawEventHeaderBase::Get(const char *datamember) const
 {
   // The method to get a data member from the header object
index f081086..da14989 100644 (file)
@@ -42,12 +42,12 @@ public:
 
    UInt_t        GetExtendedDataSize() const { return fExtendedDataSize; }
    char*         GetExtendedData() const { return fExtendedData; }
-   void          SetExtendedDataSize(Int_t size) { fExtendedDataSize = size; }
-   void          SetExtendedData(char *data) { fExtendedData = data; }
 
    const char *  GetTypeName() const;
    static AliRawEventHeaderBase* Create(char*& data);
+   void          AllocateExtendedData(Int_t extsize);
    Int_t         ReadHeader(char*& data);
+   Int_t         ReadExtendedData(char*& data);
    UInt_t        Get(const char *datamember) const;
    const UInt_t* GetP(const char *datamember) const;
 
@@ -81,6 +81,7 @@ private:
    UInt_t fVersion;       // unique version identifier
 
    UInt_t fExtendedDataSize; // size of header extension data
+   UInt_t fExtendedAllocSize;//! size of allocated memory for header extension data
    char  *fExtendedData;  //[fExtendedDataSize] pointer to header extension data 
 
    Bool_t fIsSwapped;     // is data swapped
@@ -88,7 +89,7 @@ private:
    static const UInt_t fgkEventMagicNumber        = 0xDA1E5AFE; // magic word
    static const UInt_t fgkEventMagicNumberSwapped = 0xFE5A1EDA; // swapped magic word
 
-   ClassDef(AliRawEventHeaderBase,1)  // Alice raw event header base class
+   ClassDef(AliRawEventHeaderBase,2)  // Alice raw event header base class
 };
 
 #define EVENT_HEADER_VERSION(AA,BB) AliRawEventHeaderV##AA##_##BB