2 TPC DA for online calibration
4 Contact: Haavard.Helstrup@cern.ch, peter.christiansen@hep.lu.se
6 Run Type: PHYSICS STANDALONE DAQ
8 Number of events needed: 500
9 Input Files: /castor/cern.ch/alice/raw/global/2009/08/22/11/09000080958023.30.root
10 Output Files: tpcQA.root, to be exported to the DAQ FXS
12 Trigger types used: PHYSICS_EVENT
18 TPCQAda.cxx - algorithm for TPC RAW QA
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 09/06/2008 peter.christiansen@hep.lu.se and haavard.helstrup@cern.ch : created QA DA based on AliTPCdataQA code
24 10/09/2009 Jens.Wiechula@cern.ch: Export object to AMOREdb after a defined update interval for QA
25 26/01/2010 Jens.Wiechula@cern.ch: Exclude laser triggers when running in a global partition
27 contact: marian.ivanov@cern.ch, peter.christiansen@hep.lu.se
29 This process reads RAW data from the files provided as command line arguments
30 and save results in a file (named from RESULT_FILE define - see below).
34 #define RESULT_FILE "tpcQA.root"
36 #define MAPPING_FILE "tpcMapping.root"
37 #define CONFIG_FILE "TPCQAda.conf"
51 #include <TPluginManager.h>
53 #include <TStopwatch.h>
59 #include "AliRawReader.h"
60 #include "AliRawReaderDate.h"
61 #include "AliTPCmapper.h"
62 #include "AliTPCRawStream.h"
63 #include "AliTPCROC.h"
64 #include "AliTPCCalROC.h"
65 #include "AliTPCCalPad.h"
66 #include "TTreeStream.h"
68 #include "AliTPCConfigDA.h"
74 // TPC calibration algorithm includes
76 #include "AliTPCdataQA.h"
78 //functios, implementation below
79 void SendToAmoreDB(TObject *o, unsigned long32 runNb);
82 Arguments: list of DATE raw data files
84 int main(int argc, char **argv) {
85 /* log start of process */
86 printf("TPCQAda: DA started - %s\n",__FILE__);
89 printf("TPCQAda: Wrong number of arguments\n");
93 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
99 AliLog::SetClassDebugLevel("AliTPCRawStream",-5);
100 AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
101 AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
102 AliLog::SetModuleDebugLevel("RAW",-5);
104 /* declare monitoring program */
105 int status=monitorDeclareMp( __FILE__ );
107 printf("TPCQAda: monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
110 //Set network timeout
112 monitorSetNoWaitNetworkTimeout(1000);
115 AliTPCmapper *mapping = 0; // The TPC mapping
116 unsigned long32 runNb=0; //run number
117 // if test setup get parameters from $DAQDA_TEST_DIR
120 /* copy locally the mapping file from daq detector config db */
121 status = daqDA_DB_getFile(MAPPING_FILE,"./tpcMapping.root");
123 printf("TPCQAda: Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
124 // printf("Continue anyway ... maybe it works?\n"); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
125 return -1; // temporarily uncommented for testing on pcald47 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
128 /* open the mapping file and retrieve mapping object */
129 TFile *fileMapping = new TFile(MAPPING_FILE, "read");
130 mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
135 printf("TPCQAda: Failed to get mapping object from %s. ...\n", MAPPING_FILE);
138 printf("TPCQAda: Got mapping object from %s\n", MAPPING_FILE);
142 // DA configuration from configuration file
144 //retrieve configuration file
146 sprintf(localfile,"./%s",CONFIG_FILE);
147 status = daqDA_DB_getFile(CONFIG_FILE,localfile);
149 printf("TPCQAda: Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status);
152 AliTPCConfigDA config(CONFIG_FILE);
154 // set default configuration options
155 Double_t updateInterval=30; //seconds
156 TString laserTriggerName("C0LSR-ABCE-NOPF-CENT");
157 TString forceLaserTriggerId("-1");
159 //amore update interval
160 Double_t valConf=config.GetValue("AmoreUpdateInterval");
161 if ( valConf>0 ) updateInterval=valConf;
163 //laser trigger class name
164 if ( config.GetConfigurationMap()->GetValue("LaserTriggerName") ) {
165 laserTriggerName=config.GetConfigurationMap()->GetValue("LaserTriggerName")->GetName();
166 printf("TPCRAWda: Laser trigger class name set to: %s.\n",laserTriggerName.Data());
168 //force laser trigger id
169 if ( config.GetConfigurationMap()->GetValue("ForceLaserTriggerId") ) {
170 forceLaserTriggerId=config.GetConfigurationMap()->GetValue("ForceLaserTriggerId")->GetName();
171 printf("TPCRAWda: Force laser trigger Id: %s.\n",forceLaserTriggerId.Data());
175 //reject laser triggers in a global partition if we have interleaved laser events
176 unsigned char classId=0;
177 int retClassId=daqDA_getClassIdFromName(laserTriggerName.Data(),&classId);
178 //chek if we shall force the laser trigger id. Mainly for test purposes
179 if (forceLaserTriggerId!="-1"){
181 classId=static_cast<unsigned char>(forceLaserTriggerId.Atoi());
183 //create trigger mask
185 //interleaved laser in physics runs
186 //reject laser triggered events
187 TString triggerClasses;
189 //TODO: in the next release of daq put 49 back to 50!!!
191 for (unsigned char iclassId=0; iclassId<49; ++iclassId){
192 if (iclassId==classId) continue; //exclude laser trigger
193 triggerClasses+=Form("%u|",(unsigned int)iclassId);
195 triggerClasses.Chop();
196 char *table[5] = {"PHY","Y","*",const_cast<char*>(triggerClasses.Data()),NULL};
197 monitorDeclareTableExtended(table);
198 printf("TPCRAWda: Using laser trigger class Id: %u\n",(unsigned int)classId);
199 printf("TPCRAWda: Accepted trigger class Ids: %s\n",triggerClasses.Data());
203 // create calibration object
205 AliTPCdataQA calibQA(config.GetConfigurationMap()); // qa object
206 calibQA.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
209 TStopwatch stopWatch;
211 //===========================//
212 // loop over RAW data files //
213 //==========================//
215 for(int i=1;i<argc;i++) {
217 /* define data source : this is argument i */
218 printf("TPCQAda: Processing file %s\n", argv[i]);
219 status=monitorSetDataSource( argv[i] );
221 printf("TPCQAda: monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
227 struct eventHeaderStruct *event;
229 /* check shutdown condition */
230 if (daqDA_checkShutdown()) {break;}
232 /* get next event (blocking call until timeout) */
233 status=monitorGetEventDynamic((void **)&event);
234 if (status==MON_ERR_EOF) {
235 printf ("TPCQAda: End of File %d detected\n",i);
236 break; /* end of monitoring file has been reached */
240 printf("TPCQAda: monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
244 /* retry if got no event */
249 // get the run number
250 runNb = event->eventRunNb;
252 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
253 calibQA.ProcessEvent(rawReader);
256 // sending to AMOREdb
257 if (stopWatch.RealTime()>updateInterval){
258 SendToAmoreDB(&calibQA,runNb);
261 stopWatch.Continue();
270 printf ("TPCQAda: %d events processed\n",nevents);
272 TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
273 calibQA.Write("tpcCalibQA");
275 printf("TPCQAda: Wrote %s\n",RESULT_FILE);
277 /* store the result file on FXS */
279 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
284 //Send objects to the AMORE DB
286 printf ("TPCQAda: AMORE part\n");
287 SendToAmoreDB(&calibQA, runNb);
292 void SendToAmoreDB(TObject *o, unsigned long32 runNb)
295 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
296 //cheet a little -- temporary solution (hopefully)
298 //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
299 //table in which the calib objects are stored. This table is dropped each time AmoreDA
300 //is initialised. This of course makes a problem if we would like to store different
301 //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
302 //the AMORE_DA_NAME env variable is overwritten.
304 gSystem->Setenv("AMORE_DA_NAME","TPC-dataQA");
308 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString()));
310 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
312 statusDA+=amoreDA.Send("DataQA",o);
313 statusDA+=amoreDA.Send("Info",&info);
315 printf("TPCQAda: Waring: Failed to write one of the calib objects to the AMORE database\n");
317 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);