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 contact: marian.ivanov@cern.ch, peter.christiansen@hep.lu.se
28 This process reads RAW data from the files provided as command line arguments
29 and save results in a file (named from RESULT_FILE define - see below).
33 #define RESULT_FILE "tpcQA.root"
35 #define MAPPING_FILE "tpcMapping.root"
36 #define CONFIG_FILE "TPCQAda.conf"
50 #include <TPluginManager.h>
52 #include <TStopwatch.h>
57 #include "AliRawReader.h"
58 #include "AliRawReaderDate.h"
59 #include "AliTPCmapper.h"
60 #include "AliTPCRawStream.h"
61 #include "AliTPCROC.h"
62 #include "AliTPCCalROC.h"
63 #include "AliTPCCalPad.h"
64 #include "TTreeStream.h"
66 #include "AliTPCConfigDA.h"
72 // TPC calibration algorithm includes
74 #include "AliTPCdataQA.h"
76 //functios, implementation below
77 void SendToAmoreDB(TObject *o, unsigned long32 runNb);
80 Arguments: list of DATE raw data files
82 int main(int argc, char **argv) {
84 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
90 AliLog::SetClassDebugLevel("AliTPCRawStream",-5);
91 AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
92 AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
93 AliLog::SetModuleDebugLevel("RAW",-5);
97 AliTPCmapper *mapping = 0; // The TPC mapping
98 unsigned long32 runNb=0; //run number
99 // configuration options
100 Bool_t fastDecoding = kFALSE;
101 // if test setup get parameters from $DAQDA_TEST_DIR
104 /* copy locally the mapping file from daq detector config db */
105 status = daqDA_DB_getFile(MAPPING_FILE,"./tpcMapping.root");
107 printf("Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
108 printf("Continue anyway ... maybe it works?\n"); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
109 return -1; // temporarily uncommented for testing on pcald47 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
112 /* open the mapping file and retrieve mapping object */
113 TFile *fileMapping = new TFile(MAPPING_FILE, "read");
114 mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
119 printf("Failed to get mapping object from %s. ...\n", MAPPING_FILE);
122 printf("Got mapping object from %s\n", MAPPING_FILE);
124 //retrieve configuration file
126 sprintf(localfile,"./%s",CONFIG_FILE);
127 status = daqDA_DB_getFile(CONFIG_FILE,localfile);
129 printf("Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status);
132 AliTPCConfigDA config(CONFIG_FILE);
133 // check configuration options
134 if ( (Int_t)config.GetValue("UseFastDecoder") == 1 ) {
135 printf("Info: The fast decoder will be used for the processing.\n");
140 AliTPCdataQA calibQA(config.GetConfigurationMap()); // qa object
143 printf("Wrong number of arguments\n");
148 /* log start of process */
149 printf("TPC QA DA started - %s\n",__FILE__);
152 /* set time bin range */
153 // calibQA.SetRangeTime(0,1000); // should be done in the configuration file now
154 calibQA.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
156 /* declare monitoring program */
157 status=monitorDeclareMp( __FILE__ );
159 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
162 //amore update interval
163 Double_t updateInterval=30; //seconds
164 Double_t valConf=config.GetValue("AmoreUpdateInterval");
165 if ( valConf>0 ) updateInterval=valConf;
167 TStopwatch stopWatch;
170 monitorSetNoWaitNetworkTimeout(1000);
172 /* loop over RAW data files */
174 for(i=1;i<argc;i++) {
176 /* define data source : this is argument i */
177 printf("Processing file %s\n", argv[i]);
178 status=monitorSetDataSource( argv[i] );
180 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
186 struct eventHeaderStruct *event;
188 /* check shutdown condition */
189 if (daqDA_checkShutdown()) {break;}
191 /* get next event (blocking call until timeout) */
192 status=monitorGetEventDynamic((void **)&event);
193 if (status==MON_ERR_EOF) {
194 printf ("End of File %d detected\n",i);
195 break; /* end of monitoring file has been reached */
199 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
203 /* retry if got no event */
208 // get the run number
209 runNb = event->eventRunNb;
211 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
212 if ( fastDecoding ) calibQA.ProcessEventFast(rawReader);
213 else calibQA.ProcessEvent(rawReader);
215 // sending to AMOREdb
216 if (stopWatch.RealTime()>updateInterval){
217 SendToAmoreDB(&calibQA,runNb);
220 stopWatch.Continue();
229 printf ("%d events processed\n",nevents);
231 TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
232 calibQA.Write("tpcCalibQA");
234 printf("Wrote %s\n",RESULT_FILE);
236 /* store the result file on FXS */
238 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
243 //Send objects to the AMORE DB
245 printf ("AMORE part\n");
246 SendToAmoreDB(&calibQA, runNb);
251 void SendToAmoreDB(TObject *o, unsigned long32 runNb)
254 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
255 //cheet a little -- temporary solution (hopefully)
257 //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
258 //table in which the calib objects are stored. This table is dropped each time AmoreDA
259 //is initialised. This of course makes a problem if we would like to store different
260 //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
261 //the AMORE_DA_NAME env variable is overwritten.
263 gSystem->Setenv("AMORE_DA_NAME","TPC-dataQA");
267 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString()));
269 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
271 statusDA+=amoreDA.Send("DataQA",o);
272 statusDA+=amoreDA.Send("Info",&info);
274 printf("Waring: Failed to write one of the calib objects to the AMORE database\n");
276 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);