]>
Commit | Line | Data |
---|---|---|
e43e472f | 1 | /* |
2 | PMD DA for online calibration | |
3 | ||
4 | contact: basanta@phy.iitb.ac.in | |
74c36477 | 5 | Link: |
ee562d68 | 6 | Reference Run:/afs/cern.ch/user/s/sjena/public/run83496.raw |
6b1a10fc | 7 | Run Type: PEDESTAL |
722ccc67 | 8 | DA Type: LDC |
e43e472f | 9 | Number of events needed: 1000 |
53fa2405 | 10 | Input Files: Run0_999999999_v0_s0.root from the DAQ DB for mapping |
74c36477 | 11 | Output Files: pmd_ped.root, to be exported to the DAQ FXS, pedestal230*.ped |
722ccc67 | 12 | Trigger types used: PHYSICS_EVENT |
e43e472f | 13 | |
14 | */ | |
15 | extern "C" { | |
16 | #include <daqDA.h> | |
17 | } | |
18 | ||
19 | #include "event.h" | |
20 | #include "monitor.h" | |
e43e472f | 21 | |
22 | #include <Riostream.h> | |
23 | #include <stdio.h> | |
24 | #include <stdlib.h> | |
25 | ||
26 | //AliRoot | |
27 | #include "AliRawReaderDate.h" | |
28 | #include "AliPMDCalibPedestal.h" | |
ee562d68 | 29 | #include "AliLog.h" |
30 | #include "AliCDBManager.h" | |
e43e472f | 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" | |
ee562d68 | 39 | #include "TSystem.h" |
e43e472f | 40 | |
e43e472f | 41 | /* Main routine |
42 | Arguments: | |
43 | 1- monitoring data source | |
44 | */ | |
45 | int main(int argc, char **argv) { | |
46 | ||
47 | /* magic line from Rene */ | |
48 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", | |
49 | "*", | |
50 | "TStreamerInfo", | |
51 | "RIO", | |
52 | "TStreamerInfo()"); | |
53 | ||
54 | ||
55 | AliPMDCalibPedestal calibped; | |
56 | ||
70202332 | 57 | TTree *ped = NULL; |
e43e472f | 58 | |
70202332 | 59 | // TH1F::AddDirectory(0); |
e43e472f | 60 | |
61 | ||
62 | // decoding the events | |
63 | ||
64 | int status; | |
65 | ||
66 | if (argc!=2) { | |
67 | printf("Wrong number of arguments\n"); | |
68 | return -1; | |
69 | } | |
70 | ||
e43e472f | 71 | |
72 | /* define data source : this is argument 1 */ | |
73 | status=monitorSetDataSource( argv[1] ); | |
74 | if (status!=0) { | |
75 | printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); | |
76 | return -1; | |
77 | } | |
78 | ||
79 | /* declare monitoring program */ | |
80 | status=monitorDeclareMp( __FILE__ ); | |
81 | if (status!=0) { | |
82 | printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); | |
83 | return -1; | |
84 | } | |
85 | ||
86 | /* define wait event timeout - 1s max */ | |
87 | monitorSetNowait(); | |
88 | monitorSetNoWaitNetworkTimeout(1000); | |
89 | ||
90 | /* log start of process */ | |
21dc4b14 | 91 | printf("PMD PED DA - started generating mean and rms of each channel\n"); |
e43e472f | 92 | |
93 | /* init some counters */ | |
722ccc67 | 94 | |
e43e472f | 95 | |
96 | struct eventHeaderStruct *event; | |
70202332 | 97 | eventTypeType eventT = 0; |
e43e472f | 98 | Int_t iev=0; |
ee562d68 | 99 | |
100 | // Get run number | |
0073c15c | 101 | |
ee562d68 | 102 | if (getenv("DATE_RUN_NUMBER")==0) { |
103 | printf("DATE_RUN_NUMBER not properly set.\n"); | |
104 | return -1; | |
105 | } | |
106 | int runNr = atoi(getenv("DATE_RUN_NUMBER")); | |
0073c15c | 107 | |
108 | //int runNr = 0; | |
ee562d68 | 109 | |
110 | ||
111 | if (gSystem->AccessPathName("localOCDB/PMD/Calib/Mapping",kFileExists)) | |
112 | { | |
113 | if (gSystem->mkdir("localOCDB/PMD/Calib/Mapping",kTRUE) != 0) | |
114 | { | |
115 | printf("Failed to create directory: localOCDB/PMD/Calib/Mapping"); | |
116 | return -1; | |
117 | } | |
118 | } | |
119 | status = daqDA_DB_getFile("PMD/Calib/Mapping","localOCDB/PMD/Calib/Mapping/Run0_999999999_v0_s0.root"); | |
120 | if (status) | |
121 | { | |
122 | printf("Failed to get PMD-Mapping file (PMD/Calib/Mapping) from DAQdetDB, status=%d\n", status); | |
123 | return -1; | |
124 | } | |
125 | ||
126 | // Global initializations | |
127 | AliLog::SetGlobalLogLevel(AliLog::kError); | |
128 | AliCDBManager *man = AliCDBManager::Instance(); | |
129 | man->SetDefaultStorage("local://localOCDB"); | |
130 | man->SetRun(runNr); | |
131 | ||
e43e472f | 132 | |
133 | /* main loop (infinite) */ | |
134 | for(;;) { | |
135 | ||
136 | /* check shutdown condition */ | |
137 | if (daqDA_checkShutdown()) {break;} | |
138 | ||
139 | /* get next event (blocking call until timeout) */ | |
140 | status=monitorGetEventDynamic((void **)&event); | |
141 | if (status==MON_ERR_EOF) { | |
142 | printf ("End of File detected\n"); | |
143 | break; /* end of monitoring file has been reached */ | |
144 | } | |
145 | ||
146 | if (status!=0) { | |
147 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
148 | break; | |
149 | } | |
150 | ||
151 | /* retry if got no event */ | |
152 | if (event==NULL) { | |
153 | continue; | |
154 | } | |
155 | ||
156 | iev++; | |
157 | ||
158 | /* use event - here, just write event id to result file */ | |
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 | ||
722ccc67 | 171 | case PHYSICS_EVENT: |
21dc4b14 | 172 | |
e43e472f | 173 | AliRawReader *rawReader = new AliRawReaderDate((void*)event); |
70202332 | 174 | TObjArray *pmdddlcont = new TObjArray(); |
175 | calibped.ProcessEvent(rawReader,pmdddlcont); | |
e43e472f | 176 | |
70202332 | 177 | delete pmdddlcont; |
178 | pmdddlcont = 0; | |
e43e472f | 179 | delete rawReader; |
180 | rawReader = 0x0; | |
181 | } | |
182 | ||
183 | /* free resources */ | |
184 | free(event); | |
185 | ||
186 | /* exit when last event received, no need to wait for TERM signal */ | |
722ccc67 | 187 | |
5f487e91 | 188 | // either END_OF_RUN or 1000 events |
189 | ||
190 | if (iev == 1000) | |
191 | { | |
192 | printf("-- 1000 pedestal events processed : terminating --\n"); | |
193 | printf("-- eventT is set to END_OF_RUN --\n"); | |
194 | eventT = END_OF_RUN; | |
195 | break; | |
196 | } | |
197 | ||
e43e472f | 198 | } |
40a42048 | 199 | |
21dc4b14 | 200 | printf(" Total number of events processed = %i \n",iev); |
201 | ||
40a42048 | 202 | ped = new TTree("ped","PMD Pedestal tree"); |
21dc4b14 | 203 | |
70202332 | 204 | if (eventT==END_OF_RUN) { |
205 | printf("EOR event detected\n"); | |
70202332 | 206 | calibped.Analyse(ped); |
207 | } | |
e43e472f | 208 | |
722ccc67 | 209 | TFile * pedRun = new TFile ("PMD_PED.root","RECREATE"); |
e43e472f | 210 | ped->Write(); |
211 | pedRun->Close(); | |
212 | ||
70202332 | 213 | delete ped; |
214 | ped = 0; | |
40a42048 | 215 | |
d31b0352 | 216 | /* store the pedestal file in database */ |
217 | ||
218 | status = daqDA_DB_storeFile("PMD_PED.root","PMD_PED.root"); | |
219 | ||
220 | if (!status) | |
221 | { | |
222 | printf("--- PEDESTAL root FILE IS IN THE DAQ DATABASE\n"); | |
223 | } | |
224 | else | |
225 | { | |
226 | printf("--- Storing the root file into the database failed\n"); | |
227 | } | |
21dc4b14 | 228 | |
d31b0352 | 229 | /* store the pedestal file on FES */ |
21dc4b14 | 230 | |
a5f36c63 | 231 | status = daqDA_FES_storeFile("PMD_PED.root","PMD_PED.root"); |
21dc4b14 | 232 | if (status) { |
233 | status = -2; | |
234 | } | |
235 | ||
d31b0352 | 236 | |
237 | ||
238 | ||
e43e472f | 239 | return status; |
240 | } |