Added class description comments.
[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
9c50e540 10/** \class AliL3AltroMemHandler
11// Converts digits in memory into a backlinked ALTRO like data format.
12// The file misc/read.cxx shows how to use this class.
13// As soon as you have more than 35 digits per pad, this class needs to
14// improved to properly handle the backlinked list.
15*/
16
17ClassImp(AliL3AltroMemHandler)
18
acf814d1 19AliL3AltroMemHandler::AliL3AltroMemHandler(){
20 Clear();
21};
22
23Bool_t AliL3AltroMemHandler::Write(UShort_t row, UChar_t pad, UShort_t charge, UShort_t time)
24{
25 Bool_t redo=kFALSE;
26
27 if((counter==0)||(tcounter==0)){ //new package or new sequence
28 ltime=time;
29 lpad=pad;
30 lrow=row;
31 altromem[counter]=charge;
32 counter++;
33 tcounter++;
34 } else if ((row==lrow)&&(pad==lpad)) {
35 if(time-ltime==1){ //add charge to sequence
36 ltime=time;
37 altromem[counter]=charge;
38 counter++;
39 tcounter++;
40
41 if(counter==MAX_VALS){
42 WriteFinal();
43 Clear();
44 }
45 } else { //finish old sequence
46 altromem[counter]=ltime;
47 counter++;
48 altromem[counter]=tcounter+2;
49 counter++;
50
51 //start new sequence
52 if(counter==MAX_VALS){
53 WriteTrailer();
54 Clear();
55 } else tcounter=0;
56
57 redo=kTRUE;
58 }
59 } else { //finish old package
60 WriteFinal();
61 Clear();
62
63 //start new package
64 redo=kTRUE;
65 }
66
67 if(redo==kTRUE) Write(row,pad,charge,time);
68 return kTRUE;
69};
70
71void AliL3AltroMemHandler::Clear(){
72 memset(altromem,0,ALTRO_SIZE);
73 counter=0;
74 tcounter=0;
75 lpad=0;
76 ltime=0;
77 lrow=0;
78 flag=kFALSE;
79};
80
81Bool_t AliL3AltroMemHandler::WriteFinal(){
82 if(counter>0){
83 altromem[counter]=ltime;
84 counter++;
85 altromem[counter]=tcounter+2;
86 counter++;
87 WriteTrailer();
88 }
89 return kTRUE;
90}
91
92void AliL3AltroMemHandler::WriteTrailer(){
93
94 UShort_t savecounter=counter;
95 while(counter%4!=0){
96 altromem[counter]=0x2AA;
97 counter++;
98 }
99 altromem[counter++]=0x2AA;
100 altromem[counter++]=savecounter;
101 altromem[counter++]=lpad;
102 altromem[counter++]=lrow;
103
104 UShort_t *ptr=altromem+counter;
105 for (int i=0;i<counter;i++) {
106 ptr--;
107 if(flag==kTRUE) fwrite(ptr,sizeof(UShort_t),1,fOutBinary);
108 else fprintf(fOutBinary,"%X ",*ptr);
109 }
110 if(flag==kFALSE) fprintf(fOutBinary,"\n");
111
112}
113
114/*
115Bool_t AliL3AltroMemHandler::SetBinaryInput(FILE *file){
116 fInBinary = file;
117 if(!fInBinary){
118 //LOG(AliL3Log::kWarning,"AliL3AltroMem::SetBinaryInput","File Open")<<"Pointer to File = 0x0 "<<ENDLOG;
119 return kFALSE;
120 }
121 return kTRUE;
122}
123*/
124
125Bool_t AliL3AltroMemHandler::SetBinaryOutput(FILE *file){
126 fOutBinary = file;
127 if(!fOutBinary){
128 LOG(AliL3Log::kWarning,"AliL3AltroMemHandler::SetBinaryOutput","File Open") <<"Pointer to File = 0x0 "<<ENDLOG;
129 return kFALSE;
130 }
131 return kTRUE;
132}