- exclude old HLT TPC calibration components from the list of registered components
[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
18TPCRAWda.cxx - calibration algorithm for TPC pulser events
19
2030/09/2009 J.Wiechula@gsi.de: First implementation.
21
22
23This process reads RAW data from the files provided as command line arguments
24and save results in a file (named from RESULT_FILE define - see below).
25
26*/
27
28#define RESULT_FILE "tpcCalibRaw.root"
29#define FILE_ID "tpcCalibRaw"
30#define MAPPING_FILE "tpcMapping.root"
31#define CONFIG_FILE "TPCRAWda.conf"
32#define AliDebugLevel() -1
33
34
35#include <daqDA.h>
36#include "event.h"
37#include "monitor.h"
38#include <stdio.h>
39#include <stdlib.h>
40
41//
42//Root includes
43//
44#include <TFile.h>
45#include "TROOT.h"
46#include "TPluginManager.h"
47#include "TString.h"
48#include "TObjString.h"
49#include "TDatime.h"
50//
51//AliRoot includes
52//
53#include "AliRawReader.h"
54#include "AliRawReaderDate.h"
55#include "AliTPCmapper.h"
56#include "AliTPCROC.h"
57#include "AliTPCCalROC.h"
58#include "AliTPCCalPad.h"
59#include "AliMathBase.h"
60#include "TTreeStream.h"
61#include "AliLog.h"
62#include "TSystem.h"
63// #include "AliTPCConfigDA.h"
64//
65//AMORE
66//
67#include <AmoreDA.h>
68//
69// TPC calibration algorithm includes
70//
71#include "AliTPCCalibRaw.h"
72
73/* Main routine
74 Arguments: list of DATE raw data files
75*/
76int main(int argc, char **argv) {
77 /* log start of process */
6fb51ca4 78 printf("TPC RAW DA started - %s\n",__FILE__);
ddeb9c4f 79
80 if (argc<2) {
81 printf("Wrong number of arguments\n");
82 return -1;
83 }
84 AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
85 AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
86 AliLog::SetModuleDebugLevel("RAW",-5);
87
88 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
89 "*",
90 "TStreamerInfo",
91 "RIO",
92 "TStreamerInfo()");
93
94
95 /* declare monitoring program */
96 int i,status;
97 status=monitorDeclareMp( __FILE__ );
98 if (status!=0) {
99 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
100 return -1;
101 }
e6970ab5 102 //Set network timeout
103 monitorSetNowait();
104 monitorSetNoWaitNetworkTimeout(1000);
105
ddeb9c4f 106 // variables
107 AliTPCmapper *mapping = 0; // The TPC mapping
108 char localfile[255];
109 unsigned long32 runNb=0; //run number
110 // configuration options
111 Bool_t fastDecoding = kFALSE;
112 // if test setup get parameters from $DAQDA_TEST_DIR
113
114 if (!mapping){
115 /* copy locally the mapping file from daq detector config db */
116 sprintf(localfile,"./%s",MAPPING_FILE);
117 status = daqDA_DB_getFile(MAPPING_FILE,localfile);
118 if (status) {
119 printf("Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
120 return -1;
121 }
122
123 /* open the mapping file and retrieve mapping object */
124 TFile *fileMapping = new TFile(MAPPING_FILE, "read");
125 mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
126 delete fileMapping;
127 }
128
129 if (mapping == 0) {
130 printf("Failed to get mapping object from %s. ...\n", MAPPING_FILE);
131 return -1;
132 } else {
133 printf("Got mapping object from %s\n", MAPPING_FILE);
134 }
135
136 //
137 // DA configuration from configuration file
138 //
139 //retrieve configuration file
140// sprintf(localfile,"./%s",CONFIG_FILE);
141// status = daqDA_DB_getFile(CONFIG_FILE,localfile);
142// if (status) {
143// printf("Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status);
144// return -1;
145// }
146// AliTPCConfigDA config(CONFIG_FILE);
147
148 // create calibration object
149// AliTPCCalibRaw calibRaw(config.GetConfigurationMap()); // pulser calibration algorithm
150 AliTPCCalibRaw calibRaw; // pulser calibration algorithm
151 calibRaw.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
152
153 //===========================//
154 // loop over RAW data files //
155 //==========================//
156 int nevents=0;
157 for(i=1;i<argc;i++) {
158
159 /* define data source : this is argument i */
160 printf("Processing file %s\n", argv[i]);
161 status=monitorSetDataSource( argv[i] );
162 if (status!=0) {
163 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
164 return -1;
165 }
166
167 /* read until EOF */
168 while (true) {
169 struct eventHeaderStruct *event;
170
171 /* check shutdown condition */
172 if (daqDA_checkShutdown()) {break;}
173
174 /* get next event (blocking call until timeout) */
175 status=monitorGetEventDynamic((void **)&event);
176 if (status==MON_ERR_EOF) {
177 printf ("End of File %d detected\n",i);
178 break; /* end of monitoring file has been reached */
179 }
180
181 if (status!=0) {
182 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
183 break;
184 }
185
186 /* retry if got no event */
187 if (event==NULL) {
188 continue;
189 }
190 nevents++;
191 // get the run number
192 runNb = event->eventRunNb;
6fb51ca4 193 // Raw calibration
5312f439 194 calibRaw.ProcessEvent(event);
ddeb9c4f 195
196 /* free resources */
197 free(event);
198 }
199 }
200
201 //
202 // Analyse pulser data and write them to rootfile
203 //
204 calibRaw.Analyse();
205 printf ("%d events processed\n",nevents);
206
207 TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
208 calibRaw.Write("tpcCalibRaw");
209 delete fileTPC;
210 printf("Wrote %s\n",RESULT_FILE);
211
212 /* store the result file on FES */
213
214 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
215 if (status) {
216 status = -2;
217 }
218 //
219 //Send objects to the AMORE DB
220 //
221 printf ("AMORE part\n");
222 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
223 //cheet a little -- temporary solution (hopefully)
224 //
225 //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
226 //table in which the calib objects are stored. This table is dropped each time AmoreDA
227 //is initialised. This of course makes a problem if we would like to store different
228 //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
229 //the AMORE_DA_NAME env variable is overwritten.
230
231 gSystem->Setenv("AMORE_DA_NAME","TPC-RAW");
232 //
233 // end cheet
234 TDatime time;
235 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsString()));
236
237 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
238 Int_t statusDA=0;
239 statusDA+=amoreDA.Send("CalibRaw",&calibRaw);
240 statusDA+=amoreDA.Send("Info",&info);
241 if ( statusDA!=0 )
242 printf("Waring: Failed to write one of the calib objects to the AMORE database\n");
243 // reset env var
244 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);
245
246 return status;
247}