]>
Commit | Line | Data |
---|---|---|
e43e472f | 1 | /* |
2 | PMD DA for online calibration | |
3 | ||
4 | contact: basanta@phy.iitb.ac.in | |
338c285a | 5 | Link:http://www.veccal.ernet.in/~pmd/ |
6 | Reference run: | |
e43e472f | 7 | Run Type: PHYSICS |
8 | DA Type: MON | |
9 | Number of events needed: 1 million for PB+PB, 200 milion for p+p | |
1da50520 | 10 | Input Files: PMD_PED.root, Configfile |
11 | Output Files: PMDGAINS.root, to be exported to the DAQ FXS | |
e43e472f | 12 | Trigger types used: PHYSICS_EVENT |
13 | ||
14 | */ | |
15 | extern "C" { | |
16 | #include <daqDA.h> | |
17 | } | |
18 | ||
19 | #include "event.h" | |
20 | #include "monitor.h" | |
21 | //#include "daqDA.h" | |
22 | ||
23 | #include <Riostream.h> | |
24 | #include <stdio.h> | |
25 | #include <stdlib.h> | |
26 | ||
27 | //AliRoot | |
28 | #include "AliRawReaderDate.h" | |
29 | #include "AliPMDCalibPedestal.h" | |
30 | #include "AliPMDCalibGain.h" | |
31 | ||
32 | //ROOT | |
33 | #include "TFile.h" | |
34 | #include "TH1F.h" | |
35 | #include "TBenchmark.h" | |
36 | #include "TTree.h" | |
37 | #include "TROOT.h" | |
38 | #include "TPluginManager.h" | |
39 | ||
40 | ||
41 | ||
42 | /* Main routine | |
43 | Arguments: | |
44 | 1- monitoring data source | |
45 | */ | |
46 | int main(int argc, char **argv) { | |
47 | ||
48 | /* magic line from Rene */ | |
49 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", | |
50 | "*", | |
51 | "TStreamerInfo", | |
52 | "RIO", | |
53 | "TStreamerInfo()"); | |
54 | ||
1da50520 | 55 | Int_t filestatus = -1, totevt = -1; |
56 | Int_t maxevt = -1; | |
57 | ||
58 | // Reads the pedestal file and keep the values in memory for subtraction | |
59 | ||
e43e472f | 60 | AliPMDCalibGain calibgain; |
1da50520 | 61 | Int_t pstatus = calibgain.ExtractPedestal(); |
62 | ||
63 | if(pstatus == -3) return -3; | |
e43e472f | 64 | |
338c285a | 65 | TTree *ic = NULL; |
e43e472f | 66 | |
1da50520 | 67 | FILE *fp1 = NULL; |
68 | ||
69 | fp1 = fopen("Configfile","r"); | |
70 | ||
71 | if (fp1 == NULL) | |
72 | { | |
73 | printf("**** Configfile doesn't exist, creating the file ****\n"); | |
74 | fp1 = fopen("Configfile","w"); | |
75 | filestatus = 0; | |
76 | totevt = 0; | |
77 | maxevt = 2000; | |
78 | fprintf(fp1,"%d %d %d\n",filestatus, totevt,maxevt); | |
79 | } | |
80 | else | |
81 | { | |
82 | fscanf(fp1,"%d %d %d\n",&filestatus, &totevt,&maxevt); | |
83 | //printf("%d %d %d\n",filestatus, totevt, maxevt); | |
84 | } | |
85 | fclose(fp1); | |
e43e472f | 86 | |
1da50520 | 87 | if (filestatus == 1) |
88 | { | |
89 | calibgain.ReadIntermediateFile(); | |
90 | } | |
91 | ||
e43e472f | 92 | // decoding the events |
93 | ||
94 | int status; | |
95 | ||
96 | if (argc!=2) { | |
97 | printf("Wrong number of arguments\n"); | |
98 | return -1; | |
99 | } | |
100 | ||
e43e472f | 101 | |
102 | /* define data source : this is argument 1 */ | |
103 | status=monitorSetDataSource( argv[1] ); | |
104 | if (status!=0) { | |
105 | printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); | |
106 | return -1; | |
107 | } | |
108 | ||
109 | /* declare monitoring program */ | |
110 | status=monitorDeclareMp( __FILE__ ); | |
111 | if (status!=0) { | |
112 | printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); | |
113 | return -1; | |
114 | } | |
115 | ||
116 | /* define wait event timeout - 1s max */ | |
117 | monitorSetNowait(); | |
118 | monitorSetNoWaitNetworkTimeout(1000); | |
119 | ||
120 | /* log start of process */ | |
1da50520 | 121 | printf("PMD GAIN DA - strted generating the gain of a cell\n"); |
e43e472f | 122 | |
123 | /* init some counters */ | |
124 | int nevents_physics=0; | |
125 | int nevents_total=0; | |
126 | ||
127 | struct eventHeaderStruct *event; | |
338c285a | 128 | eventTypeType eventT = 0; |
129 | ||
e43e472f | 130 | Int_t iev=0; |
131 | ||
132 | /* main loop (infinite) */ | |
133 | for(;;) { | |
134 | ||
135 | /* check shutdown condition */ | |
136 | if (daqDA_checkShutdown()) {break;} | |
137 | ||
138 | /* get next event (blocking call until timeout) */ | |
139 | status=monitorGetEventDynamic((void **)&event); | |
140 | if (status==MON_ERR_EOF) { | |
141 | printf ("End of File detected\n"); | |
142 | break; /* end of monitoring file has been reached */ | |
143 | } | |
144 | ||
145 | if (status!=0) { | |
146 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
147 | break; | |
148 | } | |
149 | ||
150 | /* retry if got no event */ | |
151 | if (event==NULL) { | |
152 | continue; | |
153 | } | |
154 | ||
155 | iev++; | |
156 | ||
157 | /* use event - here, just write event id to result file */ | |
158 | nevents_total++; | |
159 | eventT=event->eventType; | |
160 | switch (event->eventType){ | |
161 | ||
162 | /* START OF RUN */ | |
163 | case START_OF_RUN: | |
164 | break; | |
165 | /* END START OF RUN */ | |
166 | ||
167 | /* END OF RUN */ | |
168 | case END_OF_RUN: | |
169 | break; | |
170 | ||
171 | case PHYSICS_EVENT: | |
172 | nevents_physics++; | |
1da50520 | 173 | //if(nevents_physics%100 == 0)printf("Physis Events = %d\n",nevents_physics); |
e43e472f | 174 | AliRawReader *rawReader = new AliRawReaderDate((void*)event); |
338c285a | 175 | TObjArray *pmdddlcont = new TObjArray(); |
176 | calibgain.ProcessEvent(rawReader, pmdddlcont); | |
e43e472f | 177 | |
338c285a | 178 | delete pmdddlcont; |
179 | pmdddlcont = 0x0; | |
e43e472f | 180 | delete rawReader; |
181 | rawReader = 0x0; | |
182 | ||
183 | } | |
184 | ||
185 | /* free resources */ | |
186 | free(event); | |
187 | ||
338c285a | 188 | } |
189 | ||
190 | /* exit when last event received, no need to wait for TERM signal */ | |
40a42048 | 191 | |
192 | ic = new TTree("ic","PMD Gain tree"); | |
e43e472f | 193 | |
1da50520 | 194 | totevt += nevents_physics++; |
195 | ||
196 | fp1 = fopen("Configfile","w+"); | |
197 | ||
198 | if (totevt < maxevt) | |
199 | { | |
200 | printf("Required Number of Events not reached\n"); | |
201 | printf("Number of Events processed = %d\n",totevt); | |
202 | printf("Writing the intermediate ASCII file\n"); | |
203 | calibgain.WriteIntermediateFile(); | |
204 | ||
205 | filestatus = 1; | |
206 | fprintf(fp1,"%d %d %d\n",filestatus,totevt,maxevt); | |
207 | } | |
208 | else if (totevt >= maxevt) | |
209 | { | |
210 | printf("Required Number of Events reached = %d\n",totevt); | |
211 | calibgain.Analyse(ic); | |
212 | ||
213 | TFile * gainRun = new TFile ("PMDGAINS.root","RECREATE"); | |
214 | ic->Write(); | |
215 | gainRun->Close(); | |
216 | ||
217 | filestatus = 0; | |
218 | totevt = 0; | |
219 | fprintf(fp1,"%d %d %d\n",filestatus,totevt,maxevt); | |
220 | } | |
221 | fclose(fp1); | |
e43e472f | 222 | |
338c285a | 223 | delete ic; |
224 | ic = 0; | |
1da50520 | 225 | |
226 | ||
227 | /* store the result file on FES */ | |
228 | ||
229 | if (filestatus == 0) | |
230 | { | |
231 | printf("root file is created and getting exported\n"); | |
232 | status = daqDA_FES_storeFile("PMDGAINS.root","gaincalib"); | |
233 | } | |
234 | ||
235 | if (status) { | |
236 | status = -2; | |
237 | } | |
338c285a | 238 | |
338c285a | 239 | |
e43e472f | 240 | return status; |
241 | } |