AliRoot Core  3dc7879 (3dc7879)
TPCRAWda.cxx
Go to the documentation of this file.
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 */
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>
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>
61 #include <TMap.h>
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"
75 #include "AliTPCConfigDA.h"
76 //
77 //AMORE
78 //
79 #include <AmoreDA.h>
80 //
81 // TPC calibration algorithm includes
82 //
83 #include "AliTPCCalibRaw.h"
84 
85 
86 //functions, implementation below
87 void SendToAmoreDB(TObject *o, unsigned long32 runNb);
88 
89 int main(int argc, char **argv) {
92 
93  // log start of process
94  printf("TPCRAWda: DA started - %s\n",__FILE__);
95 
96  if (argc<2) {
97  printf("TPCRAWda: Wrong number of arguments\n");
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 */
112  int status=monitorDeclareMp( __FILE__ );
113  if (status!=0) {
114  printf("TPCRAWda: monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
115  return -1;
116  }
117  //Set network timeout
118  monitorSetNowait();
119  monitorSetNoWaitNetworkTimeout(1000);
120 
121  // variables
122  AliTPCmapper *mapping = 0; // The TPC mapping
123  char localfile[255];
124  unsigned long32 runNb=0; //run number
125  // if test setup get parameters from $DAQDA_TEST_DIR
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) {
132  printf("TPCRAWda: Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
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) {
143  printf("TPCRAWda: Failed to get mapping object from %s. ...\n", MAPPING_FILE);
144  return -1;
145  } else {
146  printf("TPCRAWda: Got mapping object from %s\n", MAPPING_FILE);
147  }
148 
149  //
150  // DA configuration from configuration file
151  //
152  //retrieve configuration file
153  sprintf(localfile,"./%s",CONFIG_FILE);
154  status = daqDA_DB_getFile(CONFIG_FILE,localfile);
155  if (status) {
156  printf("TPCRAWda: Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status);
157  return -1;
158  }
159  AliTPCConfigDA config(CONFIG_FILE);
160 
161  //set default configuration options
162  Double_t updateInterval=30; //seconds
163  TString laserTriggerName("C0LSR-ABCE-NOPF-CENT");
164  TString forceLaserTriggerId("-1");
165  TString monitorAttributes=Form("%d",ATTR_ORIGINAL_EVENT);
166  Bool_t skipAmore=kFALSE;
167 
168  //amore update interval
169  Double_t valConf=config.GetValue("AmoreUpdateInterval");
170  if ( valConf>0 ) updateInterval=valConf;
171 
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  }
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  }
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
210  for (unsigned char iclassId=0; iclassId<50; ++iclassId){
211  if (iclassId==classId) continue; //exclude laser trigger
212  triggerClasses+=Form("%u|",(unsigned int)iclassId);
213  }
214  triggerClasses.Chop();
215  char *table[5] = {"PHY",
216  "Y",
217  const_cast<char*>(monitorAttributes.Data()),
218  const_cast<char*>(triggerClasses.Data()),NULL};
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());
222  printf("TPCRAWda: Monitor attributes used: %s\n",monitorAttributes.Data());
223  }
224 
225  //
226  // create calibration object
227  //
228  AliTPCCalibRaw calibRaw(config.GetConfigurationMap()); // raw calibration algorithm
229  calibRaw.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
230 
231  //timer
232  TStopwatch stopWatch;
233 
234  //===========================//
235  // loop over RAW data files //
236  //==========================//
237  int nevents=0;
238  for(int i=1;i<argc;i++) {
239 
240  /* define data source : this is argument i */
241  printf("TPCRAWda: Processing file %s\n", argv[i]);
242  status=monitorSetDataSource( argv[i] );
243  if (status!=0) {
244  printf("TPCRAWda: monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
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) {
258  printf ("TPCRAWda: End of File %d detected\n",i);
259  break; /* end of monitoring file has been reached */
260  }
261 
262  if (status!=0) {
263  printf("TPCRAWda: monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
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;
274  // Raw calibration
275  calibRaw.ProcessEvent(event);
276  // sending to AMOREdb
277  if (stopWatch.RealTime()>updateInterval){
278  if (!skipAmore) SendToAmoreDB(&calibRaw,runNb);
279  stopWatch.Start();
280  } else {
281  stopWatch.Continue();
282  }
283 
284  /* free resources */
285  free(event);
286  }
287  }
288 
289  //
290  // Analyse pulser data and write them to rootfile
291  //
292  calibRaw.Analyse();
293  printf ("TPCRAWda: %d events processed\n",nevents);
294 
295  TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
296  calibRaw.Write("tpcCalibRaw");
297  delete fileTPC;
298  printf("TPCRAWda: Wrote %s\n",RESULT_FILE);
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  //
309  if (!skipAmore) {
310  printf ("TPCRAWda: AMORE part\n");
311  SendToAmoreDB(&calibRaw, runNb);
312  }
313 
314  return status;
315 }
316 
317 void SendToAmoreDB(TObject *o, unsigned long32 runNb)
318 {
319  //AMORE
320  const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
321  //cheet a little -- temporary solution (hopefully)
322  //
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
327  //the AMORE_DA_NAME env variable is overwritten.
328 
329  gSystem->Setenv("AMORE_DA_NAME","TPC-RAW");
330  //
331  // end cheet
332  TDatime time;
333  TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString()));
334 
335  amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
336  Int_t statusDA=0;
337  statusDA+=amoreDA.Send("CalibRaw",o);
338  statusDA+=amoreDA.Send("Info",&info);
339  if ( statusDA!=0 )
340  printf("TPCRAWda: Waring: Failed to write one of the calib objects to the AMORE database\n");
341  // reset env var
342  if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);
343 }
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
static void SetClassDebugLevel(const char *className, Int_t level)
Definition: AliLog.cxx:513
const TMap * GetConfigurationMap() const
AliTPCmapper.
Definition: AliTPCmapper.h:15
int main(int argc, char **argv)
Definition: TPCRAWda.cxx:89
TROOT * gROOT
void SendToAmoreDB(TObject *o, unsigned long32 runNb)
Definition: TPCRAWda.cxx:317
AliExternalInfo info
Float_t GetValue(const char *name) const
#define CONFIG_FILE
Definition: TPCRAWda.cxx:40
#define MAPPING_FILE
Definition: TPCRAWda.cxx:39
static void SetModuleDebugLevel(const char *module, Int_t level)
Definition: AliLog.cxx:485
Class for Parsing simple text configuration files.
#define RESULT_FILE
Definition: TPCRAWda.cxx:37
AliTPCAltroMapping ** GetAltroMapping()
Definition: AliTPCmapper.h:28
void SetAltroMapping(AliTPCAltroMapping **mapp)
#define FILE_ID
Definition: TPCRAWda.cxx:38
Implementation of the TPC Raw drift velocity and Altro L1 Phase calibration.