2 TPC DA for online calibration
4 Contact: Haavard.Helstrup@cern.ch
6 Run Type: PHYSICS STANDALONE DAQ
8 Number of events needed: 500
10 Output Files: tpcCE.root, to be exported to the DAQ FXS
12 Trigger types used: PHYSICS_EVENT
18 TPCCEda.cxx - calibration algorithm for TPC Central Electrode events
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 19/09/2008 J.Wiechula@gsi.de: Added support for configuration files.
24 contact: marian.ivanov@cern.ch
27 This process reads RAW data from the files provided as command line arguments
28 and save results in a file (named from RESULT_FILE define - see below).
32 #define RESULT_FILE "tpcCEnew.root"
33 #define FILE_ID "CEnew"
34 #define MAPPING_FILE "tpcMapping.root"
35 #define CONFIG_FILE "TPCCEda.conf"
36 #define LASER_TRACK_FILE "LaserTracks.root"
49 #include "TPluginManager.h"
52 #include "TObjString.h"
54 #include "TStopwatch.h"
61 #include "AliRawReader.h"
62 #include "AliRawReaderDate.h"
63 #include "AliTPCmapper.h"
64 #include "AliTPCRawStream.h"
65 #include "AliTPCROC.h"
66 #include "AliTPCCalROC.h"
67 #include "AliTPCCalPad.h"
68 #include "AliMathBase.h"
69 #include "TTreeStream.h"
71 #include "AliTPCConfigDA.h"
77 // TPC calibration algorithm includes
79 #include "AliTPCCalibCE.h"
82 //functios, implementation below
83 void SendToAmoreDB(AliTPCCalibCE &calibCE, unsigned long32 runNb);
84 //for threaded processing
88 Arguments: list of DATE raw data files
90 int main(int argc, char **argv) {
91 /* log start of process */
92 printf("TPCCEda: DA started - %s\n",__FILE__);
95 printf("TPCCEda: Wrong number of arguments\n");
99 AliLog::SetClassDebugLevel("AliTPCRawStream",-5);
100 AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
101 AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
102 AliLog::SetModuleDebugLevel("RAW",-5);
104 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
110 /* declare monitoring program */
112 status=monitorDeclareMp( __FILE__ );
114 printf("TPCCEnewda: monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
118 monitorSetNoWaitNetworkTimeout(1000);
121 AliTPCmapper *mapping = 0; // The TPC mapping
123 unsigned long32 runNb=0; //run number
127 // DA configuration from configuration file
129 //retrieve configuration file
130 sprintf(localfile,"./%s",CONFIG_FILE);
131 status = daqDA_DB_getFile(CONFIG_FILE,localfile);
133 printf("TPCCEda: Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status);
136 AliTPCConfigDA config(CONFIG_FILE);
137 // check configuration options
138 TString laserTriggerName("C0LSR-ABCE-NOPF-CENT");
139 TString monitoringType("YES");
140 TString cdb("local:///local/cdb");
141 Int_t forceTriggerId=-1;
143 if ( config.GetConfigurationMap()->GetValue("LaserTriggerName") ) {
144 laserTriggerName=config.GetConfigurationMap()->GetValue("LaserTriggerName")->GetName();
145 printf("TPCCEnewda: Laser trigger class name set to: %s.\n",laserTriggerName.Data());
148 if ( config.GetConfigurationMap()->GetValue("MonitoringType") ) {
149 monitoringType=config.GetConfigurationMap()->GetValue("MonitoringType")->GetName();
150 printf("TPCCEnewda: Monitoring type set to: %s.\n",monitoringType.Data());
153 if ( config.GetConfigurationMap()->GetValue("ForceLaserTriggerId") ) {
154 forceTriggerId=TMath::Nint(config.GetValue("ForceLaserTriggerId"));
155 printf("TPCCEnewda: Only processing triggers with Id: %d.\n",forceTriggerId);
158 //subsribe to laser triggers only in physics partition
159 //if the trigger class is not available the return value is -1
160 //in this case we are most probably running as a standalone
161 // laser run and should request all events
162 unsigned char classIdptr=0;
163 int retClassId=daqDA_getClassIdFromName(laserTriggerName.Data(),&classIdptr);
165 //interleaved laser in physics runs
166 //select proper trigger class id
168 snprintf(c,sizeof(c),"%u",(unsigned int)classIdptr);
169 char *table[5] = {"PHY",const_cast<char*>(monitoringType.Data()),"*",c,NULL};
170 monitorDeclareTableExtended(table);
171 printf("TPCCEnewda: Using monitoring table: (PHY, %s, *, %s)\n",monitoringType.Data(),c);
172 } else if (retClassId==-1){
173 //global partition without laser triggered events
174 //the DA should exit properly without processing
175 printf("TPCCEnewda: Laser trigger class '%s' was not found among trigger class names. Will stop processing.\n",laserTriggerName.Data());
177 } else if (retClassId==-2){
178 //standalone case, accept all physics events
179 char *table[5] = {"PHY","Y","*","*",NULL};
180 monitorDeclareTableExtended(table);
181 printf("TPCCEnewda: Using all trigger class Ids\n");
183 printf("TPCCEnewda: Unknown return value of 'daqDA_getClassIdFromName': %d\n",retClassId);
187 //see if we should force the trigger id
188 if (forceTriggerId>-1){
190 sprintf(c,"%d",forceTriggerId);
191 char *table[5] = {"PHY","Y","*",c,NULL};
192 monitorDeclareTableExtended(table);
196 // if test setup get parameters from $DAQDA_TEST_DIR
198 /* copy locally the mapping file from daq detector config db */
199 sprintf(localfile,"./%s",MAPPING_FILE);
200 status = daqDA_DB_getFile(MAPPING_FILE,localfile);
202 printf("TPCCEnewda: Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
206 /* open the mapping file and retrieve mapping object */
207 TFile *fileMapping = new TFile(MAPPING_FILE, "read");
208 mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
213 printf("TPCCEnewda: Failed to get mapping object from %s. ...\n", MAPPING_FILE);
216 printf("TPCCEnewda: Got mapping object from %s\n", MAPPING_FILE);
219 //========== Laser Track data base
220 sprintf(localfile,"./%s",LASER_TRACK_FILE);
221 status = daqDA_DB_getFile(LASER_TRACK_FILE,localfile);
223 printf("TPCCEnewda: Failed to get the laser track file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
228 //create calibration object with the new algorithm
229 AliTPCCalibCE calibCE(config.GetConfigurationMap()); // central electrode calibration
230 calibCE.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
231 calibCE.SetProcessOld(kFALSE);
232 calibCE.SetProcessNew();
234 //amore update interval
235 Double_t updateInterval=300; //seconds
236 Double_t valConf=config.GetValue("AmoreUpdateInterval");
237 if ( valConf>0 ) updateInterval=valConf;
239 TStopwatch stopWatch;
241 //===========================//
242 // loop over RAW data files //
243 //==========================//
247 for ( i=1; i<argc; i++) {
249 /* define data source : this is argument i */
250 printf("TPCCEnewda: Processing file %s\n", argv[i]);
251 status=monitorSetDataSource( argv[i] );
253 printf("TPCCEnewda: monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
260 struct eventHeaderStruct *event;
262 /* check shutdown condition */
263 if (daqDA_checkShutdown()) {break;}
265 /* get next event (blocking call until timeout) */
266 status=monitorGetEventDynamic((void **)&event);
267 if (status==MON_ERR_EOF) {
268 printf ("TPCCEnewda: End of File %d detected\n",i);
269 break; /* end of monitoring file has been reached */
273 printf("TPCCEnewda: monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
277 /* retry if got no event */
279 //use time in between bursts to
280 // send the data to AMOREdb
281 if (stopWatch.RealTime()>updateInterval){
283 SendToAmoreDB(calibCE,runNb);
286 stopWatch.Continue();
289 if (nevents>neventsOld){
290 printf ("TPCCEnewda: %d events processed, %d used\n",nevents,calibCE.GetNeventsProcessed());
297 /* skip start/end of run events */
298 if ( (event->eventType != physicsEvent) && (event->eventType != calibrationEvent) ){
304 // get the run number
305 runNb = event->eventRunNb;
308 calibCE.ProcessEvent(event);
317 // Analyse CE data and write them to rootfile
320 printf ("TPCCEnewda: %d events processed, %d used\n",nevents,calibCE.GetNeventsProcessed());
322 // TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
323 // calibCE.Write("tpcCalibCE");
326 calibCE.DumpToFile(RESULT_FILE,"name=tpcCalibCE,type=3");
327 printf("TPCCEnewda: Wrote %s\n",RESULT_FILE);
329 /* store the result file on FES */
331 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
336 printf("TPCCEnewda: Amore part %s\n",RESULT_FILE);
337 SendToAmoreDB(calibCE,runNb);
343 void SendToAmoreDB(AliTPCCalibCE &calibCE, unsigned long32 runNb)
346 // printf ("AMORE part\n");
347 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
348 //cheet a little -- temporary solution (hopefully)
350 //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
351 //table in which the calib objects are stored. This table is dropped each time AmoreDA
352 //is initialised. This of course makes a problem if we would like to store different
353 //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
354 //the AMORE_DA_NAME env variable is overwritten.
355 gSystem->Setenv("AMORE_DA_NAME",Form("TPC-%s",FILE_ID));
358 TGraph *grA=calibCE.MakeGraphTimeCE(-1,0,2);
359 TGraph *grC=calibCE.MakeGraphTimeCE(-2,0,2);
361 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString()));
362 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
364 // statusDA+=amoreDA.Send("CET0",calibCE.GetCalPadT0());
365 // statusDA+=amoreDA.Send("CEQ",calibCE.GetCalPadQ());
366 // statusDA+=amoreDA.Send("CERMS",calibCE.GetCalPadRMS());
367 // statusDA+=amoreDA.Send("DriftA",grA);
368 // statusDA+=amoreDA.Send("DriftC",grC);
369 statusDA+=amoreDA.Send("FitGraphs",calibCE.GetArrFitGraphs());
370 statusDA+=amoreDA.Send("Info",&info);
372 printf("TPCCEnewda: Waring: Failed to write one of the calib objects to the AMORE database\n");
374 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);