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 "AliTPCROC.h"
64 #include "AliTPCCalROC.h"
65 #include "AliTPCCalPad.h"
66 #include "AliMathBase.h"
67 #include "TTreeStream.h"
69 #include "AliTPCConfigDA.h"
75 // TPC calibration algorithm includes
77 #include "AliTPCCalibCE.h"
80 //functios, implementation below
81 void SendToAmoreDB(AliTPCCalibCE *calibCE, unsigned long32 runNb);
82 //for threaded processing
86 Arguments: list of DATE raw data files
88 int main(int argc, char **argv) {
89 /* log start of process */
90 printf("TPCCEda: DA started - %s\n",__FILE__);
93 printf("TPCCEda: Wrong number of arguments\n");
97 AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
98 AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
99 AliLog::SetModuleDebugLevel("RAW",-5);
101 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
107 /* declare monitoring program */
109 status=monitorDeclareMp( __FILE__ );
111 printf("TPCCEda: monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
115 monitorSetNoWaitNetworkTimeout(1000);
118 AliTPCmapper *mapping = 0; // The TPC mapping
120 unsigned long32 runNb=0; //run number
124 // DA configuration from configuration file
126 //retrieve configuration file
127 sprintf(localfile,"./%s",CONFIG_FILE);
128 status = daqDA_DB_getFile(CONFIG_FILE,localfile);
130 printf("TPCCEda: Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status);
133 AliTPCConfigDA config(CONFIG_FILE);
134 // check configuration options
135 TString laserTriggerName("C0LSR-ABCE-NOPF-CENT");
136 TString monitoringType("YES");
137 Int_t forceTriggerId=-1;
138 Int_t saveOption=2; // how to store the object. See AliTPCCalibCE::DumpToFile
139 Bool_t skipAmore=kFALSE;
141 if ( config.GetConfigurationMap()->GetValue("LaserTriggerName") ) {
142 laserTriggerName=config.GetConfigurationMap()->GetValue("LaserTriggerName")->GetName();
143 printf("TPCCEda: Laser trigger class name set to: %s.\n",laserTriggerName.Data());
146 if ( config.GetConfigurationMap()->GetValue("MonitoringType") ) {
147 monitoringType=config.GetConfigurationMap()->GetValue("MonitoringType")->GetName();
148 printf("TPCCEda: Monitoring type set to: %s.\n",monitoringType.Data());
151 if ( config.GetConfigurationMap()->GetValue("ForceLaserTriggerId") ) {
152 forceTriggerId=TMath::Nint(config.GetValue("ForceLaserTriggerId"));
153 printf("TPCCEda: Only processing triggers with Id: %d.\n",forceTriggerId);
156 if ( config.GetConfigurationMap()->GetValue("SaveOption") ) {
157 saveOption=TMath::Nint(config.GetValue("SaveOption"));
158 printf("TPCCEda: Saving option set to: %d.\n",saveOption);
161 if ( config.GetConfigurationMap()->GetValue("SkipAmore") ) {
162 skipAmore=((TObjString*)config.GetConfigurationMap()->GetValue("SkipAmore"))->GetString().Atoi();
163 printf("TPCCEda: Skip Amore set in config\n");
166 //subsribe to laser triggers only in physics partition
167 //if the trigger class is not available the return value is -1
168 //in this case we are most probably running as a standalone
169 // laser run and should request all events
170 unsigned char classIdptr=0;
171 int retClassId=daqDA_getClassIdFromName(laserTriggerName.Data(),&classIdptr);
173 //interleaved laser in physics runs
174 //select proper trigger class id
176 snprintf(c,sizeof(c),"%u",(unsigned int)classIdptr);
177 char *table[5] = {"PHY",const_cast<char*>(monitoringType.Data()),"*",c,NULL};
178 monitorDeclareTableExtended(table);
179 printf("TPCCEda: Using monitoring table: (PHY, %s, *, %s)\n",monitoringType.Data(),c);
180 } else if (retClassId==-1){
181 //global partition without laser triggered events
182 //the DA should exit properly without processing
183 printf("TPCCEda: Laser trigger class '%s' was not found among trigger class names. Will stop processing.\n",laserTriggerName.Data());
185 } else if (retClassId==-2){
186 //standalone case, accept all physics events
187 char *table[5] = {"PHY","Y","*","*",NULL};
188 monitorDeclareTableExtended(table);
189 printf("TPCCEda: Using all trigger class Ids\n");
191 printf("TPCCEda: Unknown return value of 'daqDA_getClassIdFromName': %d\n",retClassId);
195 //see if we should force the trigger id
196 if (forceTriggerId>-1){
198 sprintf(c,"%d",forceTriggerId);
199 char *table[5] = {"PHY","Y","*",c,NULL};
200 monitorDeclareTableExtended(table);
204 // if test setup get parameters from $DAQDA_TEST_DIR
206 /* copy locally the mapping file from daq detector config db */
207 sprintf(localfile,"./%s",MAPPING_FILE);
208 status = daqDA_DB_getFile(MAPPING_FILE,localfile);
210 printf("TPCCEda: Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
214 /* open the mapping file and retrieve mapping object */
215 TFile *fileMapping = new TFile(MAPPING_FILE, "read");
216 mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
221 printf("TPCCEda: Failed to get mapping object from %s. ...\n", MAPPING_FILE);
224 printf("TPCCEda: Got mapping object from %s\n", MAPPING_FILE);
228 //create calibration object
229 AliTPCCalibCE *calibCE=new AliTPCCalibCE(config.GetConfigurationMap()); // central electrode calibration
230 calibCE->SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
232 //amore update interval
233 Double_t updateInterval=300; //seconds
234 Double_t valConf=config.GetValue("AmoreUpdateInterval");
235 if ( valConf>0 ) updateInterval=valConf;
237 TStopwatch stopWatch;
239 //===========================//
240 // loop over RAW data files //
241 //==========================//
245 for ( i=1; i<argc; i++) {
247 /* define data source : this is argument i */
248 printf("TPCCEda: Processing file %s\n", argv[i]);
249 status=monitorSetDataSource( argv[i] );
251 printf("TPCCEda: monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
255 Bool_t hasNewData=kFALSE;
258 struct eventHeaderStruct *event;
260 /* check shutdown condition */
261 if (daqDA_checkShutdown()) {break;}
263 /* get next event (blocking call until timeout) */
264 status=monitorGetEventDynamic((void **)&event);
265 if (status==MON_ERR_EOF) {
266 printf ("TPCCEda: End of File %d detected\n",i);
267 break; /* end of monitoring file has been reached */
271 printf("TPCCEda: monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
275 /* retry if got no event */
277 //use time in between bursts to
278 // send the data to AMOREdb
279 if (stopWatch.RealTime()>updateInterval && hasNewData){
281 if (!skipAmore) SendToAmoreDB(calibCE,runNb);
284 stopWatch.Continue();
287 if (nevents>neventsOld){
288 printf ("TPCCEda: %d events processed, %d used\n",nevents,calibCE->GetNeventsProcessed());
295 /* skip start/end of run events */
296 if ( (event->eventType != physicsEvent) && (event->eventType != calibrationEvent) ){
302 // get the run number
303 runNb = event->eventRunNb;
306 calibCE->ProcessEvent(event);
316 // Analyse CE data and write them to rootfile
318 printf ("TPCCEda: %d events processed, %d used\n",nevents,calibCE->GetNeventsProcessed());
321 calibCE->DumpToFile(RESULT_FILE,Form("name=tpcCalibCE,type=%d",saveOption));
322 printf("TPCCEda: Wrote %s\n",RESULT_FILE);
324 /* store the result file on FES */
325 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
331 printf("TPCCEda: Amore part\n");
333 SendToAmoreDB(calibCE,runNb);
341 void SendToAmoreDB(AliTPCCalibCE *calibCE, unsigned long32 runNb)
344 // printf ("AMORE part\n");
345 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
346 //cheet a little -- temporary solution (hopefully)
348 //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
349 //table in which the calib objects are stored. This table is dropped each time AmoreDA
350 //is initialised. This of course makes a problem if we would like to store different
351 //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
352 //the AMORE_DA_NAME env variable is overwritten.
353 gSystem->Setenv("AMORE_DA_NAME",Form("TPC-%s",FILE_ID));
356 TGraph *grA=calibCE->MakeGraphTimeCE(-1,0,2);
357 TGraph *grC=calibCE->MakeGraphTimeCE(-2,0,2);
359 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString()));
360 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
362 statusDA+=amoreDA.Send("CET0",calibCE->GetCalPadT0());
363 statusDA+=amoreDA.Send("CEQ",calibCE->GetCalPadQ());
364 statusDA+=amoreDA.Send("CERMS",calibCE->GetCalPadRMS());
365 statusDA+=amoreDA.Send("DriftA",grA);
366 statusDA+=amoreDA.Send("DriftC",grC);
367 statusDA+=amoreDA.Send("Info",&info);
369 printf("TPCCEda: Waring: Failed to write one of the calib objects to the AMORE database\n");
371 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);