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