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