2 TPC DA for online calibration
4 Contact: Jens.Wiechula@cern.ch
6 Run Type: PHYSICS STANDALONE
8 Number of events needed: 200
9 Input Files: /castor/cern.ch/alice/raw/global/2009/08/22/11/09000080958023.30.root
10 Output Files: tpcCalibRaw.root, to be exported to the DAQ FXS
12 Trigger types used: PHYSICS_EVENT
18 TPCRAWda.cxx - calibration algorithm for L1 phase monitoring and drift velocity from last time bin determination
20 30/07/2009 Jens.Wiechula@cern.ch: First implementation.
21 10/09/2009 Jens.Wiechula@cern.ch: Add configuration file support. Export object to AMOREdb
22 after a defined update interval for QA
24 This process reads RAW data from the files provided as command line arguments
25 and save results in a file (named from RESULT_FILE define - see below).
29 #define RESULT_FILE "tpcCalibRaw.root"
30 #define FILE_ID "tpcCalibRaw"
31 #define MAPPING_FILE "tpcMapping.root"
32 #define CONFIG_FILE "TPCRAWda.conf"
33 #define AliDebugLevel() -1
47 #include <TPluginManager.h>
49 #include <TObjString.h>
51 #include <TStopwatch.h>
56 #include "AliRawReader.h"
57 #include "AliRawReaderDate.h"
58 #include "AliTPCmapper.h"
59 #include "AliTPCROC.h"
60 #include "AliTPCCalROC.h"
61 #include "AliTPCCalPad.h"
62 #include "AliMathBase.h"
63 #include "TTreeStream.h"
66 #include "AliTPCConfigDA.h"
72 // TPC calibration algorithm includes
74 #include "AliTPCCalibRaw.h"
77 //functions, implementation below
78 void SendToAmoreDB(TObject *o, unsigned long32 runNb);
81 Arguments: list of DATE raw data files
83 int main(int argc, char **argv) {
84 /* log start of process */
85 printf("TPC RAW DA started - %s\n",__FILE__);
88 printf("Wrong number of arguments\n");
91 AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
92 AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
93 AliLog::SetModuleDebugLevel("RAW",-5);
95 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
102 /* declare monitoring program */
104 status=monitorDeclareMp( __FILE__ );
106 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
109 //Set network timeout
111 monitorSetNoWaitNetworkTimeout(1000);
114 AliTPCmapper *mapping = 0; // The TPC mapping
116 unsigned long32 runNb=0; //run number
117 // configuration options
118 Bool_t fastDecoding = kFALSE;
119 // if test setup get parameters from $DAQDA_TEST_DIR
122 /* copy locally the mapping file from daq detector config db */
123 sprintf(localfile,"./%s",MAPPING_FILE);
124 status = daqDA_DB_getFile(MAPPING_FILE,localfile);
126 printf("Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
130 /* open the mapping file and retrieve mapping object */
131 TFile *fileMapping = new TFile(MAPPING_FILE, "read");
132 mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
137 printf("Failed to get mapping object from %s. ...\n", MAPPING_FILE);
140 printf("Got mapping object from %s\n", MAPPING_FILE);
144 // DA configuration from configuration file
146 //retrieve configuration file
147 sprintf(localfile,"./%s",CONFIG_FILE);
148 status = daqDA_DB_getFile(CONFIG_FILE,localfile);
150 printf("Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status);
153 AliTPCConfigDA config(CONFIG_FILE);
155 // create calibration object
156 AliTPCCalibRaw calibRaw(config.GetConfigurationMap()); // raw calibration algorithm
157 calibRaw.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
159 //amore update interval
160 Double_t updateInterval=30; //seconds
161 Double_t valConf=config.GetValue("AmoreUpdateInterval");
162 if ( valConf>0 ) updateInterval=valConf;
164 TStopwatch stopWatch;
165 //===========================//
166 // loop over RAW data files //
167 //==========================//
169 for(i=1;i<argc;i++) {
171 /* define data source : this is argument i */
172 printf("Processing file %s\n", argv[i]);
173 status=monitorSetDataSource( argv[i] );
175 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
181 struct eventHeaderStruct *event;
183 /* check shutdown condition */
184 if (daqDA_checkShutdown()) {break;}
186 /* get next event (blocking call until timeout) */
187 status=monitorGetEventDynamic((void **)&event);
188 if (status==MON_ERR_EOF) {
189 printf ("End of File %d detected\n",i);
190 break; /* end of monitoring file has been reached */
194 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
198 /* retry if got no event */
203 // get the run number
204 runNb = event->eventRunNb;
206 calibRaw.ProcessEvent(event);
207 // sending to AMOREdb
208 if (stopWatch.RealTime()>updateInterval){
209 SendToAmoreDB(&calibRaw,runNb);
212 stopWatch.Continue();
221 // Analyse pulser data and write them to rootfile
224 printf ("%d events processed\n",nevents);
226 TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
227 calibRaw.Write("tpcCalibRaw");
229 printf("Wrote %s\n",RESULT_FILE);
231 /* store the result file on FES */
233 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
238 //Send objects to the AMORE DB
240 printf ("AMORE part\n");
241 SendToAmoreDB(&calibRaw, runNb);
246 void SendToAmoreDB(TObject *o, unsigned long32 runNb)
249 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
250 //cheet a little -- temporary solution (hopefully)
252 //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
253 //table in which the calib objects are stored. This table is dropped each time AmoreDA
254 //is initialised. This of course makes a problem if we would like to store different
255 //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
256 //the AMORE_DA_NAME env variable is overwritten.
258 gSystem->Setenv("AMORE_DA_NAME","TPC-RAW");
262 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString()));
264 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
266 statusDA+=amoreDA.Send("CalibRaw",o);
267 statusDA+=amoreDA.Send("Info",&info);
269 printf("Waring: Failed to write one of the calib objects to the AMORE database\n");
271 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);