Minor changes at new Top Makefile.
[u/mrichter/AliRoot.git] / HLT / misc / AliL3AltroMemHandler.cxx
index 9c4ab6c7e403a47e2993613b66d569871bbe80ae..a6fb3ca8575001e1963abe8b120ee6d3ea588e0a 100644 (file)
@@ -8,6 +8,10 @@ Author: Constantin Loizides <mailto: loizides@ikf.physik.uni-frankfurt.de>
 #include "AliL3AltroMemHandler.h"
 
 /** \class AliL3AltroMemHandler
+//<pre>
+//--------------------------------------------------------------------
+// AliL3AltroMemHandler
+//
 // Converts digits in memory into a backlinked ALTRO like data format.
 // Its output file is used as input to the various VHDL testbenches.
 // The file misc/read.cxx shows how to use this class.
@@ -17,6 +21,7 @@ ClassImp(AliL3AltroMemHandler)
 
 AliL3AltroMemHandler::AliL3AltroMemHandler(){
   Clear();
+  ClearRead();
 };
 
 void AliL3AltroMemHandler::Clear(){
@@ -30,14 +35,22 @@ void AliL3AltroMemHandler::Clear(){
   flag=kFALSE;
 };
 
-void AliL3AltroMemHandler::Write(UShort_t row, UChar_t pad, UShort_t charge, UShort_t time)
+void AliL3AltroMemHandler::ClearRead(){
+  rcounter=0;
+  scounter=0;
+  rpad=0;
+  rrow=0;
+  rtime=0;
+}
+
+void AliL3AltroMemHandler::Write(UShort_t row, UChar_t pad, UShort_t time, UShort_t charge)
 {
   if(tcounter==0){
     lrow=row;
     lpad=pad;
   } else if((lrow!=row) || (lpad!=pad)){
     MakeAltroPackets(); //make packets
-    Write();       //write packets
+    Write();            //write packets
     Clear();            //clear up for next pad
 
     lrow=row;
@@ -59,7 +72,7 @@ void AliL3AltroMemHandler::MakeAltroPackets()
   UShort_t i=0,j=0;
   UShort_t t=0,seqlength;
   UShort_t htime,ltime;
-  int ddd=0;
+
   while(t<tcounter){
     pcounter=0;
     altromem[--counter]=0xFFFF; //mark return
@@ -77,6 +90,7 @@ void AliL3AltroMemHandler::MakeAltroPackets()
       }
       seqlength=j+1; //number of consecutive times   
       htime=times_per_pad[i]; //abs. time for sequence
+
 /*
   cout << " counter " << counter << endl;
   if(htime!=ltime+j){
@@ -84,6 +98,9 @@ void AliL3AltroMemHandler::MakeAltroPackets()
   exit(1);
   }
 */
+      //don't store sequence if it doesn't fit into packet
+      if(pcounter+seqlength>=ALTRO_SIZE) break;
+
       //store charges of sequence
       for(UShort_t k=0;k<seqlength;k++){
        altromem[--counter]=charges_per_pad[t];
@@ -143,16 +160,150 @@ void AliL3AltroMemHandler::WriteFinal()
   }
 }
 
