]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawReader.cxx
AOD analysis for protons - analysis train
[u/mrichter/AliRoot.git] / RAW / AliRawReader.cxx
index 95570b08b46da1f343aa8ec3c7b8a03d0b3bf287..cb626f33526ba1a67f318207ee1b2c9746c64ee3 100644 (file)
@@ -39,6 +39,7 @@
 #include <Riostream.h>
 #include "AliRawReader.h"
 #include "AliDAQ.h"
+#include "AliLog.h"
 
 ClassImp(AliRawReader)
 
@@ -54,9 +55,16 @@ AliRawReader::AliRawReader() :
   fSelectMaxEquipmentId(-1),
   fSkipInvalid(kFALSE),
   fSelectEventType(-1),
-  fErrorCode(0)
+  fErrorCode(0),
+  fEventNumber(-1),
+  fErrorLogs("AliRawDataErrorLog",100),
+  fHeaderSwapped(NULL)
 {
 // default constructor: initialize data members
+// Allocate the swapped header in case of Mac
+#ifndef R__BYTESWAP
+  fHeaderSwapped=new AliRawDataHeader();
+#endif
 }
 
 Bool_t AliRawReader::LoadEquipmentIdsMap(const char *fileName)
@@ -103,9 +111,16 @@ AliRawReader::AliRawReader(const AliRawReader& rawReader) :
   fSelectMaxEquipmentId(rawReader.fSelectMaxEquipmentId),
   fSkipInvalid(rawReader.fSkipInvalid),
   fSelectEventType(rawReader.fSelectEventType),
-  fErrorCode(0)
+  fErrorCode(0),
+  fEventNumber(-1),
+  fErrorLogs("AliRawDataErrorLog",100),
+  fHeaderSwapped(NULL)
 {
 // copy constructor
+// Allocate the swapped header in case of Mac
+#ifndef R__BYTESWAP
+  fHeaderSwapped=new AliRawDataHeader(*rawReader.fHeaderSwapped);
+#endif
 }
 
 AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
@@ -125,6 +140,9 @@ AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
 
   fErrorCode = rawReader.fErrorCode;
 
+  fEventNumber = rawReader.fEventNumber;
+  fErrorLogs = *((TClonesArray*)rawReader.fErrorLogs.Clone());
+
   return *this;
 }
 
@@ -135,6 +153,8 @@ AliRawReader::~AliRawReader()
   // initialized
   if (fEquipmentIdsIn) delete fEquipmentIdsIn;
   if (fEquipmentIdsOut) delete fEquipmentIdsOut;
+  fErrorLogs.Delete();
+  if (fHeaderSwapped) delete fHeaderSwapped;
 }
 
 Int_t AliRawReader::GetMappedEquipmentId() const
@@ -277,6 +297,20 @@ Bool_t AliRawReader::IsEventSelected() const
   return kTRUE;
 }
 
+UInt_t AliRawReader::SwapWord(UInt_t x) const
+{
+   // Swap the endianess of the integer value 'x'
+
+   return (((x & 0x000000ffU) << 24) | ((x & 0x0000ff00U) <<  8) |
+           ((x & 0x00ff0000U) >>  8) | ((x & 0xff000000U) >> 24));
+}
+
+UShort_t AliRawReader::SwapShort(UShort_t x) const
+{
+   // Swap the endianess of the short value 'x'
+
+   return (((x & 0x00ffU) <<  8) | ((x & 0xff00U) >>  8)) ;
+}
 
 Bool_t AliRawReader::ReadNextInt(UInt_t& data)
 {
@@ -295,6 +329,9 @@ Bool_t AliRawReader::ReadNextInt(UInt_t& data)
     Error("ReadNextInt", "could not read data!");
     return kFALSE;
   }
+#ifndef R__BYTESWAP
+  data=SwapWord(data);
+#endif
   return kTRUE;
 }
 
@@ -315,6 +352,9 @@ Bool_t AliRawReader::ReadNextShort(UShort_t& data)
     Error("ReadNextShort", "could not read data!");
     return kFALSE;
   }
+#ifndef R__BYTESWAP
+  data=SwapShort(data);
+#endif
   return kTRUE;
 }
 
@@ -448,3 +488,44 @@ void AliRawReader::DumpData(Int_t limit)
           
   } while (ReadHeader());
 }
+
+void AliRawReader::AddErrorLog(AliRawDataErrorLog::ERawDataErrorLevel level,
+                              Int_t code,
+                              const char *message)
+{
+  // Add a raw data error message to the list
+  // of raw-data decoding errors
+  if (fEventNumber < 0) {
+    AliError("No events have read so far! Impossible to add a raw data error log!");
+    return;
+  }
+  Int_t ddlId = GetEquipmentId();
+  if (ddlId < 0) {
+    AliError("No ddl raw data have been read so far! Impossible to add a raw data error log!");
+    return;
+  }
+
+  Int_t prevEventNumber = -1;
+  Int_t prevDdlId = -1;
+  Int_t prevErrorCode = -1;
+  AliRawDataErrorLog *prevLog = (AliRawDataErrorLog *)fErrorLogs.Last();
+  if (prevLog) {
+    prevEventNumber = prevLog->GetEventNumber();
+    prevDdlId       = prevLog->GetDdlID();
+    prevErrorCode   = prevLog->GetErrorCode();
+  }
+
+  if ((prevEventNumber != fEventNumber) ||
+      (prevDdlId != ddlId) ||
+      (prevErrorCode != code)) {
+    new (fErrorLogs[fErrorLogs.GetEntriesFast()])
+      AliRawDataErrorLog(fEventNumber,
+                        ddlId,
+                        level,
+                        code,
+                        message);
+  }
+  else
+    if (prevLog) prevLog->AddCount();
+
+}