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
15 /// \brief TPC DA for online calibration
18 /// Run Type: PHYSICS STANDALONE DAQ
20 /// Number of events needed: 500
22 /// Output Files: tpcCE.root, to be exported to the DAQ FXS
24 /// Trigger types used: PHYSICS_EVENT
26 /// TPCCEda.cxx - calibration algorithm for TPC Central Electrode events
28 /// 10/06/2007 sylvain.chapeland@cern.ch : first version - clean skeleton based on DAQ DA case1
29 /// 06/12/2007 haavard.helstrup@cern.ch : created CE DA based on pulser code
30 /// 19/09/2008 J.Wiechula@gsi.de: Added support for configuration files.
32 /// This process reads RAW data from the files provided as command line arguments
33 /// and save results in a file (named from RESULT_FILE define - see below).
35 /// \author marian.ivanov@cern.ch
37 #define RESULT_FILE "tpcCEnew.root"
38 #define FILE_ID "CEnew"
39 #define MAPPING_FILE "tpcMapping.root"
40 #define CONFIG_FILE "TPCCEda.conf"
41 #define LASER_TRACK_FILE "LaserTracks.root"
54 #include "TPluginManager.h"
57 #include "TObjString.h"
59 #include "TStopwatch.h"
66 #include "AliRawReader.h"
67 #include "AliRawReaderDate.h"
68 #include "AliTPCmapper.h"
69 #include "AliTPCROC.h"
70 #include "AliTPCCalROC.h"
71 #include "AliTPCCalPad.h"
72 #include "AliMathBase.h"
73 #include "TTreeStream.h"
75 #include "AliTPCConfigDA.h"
81 // TPC calibration algorithm includes
83 #include "AliTPCCalibCE.h"
86 //functios, implementation below
87 void SendToAmoreDB(AliTPCCalibCE &calibCE, unsigned long32 runNb);
88 //for threaded processing
91 int main(int argc, char **argv) {
93 /// Arguments: list of DATE raw data files
95 // log start of process
96 printf("TPCCEda: DA started - %s\n",__FILE__);
99 printf("TPCCEda: Wrong number of arguments\n");
103 AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
104 AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
105 AliLog::SetModuleDebugLevel("RAW",-5);
107 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
113 /* declare monitoring program */
115 status=monitorDeclareMp( __FILE__ );
117 printf("TPCCEnewda: monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
121 monitorSetNoWaitNetworkTimeout(1000);
124 AliTPCmapper *mapping = 0; // The TPC mapping
126 unsigned long32 runNb=0; //run number
130 // DA configuration from configuration file
132 //retrieve configuration file
133 sprintf(localfile,"./%s",CONFIG_FILE);
134 status = daqDA_DB_getFile(CONFIG_FILE,localfile);
136 printf("TPCCEda: Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status);
139 AliTPCConfigDA config(CONFIG_FILE);
140 // check configuration options
141 TString laserTriggerName("C0LSR-ABCE-NOPF-CENT");
142 TString monitoringType("YES");
143 TString cdb("local:///local/cdb");
144 Int_t forceTriggerId=-1;
145 Bool_t skipAmore=kFALSE;
147 if ( config.GetConfigurationMap()->GetValue("LaserTriggerName") ) {
148 laserTriggerName=config.GetConfigurationMap()->GetValue("LaserTriggerName")->GetName();
149 printf("TPCCEnewda: Laser trigger class name set to: %s.\n",laserTriggerName.Data());
152 if ( config.GetConfigurationMap()->GetValue("MonitoringType") ) {
153 monitoringType=config.GetConfigurationMap()->GetValue("MonitoringType")->GetName();
154 printf("TPCCEnewda: Monitoring type set to: %s.\n",monitoringType.Data());
157 if ( config.GetConfigurationMap()->GetValue("ForceLaserTriggerId") ) {
158 forceTriggerId=TMath::Nint(config.GetValue("ForceLaserTriggerId"));
159 printf("TPCCEnewda: Only processing triggers with Id: %d.\n",forceTriggerId);
162 if ( config.GetConfigurationMap()->GetValue("SkipAmore") ) {
163 skipAmore=((TObjString*)config.GetConfigurationMap()->GetValue("SkipAmore"))->GetString().Atoi();
164 printf("TPCCENEWda: Skip Amore set in config\n");
167 //subsribe to laser triggers only in physics partition
168 //if the trigger class is not available the return value is -1
169 //in this case we are most probably running as a standalone
170 // laser run and should request all events
171 unsigned char classIdptr=0;
172 int retClassId=daqDA_getClassIdFromName(laserTriggerName.Data(),&classIdptr);
174 //interleaved laser in physics runs
175 //select proper trigger class id
177 snprintf(c,sizeof(c),"%u",(unsigned int)classIdptr);
178 char *table[5] = {"PHY",const_cast<char*>(monitoringType.Data()),"*",c,NULL};
179 monitorDeclareTableExtended(table);
180 printf("TPCCEnewda: Using monitoring table: (PHY, %s, *, %s)\n",monitoringType.Data(),c);
181 } else if (retClassId==-1){
182 //global partition without laser triggered events
183 //the DA should exit properly without processing
184 printf("TPCCEnewda: Laser trigger class '%s' was not found among trigger class names. Will stop processing.\n",laserTriggerName.Data());
186 } else if (retClassId==-2){
187 //standalone case, accept all physics events
188 char *table[5] = {"PHY","Y","*","*",NULL};
189 monitorDeclareTableExtended(table);
190 printf("TPCCEnewda: Using all trigger class Ids\n");
192 printf("TPCCEnewda: Unknown return value of 'daqDA_getClassIdFromName': %d\n",retClassId);
196 //see if we should force the trigger id
197 if (forceTriggerId>-1){
199 sprintf(c,"%d",forceTriggerId);
200 char *table[5] = {"PHY","Y","*",c,NULL};
201 monitorDeclareTableExtended(table);
205 // if test setup get parameters from $DAQDA_TEST_DIR
207 /* copy locally the mapping file from daq detector config db */
208 sprintf(localfile,"./%s",MAPPING_FILE);
209 status = daqDA_DB_getFile(MAPPING_FILE,localfile);
211 printf("TPCCEnewda: Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
215 /* open the mapping file and retrieve mapping object */
216 TFile *fileMapping = new TFile(MAPPING_FILE, "read");
217 mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
222 printf("TPCCEnewda: Failed to get mapping object from %s. ...\n", MAPPING_FILE);
225 printf("TPCCEnewda: Got mapping object from %s\n", MAPPING_FILE);
228 //========== Laser Track data base
229 sprintf(localfile,"./%s",LASER_TRACK_FILE);
230 status = daqDA_DB_getFile(LASER_TRACK_FILE,localfile);
232 printf("TPCCEnewda: Failed to get the laser track file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
237 //create calibration object with the new algorithm
238 AliTPCCalibCE calibCE(config.GetConfigurationMap()); // central electrode calibration
239 calibCE.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
240 calibCE.SetProcessOld(kFALSE);
241 calibCE.SetProcessNew();
243 //amore update interval
244 Double_t updateInterval=300; //seconds
245 Double_t valConf=config.GetValue("AmoreUpdateInterval");
246 if ( valConf>0 ) updateInterval=valConf;
248 TStopwatch stopWatch;
250 //===========================//
251 // loop over RAW data files //
252 //==========================//
256 for ( i=1; i<argc; i++) {
258 /* define data source : this is argument i */
259 printf("TPCCEnewda: Processing file %s\n", argv[i]);
260 status=monitorSetDataSource( argv[i] );
262 printf("TPCCEnewda: monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
269 struct eventHeaderStruct *event;
271 /* check shutdown condition */
272 if (daqDA_checkShutdown()) {break;}
274 /* get next event (blocking call until timeout) */
275 status=monitorGetEventDynamic((void **)&event);
276 if (status==MON_ERR_EOF) {
277 printf ("TPCCEnewda: End of File %d detected\n",i);
278 break; /* end of monitoring file has been reached */
282 printf("TPCCEnewda: monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
286 /* retry if got no event */
288 //use time in between bursts to
289 // send the data to AMOREdb
290 if (stopWatch.RealTime()>updateInterval){
292 if (!skipAmore) SendToAmoreDB(calibCE,runNb);
295 stopWatch.Continue();
298 if (nevents>neventsOld){
299 printf ("TPCCEnewda: %d events processed, %d used\n",nevents,calibCE.GetNeventsProcessed());
306 /* skip start/end of run events */
307 if ( (event->eventType != physicsEvent) && (event->eventType != calibrationEvent) ){
313 // get the run number
314 runNb = event->eventRunNb;
317 calibCE.ProcessEvent(event);
326 // Analyse CE data and write them to rootfile
329 printf ("TPCCEnewda: %d events processed, %d used\n",nevents,calibCE.GetNeventsProcessed());
331 // TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
332 // calibCE.Write("tpcCalibCE");
335 calibCE.DumpToFile(RESULT_FILE,"name=tpcCalibCE,type=4");
336 printf("TPCCEnewda: Wrote %s\n",RESULT_FILE);
338 /* store the result file on FES */
340 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
346 printf("TPCCEnewda: Amore part %s\n",RESULT_FILE);
347 SendToAmoreDB(calibCE,runNb);
354 void SendToAmoreDB(AliTPCCalibCE &calibCE, unsigned long32 runNb)
357 // printf ("AMORE part\n");
358 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
359 //cheet a little -- temporary solution (hopefully)
361 //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
362 //table in which the calib objects are stored. This table is dropped each time AmoreDA
363 //is initialised. This of course makes a problem if we would like to store different
364 //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
365 //the AMORE_DA_NAME env variable is overwritten.
366 gSystem->Setenv("AMORE_DA_NAME",Form("TPC-%s",FILE_ID));
369 TGraph *grA=calibCE.MakeGraphTimeCE(-1,0,2);
370 TGraph *grC=calibCE.MakeGraphTimeCE(-2,0,2);
372 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString()));
373 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
375 // statusDA+=amoreDA.Send("CET0",calibCE.GetCalPadT0());
376 // statusDA+=amoreDA.Send("CEQ",calibCE.GetCalPadQ());
377 // statusDA+=amoreDA.Send("CERMS",calibCE.GetCalPadRMS());
378 // statusDA+=amoreDA.Send("DriftA",grA);
379 // statusDA+=amoreDA.Send("DriftC",grC);
380 statusDA+=amoreDA.Send("FitGraphs",calibCE.GetArrFitGraphs());
381 statusDA+=amoreDA.Send("Info",&info);
383 printf("TPCCEnewda: Waring: Failed to write one of the calib objects to the AMORE database\n");
385 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);