]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - TPC/TPCPULSERda.cxx
AliTPCCalibCE.cxx.diff Add ctor with configuration options; Bug fixes
[u/mrichter/AliRoot.git] / TPC / TPCPULSERda.cxx
... / ...
CommitLineData
1/*
2TPC DA for online calibration
3
4Contact: Haavard.Helstrup@cern.ch
5Link:
6Run Type: CALIBRATION_PULSER
7DA Type: LDC
8Number of events needed: 100
9Input Files:
10Output Files: tpcPulser.root, to be exported to the DAQ FXS
11fileId: pulser
12Trigger types used: CALIBRATION_EVENT
13
14*/
15
16/*
17
18TPCda_pulser.cxx - calibration algorithm for TPC pulser events
19
2010/06/2007 sylvain.chapeland@cern.ch : first version - clean skeleton based on DAQ DA case1
2130/09/2007 haavard.helstrup@cern.ch : created pulser DA based on pedestal code
2219/09/2008 J.Wiechula@gsi.de: Added export of the calibration data to the AMORE data base.
23 Added support for configuration files.
24contact: marian.ivanov@cern.ch
25
26
27This process reads RAW data from the files provided as command line arguments
28and save results in a file (named from RESULT_FILE define - see below).
29
30*/
31
32#define RESULT_FILE "tpcPulser.root"
33#define FILE_ID "pulser"
34#define MAPPING_FILE "tpcMapping.root"
35#define CONFIG_FILE "TPCPULSERda.conf"
36#define AliDebugLevel() -1
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>
49#include "TROOT.h"
50#include "TPluginManager.h"
51#include "TString.h"
52#include "TObjString.h"
53#include "TDatime.h"
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 "AliMathBase.h"
65#include "TTreeStream.h"
66#include "AliLog.h"
67#include "TSystem.h"
68#include "AliTPCConfigDA.h"
69//
70//AMORE
71//
72#include <AmoreDA.h>
73//
74// TPC calibration algorithm includes
75//
76#include "AliTPCCalibPulser.h"
77
78/* Main routine
79 Arguments: list of DATE raw data files
80*/
81int main(int argc, char **argv) {
82 /* log start of process */
83 printf("TPC Pulser DA started - %s\n",__FILE__);
84
85 if (argc<2) {
86 printf("Wrong number of arguments\n");
87 return -1;
88 }
89 AliLog::SetClassDebugLevel("AliTPCRawStream",-5);
90 AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
91 AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
92 AliLog::SetModuleDebugLevel("RAW",-5);
93
94 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
95 "*",
96 "TStreamerInfo",
97 "RIO",
98 "TStreamerInfo()");
99
100
101 /* declare monitoring program */
102 int i,status;
103 status=monitorDeclareMp( __FILE__ );
104 if (status!=0) {
105 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
106 return -1;
107 }
108
109 // variables
110 AliTPCmapper *mapping = 0; // The TPC mapping
111 char localfile[255];
112 unsigned long32 runNb=0; //run number
113 // configuration options
114 Bool_t fastDecoding = kFALSE;
115 // if test setup get parameters from $DAQDA_TEST_DIR
116
117 if (!mapping){
118 /* copy locally the mapping file from daq detector config db */
119 sprintf(localfile,"./%s",MAPPING_FILE);
120 status = daqDA_DB_getFile(MAPPING_FILE,localfile);
121 if (status) {
122 printf("Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
123 return -1;
124 }
125
126 /* open the mapping file and retrieve mapping object */
127 TFile *fileMapping = new TFile(MAPPING_FILE, "read");
128 mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
129 delete fileMapping;
130 }
131
132 if (mapping == 0) {
133 printf("Failed to get mapping object from %s. ...\n", MAPPING_FILE);
134 return -1;
135 } else {
136 printf("Got mapping object from %s\n", MAPPING_FILE);
137 }
138
139 //
140 // DA configuration from configuration file
141 //
142 //retrieve configuration file
143 sprintf(localfile,"./%s",CONFIG_FILE);
144 status = daqDA_DB_getFile(CONFIG_FILE,localfile);
145 if (status) {
146 printf("Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status);
147 return -1;
148 }
149 AliTPCConfigDA config(CONFIG_FILE);
150 // check configuration options
151 if ( (Int_t)config.GetValue("UseFastDecoder") == 1 ) {
152 printf("Info: The fast decoder will be used for the processing.\n");
153 fastDecoding=kTRUE;
154 }
155
156 // create calibration object
157 AliTPCCalibPulser calibPulser(config.GetConfigurationMap()); // pulser calibration algorithm
158 calibPulser.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
159
160 //===========================//
161 // loop over RAW data files //
162 //==========================//
163 int nevents=0;
164 for(i=1;i<argc;i++) {
165
166 /* define data source : this is argument i */
167 printf("Processing file %s\n", argv[i]);
168 status=monitorSetDataSource( argv[i] );
169 if (status!=0) {
170 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
171 return -1;
172 }
173
174 /* read until EOF */
175 while (true) {
176 struct eventHeaderStruct *event;
177
178 /* check shutdown condition */
179 if (daqDA_checkShutdown()) {break;}
180
181 /* get next event (blocking call until timeout) */
182 status=monitorGetEventDynamic((void **)&event);
183 if (status==MON_ERR_EOF) {
184 printf ("End of File %d detected\n",i);
185 break; /* end of monitoring file has been reached */
186 }
187
188 if (status!=0) {
189 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
190 break;
191 }
192
193 /* retry if got no event */
194 if (event==NULL) {
195 continue;
196 }
197 nevents++;
198 // get the run number
199 runNb = event->eventRunNb;
200 // Pulser calibration
201 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
202 if ( fastDecoding ) calibPulser.ProcessEventFast(rawReader);
203 else calibPulser.ProcessEvent(rawReader);
204 delete rawReader;
205
206 /* free resources */
207 free(event);
208 }
209 }
210
211 //
212 // Analyse pulser data and write them to rootfile
213 //
214 calibPulser.Analyse();
215 printf ("%d events processed\n",nevents);
216
217 TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
218 calibPulser.Write("tpcCalibPulser");
219 delete fileTPC;
220 printf("Wrote %s\n",RESULT_FILE);
221
222 /* store the result file on FES */
223
224 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
225 if (status) {
226 status = -2;
227 }
228 //
229 //Send objects to the AMORE DB
230 //
231 printf ("AMORE part\n");
232 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
233 //cheet a little -- temporary solution (hopefully)
234 //
235 //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
236 //table in which the calib objects are stored. This table is dropped each time AmoreDA
237 //is initialised. This of course makes a problem if we would like to store different
238 //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
239 //the AMORE_DA_NAME env variable is overwritten.
240 const char *role=gSystem->Getenv("DATE_ROLE_NAME");
241 gSystem->Setenv("AMORE_DA_NAME",Form("%s-%s",role,FILE_ID));
242 //
243 // end cheet
244 if ( role ){
245 TDatime time;
246 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsString()));
247
248 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
249 Int_t status=0;
250 status+=amoreDA.Send("PulserT0",calibPulser.GetCalPadT0());
251 status+=amoreDA.Send("PulserQ",calibPulser.GetCalPadQ());
252 status+=amoreDA.Send("PulserRMS",calibPulser.GetCalPadRMS());
253 status+=amoreDA.Send("arrayTmean",calibPulser.GetMeanTimeSectorArray());
254 status+=amoreDA.Send("Info",&info);
255 if ( status!=0 )
256 printf("Waring: Failed to write one of the calib objects to the AMORE database\n");
257 // reset env var
258 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);
259 } else {
260 printf ("Warning: environment variable 'AMORE_DA_NAME' not set. Cannot write to the AMORE database\n");
261 }
262
263 return status;
264}