]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawReaderDate.cxx
Increasing histo clu. lay.1 upper lim.
[u/mrichter/AliRoot.git] / RAW / AliRawReaderDate.cxx
index 89732d1fe8c8c71942531c63def2a86b5ea32b87..8553e19aace7034412331a7cbee98c95f3184880 100644 (file)
@@ -34,9 +34,9 @@ ClassImp(AliRawReaderDate)
 
 AliRawReaderDate::AliRawReaderDate(
 #ifdef ALI_DATE
-                                  void* event
+                                  void* event, Bool_t owner
 #else
-                                  void* /* event */
+                                  void* /* event */, Bool_t owner
 #endif
                                   ) :
   fFile(NULL),
@@ -44,7 +44,8 @@ AliRawReaderDate::AliRawReaderDate(
   fSubEvent(NULL),
   fEquipment(NULL),
   fPosition(NULL),
-  fEnd(NULL)
+  fEnd(NULL),
+  fOwner(owner)
 {
 // create an object to read digits from the given date event
 
@@ -68,7 +69,8 @@ AliRawReaderDate::AliRawReaderDate(
   fSubEvent(NULL),
   fEquipment(NULL),
   fPosition(NULL),
-  fEnd(NULL)
+  fEnd(NULL),
+  fOwner(kTRUE)
 {
 // create an object to read digits from the given date event
 
@@ -76,6 +78,7 @@ AliRawReaderDate::AliRawReaderDate(
   fFile = fopen(fileName, "rb");
   if (!fFile) {
     Error("AliRawReaderDate", "could not open file %s", fileName);
+    fIsValid = kFALSE;
     return;
   }
   if (eventNumber < 0) return;
@@ -85,7 +88,7 @@ AliRawReaderDate::AliRawReaderDate(
   while (fread(&header, 1, headerSize, fFile) == headerSize) {
     if (eventNumber == 0) {
       UChar_t* buffer = new UChar_t[header.eventSize];
-      fseek(fFile, -headerSize, SEEK_CUR);
+      fseek(fFile, -(long)headerSize, SEEK_CUR);
       if (fread(buffer, 1, header.eventSize, fFile) != header.eventSize) break;
       fEvent = (eventHeaderStruct*) buffer;
       break;
@@ -106,7 +109,8 @@ AliRawReaderDate::AliRawReaderDate(const AliRawReaderDate& rawReader) :
   fSubEvent(rawReader.fSubEvent),
   fEquipment(rawReader.fEquipment),
   fPosition(rawReader.fPosition),
-  fEnd(rawReader.fEnd)
+  fEnd(rawReader.fEnd),
+  fOwner(rawReader.fOwner)
 
 {
 // copy constructor
@@ -128,8 +132,8 @@ AliRawReaderDate::~AliRawReaderDate()
 // destructor
 
 #ifdef ALI_DATE
+  if (fEvent && fOwner) delete[] fEvent;
   if (fFile) {
-    delete[] fEvent;
     fclose(fFile);
   }
 #endif
@@ -244,6 +248,17 @@ UInt_t AliRawReaderDate::GetGDCId() const
 #endif
 }
 
+UInt_t AliRawReaderDate::GetTimestamp() const
+{
+// get the timestamp from the event header
+
+#ifdef ALI_DATE
+  if (!fEvent) return 0;
+  return fEvent->eventTimestamp;
+#else
+  return 0;
+#endif
+}
 
 Int_t AliRawReaderDate::GetEquipmentSize() const
 {
@@ -413,9 +428,11 @@ Bool_t AliRawReaderDate::ReadHeader()
       // "read" the data header
       fHeader = (AliRawDataHeader*) fPosition;
       if ((fPosition + fHeader->fSize) != fEnd) {
-       Warning("ReadHeader",
-               "raw data size found in the header is wrong (%d != %d)! Using the equipment size instead !",
-               fHeader->fSize, fEnd - fPosition);
+       if ((fHeader->fSize != 0xFFFFFFFF) &&
+           (fEquipment->equipmentId != 4352))
+         Warning("ReadHeader",
+                 "raw data size found in the header is wrong (%d != %d)! Using the equipment size instead !",
+                 fHeader->fSize, fEnd - fPosition);
        fHeader->fSize = fEnd - fPosition;
       }
       fPosition += sizeof(AliRawDataHeader);
@@ -502,7 +519,14 @@ Bool_t AliRawReaderDate::NextEvent()
 // go to the next event in the date file
 
 #ifdef ALI_DATE
-  if (!fFile) return kFALSE;
+  if (!fFile) {
+    if (fEventNumber < 0 && fEvent) {
+      fEventNumber++;
+      return kTRUE;
+    }
+    else
+      return kFALSE;
+  }
 
   Reset();
   eventHeaderStruct header;
@@ -516,7 +540,7 @@ Bool_t AliRawReaderDate::NextEvent()
       continue;
     }
     UChar_t* buffer = new UChar_t[header.eventSize];
-    fseek(fFile, -headerSize, SEEK_CUR);
+    fseek(fFile, -(long)headerSize, SEEK_CUR);
     if (fread(buffer, 1, header.eventSize, fFile) != header.eventSize) {
       Error("NextEvent", "could not read event from file");
       delete[] buffer;
@@ -537,9 +561,9 @@ Bool_t AliRawReaderDate::RewindEvents()
 {
 // go back to the beginning of the date file
 
-  if (!fFile) return kFALSE;
+  if (fFile)
+    fseek(fFile, 0, SEEK_SET);
 
-  fseek(fFile, 0, SEEK_SET);
   fEventNumber = -1;
   return Reset();
 }
@@ -601,9 +625,10 @@ Int_t AliRawReaderDate::CheckData() const
       // check consistency of data size in the data header and in the sub event
       AliRawDataHeader* header = (AliRawDataHeader*) position;
       if ((position + header->fSize) != end) {
-       Warning("ReadHeader",
-               "raw data size found in the header is wrong (%d != %d)! Using the equipment size instead !",
-               header->fSize, end - position);
+       if (header->fSize != 0xFFFFFFFF)
+         Warning("ReadHeader",
+                 "raw data size found in the header is wrong (%d != %d)! Using the equipment size instead !",
+                 header->fSize, end - position);
        header->fSize = end - position;
        result |= kErrSize;
       }
@@ -614,3 +639,26 @@ Int_t AliRawReaderDate::CheckData() const
 #endif
   return 0;
 }
+
+AliRawReader* AliRawReaderDate::CloneSingleEvent() const
+{
+  // Clones the current event and
+  // creates raw-reader for the cloned event
+  // Can be used in order to make asynchronious
+  // access to the current raw data within
+  // several threads (online event display/reco)
+
+#ifdef ALI_DATE
+  if (fEvent) {
+    UInt_t evSize = fEvent->eventSize;
+    if (evSize) {
+      UChar_t *newEvent = new UChar_t[evSize];
+      memcpy(newEvent,fEvent,evSize);
+      return new AliRawReaderDate((void *)newEvent,kTRUE);
+    }
+  }
+#else
+  Fatal("AliRawReaderDate", "this class was compiled without DATE");
+#endif
+  return NULL;
+}