]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/TPCRAWda.cxx
GraphErrors * FitSlices
[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
6e7d7dc4 156 AliTPCCalibRaw calibRaw(config.GetConfigurationMap()); // raw calibration algorithm
ddeb9c4f 157 calibRaw.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
f113dfeb 158
159 //amore update interval
160 Double_t updateInterval=30; //seconds
161 Double_t valConf=config.GetValue("AmoreUpdateInterval");
162 if ( valConf>0 ) updateInterval=valConf;
163 //timer
164 TStopwatch stopWatch;
ddeb9c4f 165 //===========================//
166 // loop over RAW data files //
167 //==========================//
168 int nevents=0;
169 for(i=1;i<argc;i++) {
170
171 /* define data source : this is argument i */
172 printf("Processing file %s\n", argv[i]);
173 status=monitorSetDataSource( argv[i] );
174 if (status!=0) {
175 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
176 return -1;
177 }
178
179 /* read until EOF */
180 while (true) {
181 struct eventHeaderStruct *event;
182
183 /* check shutdown condition */
184 if (daqDA_checkShutdown()) {break;}
185
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 */
191 }
192
193 if (status!=0) {
194 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
195 break;
196 }
197
198 /* retry if got no event */
199 if (event==NULL) {
200 continue;
201 }
202 nevents++;
203 // get the run number
204 runNb = event->eventRunNb;
6fb51ca4 205 // Raw calibration
5312f439 206 calibRaw.ProcessEvent(event);
f113dfeb 207 // sending to AMOREdb
208 if (stopWatch.RealTime()>updateInterval){
209 SendToAmoreDB(&calibRaw,runNb);
210 stopWatch.Start();
211 } else {
212 stopWatch.Continue();
213 }
214
ddeb9c4f 215 /* free resources */
216 free(event);
217 }
218 }
219
220 //
221 // Analyse pulser data and write them to rootfile
222 //
223 calibRaw.Analyse();
224 printf ("%d events processed\n",nevents);
225
226 TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
227 calibRaw.Write("tpcCalibRaw");
228 delete fileTPC;
229 printf("Wrote %s\n",RESULT_FILE);
230
231 /* store the result file on FES */
232
233 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
234 if (status) {
235 status = -2;
236 }
237 //
238 //Send objects to the AMORE DB
239 //
240 printf ("AMORE part\n");
f113dfeb 241 SendToAmoreDB(&calibRaw, runNb);
242
243 return status;
244}
245
246void SendToAmoreDB(TObject *o, unsigned long32 runNb)
247{
248 //AMORE
ddeb9c4f 249 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
250 //cheet a little -- temporary solution (hopefully)
f113dfeb 251 //
ddeb9c4f 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
f113dfeb 256 //the AMORE_DA_NAME env variable is overwritten.
257
ddeb9c4f 258 gSystem->Setenv("AMORE_DA_NAME","TPC-RAW");
f113dfeb 259 //
ddeb9c4f 260 // end cheet
261 TDatime time;
6e7d7dc4 262 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString()));
f113dfeb 263
ddeb9c4f 264 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
f113dfeb 265 Int_t statusDA=0;
266 statusDA+=amoreDA.Send("CalibRaw",o);
ddeb9c4f 267 statusDA+=amoreDA.Send("Info",&info);
268 if ( statusDA!=0 )
269 printf("Waring: Failed to write one of the calib objects to the AMORE database\n");
f113dfeb 270 // reset env var
ddeb9c4f 271 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);
ddeb9c4f 272}