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