RESET detector function implemented
[u/mrichter/AliRoot.git] / TPC / TPCQAda.cxx
CommitLineData
b00137d4 1/*
2TPC DA for online calibration
3
4Contact: Haavard.Helstrup@cern.ch, peter.christiansen@hep.lu.se
5Link:
6Run Type: PHYSICS STANDALONE DAQ
7DA Type: MON
8Number of events needed: 500
6fb51ca4 9Input Files: /castor/cern.ch/alice/raw/global/2009/08/22/11/09000080958023.30.root
b00137d4 10Output Files: tpcQA.root, to be exported to the DAQ FXS
11fileId: QA
12Trigger types used: PHYSICS_EVENT
13
14*/
15
16/*
17
18TPCQAda.cxx - algorithm for TPC RAW QA
19
2010/06/2007 sylvain.chapeland@cern.ch : first version - clean skeleton based on DAQ DA case1
2106/12/2007 haavard.helstrup@cern.ch : created CE DA based on pulser code
2209/06/2008 peter.christiansen@hep.lu.se and haavard.helstrup@cern.ch : created QA DA based on AliTPCdataQA code
23
f113dfeb 2410/09/2009 Jens.Wiechula@cern.ch: Export object to AMOREdb after a defined update interval for QA
b00137d4 25contact: marian.ivanov@cern.ch, peter.christiansen@hep.lu.se
26
27
28This process reads RAW data from the files provided as command line arguments
29and save results in a file (named from RESULT_FILE define - see below).
30
31*/
32
33#define RESULT_FILE "tpcQA.root"
34#define FILE_ID "QA"
35#define MAPPING_FILE "tpcMapping.root"
ac940b58 36#define CONFIG_FILE "TPCQAda.conf"
b00137d4 37
38
39#include <daqDA.h>
40#include "event.h"
41#include "monitor.h"
42#include <stdio.h>
43#include <stdlib.h>
44
45//
46//Root includes
47//
48#include <TFile.h>
f113dfeb 49#include <TROOT.h>
50#include <TPluginManager.h>
51#include <TSystem.h>
52#include <TStopwatch.h>
53#include <TObject.h>
b00137d4 54//
55//AliRoot includes
56//
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"
65#include "AliLog.h"
ac940b58 66#include "AliTPCConfigDA.h"
f113dfeb 67//
68//AMORE
69//
70#include <AmoreDA.h>
b00137d4 71//
72// TPC calibration algorithm includes
73//
74#include "AliTPCdataQA.h"
75
f113dfeb 76//functios, implementation below
77void SendToAmoreDB(TObject *o, unsigned long32 runNb);
78
b00137d4 79/* Main routine
80 Arguments: list of DATE raw data files
81*/
82int main(int argc, char **argv) {
83
84 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
85 "*",
86 "TStreamerInfo",
87 "RIO",
88 "TStreamerInfo()");
89
90 AliLog::SetClassDebugLevel("AliTPCRawStream",-5);
91 AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
92 AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
93 AliLog::SetModuleDebugLevel("RAW",-5);
94
ac940b58 95 //variables
b00137d4 96 int i,status;
97 AliTPCmapper *mapping = 0; // The TPC mapping
f113dfeb 98 unsigned long32 runNb=0; //run number
ac940b58 99 // configuration options
100 Bool_t fastDecoding = kFALSE;
101 // if test setup get parameters from $DAQDA_TEST_DIR
b00137d4 102
103 if (!mapping){
104 /* copy locally the mapping file from daq detector config db */
105 status = daqDA_DB_getFile(MAPPING_FILE,"./tpcMapping.root");
106 if (status) {
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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
110 }
111
112 /* open the mapping file and retrieve mapping object */
113 TFile *fileMapping = new TFile(MAPPING_FILE, "read");
114 mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
115 delete fileMapping;
116 }
117
118 if (mapping == 0) {
119 printf("Failed to get mapping object from %s. ...\n", MAPPING_FILE);
120 //return -1;
121 } else {
122 printf("Got mapping object from %s\n", MAPPING_FILE);
123 }
ac940b58 124 //retrieve configuration file
125 char localfile[255];
126 sprintf(localfile,"./%s",CONFIG_FILE);
127 status = daqDA_DB_getFile(CONFIG_FILE,localfile);
128 if (status) {
129 printf("Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status);
130 return -1;
131 }
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");
136 fastDecoding=kTRUE;
137 }
b00137d4 138
139
f113dfeb 140 AliTPCdataQA calibQA(config.GetConfigurationMap()); // qa object
b00137d4 141
142 if (argc<2) {
143 printf("Wrong number of arguments\n");
144 return -1;
145 }
146
147
148 /* log start of process */
149 printf("TPC QA DA started - %s\n",__FILE__);
150
151
152 /* set time bin range */
ac940b58 153 // calibQA.SetRangeTime(0,1000); // should be done in the configuration file now
b00137d4 154 calibQA.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
155
156 /* declare monitoring program */
157 status=monitorDeclareMp( __FILE__ );
158 if (status!=0) {
159 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
160 return -1;
161 }
f113dfeb 162 //amore update interval
163 Double_t updateInterval=30; //seconds
164 Double_t valConf=config.GetValue("AmoreUpdateInterval");
165 if ( valConf>0 ) updateInterval=valConf;
166 //timer
167 TStopwatch stopWatch;
168
ac940b58 169 monitorSetNowait();
170 monitorSetNoWaitNetworkTimeout(1000);
b00137d4 171
172 /* loop over RAW data files */
173 int nevents=0;
174 for(i=1;i<argc;i++) {
175
176 /* define data source : this is argument i */
177 printf("Processing file %s\n", argv[i]);
178 status=monitorSetDataSource( argv[i] );
179 if (status!=0) {
180 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
181 return -1;
182 }
183
184 /* read until EOF */
185 while (true) {
186 struct eventHeaderStruct *event;
187
188 /* check shutdown condition */
189 if (daqDA_checkShutdown()) {break;}
190
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 */
196 }
197
198 if (status!=0) {
199 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
200 break;
201 }
202
203 /* retry if got no event */
204 if (event==NULL) {
205 continue;
206 }
207 nevents++;
f113dfeb 208 // get the run number
209 runNb = event->eventRunNb;
210 // QA
b00137d4 211 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
ac940b58 212 if ( fastDecoding ) calibQA.ProcessEventFast(rawReader);
213 else calibQA.ProcessEvent(rawReader);
b00137d4 214 delete rawReader;
f113dfeb 215 // sending to AMOREdb
216 if (stopWatch.RealTime()>updateInterval){
217 SendToAmoreDB(&calibQA,runNb);
218 stopWatch.Start();
219 } else {
220 stopWatch.Continue();
221 }
222
b00137d4 223 /* free resources */
224 free(event);
225 }
226 }
227
228 calibQA.Analyse();
229 printf ("%d events processed\n",nevents);
230
231 TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
232 calibQA.Write("tpcCalibQA");
233 delete fileTPC;
234 printf("Wrote %s\n",RESULT_FILE);
235
236 /* store the result file on FXS */
237
238 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
239 if (status) {
240 status = -2;
241 }
f113dfeb 242 //
243 //Send objects to the AMORE DB
244 //
245 printf ("AMORE part\n");
246 SendToAmoreDB(&calibQA, runNb);
247
b00137d4 248 return status;
249}
f113dfeb 250
251void SendToAmoreDB(TObject *o, unsigned long32 runNb)
252{
253 //AMORE
254 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
255 //cheet a little -- temporary solution (hopefully)
256 //
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.
262
263 gSystem->Setenv("AMORE_DA_NAME","TPC-dataQA");
264 //
265 // end cheet
266 TDatime time;
6e7d7dc4 267 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString()));
f113dfeb 268
269 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
270 Int_t statusDA=0;
271 statusDA+=amoreDA.Send("DataQA",o);
272 statusDA+=amoreDA.Send("Info",&info);
273 if ( statusDA!=0 )
274 printf("Waring: Failed to write one of the calib objects to the AMORE database\n");
275 // reset env var
276 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);
277}