-/*
-Bool_t AliL3AltroMemHandler::SetBinaryInput(FILE *file){
+Bool_t AliL3AltroMemHandler::Read(UShort_t &row, UChar_t &pad, UShort_t &time, UShort_t &charge)
+{
+  if(flag==kTRUE) {
+    LOG(AliL3Log::kWarning,"AliL3AltroMemHandler::Read","File Open")<<"Binary not supported!"<<ENDLOG;
+    return kFALSE;
+  }
+  
+  if(feof(fInBinary)){
+    LOG(AliL3Log::kDebug,"AliL3AltroMemHandler::Read","File Open")<<"End of File!"<<ENDLOG;
+    return kFALSE;
+  }
+
+  unsigned int dummy,dummy1;
+
+  if(rcounter==0){
+    fscanf(fInBinary,"%x",&dummy);
+    rrow=(UShort_t)dummy;
+    fscanf(fInBinary,"%x",&dummy);
+    rpad=(UShort_t)dummy;
+    fscanf(fInBinary,"%x",&dummy);
+    rcounter=(UShort_t)dummy;
+    fscanf(fInBinary,"%x",&dummy);
+    if(dummy!=682){
+      if(feof(fInBinary)){
+       ClearRead();
+       return kFALSE;
+      } else {
+       LOG(AliL3Log::kError,"AliL3AltroMemHandler::Read","Trailer not found!")<<ENDLOG;
+       return kFALSE;
+      }
+    }
+    dummy1 = rcounter;
+    while(dummy1 % 4 != 0) {
+      fscanf(fInBinary,"%x",&dummy);
+      dummy1++;
+    } 
+  } 
+  if(scounter==0){
+    fscanf(fInBinary,"%x",&dummy);
+    scounter=(UShort_t)dummy-2;
+    fscanf(fInBinary,"%x",&dummy);
+    rtime=(UShort_t)dummy;
+    rcounter-=2;
+  }
+  fscanf(fInBinary,"%x",&dummy);
+
+  row=rrow;
+  pad=rpad;
+  time=rtime;
+  charge=(UShort_t)dummy;
+
+  scounter--;
+  rcounter--;
+  rtime--;
+  return kTRUE;
+}
+
+Bool_t AliL3AltroMemHandler::ReadSequence(UShort_t &row, UChar_t &pad, UShort_t &time, UChar_t &n, UShort_t **charges)
+{
+  if(flag==kTRUE) {
+    LOG(AliL3Log::kWarning,"AliL3AltroMemHandler::ReadSequence","File Open")<<"Binary not supported!"<<ENDLOG;
+    return kFALSE;
+  }
+  
+  if(feof(fInBinary)){
+    LOG(AliL3Log::kDebug,"AliL3AltroMemHandler::ReadSequence","File Open")<<"End of File!"<<ENDLOG;
+    return kFALSE;
+  }
+
+  unsigned int dummy,dummy1,dummy2;
+
+  if(rcounter==0){
+    fscanf(fInBinary,"%x",&dummy);
+    rrow=(UShort_t)dummy;
+    fscanf(fInBinary,"%x",&dummy);
+    rpad=(UShort_t)dummy;
+    fscanf(fInBinary,"%x",&dummy);
+    rcounter=(UShort_t)dummy;
+    fscanf(fInBinary,"%x",&dummy);
+    if(dummy!=682){
+      if(feof(fInBinary)){
+       ClearRead();
+       return kFALSE;
+      } else {
+       LOG(AliL3Log::kError,"AliL3AltroMemHandler::ReadSequence","Format") <<"Trailer not found!"<<ENDLOG;
+       return kFALSE;
+      }
+    }
+    dummy1 = rcounter;
+    while(dummy1 % 4 != 0) {
+      fscanf(fInBinary,"%x",&dummy);
+      dummy1++;
+    } 
+  } 
+
+  fscanf(fInBinary,"%x",&dummy);
+  scounter=(UShort_t)dummy-2;
+  fscanf(fInBinary,"%x",&dummy);
+  rtime=(UShort_t)dummy;
+  rcounter-=2;
+
+  if(n<scounter){
+    if(*charges) delete[] *charges;
+    *charges=new UShort_t[scounter];
+  }
+
+  dummy2=0;
+  while(dummy2<scounter){
+    fscanf(fInBinary,"%x",&dummy);
+    (*charges)[dummy2]=(UShort_t)dummy;
+    dummy2++;
+    rcounter--;
+  }
+
+  row=rrow;
+  pad=rpad;
+  time=rtime;
+  n=scounter;
+  return kTRUE;
+}
+
+Bool_t AliL3AltroMemHandler::SetBinaryInput(FILE *file)
+{
   fInBinary = file;
   if(!fInBinary){
-    //LOG(AliL3Log::kWarning,"AliL3AltroMem::SetBinaryInput","File Open")<<"Pointer to File = 0x0 "<<ENDLOG;
+    LOG(AliL3Log::kWarning,"AliL3AltroMemHandler::SetBinaryInput","File Open")<<"Pointer to File = 0x0 "<<ENDLOG;
     return kFALSE;
   }
+  ClearRead();
+  flag=kTRUE;
+  return kTRUE;
+}
+
+Bool_t AliL3AltroMemHandler::SetASCIIInput(FILE *file)
+{
+  fInBinary = file;
+  if(!fInBinary){
+    LOG(AliL3Log::kWarning,"AliL3AltroMemHandler::SetASCIIInput","File Open")<<"Pointer to File = 0x0 "<<ENDLOG;
+    return kFALSE;
+  }
+  ClearRead();
+  flag=kFALSE;
   return kTRUE;
 }
-*/
 
 Bool_t AliL3AltroMemHandler::SetBinaryOutput(FILE *file){
   fOutBinary = file;
@@ -160,6 +311,7 @@ Bool_t AliL3AltroMemHandler::SetBinaryOutput(FILE *file){
     LOG(AliL3Log::kWarning,"AliL3AltroMemHandler::SetBinaryOutput","File Open") <<"Pointer to File = 0x0 "<<ENDLOG;
     return kFALSE;
   }
+  Clear();
   flag=kTRUE;
   return kTRUE;
 }
@@ -170,6 +322,8 @@ Bool_t AliL3AltroMemHandler::SetASCIIOutput(FILE *file){
     LOG(AliL3Log::kWarning,"AliL3AltroMemHandler::SetASCIIOutput","File Open") <<"Pointer to File = 0x0 "<<ENDLOG;
     return kFALSE;
   }
+  Clear();
   flag=kFALSE;
   return kTRUE;
 }
+