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