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 "tpcCE.root"
34 #define MAPPING_FILE "tpcMapping.root"
35 #define CONFIG_FILE "TPCCEda.conf"
48 #include "TPluginManager.h"
51 #include "TObjString.h"
53 #include "TStopwatch.h"
60 #include "AliRawReader.h"
61 #include "AliRawReaderDate.h"
62 #include "AliTPCmapper.h"
63 #include "AliTPCRawStream.h"
64 #include "AliTPCROC.h"
65 #include "AliTPCCalROC.h"
66 #include "AliTPCCalPad.h"
67 #include "AliMathBase.h"
68 #include "TTreeStream.h"
70 #include "AliTPCConfigDA.h"
76 // TPC calibration algorithm includes
78 #include "AliTPCCalibCE.h"
81 //functios, implementation below
82 void SendToAmoreDB(AliTPCCalibCE *calibCE, unsigned long32 runNb);
83 //for threaded processing
87 Arguments: list of DATE raw data files
89 int main(int argc, char **argv) {
90 /* log start of process */
91 printf("TPCCEda: DA started - %s\n",__FILE__);
94 printf("TPCCEda: Wrong number of arguments\n");
98 AliLog::SetClassDebugLevel("AliTPCRawStream",-5);
99 AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
100 AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
101 AliLog::SetModuleDebugLevel("RAW",-5);
103 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
109 /* declare monitoring program */
111 status=monitorDeclareMp( __FILE__ );
113 printf("TPCCEda: monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
117 monitorSetNoWaitNetworkTimeout(1000);
120 AliTPCmapper *mapping = 0; // The TPC mapping
122 unsigned long32 runNb=0; //run number
126 // DA configuration from configuration file
128 //retrieve configuration file
129 sprintf(localfile,"./%s",CONFIG_FILE);
130 status = daqDA_DB_getFile(CONFIG_FILE,localfile);
132 printf("TPCCEda: Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status);
135 AliTPCConfigDA config(CONFIG_FILE);
136 // check configuration options
137 TString laserTriggerName("C0LSR-ABCE-NOPF-CENT");
138 TString monitoringType("YES");
139 Int_t forceTriggerId=-1;
140 Int_t saveOption=2; // how to store the object. See AliTPCCalibCE::DumpToFile
142 if ( config.GetConfigurationMap()->GetValue("LaserTriggerName") ) {
143 laserTriggerName=config.GetConfigurationMap()->GetValue("LaserTriggerName")->GetName();
144 printf("TPCCEda: Laser trigger class name set to: %s.\n",laserTriggerName.Data());
147 if ( config.GetConfigurationMap()->GetValue("MonitoringType") ) {
148 monitoringType=config.GetConfigurationMap()->GetValue("MonitoringType")->GetName();
149 printf("TPCCEda: Monitoring type set to: %s.\n",monitoringType.Data());
152 if ( config.GetConfigurationMap()->GetValue("ForceLaserTriggerId") ) {
153 forceTriggerId=TMath::Nint(config.GetValue("ForceLaserTriggerId"));
154 printf("TPCCEda: Only processing triggers with Id: %d.\n",forceTriggerId);
157 if ( config.GetConfigurationMap()->GetValue("SaveOption") ) {
158 saveOption=TMath::Nint(config.GetValue("SaveOption"));
159 printf("TPCCEda: Saving option set to: %d.\n",saveOption);
162 //subsribe to laser triggers only in physics partition
163 //if the trigger class is not available the return value is -1
164 //in this case we are most probably running as a standalone
165 // laser run and should request all events
166 unsigned char classIdptr=0;
167 int retClassId=daqDA_getClassIdFromName(laserTriggerName.Data(),&classIdptr);
169 //interleaved laser in physics runs
170 //select proper trigger class id
172 snprintf(c,sizeof(c),"%u",(unsigned int)classIdptr);
173 char *table[5] = {"PHY",const_cast<char*>(monitoringType.Data()),"*",c,NULL};
174 monitorDeclareTableExtended(table);
175 printf("TPCCEda: Using monitoring table: (PHY, %s, *, %s)\n",monitoringType.Data(),c);
176 } else if (retClassId==-1){
177 //global partition without laser triggered events
178 //the DA should exit properly without processing
179 printf("TPCCEda: Laser trigger class '%s' was not found among trigger class names. Will stop processing.\n",laserTriggerName.Data());
181 } else if (retClassId==-2){
182 //standalone case, accept all physics events
183 char *table[5] = {"PHY","Y","*","*",NULL};
184 monitorDeclareTableExtended(table);
185 printf("TPCCEda: Using all trigger class Ids\n");
187 printf("TPCCEda: Unknown return value of 'daqDA_getClassIdFromName': %d\n",retClassId);
191 //see if we should force the trigger id
192 if (forceTriggerId>-1){
194 sprintf(c,"%d",forceTriggerId);
195 char *table[5] = {"PHY","Y","*",c,NULL};
196 monitorDeclareTableExtended(table);
200 // if test setup get parameters from $DAQDA_TEST_DIR
202 /* copy locally the mapping file from daq detector config db */
203 sprintf(localfile,"./%s",MAPPING_FILE);
204 status = daqDA_DB_getFile(MAPPING_FILE,localfile);
206 printf("TPCCEda: Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
210 /* open the mapping file and retrieve mapping object */
211 TFile *fileMapping = new TFile(MAPPING_FILE, "read");
212 mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
217 printf("TPCCEda: Failed to get mapping object from %s. ...\n", MAPPING_FILE);
220 printf("TPCCEda: Got mapping object from %s\n", MAPPING_FILE);
224 //create calibration object
225 AliTPCCalibCE *calibCE=new AliTPCCalibCE(config.GetConfigurationMap()); // central electrode calibration
226 calibCE->SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
228 //amore update interval
229 Double_t updateInterval=300; //seconds
230 Double_t valConf=config.GetValue("AmoreUpdateInterval");
231 if ( valConf>0 ) updateInterval=valConf;
233 TStopwatch stopWatch;
235 //===========================//
236 // loop over RAW data files //
237 //==========================//
241 for ( i=1; i<argc; i++) {
243 /* define data source : this is argument i */
244 printf("TPCCEda: Processing file %s\n", argv[i]);
245 status=monitorSetDataSource( argv[i] );
247 printf("TPCCEda: monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
254 struct eventHeaderStruct *event;
256 /* check shutdown condition */
257 if (daqDA_checkShutdown()) {break;}
259 /* get next event (blocking call until timeout) */
260 status=monitorGetEventDynamic((void **)&event);
261 if (status==MON_ERR_EOF) {
262 printf ("TPCCEda: End of File %d detected\n",i);
263 break; /* end of monitoring file has been reached */
267 printf("TPCCEda: monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
271 /* retry if got no event */
273 //use time in between bursts to
274 // send the data to AMOREdb
275 if (stopWatch.RealTime()>updateInterval){
277 SendToAmoreDB(calibCE,runNb);
280 stopWatch.Continue();
283 if (nevents>neventsOld){
284 printf ("TPCCEda: %d events processed, %d used\n",nevents,calibCE->GetNeventsProcessed());
291 /* skip start/end of run events */
292 if ( (event->eventType != physicsEvent) && (event->eventType != calibrationEvent) ){
298 // get the run number
299 runNb = event->eventRunNb;
302 calibCE->ProcessEvent(event);
311 // Analyse CE data and write them to rootfile
313 // calibCE->Analyse();
314 printf ("TPCCEda: %d events processed, %d used\n",nevents,calibCE->GetNeventsProcessed());
316 // TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
317 // calibCE->Write("tpcCalibCE");
319 calibCE->DumpToFile(RESULT_FILE,Form("name=tpcCalibCE,type=%d",saveOption));
320 printf("TPCCEda: Wrote %s\n",RESULT_FILE);
322 /* store the result file on FES */
324 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
329 SendToAmoreDB(calibCE,runNb);
336 void SendToAmoreDB(AliTPCCalibCE *calibCE, unsigned long32 runNb)
339 // printf ("AMORE part\n");
340 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
341 //cheet a little -- temporary solution (hopefully)
343 //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
344 //table in which the calib objects are stored. This table is dropped each time AmoreDA
345 //is initialised. This of course makes a problem if we would like to store different
346 //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
347 //the AMORE_DA_NAME env variable is overwritten.
348 gSystem->Setenv("AMORE_DA_NAME",Form("TPC-%s",FILE_ID));
351 TGraph *grA=calibCE->MakeGraphTimeCE(-1,0,2);
352 TGraph *grC=calibCE->MakeGraphTimeCE(-2,0,2);
354 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString()));
355 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
357 statusDA+=amoreDA.Send("CET0",calibCE->GetCalPadT0());
358 statusDA+=amoreDA.Send("CEQ",calibCE->GetCalPadQ());
359 statusDA+=amoreDA.Send("CERMS",calibCE->GetCalPadRMS());
360 statusDA+=amoreDA.Send("DriftA",grA);
361 statusDA+=amoreDA.Send("DriftC",grC);
362 statusDA+=amoreDA.Send("Info",&info);
364 printf("TPCCEda: Waring: Failed to write one of the calib objects to the AMORE database\n");
366 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);