Added read support for Altro like data.
authorloizides <loizides@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 14 Jun 2002 21:35:01 +0000 (21:35 +0000)
committerloizides <loizides@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 14 Jun 2002 21:35:01 +0000 (21:35 +0000)
HLT/misc/AliL3AltroMemHandler.cxx
HLT/misc/AliL3AltroMemHandler.h

index 9c4ab6c..a6fb3ca 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;
 }
+
index 57bde82..a0205dc 100644 (file)
@@ -18,12 +18,15 @@ class AliL3AltroMemHandler {
   public: 
 
    AliL3AltroMemHandler();
-   void Write(UShort_t row, UChar_t pad, UShort_t charge, UShort_t time);
+   void Write(UShort_t row, UChar_t pad, UShort_t time, UShort_t charge);
+   Bool_t Read(UShort_t &row, UChar_t &pad, UShort_t &time, UShort_t &charge);
+   Bool_t ReadSequence(UShort_t &row, UChar_t &pad, UShort_t &time, UChar_t &n, UShort_t **charges);
    void WriteFinal();
 
    Bool_t SetASCIIOutput(FILE *file);
    Bool_t SetBinaryOutput(FILE *file);
-   //Bool_t SetBinaryInput(FILE *file);
+   Bool_t SetASCIIInput(FILE *file);
+   Bool_t SetBinaryInput(FILE *file);
 
   private:
 
@@ -31,17 +34,22 @@ class AliL3AltroMemHandler {
    UShort_t times_per_pad[1024];
    UShort_t charges_per_pad[1024];
 
-   //FILE *fInBinary;
-   FILE *fOutBinary;
+   FILE *fInBinary;  //!
+   FILE *fOutBinary; //!
    UShort_t lrow;
    UChar_t lpad;
-
-   UShort_t counter;  //totalcounter
-   UShort_t tcounter; //timecounter
-   UShort_t pcounter; //packetcounter
-   Bool_t flag;
+   UShort_t rrow;  //read row
+   UChar_t rpad;   //read pad
+   UShort_t rtime; //read time
+   UShort_t counter;  //total counter
+   UShort_t tcounter; //time counter
+   UShort_t pcounter; //packet counter
+   UShort_t rcounter; //read counter
+   UShort_t scounter; //sequence counter
+   Bool_t flag; //Binary File?
 
    void Clear();
+   void ClearRead();
    void Add(UShort_t charge, UShort_t time);
    void MakeAltroPackets();
    void AddTrailer();