]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/TOFpulserda.cxx
filter out additional compile defines to fit into rootcints 1024 char limit
[u/mrichter/AliRoot.git] / TOF / TOFpulserda.cxx
CommitLineData
6b034754 1/*
2
3TOF DA for online calibration from pulser data
4
5Contact: Chiara.Zampolli@bo.infn.it
6Link: www.bo.infn.it/~zampolli
7Run Type: CALIBRATION, PULSER - to be properly defined
8DA Type: LDC
9Number of events needed: 10000
10Input Files: TOF<nrun>.raw, where <nrun> is the run number
11Output Files: TOFoutPulserLDC_<LDCid>.root, where <LDCid> is the id of the LDC which is read (2 characters field, e.g. TOFoutPulserLDC_03.root),to be exported to the DAQ FXS
12Trigger types used: PHYSICS_EVENT, for the time being
13
14*/
15
16// DATE
17#include "event.h"
18#include "monitor.h"
89b3ea8c 19#include "daqDA.h"
6b034754 20
21#include <stdio.h>
22#include <stdlib.h>
23
24//AliRoot
25#include <AliTOFRawStream.h>
26#include <AliRawReaderDate.h>
27#include <AliRawReader.h>
28#include <AliTOFGeometry.h>
29#include <AliDAQ.h>
30#include <AliTOFHitData.h>
31#include <AliTOFHitDataBuffer.h>
32#include <AliTOFDecoder.h>
33
34//ROOT
35#include <TFile.h>
36#include <TKey.h>
37#include <TH1I.h>
38#include <TObject.h>
39#include <TMath.h>
40#include <TSystem.h>
41
42/* Main routine
43 Arguments: list of DATE raw data files
44*/
45int main(int argc, char **argv) {
46
47 AliTOFGeometry * geom = new AliTOFGeometry();
48
49 static const Int_t size = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
50 TH1F::AddDirectory(0);
51 TH1I * htofPulser = new TH1I("hTOFpulser","histo with signals on TOF during pulser", size,-0.5,size-0.5);
52 for (Int_t ibin =1;ibin<=size;ibin++){
53 htofPulser->SetBinContent(ibin,-1);
54 }
55
56 UInt_t ldcId=0;
57
58 int status;
59
60 /* log start of process */
61 printf("TOF DA started\n");
62
63 /* check that we got some arguments = list of files */
64 if (argc<2) {
65 printf("Wrong number of arguments\n");
66 return -1;
67 }
68
69 /* open result file */
70 FILE *fp=NULL;
71 fp=fopen("./result.txt","a");
72 if (fp==NULL) {
73 printf("Failed to open file\n");
74 return -1;
75 }
76
77 /* init some counters */
78 int nevents_physics=0;
79 int nevents_total=0;
80
81 /* read the data files */
82 int n;
83 for (n=1;n<argc;n++) {
84
85 status=monitorSetDataSource( argv[n] );
86 if (status!=0) {
87 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
88 return -1;
89 }
90
91 /* read the file */
92 for(;;) {
93 struct eventHeaderStruct *event;
94 eventTypeType eventT;
95
96 /* get next event */
97 status=monitorGetEventDynamic((void **)&event);
98 if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
99 if (status!=0) {
100 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
101 return -1;
102 }
103
104 /* retry if got no event */
105 if (event==NULL) {
106 break;
107 }
108
109 /* use event - here, just write event id to result file */
110 eventT=event->eventType;
111
112 if (eventT==PHYSICS_EVENT) {
113 //printf ("event %i \n", nevents_physics);
114 Int_t nPDBEntriesToT = 0;
115 Int_t nDBEntriesToT = 0;
116 AliTOFHitData *HitData;
117 Int_t dummy = -1;
118 Int_t Volume[5];
119 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
120 AliTOFRawStream *rawStreamTOF = new AliTOFRawStream(rawReader);
121 AliTOFDecoder * decoderTOF = new AliTOFDecoder();
122 AliTOFHitDataBuffer *DataBuffer[72];
123 AliTOFHitDataBuffer *PackedDataBuffer[72];
124 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
125 DataBuffer[i]=new AliTOFHitDataBuffer();
126 PackedDataBuffer[i]=new AliTOFHitDataBuffer();
127 }
128 Int_t currentEquipment;
129 Int_t currentDDL;
130 UChar_t *data = 0x0;
131 while(rawReader->ReadHeader()){
132 ldcId = rawReader->GetLDCId();
133 //printf ("ldcId = %i \n",ldcId);
134
135 //memory leak prevention (actually data should be always 0x0 here)
136 if (data != 0x0)delete [] data;
137
138 //get equipment infos
139 currentEquipment = rawReader->GetEquipmentId();
140 currentDDL = rawReader->GetDDLID();
141 Int_t nchDDL = 0;
142 if (currentDDL%2==0) {
143 nchDDL = 2160;
144 }
145 else {
146 nchDDL = 2208;
147 }
148 Int_t * array = new Int_t[nchDDL];
149 decoderTOF->GetArrayDDL(array, currentDDL);
150
151 for (Int_t i=0;i<nchDDL;i++){
152 if (htofPulser->GetBinContent(array[i]+1)<0) htofPulser->SetBinContent(array[i]+1,0);
153 }
154
155 //printf(" Equipment = %i, and DDL = %i \n", currentEquipment,currentDDL);
156 const Int_t kDataSize = rawReader->GetDataSize();
157 const Int_t kDataWords = kDataSize / 4;
158 data = new UChar_t[kDataSize];
159 decoderTOF->SetDataBuffer(DataBuffer[currentDDL]);
160 decoderTOF->SetPackedDataBuffer(PackedDataBuffer[currentDDL]);
161 //start decoding
162 if (!rawReader->ReadNext(data, kDataSize)){
163 rawReader->AddMajorErrorLog(AliTOFRawStream::kDDLdataReading);
164 printf("Error while reading DDL data. Go to next equipment \n");
165 delete [] data;
166 data = 0x0;
167 continue;
168 }
169 if (decoderTOF->Decode((UInt_t *)data, kDataWords) == kTRUE) {
170 rawReader->AddMajorErrorLog(AliTOFRawStream::kDDLDecoder,Form("DDL # = %d",currentDDL));
171 printf("Error while decoding DDL # %d: decoder returned with errors \n", currentDDL);
172 }
173
174 Int_t nDBEntries = DataBuffer[currentDDL]->GetEntries();
175 Int_t nPDBEntries = PackedDataBuffer[currentDDL]->GetEntries();
176 nPDBEntriesToT+=nPDBEntries;
177 nDBEntriesToT+=nDBEntries;
178 /* reset buffer */
179 DataBuffer[currentDDL]->Reset();
180
181 /* read data buffer hits */
182 for (Int_t iHit = 0; iHit < nPDBEntries; iHit++){
183 HitData = PackedDataBuffer[currentDDL]->GetHit(iHit);
184 /* add volume information */
185 HitData->SetDDLID(currentDDL);
186 rawStreamTOF->EquipmentId2VolumeId(HitData, Volume);
187 if (Volume[0]==-1 ||
188 Volume[1]==-1 ||
189 Volume[2]==-1 ||
190 Volume[3]==-1 ||
191 Volume[4]==-1) continue;
192 else {
193 dummy = Volume[3];
194 Volume[3] = Volume[4];
195 Volume[4] = dummy;
196 Int_t index = geom->GetIndex(Volume);
197 //printf ("index = %i \n",index);
198 htofPulser->Fill(index); //channel index start from 0, bin index from 1
199 //debugging printings
200 //printf("sector %i, plate %i, strip %i, padz %i, padx %i \n",Volume[0],Volume[1],Volume[2],Volume[3],Volume[4]);
201 }
202 }
203 /* reset buffer */
204 PackedDataBuffer[currentDDL]->Reset();
205 delete [] data;
206 data = 0x0;
207 delete [] array;
208 }
209
210 //printf(" Packed Hit Buffer Entries = %i \n",nPDBEntriesToT);
211 //printf(" Hit Buffer Entries = %i \n",nDBEntriesToT);
212
213 delete decoderTOF;
214 decoderTOF=0x0;
215
216 for (Int_t i=0;i<72;i++){
217 delete DataBuffer[i];
218 delete PackedDataBuffer[i];
219 }
220
221 delete rawStreamTOF;
222 rawStreamTOF = 0x0;
223
224 delete rawReader;
225 rawReader = 0x0;
226 nevents_physics++;
227 }
228 nevents_total++;
229
230 /* free resources */
231 free(event);
232 }
233 }
234
235 delete geom;
236 geom = 0x0;
237
238 //write the Run level file
239 char filename[100];
240 sprintf(filename,"TOFoutPulserLDC_%02i.root",ldcId);
241 TFile * fileRun = new TFile (filename,"RECREATE");
242 htofPulser->Write();
243 fileRun->Close();
244
245 /* write report */
246 fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
247
248 /* close result file */
249 fclose(fp);
250
251 /* store the result file on FES */
252 status=daqDA_FES_storeFile(filename,filename);
253 if (status) {
254 status = -2;
255 }
256
257 return status;
258}