]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | TPC DA for online calibration | |
3 | ||
4 | Contact: Jens.Wiechula@cern.ch | |
5 | Link: | |
6 | Run Type: PHYSICS STANDALONE | |
7 | DA Type: MON | |
8 | Number of events needed: 200 | |
9 | Input Files: /castor/cern.ch/alice/raw/global/2009/08/22/11/09000080958023.30.root | |
10 | Output Files: tpcCalibRaw.root, to be exported to the DAQ FXS | |
11 | fileId: tpcCalibRaw | |
12 | Trigger types used: PHYSICS_EVENT | |
13 | ||
14 | */ | |
15 | ||
16 | /* | |
17 | ||
18 | TPCRAWda.cxx - calibration algorithm for L1 phase monitoring and drift velocity from last time bin determination | |
19 | ||
20 | 30/07/2009 Jens.Wiechula@cern.ch: First implementation. | |
21 | 10/09/2009 Jens.Wiechula@cern.ch: Add configuration file support. Export object to AMOREdb | |
22 | after a defined update interval for QA | |
23 | 26/01/2010 Jens.Wiechula@cern.ch: Exclude laser triggers when running in a global partition | |
24 | ||
25 | This process reads RAW data from the files provided as command line arguments | |
26 | and save results in a file (named from RESULT_FILE define - see below). | |
27 | ||
28 | */ | |
29 | ||
30 | #define RESULT_FILE "tpcCalibRaw.root" | |
31 | #define FILE_ID "tpcCalibRaw" | |
32 | #define MAPPING_FILE "tpcMapping.root" | |
33 | #define CONFIG_FILE "TPCRAWda.conf" | |
34 | #define AliDebugLevel() -1 | |
35 | ||
36 | ||
37 | #include <daqDA.h> | |
38 | #include "event.h" | |
39 | #include "monitor.h" | |
40 | #include <stdio.h> | |
41 | #include <stdlib.h> | |
42 | ||
43 | // | |
44 | //Root includes | |
45 | // | |
46 | #include <TFile.h> | |
47 | #include <TROOT.h> | |
48 | #include <TPluginManager.h> | |
49 | #include <TString.h> | |
50 | #include <TObjString.h> | |
51 | #include <TDatime.h> | |
52 | #include <TStopwatch.h> | |
53 | #include <TObject.h> | |
54 | #include <TMap.h> | |
55 | // | |
56 | //AliRoot includes | |
57 | // | |
58 | #include "AliRawReader.h" | |
59 | #include "AliRawReaderDate.h" | |
60 | #include "AliTPCmapper.h" | |
61 | #include "AliTPCROC.h" | |
62 | #include "AliTPCCalROC.h" | |
63 | #include "AliTPCCalPad.h" | |
64 | #include "AliMathBase.h" | |
65 | #include "TTreeStream.h" | |
66 | #include "AliLog.h" | |
67 | #include "TSystem.h" | |
68 | #include "AliTPCConfigDA.h" | |
69 | // | |
70 | //AMORE | |
71 | // | |
72 | #include <AmoreDA.h> | |
73 | // | |
74 | // TPC calibration algorithm includes | |
75 | // | |
76 | #include "AliTPCCalibRaw.h" | |
77 | ||
78 | ||
79 | //functions, implementation below | |
80 | void SendToAmoreDB(TObject *o, unsigned long32 runNb); | |
81 | ||
82 | /* Main routine | |
83 | Arguments: list of DATE raw data files | |
84 | */ | |
85 | int main(int argc, char **argv) { | |
86 | /* log start of process */ | |
87 | printf("TPCRAWda: DA started - %s\n",__FILE__); | |
88 | ||
89 | if (argc<2) { | |
90 | printf("TPCRAWda: Wrong number of arguments\n"); | |
91 | return -1; | |
92 | } | |
93 | AliLog::SetClassDebugLevel("AliRawReaderDate",-5); | |
94 | AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5); | |
95 | AliLog::SetModuleDebugLevel("RAW",-5); | |
96 | ||
97 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", | |
98 | "*", | |
99 | "TStreamerInfo", | |
100 | "RIO", | |
101 | "TStreamerInfo()"); | |
102 | ||
103 | ||
104 | /* declare monitoring program */ | |
105 | int status=monitorDeclareMp( __FILE__ ); | |
106 | if (status!=0) { | |
107 | printf("TPCRAWda: monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); | |
108 | return -1; | |
109 | } | |
110 | //Set network timeout | |
111 | monitorSetNowait(); | |
112 | monitorSetNoWaitNetworkTimeout(1000); | |
113 | ||
114 | // variables | |
115 | AliTPCmapper *mapping = 0; // The TPC mapping | |
116 | char localfile[255]; | |
117 | unsigned long32 runNb=0; //run number | |
118 | // if test setup get parameters from $DAQDA_TEST_DIR | |
119 | ||
120 | if (!mapping){ | |
121 | /* copy locally the mapping file from daq detector config db */ | |
122 | sprintf(localfile,"./%s",MAPPING_FILE); | |
123 | status = daqDA_DB_getFile(MAPPING_FILE,localfile); | |
124 | if (status) { | |
125 | printf("TPCRAWda: Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status); | |
126 | return -1; | |
127 | } | |
128 | ||
129 | /* open the mapping file and retrieve mapping object */ | |
130 | TFile *fileMapping = new TFile(MAPPING_FILE, "read"); | |
131 | mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping"); | |
132 | delete fileMapping; | |
133 | } | |
134 | ||
135 | if (mapping == 0) { | |
136 | printf("TPCRAWda: Failed to get mapping object from %s. ...\n", MAPPING_FILE); | |
137 | return -1; | |
138 | } else { | |
139 | printf("TPCRAWda: Got mapping object from %s\n", MAPPING_FILE); | |
140 | } | |
141 | ||
142 | // | |
143 | // DA configuration from configuration file | |
144 | // | |
145 | //retrieve configuration file | |
146 | sprintf(localfile,"./%s",CONFIG_FILE); | |
147 | status = daqDA_DB_getFile(CONFIG_FILE,localfile); | |
148 | if (status) { | |
149 | printf("TPCRAWda: Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status); | |
150 | return -1; | |
151 | } | |
152 | AliTPCConfigDA config(CONFIG_FILE); | |
153 | ||
154 | //set default configuration options | |
155 | Double_t updateInterval=30; //seconds | |
156 | TString laserTriggerName("C0LSR-ABCE-NOPF-CENT"); | |
157 | TString forceLaserTriggerId("-1"); | |
158 | ||
159 | //amore update interval | |
160 | Double_t valConf=config.GetValue("AmoreUpdateInterval"); | |
161 | if ( valConf>0 ) updateInterval=valConf; | |
162 | ||
163 | //laser trigger class name | |
164 | if ( config.GetConfigurationMap()->GetValue("LaserTriggerName") ) { | |
165 | laserTriggerName=config.GetConfigurationMap()->GetValue("LaserTriggerName")->GetName(); | |
166 | printf("TPCRAWda: Laser trigger class name set to: %s.\n",laserTriggerName.Data()); | |
167 | } | |
168 | //force laser trigger id | |
169 | if ( config.GetConfigurationMap()->GetValue("ForceLaserTriggerId") ) { | |
170 | forceLaserTriggerId=config.GetConfigurationMap()->GetValue("ForceLaserTriggerId")->GetName(); | |
171 | printf("TPCRAWda: Force laser trigger Id: %s.\n",forceLaserTriggerId.Data()); | |
172 | } | |
173 | ||
174 | ||
175 | //reject laser triggers in a global partition if we have interleaved laser events | |
176 | unsigned char classId=0; | |
177 | int retClassId=daqDA_getClassIdFromName(laserTriggerName.Data(),&classId); | |
178 | //chek if we shall force the laser trigger id. Mainly for test purposes | |
179 | if (forceLaserTriggerId!="-1"){ | |
180 | retClassId=0; | |
181 | classId=static_cast<unsigned char>(forceLaserTriggerId.Atoi()); | |
182 | } | |
183 | //create trigger mask | |
184 | if (retClassId==0){ | |
185 | //interleaved laser in physics runs | |
186 | //reject laser triggered events | |
187 | TString triggerClasses; | |
188 | //TODO | |
189 | //TODO: in the next release of daq put 49 back to 50!!! | |
190 | //TODO | |
191 | for (unsigned char iclassId=0; iclassId<49; ++iclassId){ | |
192 | if (iclassId==classId) continue; //exclude laser trigger | |
193 | triggerClasses+=Form("%u|",(unsigned int)iclassId); | |
194 | } | |
195 | triggerClasses.Chop(); | |
196 | char *table[5] = {"PHY","Y","*",const_cast<char*>(triggerClasses.Data()),NULL}; | |
197 | monitorDeclareTableExtended(table); | |
198 | printf("TPCRAWda: Using laser trigger class Id: %u\n",(unsigned int)classId); | |
199 | printf("TPCRAWda: Accepted trigger class Ids: %s\n",triggerClasses.Data()); | |
200 | } | |
201 | ||
202 | // | |
203 | // create calibration object | |
204 | // | |
205 | AliTPCCalibRaw calibRaw(config.GetConfigurationMap()); // raw calibration algorithm | |
206 | calibRaw.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb | |
207 | ||
208 | //timer | |
209 | TStopwatch stopWatch; | |
210 | ||
211 | //===========================// | |
212 | // loop over RAW data files // | |
213 | //==========================// | |
214 | int nevents=0; | |
215 | for(int i=1;i<argc;i++) { | |
216 | ||
217 | /* define data source : this is argument i */ | |
218 | printf("TPCRAWda: Processing file %s\n", argv[i]); | |
219 | status=monitorSetDataSource( argv[i] ); | |
220 | if (status!=0) { | |
221 | printf("TPCRAWda: monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); | |
222 | return -1; | |
223 | } | |
224 | ||
225 | /* read until EOF */ | |
226 | while (true) { | |
227 | struct eventHeaderStruct *event; | |
228 | ||
229 | /* check shutdown condition */ | |
230 | if (daqDA_checkShutdown()) {break;} | |
231 | ||
232 | /* get next event (blocking call until timeout) */ | |
233 | status=monitorGetEventDynamic((void **)&event); | |
234 | if (status==MON_ERR_EOF) { | |
235 | printf ("TPCRAWda: End of File %d detected\n",i); | |
236 | break; /* end of monitoring file has been reached */ | |
237 | } | |
238 | ||
239 | if (status!=0) { | |
240 | printf("TPCRAWda: monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
241 | break; | |
242 | } | |
243 | ||
244 | /* retry if got no event */ | |
245 | if (event==NULL) { | |
246 | continue; | |
247 | } | |
248 | nevents++; | |
249 | // get the run number | |
250 | runNb = event->eventRunNb; | |
251 | // Raw calibration | |
252 | calibRaw.ProcessEvent(event); | |
253 | // sending to AMOREdb | |
254 | if (stopWatch.RealTime()>updateInterval){ | |
255 | SendToAmoreDB(&calibRaw,runNb); | |
256 | stopWatch.Start(); | |
257 | } else { | |
258 | stopWatch.Continue(); | |
259 | } | |
260 | ||
261 | /* free resources */ | |
262 | free(event); | |
263 | } | |
264 | } | |
265 | ||
266 | // | |
267 | // Analyse pulser data and write them to rootfile | |
268 | // | |
269 | calibRaw.Analyse(); | |
270 | printf ("TPCRAWda: %d events processed\n",nevents); | |
271 | ||
272 | TFile * fileTPC = new TFile (RESULT_FILE,"recreate"); | |
273 | calibRaw.Write("tpcCalibRaw"); | |
274 | delete fileTPC; | |
275 | printf("TPCRAWda: Wrote %s\n",RESULT_FILE); | |
276 | ||
277 | /* store the result file on FES */ | |
278 | ||
279 | status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID); | |
280 | if (status) { | |
281 | status = -2; | |
282 | } | |
283 | // | |
284 | //Send objects to the AMORE DB | |
285 | // | |
286 | printf ("TPCRAWda: AMORE part\n"); | |
287 | SendToAmoreDB(&calibRaw, runNb); | |
288 | ||
289 | return status; | |
290 | } | |
291 | ||
292 | void SendToAmoreDB(TObject *o, unsigned long32 runNb) | |
293 | { | |
294 | //AMORE | |
295 | const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME"); | |
296 | //cheet a little -- temporary solution (hopefully) | |
297 | // | |
298 | //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql | |
299 | //table in which the calib objects are stored. This table is dropped each time AmoreDA | |
300 | //is initialised. This of course makes a problem if we would like to store different | |
301 | //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB | |
302 | //the AMORE_DA_NAME env variable is overwritten. | |
303 | ||
304 | gSystem->Setenv("AMORE_DA_NAME","TPC-RAW"); | |
305 | // | |
306 | // end cheet | |
307 | TDatime time; | |
308 | TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString())); | |
309 | ||
310 | amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender); | |
311 | Int_t statusDA=0; | |
312 | statusDA+=amoreDA.Send("CalibRaw",o); | |
313 | statusDA+=amoreDA.Send("Info",&info); | |
314 | if ( statusDA!=0 ) | |
315 | printf("TPCRAWda: Waring: Failed to write one of the calib objects to the AMORE database\n"); | |
316 | // reset env var | |
317 | if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig); | |
318 | } |