]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliAltroBufferV3.cxx
make scan of dEdx blocks consistent, there is only one block
[u/mrichter/AliRoot.git] / RAW / AliAltroBufferV3.cxx
index f2d5fc85188d313b371774badbfb0c2a9e97c3ef..9dd57868e082aa58dff1fea45647433af8b5fe26 100644 (file)
@@ -31,17 +31,13 @@ AliAltroBuffer(fileName,mapping),
   fN(0)
 {
   // Constructor
+  memset(fArray, 0, kMaxWords*sizeof(UShort_t));
 }
 
 //_____________________________________________________________________________
 AliAltroBufferV3::~AliAltroBufferV3()
 {
 // destructor
-
-  if (fVerbose) Info("~AliAltroBufferV3", "File Created");
-
-  delete fFile;
-
 }
 
 //_____________________________________________________________________________
@@ -87,8 +83,8 @@ void AliAltroBufferV3::WriteTrailer(Int_t wordsNumber, Short_t hwAddress)
   //Writes a trailer (header) of 32 bits using
   //a given hardware adress
   UInt_t temp = hwAddress & 0xFFF;
-  temp = (wordsNumber << 16) & 0x3FF;
-  temp |= (0x1 << 30);
+  temp |= ((wordsNumber & 0x3FF) << 16);
+  temp |= (0x1U << 30);
 
   fFile->WriteBuffer((char *)(&temp),sizeof(UInt_t));
 
@@ -102,7 +98,7 @@ void AliAltroBufferV3::ReverseAndWrite()
   // write the buffer to the file
   UInt_t temp = 0;
   Int_t shift = 20;
-  for(Int_t i = fN; i >= 0; i--) {
+  for(Int_t i = (fN-1); i >= 0; i--) {
     temp |= (fArray[i] << shift);
     shift -= 10;
     if (shift < 0) {
@@ -120,7 +116,7 @@ void AliAltroBufferV3::ReverseAndWrite()
 }
 
 //_____________________________________________________________________________
-void AliAltroBufferV3::WriteRCUTrailer(Int_t rcuId)
+UChar_t AliAltroBufferV3::WriteRCUTrailer(Int_t rcuId)
 {
   // Writes the RCU trailer
   // rcuId the is serial number of the corresponding
@@ -132,28 +128,58 @@ void AliAltroBufferV3::WriteRCUTrailer(Int_t rcuId)
   UInt_t currentFilePos = fFile->Tellp();
   UInt_t size = currentFilePos-fDataHeaderPos;
   size -= sizeof(AliRawDataHeader);
+  size /= 4;
   
-  if ((size % 5) != 0) {
-    AliFatal(Form("The current raw data payload is not a mutiple of 5 (%d) ! Can not write the RCU trailer !",size));
-    return;
+  if (size > 0x3FFFFFF) {
+    AliFatal(Form("The current raw data payload size of %d is bigger than the max possible one ! Can not write the RCU trailer !",size));
+    return 2;
   }
 
-  // Now put the size in unit of number of 40bit words
-  size /= 5;
+  // Now add the the RCU trailer tag
+  size |= (1U << 31);
   fFile->WriteBuffer((char *)(&size),sizeof(UInt_t));
 
-  // Now several not yet full defined fields
-  // In principle they are supposed to contain
-  // information about the sampling frequency,
-  // L1 phase, list of 'dead' FECs, etc.
-  //  UInt_t buffer[n];
-  //  fFile->WriteBuffer((char *)(buffer),sizeof(UInt_t)*n);
+  // Now several well defined fields contained
+  // in the trailer
+  // For details check the RCU manual
+  UInt_t buffer;
+
+  buffer  = (0x1U << 26);
+  buffer |= (0x1U << 31);
+  fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
+  
+  buffer  = (0x2U << 26);
+  buffer |= (0x1U << 31);
+  fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
+  
+  buffer  = (0x3U << 26);
+  buffer |= (0x1U << 31);
+  fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
+
+  buffer  = 0x3FFFFFF;
+  buffer |= (0x4U << 26);
+  buffer |= (0x1U << 31);
+  fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
+  buffer  = 0x3FFFFFF;
+  buffer |= (0x5U << 26);
+  buffer |= (0x1U << 31);
+  fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
+
+  buffer  = (0x6U << 26);
+  buffer |= (0x1U << 31);
+  fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
+  
+  buffer  = (0x7U << 26);
+  buffer |= (0x1U << 31);
+  fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
   
   //  Now the RCU identifier and size of the trailer
-  //  FOr the moment the triler size is 2 32-bit words
-  UInt_t buffer = (2 & 0x7F);
+  buffer = (9 & 0x7F);
   buffer |= ((rcuId & 0x1FF) << 7);
-  buffer |= 0xAAAA << 16;
+  buffer |= (0x2U << 16);
+  buffer |= (0x8U << 26);
+  buffer |= (0x3U << 30);
   fFile->WriteBuffer((char *)(&buffer),sizeof(UInt_t));
 
+  return 2;
 }