3b5beac9 |
1 | /* |
22580691 |
2 | EMCAL DA for online calibration: for pedestal studies |
3b5beac9 |
3 | |
4 | Contact: silvermy@ornl.gov |
22580691 |
5 | Run Type: PEDESTAL |
6 | DA Type: LDC |
07cc7773 |
7 | Number of events needed: ~1000 |
22580691 |
8 | Frequency: expect to run this once per day initially |
9 | (maybe less frequent later) |
3b5beac9 |
10 | Input Files: argument list |
22580691 |
11 | Output Files: RESULT_FILE=EMCALPED.root, to be exported to the DAQ FXS |
12 | fileId: FILE_ID=EMCALPED |
3b5beac9 |
13 | |
22580691 |
14 | Trigger types used: at least for now, all events in special PEDESTAL run |
15 | (physics, calibration, systemSoftwareTrigger, detectorSoftwareTrigger) |
16 | [When we have real data files later, we may restrict this further] |
3b5beac9 |
17 | */ |
18 | /* |
19 | This process reads RAW data from the files provided as command line arguments |
22580691 |
20 | and save results (class itself) in a file (named from RESULT_FILE define |
21 | - see below). |
3b5beac9 |
22 | */ |
23 | |
22580691 |
24 | #define RESULT_FILE "EMCALPED.root" |
5ea60b80 |
25 | #define FILE_ID "pedestals" |
3b5beac9 |
26 | #define AliDebugLevel() -1 |
22580691 |
27 | #define FILE_PEDClassName "emcCalibPedestal" |
21cad85c |
28 | const int kNRCU = 4; |
f4fc542c |
29 | /* LOCAL_DEBUG is used to bypass daq* calls, for local testing */ |
22580691 |
30 | //#define LOCAL_DEBUG 1 // comment out to run normally |
3b5beac9 |
31 | |
32 | extern "C" { |
33 | #include <daqDA.h> |
34 | } |
22580691 |
35 | #include "event.h" /* in $DATE_COMMON_DEFS/; includes definition of event types */ |
36 | #include "monitor.h" /* in $DATE_MONITOR_DIR/; monitor* interfaces */ |
3b5beac9 |
37 | |
38 | #include "stdio.h" |
39 | #include "stdlib.h" |
40 | |
f4fc542c |
41 | // ROOT includes |
42 | #include <TFile.h> |
43 | #include <TROOT.h> |
44 | #include <TPluginManager.h> |
45 | #include <TSystem.h> |
46 | |
3b5beac9 |
47 | // |
48 | //AliRoot includes |
49 | // |
50 | #include "AliRawReader.h" |
51 | #include "AliRawReaderDate.h" |
52 | #include "AliRawEventHeaderBase.h" |
32cd4c24 |
53 | #include "AliCaloRawStreamV3.h" |
f4fc542c |
54 | #include "AliCaloAltroMapping.h" |
3b5beac9 |
55 | #include "AliLog.h" |
56 | |
57 | // |
58 | // EMC calibration-helper algorithm includes |
59 | // |
60 | #include "AliCaloCalibPedestal.h" |
61 | |
62 | /* |
f4fc542c |
63 | Main routine, EMC pedestal detector algorithm |
3b5beac9 |
64 | Arguments: list of DATE raw data files |
65 | */ |
66 | |
67 | int main(int argc, char **argv) { |
b07ee441 |
68 | |
32cd4c24 |
69 | AliLog::SetClassDebugLevel("AliCaloRawStreamV3",-5); |
3b5beac9 |
70 | AliLog::SetClassDebugLevel("AliRawReaderDate",-5); |
71 | AliLog::SetModuleDebugLevel("RAW",-5); |
b07ee441 |
72 | |
3b5beac9 |
73 | if (argc<2) { |
74 | printf("Wrong number of arguments\n"); |
f4fc542c |
75 | return -1; |
3b5beac9 |
76 | } |
b07ee441 |
77 | |
f4fc542c |
78 | /* magic line - for TStreamerInfo */ |
79 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", |
80 | "*", |
81 | "TStreamerInfo", |
82 | "RIO", |
83 | "TStreamerInfo()"); |
b07ee441 |
84 | |
3b5beac9 |
85 | int i, status; |
b07ee441 |
86 | |
3b5beac9 |
87 | /* log start of process */ |
88 | printf("EMCAL DA started - %s\n",__FILE__); |
b07ee441 |
89 | |
3b5beac9 |
90 | /* declare monitoring program */ |
91 | status=monitorDeclareMp( __FILE__ ); |
92 | if (status!=0) { |
93 | printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); |
94 | return -1; |
95 | } |
f4fc542c |
96 | /* define wait event timeout - 1s max */ |
97 | monitorSetNowait(); |
98 | monitorSetNoWaitNetworkTimeout(1000); |
b07ee441 |
99 | |
f4fc542c |
100 | /* Retrieve mapping files from DAQ DB */ |
21cad85c |
101 | const char* mapFiles[kNRCU] = {"RCU0A.data","RCU1A.data","RCU0C.data","RCU1C.data"}; |
b07ee441 |
102 | |
f4fc542c |
103 | for(Int_t iFile=0; iFile<kNRCU; iFile++) { |
104 | int failed = daqDA_DB_getFile(mapFiles[iFile], mapFiles[iFile]); |
105 | if(failed) { |
106 | printf("Cannot retrieve file %d : %s from DAQ DB. Exit now..\n", |
107 | iFile, mapFiles[iFile]); |
108 | #ifdef LOCAL_DEBUG |
109 | #else |
b07ee441 |
110 | return -1; |
f4fc542c |
111 | #endif |
112 | } |
113 | } |
114 | |
115 | /* Open mapping files */ |
116 | AliCaloAltroMapping *mapping[kNRCU]; |
117 | TString path = "./"; |
118 | path += "RCU"; |
119 | TString path2; |
b07ee441 |
120 | TString side[] = {"A","C"};//+ and - pseudarapidity supermodules |
121 | for(Int_t j = 0; j < 2; j++){ |
122 | for(Int_t i = 0; i < 2; i++) { |
123 | path2 = path; |
124 | path2 += i; |
125 | path2 +=side[j]; |
126 | path2 += ".data"; |
127 | mapping[j*2 + i] = new AliCaloAltroMapping(path2.Data()); |
128 | } |
129 | } |
130 | |
131 | /* Retrieve cut=parameter file from DAQ DB */ |
132 | const char* parameterFile = {"EMCALPEDda.dat"}; |
133 | |
134 | int failed = daqDA_DB_getFile(parameterFile, parameterFile); |
135 | if (failed) { |
136 | printf("Cannot retrieve file : %s from DAQ DB. Exit now..\n", |
137 | parameterFile); |
138 | #ifdef LOCAL_DEBUG |
139 | #else |
140 | return -1; |
141 | #endif |
142 | } |
143 | |
f4fc542c |
144 | /* set up our analysis class */ |
145 | AliCaloCalibPedestal * calibPedestal = new AliCaloCalibPedestal(AliCaloCalibPedestal::kEmCal); // pedestal and noise calibration |
146 | calibPedestal->SetAltroMapping( mapping ); |
b07ee441 |
147 | calibPedestal->SetParametersFromFile( parameterFile ); |
3b5beac9 |
148 | |
f4fc542c |
149 | AliRawReader *rawReader = NULL; |
150 | int nevents=0; |
b07ee441 |
151 | |
3b5beac9 |
152 | /* loop over RAW data files */ |
3b5beac9 |
153 | for ( i=1; i<argc; i++ ) { |
b07ee441 |
154 | |
3b5beac9 |
155 | /* define data source : this is argument i */ |
156 | printf("Processing file %s\n", argv[i]); |
f4fc542c |
157 | status=monitorSetDataSource( argv[i] ); |
158 | if (status!=0) { |
159 | printf("monitorSetDataSource() failed. Error=%s. Exiting ...\n", monitorDecodeError(status)); |
160 | return -1; |
161 | } |
b07ee441 |
162 | |
3b5beac9 |
163 | /* read until EOF */ |
f4fc542c |
164 | struct eventHeaderStruct *event; |
165 | eventTypeType eventT; |
166 | |
167 | for ( ; ; ) { // infinite loop |
b07ee441 |
168 | |
3b5beac9 |
169 | /* check shutdown condition */ |
170 | if (daqDA_checkShutdown()) {break;} |
b07ee441 |
171 | |
f4fc542c |
172 | /* get next event (blocking call until timeout) */ |
173 | status=monitorGetEventDynamic((void **)&event); |
174 | if (status==MON_ERR_EOF) { |
175 | printf ("End of File %d (%s) detected\n", i, argv[i]); |
176 | break; /* end of monitoring file has been reached */ |
177 | } |
178 | if (status!=0) { |
179 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); |
180 | break; |
181 | } |
b07ee441 |
182 | |
f4fc542c |
183 | /* retry if got no event */ |
184 | if (event==NULL) { |
185 | continue; |
186 | } |
22580691 |
187 | eventT = event->eventType; /* just convenient shorthand */ |
b07ee441 |
188 | |
f4fc542c |
189 | /* skip start/end of run events */ |
22580691 |
190 | if ( (eventT != physicsEvent) && (eventT != calibrationEvent) && |
191 | (eventT != systemSoftwareTriggerEvent) && (eventT != detectorSoftwareTriggerEvent) ) { |
f4fc542c |
192 | continue; |
193 | } |
b07ee441 |
194 | |
f4fc542c |
195 | nevents++; // count how many acceptable events we have |
b07ee441 |
196 | |
f4fc542c |
197 | // Pedestal calibration |
198 | rawReader = new AliRawReaderDate((void*)event); |
b07ee441 |
199 | calibPedestal->SetRunNumber(event->eventRunNb); |
f4fc542c |
200 | calibPedestal->ProcessEvent(rawReader); |
201 | delete rawReader; |
b07ee441 |
202 | |
f4fc542c |
203 | /* free resources */ |
204 | free(event); |
b07ee441 |
205 | |
f4fc542c |
206 | } //until EOF |
3b5beac9 |
207 | } // loop over files |
b07ee441 |
208 | |
3b5beac9 |
209 | // |
452729ca |
210 | // write class to rootfile |
3b5beac9 |
211 | // |
b07ee441 |
212 | |
3b5beac9 |
213 | printf ("%d physics/calibration events processed.\n",nevents); |
59ed788d |
214 | |
215 | // look for dead, hot and noisy towers |
216 | calibPedestal->ComputeDeadTowers(); |
217 | calibPedestal->ComputeHotAndWarningTowers(); |
218 | |
452729ca |
219 | TFile f(RESULT_FILE, "recreate"); |
220 | if (!f.IsZombie()) { |
221 | f.cd(); |
22580691 |
222 | calibPedestal->Write(FILE_PEDClassName); |
452729ca |
223 | f.Close(); |
22580691 |
224 | printf("Object saved to file \"%s\" as \"%s\".\n", |
225 | RESULT_FILE, FILE_PEDClassName); |
452729ca |
226 | } |
227 | else { |
22580691 |
228 | printf("Could not save the object to file \"%s\".\n", |
229 | RESULT_FILE); |
452729ca |
230 | } |
b07ee441 |
231 | |
22580691 |
232 | // |
233 | // closing down; see if we can delete our analysis helper also |
234 | // |
3b5beac9 |
235 | delete calibPedestal; |
f4fc542c |
236 | for(Int_t iFile=0; iFile<kNRCU; iFile++) { |
237 | if (mapping[iFile]) delete mapping[iFile]; |
238 | } |
b07ee441 |
239 | |
f4fc542c |
240 | /* store the result file on FES */ |
241 | #ifdef LOCAL_DEBUG |
242 | #else |
243 | status = daqDA_FES_storeFile(RESULT_FILE, FILE_ID); |
244 | #endif |
b07ee441 |
245 | |
3b5beac9 |
246 | return status; |
247 | } |