]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ACORDE/ACORDEda.cxx
First version of ACORDE DA
[u/mrichter/AliRoot.git] / ACORDE / ACORDEda.cxx
CommitLineData
b7f06c9d 1/*
2
3ACORDE DA for online calibration
4
5Contact: Pedro.Gonzalez.Zamora@cern.ch
6
7Run Type: PHYSICS
8
9Number of events needed: depending on the run, being run-level
10Input Files: ACORDEDa.root
11Output Files: ACORDEHistos to be exported to the DAQ FXS
12Trigger types used: PHYSICS_EVENT
13
14*/
15
16#define FILE_TOTAL "ACORDEHistos.root"
17// DATE
18#include "event.h"
19#include "monitor.h"
20#include "daqDA.h"
21
22//AliRoot
23#include "AliACORDERawStream.h"
24#include "AliRawReaderDate.h"
25#include "AliRawReader.h"
26#include "AliDAQ.h"
27
28//ROOT
29#include "TROOT.h"
30#include "TPluginManager.h"
31#include <TFile.h>
32#include <TH1F.h>
33#include <TMath.h>
34
35
36#include <stdio.h>
37#include <stdlib.h>
38
39
40
41/* Main routine
42 Arguments: list of DATE raw data files
43*/
44int main(int argc, char **argv) {
45
46 int status;
47
48 // AliACORDERawStream reader;
49
50 bool fHitMap[60];
51 bool fMultMap[60];
52 int eventHits=0;
53 int multHits=0;
54
55 Int_t nEvents=0;
56 UInt_t word;
57 int kModules=60;
58
59 TH1D *fH1=new TH1D("fHist1", "Single MUON Hits", kModules+1, 0, kModules);
60 TH1D *fH2=new TH1D("fHist2", "Total MUON Hits ", 10, 0, 9);
61 TH1D *fH3=new TH1D("fHist3", "Hit Multiplicity (Mult words)", kModules+1, 0, kModules);
62 TH1D *fH4=new TH1D("fHist4", "Total Hit Multiplicity (Mult words)", 10, 0, 9);
63
64
65
66
67
68
69 /* log start of process */
70 printf("ACORDE DA program started\n");
71
72
73 /* check that we got some arguments = list of files */
74 if (argc<2)
75 {
76 printf("Wrong number of arguments\n");
77 return -1;
78 }
79
80 /* open log */
81
82 FILE *fp=NULL;
83 fp=fopen("./da.log","a");
84 if (fp==NULL) {
85 printf("Failed to open file\n");
86 return -1;
87 }
88
89
90
91 /* report progress */
92 daqDA_progressReport(10);
93
94
95 /* init some counters */
96 int nevents_physics=0;
97 int nevents_total=0;
98
99
100 /* read the data files */
101 int n;
102 for (n=1;n<argc;n++) {
103
104 status=monitorSetDataSource( argv[n] );
105 if (status!=0) {
106 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
107 return -1;
108 }
109
110 /* report progress */
111 daqDA_progressReport(10+80*n/argc);
112
113 /* read the file */
114 for(;;) {
115 struct eventHeaderStruct *event;
116 eventTypeType eventT;
117
118 /* get next event */
119 status=monitorGetEventDynamic((void **)&event);
120
121 if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
122
123 if (status!=0)
124 {
125 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
126 return -1;
127 }
128
129 /* retry if got no event */
130 if (event==NULL)
131 {
132 break;
133 }
134
135 /* use event - here, just write event id to result file */
136 eventT=event->eventType;
137
138 switch (event->eventType)
139 {
140
141 case: START_OF_RUN;
142 break;
143 case: END_OF_RUN:
144 break;
145 case: PHYSICS_EVENT:
146 nevents_physics++;
147 fprintf(fp,"Run #%lu, event size: %lu, BC:%u, Orbit:%u, Period:%u\n",
148 (unsigned long)event->eventRunNb,
149 (unsigned long)event->eventSize,
150 EVENT_ID_GET_BUNCH_CROSSING(event->eventId),
151 EVENT_ID_GET_ORBIT(event->eventId),
152 EVENT_ID_GET_PERIOD(event->eventId));
153
154 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
155
156 AliACORDERawStream* rawStream = new AliACORDERawStream(rawReader);
157
158 rawStream->Reset();
159
160 rawStream->Next();
161
162 word = rawStream->GetWord(0);
163 for(int i=0;i<30;i++){
164 fHitMap[i]=word & 1;
165 word>>=1;
166 }
167
168 word = rawStream->GetWord(1);
169 for(int i=30;i<60;i++){
170 fHitMap[i]=word & 1;
171 word>>=1;
172 }
173
174 word = rawStream->GetWord(2);
175 for(int i=0;i<30;i++){
176 fMultMap[i]=word & 1;
177 word>>=1;
178 }
179
180 word = rawStream->GetWord(3);
181 for(int i=30;i<60;i++){
182 fMultMap[i]=word & 1;
183 word>>=1;
184 }
185
186 for(int i=0; i<kModules; ++i){
187 if(fHitMap[i]){
188 fH1->Fill(i);
189 ++eventHits;
190 }
191 if(fMultMap[i]){
192 fH3->Fill(i);
193 ++multHits;
194 }
195 }
196 fH2->Fill(eventHits);
197 fH4->Fill(multHits);
198
199 delete rawStream;
200 rawStream = 0x0;
201 delete rawReader;
202 rawReader = 0x0;
203 } //End Swicht
204
205
206
207
208
209 nevents_total++;
210
211 /* free resources */
212 free(event);
213 }
214
215 }
216
217
218//write root file
219
220
221 TObjArray Hlist(0);
222 Hlist.Add(fH1);
223 Hlist.Add(fH2);
224 Hlist.Add(fH3);
225 Hlist.Add(fH4);
226
227 TFile *histoFile = new TFile(FILE_TOTAL,"recreate");
228 Hlist.Write();
229 histoFile->Close();
230 delete histoFile;
231
232
233
234 /* write report */
235 fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
236
237
238 /* close result file */
239 fclose(fp);
240
241
242 /* report progress */
243 daqDA_progressReport(90);
244
245
246 /* store the result file on FES */
247 status=daqDA_FES_storeFile(FILE_TOTAL,"CALIB");
248 if (status) {
249 printf("Failed to export file : %d\n",status);
250 return -1;
251 }
252
253
254 /* report progress */
255 daqDA_progressReport(100);
256
257
258 return status;
259}