]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
New version of the START raw data reader. This one should be endian independent ...
authorcvetan <cvetan@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 10 May 2006 09:03:11 +0000 (09:03 +0000)
committercvetan <cvetan@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 10 May 2006 09:03:11 +0000 (09:03 +0000)
START/AliSTARTRawReader.cxx
START/AliSTARTRawReader.h

index 81764689a24fe7033ba2a3fe4e4aa7ac7d032099..94a666eb1c9c45d0e0c42df13b56f27342e33bbf 100644 (file)
@@ -2,6 +2,7 @@
 #include "AliSTARTRawData.h"
 #include "AliSTARTdigit.h"
 #include "AliBitPacking.h"
+#include "TBits.h"
 
 #include <Riostream.h>
 #include "TMath.h"
@@ -20,7 +21,12 @@ ClassImp(AliSTARTRawReader)
   //
 // create an object to read STARTraw digits
   AliDebug(1,"Start ");
-
+  if (fDigits == 0x0) fDigits = new AliSTARTdigit(); 
+  fTree->Branch("START","AliSTARTdigit",&fDigits,405,1);
+  fRawReader->Reset();
+  fRawReader->Select(13,0,1);
  
 }
  AliSTARTRawReader::~AliSTARTRawReader ()
@@ -34,182 +40,220 @@ Bool_t  AliSTARTRawReader::Next()
 // returns kFALSE if there is no digit left
   AliBitPacking *pack ;
 
-  UInt_t word, unpackword; 
-  Int_t time, adc, pmt;
+  UInt_t word, unpackword;
+  Int_t time, adc,  pmt;
   TArrayI *timeTDC1 = new TArrayI(24);
   TArrayI * chargeTDC1 = new TArrayI(24);
   TArrayI *timeTDC2 = new TArrayI(24);
   TArrayI *chargeTDC2 = new TArrayI(24);
 
-  fRawReader->Reset();
-  fRawReader->Select(13,0,1);
   
   if (!fRawReader->ReadHeader()){
     Error("ReadSTARTRaw","Couldn't read header");
     return kFALSE;
   }
-  if (fDigits == 0x0) fDigits = new AliSTARTdigit(); 
-  fTree->Branch("START","AliSTARTdigit",&fDigits,405,1);
-  if (!fRawReader->ReadNextInt(word)) return kFALSE;
-   
-  for (Int_t i=0; i<24; i++) //time LED
-    {
-      word=0;
-      unpackword=0;
-      fRawReader->ReadNextInt(word);
-       unpackword=pack->UnpackWord(word,0,8);
-      pmt=unpackword; 
-     
-      word=0;
-      unpackword=0;
-      fRawReader->ReadNextInt(word);
-      unpackword=pack->UnpackWord(word,8,31);
-      time=unpackword;
-      timeTDC1->AddAt(time,i);
-      word=0;
-      unpackword=0;
-    }
-
-  for (Int_t i=0; i<24; i++) //time CFD
-    {
-      word=0;
-      unpackword=0;
-      fRawReader->ReadNextInt(word);
-      unpackword=pack->UnpackWord(word,0,8);
-      pmt=unpackword;
-      word=0;
-      unpackword=0;
-      fRawReader->ReadNextInt(word);
-      unpackword=pack->UnpackWord(word,8,31);
-      time=unpackword;
-      timeTDC2->AddAt(time,pmt-24);
-      word=0;
-      unpackword=0;
-    } 
-
-
-  for (Int_t i=0; i<24; i++)
-    {
-      //  QTC
-      word=0;
-      unpackword=0;
-      fRawReader->ReadNextInt(word);
-      unpackword=pack->UnpackWord(word,0,8);
-      pmt=unpackword;
-      word=0;
-      unpackword=0;
-      fRawReader->ReadNextInt(word);
-      unpackword= pack->UnpackWord(word,8,31);
-      adc=unpackword; //
-      chargeTDC1->AddAt(adc,pmt-48);
-
-      word=0;
-      unpackword=0;
-    }
+  //    if (!fRawReader->ReadNextInt(word)) return kFALSE;
+  do {
+    if (!fRawReader->ReadNextData(fData)) return kFALSE;
+  } while (fRawReader->GetDataSize() == 0);
   
