Hotfix for online display GUI application (Matevz)
[u/mrichter/AliRoot.git] / TPC / TPCRAWda.cxx
CommitLineData
ddeb9c4f 1/*
2TPC DA for online calibration
3
4Contact: Jens.Wiechula@cern.ch
5Link:
6fb51ca4 6Run Type: PHYSICS STANDALONE
7DA Type: MON
8Number of events needed: 200
9Input Files: /castor/cern.ch/alice/raw/global/2009/08/22/11/09000080958023.30.root
ddeb9c4f 10Output Files: tpcCalibRaw.root, to be exported to the DAQ FXS
6fb51ca4 11fileId: tpcCalibRaw
12Trigger types used: PHYSICS_EVENT
ddeb9c4f 13
14*/
15
16/*
17
f113dfeb 18TPCRAWda.cxx - calibration algorithm for L1 phase monitoring and drift velocity from last time bin determination
ddeb9c4f 19
f113dfeb 2030/07/2009 Jens.Wiechula@cern.ch: First implementation.
2110/09/2009 Jens.Wiechula@cern.ch: Add configuration file support. Export object to AMOREdb
22 after a defined update interval for QA
ddeb9c4f 23
24This process reads RAW data from the files provided as command line arguments
25and save results in a file (named from RESULT_FILE define - see below).
26
27*/
28
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
34
35
36#include <daqDA.h>
37#include "event.h"
38#include "monitor.h"
39#include <stdio.h>
40#include <stdlib.h>
41
42//
43//Root includes
44//
45#include <TFile.h>
f113dfeb 46#include <TROOT.h>
47#include <TPluginManager.h>
48#include <TString.h>
49#include <TObjString.h>
50#include <TDatime.h>
51#include <TStopwatch.h>
52#include <TObject.h>
ddeb9c4f 53//
54//AliRoot includes
55//
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"
64#include "AliLog.h"
65#include "TSystem.h"
f113dfeb 66#include "AliTPCConfigDA.h"
ddeb9c4f 67//
68//AMORE
69//
70#include <AmoreDA.h>
71//
72// TPC calibration algorithm includes
73//
74#include "AliTPCCalibRaw.h"
75
f113dfeb 76
77//functions, implementation below
78void SendToAmoreDB(TObject *o, unsigned long32 runNb);
79
ddeb9c4f 80/* Main routine
81 Arguments: list of DATE raw data files
82*/
83int main(int argc, char **argv) {
84 /* log start of process */
6fb51ca4 85 printf("TPC RAW DA started - %s\n",__FILE__);
ddeb9c4f 86
87 if (argc<2) {
88 printf("Wrong number of arguments\n");
89 return -1;
90 }
91 AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
92 AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
93 AliLog::SetModuleDebugLevel("RAW",-5);
94
95 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
96 "*",
97 "TStreamerInfo",
98 "RIO",
99 "TStreamerInfo()");
100
101
102 /* declare monitoring program */
103 int i,status;
104 status=monitorDeclareMp( __FILE__ );
105 if (status!=0) {
106 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
107 return -1;
108 }
e6970ab5 109 //Set network timeout
110 monitorSetNowait();
111 monitorSetNoWaitNetworkTimeout(1000);
112
ddeb9c4f 113 // variables
114 AliTPCmapper *mapping = 0; // The TPC mapping
115 char localfile[255];
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
120
121 if (!mapping){
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);
125 if (status) {
126 printf("Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
127 return -1;
128 }
129
130 /* open the mapping file and retrieve mapping object */
131 TFile *fileMapping = new TFile(MAPPING_FILE, "read");
132 mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
133 delete fileMapping;
134 }
135
136 if (mapping == 0) {
137 printf("Failed to get mapping object from %s. ...\n", MAPPING_FILE);
138 return -1;
139 } else {
140 printf("Got mapping object from %s\n", MAPPING_FILE);
141 }
142
143 //
144 // DA configuration from configuration file
145 //
146 //retrieve configuration file
f113dfeb 147 sprintf(localfile,"./%s",CONFIG_FILE);
148 status = daqDA_DB_getFile(CONFIG_FILE,localfile);
149 if (status) {
150 printf("Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status);
151 return -1;
152 }
153 AliTPCConfigDA config(CONFIG_FILE);
ddeb9c4f 154
155 // create calibration object
156// AliTPCCalibRaw calibRaw(config.GetConfigurationMap()); // pulser calibration algorithm
f113dfeb 157 AliTPCCalibRaw calibRaw(config.GetConfigurationMap()); // pulser calibration algorithm
ddeb9c4f 158 calibRaw.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
f113dfeb 159
160 //amore update interval
161 Double_t updateInterval=30; //seconds
162 Double_t valConf=config.GetValue("AmoreUpdateInterval");
163 if ( valConf>0 ) updateInterval=valConf;
164 //timer
165 TStopwatch stopWatch;
ddeb9c4f 166 //===========================//
167 // loop over RAW data files //
168 //==========================//
169 int nevents=0;
170 for(i=1;i<argc;i++) {
171
172 /* define data source : this is argument i */
173 printf("Processing file %s\n", argv[i]);
174 status=monitorSetDataSource( argv[i] );
175 if (status!=0) {
176 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
177 return -1;
178 }
179
180 /* read until EOF */
181 while (true) {
182 struct eventHeaderStruct *event;
183
184 /* check shutdown condition */
185 if (daqDA_checkShutdown()) {break;}
186
187 /* get next event (blocking call until timeout) */
188 status=monitorGetEventDynamic((void **)&event);
189 if (status==MON_ERR_EOF) {
190 printf ("End of File %d detected\n",i);
191 break; /* end of monitoring file has been reached */
192 }
193
194 if (status!=0) {
195 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
196 break;
197 }
198
199 /* retry if got no event */
200 if (event==NULL) {
201 continue;
202 }
203 nevents++;
204 // get the run number
205 runNb = event->eventRunNb;
6fb51ca4 206 // Raw calibration
5312f439 207 calibRaw.ProcessEvent(event);
f113dfeb 208 // sending to AMOREdb
209 if (stopWatch.RealTime()>updateInterval){
210 SendToAmoreDB(&calibRaw,runNb);
211 stopWatch.Start();
212 } else {
213 stopWatch.Continue();
214 }
215
ddeb9c4f 216 /* free resources */
217 free(event);
218 }
219 }
220
221 //
222 // Analyse pulser data and write them to rootfile
223 //
224 calibRaw.Analyse();
225 printf ("%d events processed\n",nevents);
226
227 TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
228 calibRaw.Write("tpcCalibRaw");
229 delete fileTPC;
230 printf("Wrote %s\n",RESULT_FILE);
231
232 /* store the result file on FES */
233
234 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
235 if (status) {
236 status = -2;
237 }
238 //
239 //Send objects to the AMORE DB
240 //
241 printf ("AMORE part\n");
f113dfeb 242 SendToAmoreDB(&calibRaw, runNb);
243
244 return status;
245}
246
247void SendToAmoreDB(TObject *o, unsigned long32 runNb)
248{
249 //AMORE
ddeb9c4f 250 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
251 //cheet a little -- temporary solution (hopefully)
f113dfeb 252 //
ddeb9c4f 253 //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
254 //table in which the calib objects are stored. This table is dropped each time AmoreDA
255 //is initialised. This of course makes a problem if we would like to store different
256 //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
f113dfeb 257 //the AMORE_DA_NAME env variable is overwritten.
258
ddeb9c4f 259 gSystem->Setenv("AMORE_DA_NAME","TPC-RAW");
f113dfeb 260 //
ddeb9c4f 261 // end cheet
262 TDatime time;
263 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsString()));
f113dfeb 264
ddeb9c4f 265 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
f113dfeb 266 Int_t statusDA=0;
267 statusDA+=amoreDA.Send("CalibRaw",o);
ddeb9c4f 268 statusDA+=amoreDA.Send("Info",&info);
269 if ( statusDA!=0 )
270 printf("Waring: Failed to write one of the calib objects to the AMORE database\n");
f113dfeb 271 // reset env var
ddeb9c4f 272 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);
ddeb9c4f 273}