/** \class 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.
-// As soon as you have more than 35 digits per pad, this class needs to
-// improved to properly handle the backlinked list.
*/
ClassImp(AliL3AltroMemHandler)
Clear();
};
-Bool_t AliL3AltroMemHandler::Write(UShort_t row, UChar_t pad, UShort_t charge, UShort_t time)
-{
- Bool_t redo=kFALSE;
-
- if((counter==0)||(tcounter==0)){ //new package or new sequence
- ltime=time;
- lpad=pad;
- lrow=row;
- altromem[counter]=charge;
- counter++;
- tcounter++;
- } else if ((row==lrow)&&(pad==lpad)) {
- if(time-ltime==1){ //add charge to sequence
- ltime=time;
- altromem[counter]=charge;
- counter++;
- tcounter++;
-
- if(counter==MAX_VALS){
- WriteFinal();
- Clear();
- }
- } else { //finish old sequence
- altromem[counter]=ltime;
- counter++;
- altromem[counter]=tcounter+2;
- counter++;
-
- //start new sequence
- if(counter==MAX_VALS){
- WriteTrailer();
- Clear();
- } else tcounter=0;
-
- redo=kTRUE;
- }
- } else { //finish old package
- WriteFinal();
- Clear();
-
- //start new package
- redo=kTRUE;
- }
-
- if(redo==kTRUE) Write(row,pad,charge,time);
- return kTRUE;
-};
-
void AliL3AltroMemHandler::Clear(){
memset(altromem,0,ALTRO_SIZE);
- counter=0;
+ memset(times_per_pad,0,1024);
+ memset(charges_per_pad,0,1024);
+ counter=ALTRO_SIZE;
tcounter=0;
lpad=0;
- ltime=0;
lrow=0;
flag=kFALSE;
};
-Bool_t AliL3AltroMemHandler::WriteFinal(){
- if(counter>0){
- altromem[counter]=ltime;
- counter++;
- altromem[counter]=tcounter+2;
- counter++;
- WriteTrailer();
- }
- return kTRUE;
+void AliL3AltroMemHandler::Write(UShort_t row, UChar_t pad, UShort_t charge, UShort_t time)
+{
+ if(tcounter==0){
+ lrow=row;
+ lpad=pad;
+ } else if((lrow!=row) || (lpad!=pad)){
+ MakeAltroPackets(); //make packets
+ Write(); //write packets
+ Clear(); //clear up for next pad
+
+ lrow=row;
+ lpad=pad;
+ }
+
+ Add(charge,time);
+}
+
+void AliL3AltroMemHandler::Add(UShort_t charge, UShort_t time)
+{
+ times_per_pad[tcounter]=time;
+ charges_per_pad[tcounter]=charge;
+ tcounter++;
+}
+
+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
+
+ //make packets
+ while((pcounter<ALTRO_SIZE) && (t<tcounter)){
+
+ //find sequence
+ i=t;
+ ltime=times_per_pad[t];
+ j=0;
+ while((i+1<tcounter)&&(times_per_pad[i+1]==ltime+j+1)){
+ i++;
+ j++;
+ }
+ seqlength=j+1; //number of consecutive times
+ htime=times_per_pad[i]; //abs. time for sequence
+/*
+ cout << " counter " << counter << endl;
+ if(htime!=ltime+j){
+ cerr << "Error: " << ltime << " - " << htime << endl;
+ exit(1);
+ }
+*/
+ //store charges of sequence
+ for(UShort_t k=0;k<seqlength;k++){
+ altromem[--counter]=charges_per_pad[t];
+ pcounter++;
+ t++;
+ }
+
+ altromem[--counter]=htime; //store abs. time of sequence
+ pcounter++;
+ altromem[--counter]=seqlength+2; //store length of sequence
+ pcounter++;
+ }
+
+ AddTrailer();
+ }
}
-void AliL3AltroMemHandler::WriteTrailer(){
+void AliL3AltroMemHandler::AddTrailer()
+{
+ UShort_t savepcounter=pcounter;
- UShort_t savecounter=counter;
- while(counter%4!=0){
- altromem[counter]=0x2AA;
- counter++;
+ while(pcounter%4!=0){
+ altromem[--counter]=0x2AA;
+ pcounter++;
}
- altromem[counter++]=0x2AA;
- altromem[counter++]=savecounter;
- altromem[counter++]=lpad;
- altromem[counter++]=lrow;
+ altromem[--counter]=0x2AA;
+ altromem[--counter]=savepcounter;
+ altromem[--counter]=lpad;
+ altromem[--counter]=lrow;
+}
+void AliL3AltroMemHandler::Write()
+{
+ if(counter==ALTRO_SIZE) return;
+
+ //save packets (reversed) to file
UShort_t *ptr=altromem+counter;
- for (int i=0;i<counter;i++) {
- ptr--;
- if(flag==kTRUE) fwrite(ptr,sizeof(UShort_t),1,fOutBinary);
- else fprintf(fOutBinary,"%X ",*ptr);
+ for (int i=counter;i<ALTRO_SIZE;i++) {
+
+ if(flag==kTRUE){
+ if (*ptr==0xFFFF) continue; //no return for end of packet
+ fwrite(ptr,sizeof(UShort_t),1,fOutBinary);
+ } else {
+ if (*ptr==0xFFFF) fprintf(fOutBinary,"\n");
+ else fprintf(fOutBinary,"%X ",*ptr);
+ }
+
+ ptr++;
}
- if(flag==kFALSE) fprintf(fOutBinary,"\n");
+}
+void AliL3AltroMemHandler::WriteFinal()
+{
+ if(tcounter>0){
+ MakeAltroPackets();
+ Write();
+ }
}
/*
LOG(AliL3Log::kWarning,"AliL3AltroMemHandler::SetBinaryOutput","File Open") <<"Pointer to File = 0x0 "<<ENDLOG;
return kFALSE;
}
+ flag=kTRUE;
+ return kTRUE;
+}
+
+Bool_t AliL3AltroMemHandler::SetASCIIOutput(FILE *file){
+ fOutBinary = file;
+ if(!fOutBinary){
+ LOG(AliL3Log::kWarning,"AliL3AltroMemHandler::SetASCIIOutput","File Open") <<"Pointer to File = 0x0 "<<ENDLOG;
+ return kFALSE;
+ }
+ flag=kFALSE;
return kTRUE;
}
#include "AliL3RootTypes.h"
#include "AliL3Logging.h"
-//Maximum Size of Altro Packet equals 1000 Bit
-#define ALTRO_SIZE 125
-//Maximum 10Bit data to be stored in one Packet
+//Maximum size of Altro packet equals 1000 bit
+#define ALTRO_PACKET_SIZE 125
+
+//Maximum 10 bit data to be stored in one packet
#define MAX_VALS 94
+//Maximum size of array to store whole pad
+#define ALTRO_SIZE (100*ALTRO_PACKET_SIZE)
+
class AliL3AltroMemHandler {
public:
+
AliL3AltroMemHandler();
- Bool_t Write(UShort_t row, UChar_t pad, UShort_t charge, UShort_t time);
- Bool_t WriteFinal();
+ void Write(UShort_t row, UChar_t pad, UShort_t charge, UShort_t time);
+ void WriteFinal();
+
+ Bool_t SetASCIIOutput(FILE *file);
Bool_t SetBinaryOutput(FILE *file);
//Bool_t SetBinaryInput(FILE *file);
- void SetBinary(Bool_t flag_=kTRUE){flag=flag_;};
private:
+
UShort_t altromem[ALTRO_SIZE];
+ UShort_t times_per_pad[1024];
+ UShort_t charges_per_pad[1024];
+
//FILE *fInBinary;
FILE *fOutBinary;
UShort_t lrow;
UChar_t lpad;
- UShort_t ltime;
- UShort_t counter;
- UShort_t tcounter;
+
+ UShort_t counter; //totalcounter
+ UShort_t tcounter; //timecounter
+ UShort_t pcounter; //packetcounter
Bool_t flag;
- void WriteTrailer();
+
void Clear();
+ void Add(UShort_t charge, UShort_t time);
+ void MakeAltroPackets();
+ void AddTrailer();
+ void Write();
+
ClassDef(AliL3AltroMemHandler,1)
};