-   for (Int_t i=0; i<24; i++)   //QTC amplified
-     {
-      word=0;
-      unpackword=0;
-    
-      fRawReader->ReadNextInt(word);
-      unpackword=pack->UnpackWord(word,0,8);
-      pmt=unpackword;
-      word=0;
-      unpackword=0;
-      fRawReader->ReadNextInt(word);
-      unpackword= pack->UnpackWord(word,8,31);
-      adc=unpackword;  
-      chargeTDC2->AddAt(adc,pmt-72);
-     }
-
-   fDigits->SetTime(*timeTDC2);
-   fDigits->SetADC(*chargeTDC1);
-   fDigits->SetTimeAmp(*timeTDC1);
-   fDigits->SetADCAmp(*chargeTDC2);
+    fPosition = GetPosition();
+  //  fPosition = 0;
+  cout<<" !!!! fPosition "<<fPosition<<endl;
 
+  for( Int_t i=0; i<9; i++) word = GetNextWord();
+ //  multiplicity 
    word=0;
    unpackword=0;
-    
-   fRawReader->ReadNextInt(word);
+      word = GetNextWord();
    unpackword=pack->UnpackWord(word,0,8);
    pmt=unpackword;
-
    word=0;
    unpackword=0;
-   
-   fRawReader->ReadNextInt(word);
+      word = GetNextWord();
    unpackword=pack->UnpackWord(word,8,31);
    time=unpackword;
-   fDigits->SetMeanTime(time);   
-    
-   // Best time right &left  
-   word=0;
+   fDigits->SetSumMult(time);   
+
+  
+   // best time differece  
+    word=0;
    unpackword=0;
    
-   fRawReader->ReadNextInt(word);
+      word = GetNextWord();
    unpackword=pack->UnpackWord(word,0,8);
    pmt=unpackword;
 
    word=0;
    unpackword=0;
-
-   fRawReader->ReadNextInt(word);
+   
+      word = GetNextWord();
    unpackword=pack->UnpackWord(word,8,31);
    time=unpackword;
-   fDigits->SetTimeBestRight(time);   
-
-   // best time left 
+   fDigits->SetDiffTime(time);   
+  // best time left 
    word=0;
    unpackword=0;
      
-   fRawReader->ReadNextInt(word);
+      word = GetNextWord();
    unpackword=pack->UnpackWord(word,0,8);
    pmt=unpackword;
-
    word=0;
    unpackword=0;
    
-   fRawReader->ReadNextInt(word);
+      word = GetNextWord();
    unpackword=pack->UnpackWord(word,8,31);
    time=unpackword;
    fDigits->SetTimeBestLeft(time);   
    
-
-   // best time differece  
-    word=0;
+  // Best time right &left  
+   word=0;
    unpackword=0;
    
-   fRawReader->ReadNextInt(word);
+   word = GetNextWord();
    unpackword=pack->UnpackWord(word,0,8);
    pmt=unpackword;
-
    word=0;
    unpackword=0;
-   
-   fRawReader->ReadNextInt(word);
+
+      word = GetNextWord();
    unpackword=pack->UnpackWord(word,8,31);
    time=unpackword;
-   fDigits->SetDiffTime(time);   
+   fDigits->SetTimeBestRight(time);   
  
- //  multiplicity 
-   word=0;
+     word=0;
    unpackword=0;
-   fRawReader->ReadNextInt(word);
+    
+      word = GetNextWord();
    unpackword=pack->UnpackWord(word,0,8);
    pmt=unpackword;
    word=0;
    unpackword=0;
-   fRawReader->ReadNextInt(word);
+   
+      word = GetNextWord();
    unpackword=pack->UnpackWord(word,8,31);
    time=unpackword;
