]>
Commit | Line | Data |
---|---|---|
6145b1a7 | 1 | /* |
2 | T0 DA for online calibration | |
3 | ||
4 | Contact: Michal.Oledzki@cern.ch | |
5 | Link: http://users.jyu.fi/~mioledzk/ | |
6 | Run Type: PHYSICS | |
7 | DA Type: MON | |
8 | Number of events needed: 500000 | |
9 | Input Files: inPhys.dat, external parameters | |
10 | Output Files: daPhys.root, to be exported to the DAQ FXS | |
11 | Trigger types used: PHYSICS_EVENT | |
99194e07 | 12 | |
6145b1a7 | 13 | */ |
99194e07 | 14 | |
6145b1a7 | 15 | #define FILE_OUT "daPhys.root" |
16 | #define FILE_IN "inPhys.dat" | |
17 | #include <daqDA.h> | |
99194e07 | 18 | #include <event.h> |
19 | #include <monitor.h> | |
20 | ||
21 | #include <Riostream.h> | |
22 | #include <stdio.h> | |
23 | #include <stdlib.h> | |
24 | ||
25 | //AliRoot | |
26 | #include <AliRawReaderDate.h> | |
27 | #include <AliRawReader.h> | |
28 | #include <AliT0RawReader.h> | |
99194e07 | 29 | |
30 | //ROOT | |
6145b1a7 | 31 | #include "TROOT.h" |
32 | #include "TPluginManager.h" | |
99194e07 | 33 | #include "TFile.h" |
34 | #include "TKey.h" | |
35 | #include "TH2S.h" | |
36 | #include "TObject.h" | |
37 | #include "TBenchmark.h" | |
38 | #include "TRandom.h" | |
99194e07 | 39 | #include "TCanvas.h" |
40 | #include "TString.h" | |
41 | #include "TH1.h" | |
42 | #include "TF1.h" | |
43 | #include "TSpectrum.h" | |
44 | #include "TVirtualFitter.h" | |
6145b1a7 | 45 | int cbx, ccbx; |
46 | float clx,cmx,cclx,ccmx; | |
99194e07 | 47 | |
48 | /* Main routine | |
49 | Arguments: | |
50 | 1- monitoring data source | |
51 | */ | |
52 | int main(int argc, char **argv) { | |
53 | //int main(){ | |
54 | int status; | |
6145b1a7 | 55 | |
56 | /* magic line */ | |
57 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", | |
58 | "*", | |
59 | "TStreamerInfo", | |
60 | "RIO", | |
61 | "TStreamerInfo()"); | |
19e2ac29 | 62 | |
63 | if(daqDA_DB_getFile(FILE_IN, FILE_IN)){ | |
64 | printf("Couldn't get input file >>inPhys.dat<< from DAQ_DB !!!\n"); | |
65 | return -1; | |
66 | } | |
67 | ||
99194e07 | 68 | |
6145b1a7 | 69 | FILE *inp; |
70 | char c; | |
71 | inp = fopen(FILE_IN, "r"); | |
19e2ac29 | 72 | if(!inp){ |
73 | printf("Input file >>inPhys.dat<< not found !!!\n"); | |
74 | return -1; | |
75 | } | |
76 | ||
6145b1a7 | 77 | while((c=getc(inp))!=EOF) { |
78 | switch(c) { | |
79 | case 'a': {fscanf(inp, "%d", &ccbx ); break;} //N of X bins hCFD1_CFD | |
80 | case 'b': {fscanf(inp, "%f", &cclx ); break;} //Low x hCFD1_CFD | |
81 | case 'c': {fscanf(inp, "%f", &ccmx ); break;} //High x hCFD1_CFD | |
82 | case 'd': {fscanf(inp, "%d", &cbx ); break;} //N of X bins hCFD | |
83 | case 'e': {fscanf(inp, "%f", &clx ); break;} //Low x hCFD | |
84 | case 'f': {fscanf(inp, "%f", &cmx ); break;} //High x hCFD | |
85 | } | |
86 | } | |
87 | fclose(inp); | |
88 | ||
99194e07 | 89 | if (argc!=2) { |
90 | printf("Wrong number of arguments\n"); | |
91 | return -1; | |
92 | } | |
93 | ||
94 | ||
95 | /* define data source : this is argument 1 */ | |
96 | status=monitorSetDataSource( argv[1] ); | |
97 | if (status!=0) { | |
98 | printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); | |
99 | return -1; | |
100 | } | |
101 | ||
102 | ||
103 | /* declare monitoring program */ | |
104 | status=monitorDeclareMp( __FILE__ ); | |
105 | if (status!=0) { | |
106 | printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); | |
107 | return -1; | |
108 | } | |
109 | ||
110 | ||
111 | /* define wait event timeout - 1s max */ | |
112 | monitorSetNowait(); | |
113 | monitorSetNoWaitNetworkTimeout(1000); | |
114 | ||
115 | ||
116 | /* log start of process */ | |
117 | printf("T0 monitoring program started\n"); | |
118 | ||
119 | // Allocation of histograms - start | |
120 | ||
ae4882b1 | 121 | TH1F *hCFD1minCFD[24]; |
99194e07 | 122 | TH1F *hCFD[24]; |
6145b1a7 | 123 | |
99194e07 | 124 | for(Int_t ic=0; ic<24; ic++) { |
125 | if(ic<12) { | |
ae4882b1 | 126 | hCFD1minCFD[ic] = new TH1F(Form("CFD1-CFD%d",ic+1),"CFD-CFD",ccbx,cclx,ccmx); |
6145b1a7 | 127 | hCFD[ic] = new TH1F(Form("CFD%i",ic+1),"CFD",cbx,clx,cmx); |
99194e07 | 128 | } |
129 | if(ic>11){ | |
ae4882b1 | 130 | hCFD1minCFD[ic] = new TH1F(Form("CFD1-CFD%i",ic+1),"CFD-CFD",ccbx,cclx,ccmx); |
6145b1a7 | 131 | hCFD[ic] = new TH1F(Form("CFD%i",ic+1),"CFD",cbx,clx,cmx); |
99194e07 | 132 | } |
133 | } | |
134 | ||
135 | // Allocation of histograms - end | |
136 | ||
137 | Int_t iev=0; | |
138 | /* main loop (infinite) */ | |
139 | for(;;) { | |
140 | struct eventHeaderStruct *event; | |
141 | eventTypeType eventT; | |
142 | ||
143 | /* check shutdown condition */ | |
144 | if (daqDA_checkShutdown()) {break;} | |
145 | ||
146 | /* get next event (blocking call until timeout) */ | |
147 | status=monitorGetEventDynamic((void **)&event); | |
148 | if (status==(int)MON_ERR_EOF) { | |
149 | printf ("End of File detected\n"); | |
150 | break; /* end of monitoring file has been reached */ | |
151 | } | |
152 | ||
153 | if (status!=0) { | |
154 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
155 | break; | |
156 | } | |
157 | ||
158 | /* retry if got no event */ | |
159 | if (event==NULL) { | |
160 | continue; | |
161 | } | |
162 | ||
19e2ac29 | 163 | // iev++; |
99194e07 | 164 | |
165 | /* use event - here, just write event id to result file */ | |
166 | eventT=event->eventType; | |
167 | ||
168 | switch (event->eventType){ | |
169 | ||
170 | case START_OF_RUN: | |
171 | break; | |
172 | ||
173 | case END_OF_RUN: | |
174 | break; | |
175 | ||
176 | case PHYSICS_EVENT: | |
ae4882b1 | 177 | // case CALIBRATION_EVENT: |
19e2ac29 | 178 | iev++; |
179 | ||
180 | if(iev==1){ | |
181 | printf("First event - %i\n",iev); | |
182 | } | |
99194e07 | 183 | |
99194e07 | 184 | // Initalize raw-data reading and decoding |
185 | AliRawReader *reader = new AliRawReaderDate((void*)event); | |
186 | ||
187 | // Enable the following two lines in case of real-data | |
387638f7 | 188 | reader->RequireHeader(kTRUE); |
99194e07 | 189 | AliT0RawReader *start = new AliT0RawReader(reader, kTRUE); |
190 | ||
191 | // Read raw data | |
192 | Int_t allData[105][5]; | |
193 | for(Int_t i0=0;i0<105;i0++) | |
194 | for(Int_t j0=0;j0<5;j0++) | |
195 | allData[i0][j0] = 0; | |
99194e07 | 196 | |
197 | if(start->Next()) | |
198 | for (Int_t i=0; i<105; i++) { | |
199 | for(Int_t iHit=0;iHit<5;iHit++){ | |
200 | allData[i][iHit]= start->GetData(i,iHit); | |
201 | } | |
202 | } | |
203 | else | |
204 | printf("No T0 data found!!\n"); | |
205 | ||
206 | // Fill the histograms | |
207 | ||
ae4882b1 | 208 | for (Int_t ik = 0; ik<24; ik++) |
99194e07 | 209 | for (Int_t iHt=0; iHt<5; iHt++){ |
ae4882b1 | 210 | if(allData[ik+1][iHt]!=0 ){ |
211 | if(ik<12){ | |
212 | hCFD1minCFD[ik]->Fill(allData[ik+1][iHt]-allData[1][iHt]); | |
213 | hCFD[ik]->Fill(allData[ik+13][iHt]); | |
214 | } | |
215 | if(ik>11){ | |
216 | hCFD1minCFD[ik]->Fill(allData[ik+45][iHt]-allData[57][iHt]); | |
217 | hCFD[ik]->Fill(allData[ik+45][iHt]); | |
218 | } | |
99194e07 | 219 | } |
220 | } | |
221 | ||
99194e07 | 222 | delete start; |
223 | start = 0x0; | |
224 | reader->Reset(); | |
225 | // End of fill histograms | |
226 | ||
227 | } | |
228 | ||
99194e07 | 229 | /* free resources */ |
230 | free(event); | |
231 | ||
232 | /* exit when last event received, no need to wait for TERM signal */ | |
233 | if (eventT==END_OF_RUN) { | |
234 | printf("EOR event detected\n"); | |
19e2ac29 | 235 | printf("Number of events processed - %i\n ",iev); |
99194e07 | 236 | break; |
237 | } | |
238 | } | |
6145b1a7 | 239 | printf("After loop, before writing histos\n"); |
99194e07 | 240 | // write a file with the histograms |
6145b1a7 | 241 | TFile *hist = new TFile(FILE_OUT,"RECREATE"); |
99194e07 | 242 | |
243 | for(Int_t j=0;j<24;j++){ | |
ae4882b1 | 244 | hCFD1minCFD[j]->Write(); |
99194e07 | 245 | hCFD[j]->Write(); |
246 | } | |
247 | hist->Close(); | |
248 | delete hist; | |
249 | ||
6145b1a7 | 250 | status=0; |
251 | ||
252 | /* export file to FXS */ | |
387638f7 | 253 | if (daqDA_FES_storeFile(FILE_OUT, "PHYSICS")) { |
6145b1a7 | 254 | status=-2; |
255 | } | |
256 | ||
99194e07 | 257 | return status; |
258 | } | |
259 | ||
260 |