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