-   fDigits->SetSumMult(time);   
+   fDigits->SetMeanTime(time);   
+    
+   for (Int_t i=0; i<24; i++)   //QTC amplified
+     {
+      word=0;
+      unpackword=0;
+    
+      word = GetNextWord();
+      unpackword=pack->UnpackWord(word,0,8);
+      pmt=unpackword;
+      word=0;
+      unpackword=0;
+      word = GetNextWord();
+      unpackword= pack->UnpackWord(word,8,31);
+      adc=unpackword;  
+      chargeTDC2->AddAt(adc,pmt-72);
+     }
+
+  for (Int_t i=0; i<24; i++)
+    {
+      //  QTC
+      word=0;
+      unpackword=0;
+      word = GetNextWord();
+      unpackword=pack->UnpackWord(word,0,8);
+      pmt=unpackword;
+      word=0;
+      unpackword=0;
+      word = GetNextWord();
+      unpackword= pack->UnpackWord(word,8,31);
+      adc=unpackword; //
+      chargeTDC1->AddAt(adc,pmt-48);
+
+      word=0;
+      unpackword=0;
+    }
+  
+  for (Int_t i=0; i<24; i++) //time CFD
+    {
+      word=0;
+      unpackword=0;
+      word = GetNextWord();
+      unpackword=pack->UnpackWord(word,0,8);
+      pmt=unpackword;
+      word=0;
+      unpackword=0;
+      word = GetNextWord();
+       unpackword=pack->UnpackWord(word,8,31);
+      time=unpackword;
+      timeTDC2->AddAt(time,pmt-24);
+      word=0;
+      unpackword=0;
+    } 
+
+  
+  for (Int_t i=0; i<24; i++) //time LED
+    {
+      word=0;
+      unpackword=0;
+      word = GetNextWord();
+      unpackword=pack->UnpackWord(word,0,31);
+      pmt=unpackword; 
       
+      word=0;
+      unpackword=0;
+      word = GetNextWord();
+      unpackword=pack->UnpackWord(word,8,31);
+      time=unpackword;
+      timeTDC1->AddAt(time,i);
+      word=0;
+      unpackword=0;
+    }
+  
+  fDigits->SetTime(*timeTDC2);
+  fDigits->SetADC(*chargeTDC1);
+  
+  fDigits->SetTimeAmp(*timeTDC1);
+  fDigits->SetADCAmp(*chargeTDC2);
     fTree->Fill();
 
+    delete timeTDC1 ;
+    delete chargeTDC1;
+    delete timeTDC2 ;
+    delete chargeTDC2;
+  
     return kTRUE;
 }
  
+//_____________________________________________________________________________
+Int_t AliSTARTRawReader::GetPosition()
+{
+  // Sets the position in the
+  // input stream
+  if (((fRawReader->GetDataSize() * 8) % 32) != 0)
+    AliFatal(Form("Incorrect raw data size ! %d words are found !",fRawReader->GetDataSize()));
+  return (fRawReader->GetDataSize() * 8) / 32;
+}
+//_____________________________________________________________________________
+UInt_t AliSTARTRawReader::GetNextWord()
+{
+  // Read the next 32 bit word in backward direction
+  // The input stream access is given by fData and fPosition
+
+   fPosition--;
+
+
+  Int_t iBit = fPosition * 32;
+  Int_t iByte = iBit / 8;
+  // recalculate the byte numbers and the shift because
+  // the raw data is written as integers where the high bits are filled first
+  // -> little endian is assumed here !
+  UInt_t word = 0;
+  word += fData[iByte+3]<<24;
+  word += fData[iByte+2]<<16;
+  word += fData[iByte+1]<<8;
+  word += fData[iByte];
+  return word;
+
+}
+
index fcc048e1b9522804efdb67aa9938370e0c827b4c..50eb67885288500bf9d6e05fd905b8b540583dc4 100644 (file)
@@ -16,13 +16,18 @@ class AliSTARTRawReader : public TTask {
 
 
   Bool_t  Next(); //read next raw digit
+  Int_t            GetPosition();
+  UInt_t         GetNextWord();
   
   protected :
 
-    UInt_t           fData;         // data read for file
   AliSTARTdigit* fDigits;
   TTree*        fTree;
   AliRawReader*    fRawReader;    // object for reading the raw data
+
+  UChar_t*         fData;         // raw data
+  Int_t            fPosition;     // current (32 bit) position in fData
+
   
  ClassDef(AliSTARTRawReader, 0) //class for reading START Raw data
 };