Converts Digits in Memory to Altro like back linked list and stores them
[u/mrichter/AliRoot.git] / HLT / misc / AliL3AltroMemHandler.cxx
CommitLineData
acf814d1 1/* $Id$
2Author: Constantin Loizides <mailto: loizides@ikf.physik.uni-frankfurt.de>
3*/
4
5#include <iostream.h>
6#include <stdio.h>
7#include <string.h>
8#include "AliL3AltroMemHandler.h"
9
10AliL3AltroMemHandler::AliL3AltroMemHandler(){
11 Clear();
12};
13
14Bool_t AliL3AltroMemHandler::Write(UShort_t row, UChar_t pad, UShort_t charge, UShort_t time)
15{
16 Bool_t redo=kFALSE;
17
18 if((counter==0)||(tcounter==0)){ //new package or new sequence
19 ltime=time;
20 lpad=pad;
21 lrow=row;
22 altromem[counter]=charge;
23 counter++;
24 tcounter++;
25 } else if ((row==lrow)&&(pad==lpad)) {
26 if(time-ltime==1){ //add charge to sequence
27 ltime=time;
28 altromem[counter]=charge;
29 counter++;
30 tcounter++;
31
32 if(counter==MAX_VALS){
33 WriteFinal();
34 Clear();
35 }
36 } else { //finish old sequence
37 altromem[counter]=ltime;
38 counter++;
39 altromem[counter]=tcounter+2;
40 counter++;
41
42 //start new sequence
43 if(counter==MAX_VALS){
44 WriteTrailer();
45 Clear();
46 } else tcounter=0;
47
48 redo=kTRUE;
49 }
50 } else { //finish old package
51 WriteFinal();
52 Clear();
53
54 //start new package
55 redo=kTRUE;
56 }
57
58 if(redo==kTRUE) Write(row,pad,charge,time);
59 return kTRUE;
60};
61
62void AliL3AltroMemHandler::Clear(){
63 memset(altromem,0,ALTRO_SIZE);
64 counter=0;
65 tcounter=0;
66 lpad=0;
67 ltime=0;
68 lrow=0;
69 flag=kFALSE;
70};
71
72Bool_t AliL3AltroMemHandler::WriteFinal(){
73 if(counter>0){
74 altromem[counter]=ltime;
75 counter++;
76 altromem[counter]=tcounter+2;
77 counter++;
78 WriteTrailer();
79 }
80 return kTRUE;
81}
82
83void AliL3AltroMemHandler::WriteTrailer(){
84
85 UShort_t savecounter=counter;
86 while(counter%4!=0){
87 altromem[counter]=0x2AA;
88 counter++;
89 }
90 altromem[counter++]=0x2AA;
91 altromem[counter++]=savecounter;
92 altromem[counter++]=lpad;
93 altromem[counter++]=lrow;
94
95 UShort_t *ptr=altromem+counter;
96 for (int i=0;i<counter;i++) {
97 ptr--;
98 if(flag==kTRUE) fwrite(ptr,sizeof(UShort_t),1,fOutBinary);
99 else fprintf(fOutBinary,"%X ",*ptr);
100 }
101 if(flag==kFALSE) fprintf(fOutBinary,"\n");
102
103}
104
105/*
106Bool_t AliL3AltroMemHandler::SetBinaryInput(FILE *file){
107 fInBinary = file;
108 if(!fInBinary){
109 //LOG(AliL3Log::kWarning,"AliL3AltroMem::SetBinaryInput","File Open")<<"Pointer to File = 0x0 "<<ENDLOG;
110 return kFALSE;
111 }
112 return kTRUE;
113}
114*/
115
116Bool_t AliL3AltroMemHandler::SetBinaryOutput(FILE *file){
117 fOutBinary = file;
118 if(!fOutBinary){
119 LOG(AliL3Log::kWarning,"AliL3AltroMemHandler::SetBinaryOutput","File Open") <<"Pointer to File = 0x0 "<<ENDLOG;
120 return kFALSE;
121 }
122 return kTRUE;
123}
124
125
126
127
128
129
130