]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/TPCPULSERda.cxx
Forgotten commit
[u/mrichter/AliRoot.git] / TPC / TPCPULSERda.cxx
CommitLineData
9c754ce7 1/*
2TPC DA for online calibration
3
4Contact: Haavard.Helstrup@cern.ch
5Link:
c23b10ec 6Run Type: CALIBRATION_PULSER
9c754ce7 7DA Type: LDC
8Number of events needed: 100
9Input Files:
10Output Files: tpcPulser.root, to be exported to the DAQ FXS
bd955ed2 11fileId: pulser
9c754ce7 12Trigger types used: CALIBRATION_EVENT
13
14*/
15
ec2624ea 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
ac940b58 2219/09/2008 J.Wiechula@gsi.de: Added export of the calibration data to the AMORE data base.
23 Added support for configuration files.
ec2624ea 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"
bd955ed2 33#define FILE_ID "pulser"
04049c81 34#define MAPPING_FILE "tpcMapping.root"
ac940b58 35#define CONFIG_FILE "TPCPULSERda.conf"
b401648b 36#define AliDebugLevel() -1
ec2624ea 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"
ac940b58 51#include "TString.h"
52#include "TObjString.h"
53#include "TDatime.h"
ec2624ea 54//
55//AliRoot includes
56//
57#include "AliRawReader.h"
58#include "AliRawReaderDate.h"
97b609ee 59#include "AliTPCmapper.h"
ec2624ea 60#include "AliTPCRawStream.h"
61#include "AliTPCROC.h"
62#include "AliTPCCalROC.h"
63#include "AliTPCCalPad.h"
64#include "AliMathBase.h"
65#include "TTreeStream.h"
b401648b 66#include "AliLog.h"
67#include "TSystem.h"
ac940b58 68#include "AliTPCConfigDA.h"
69//
70//AMORE
71//
72#include <AmoreDA.h>
ec2624ea 73//
74// TPC calibration algorithm includes
75//
76#include "AliTPCCalibPulser.h"
77
ec2624ea 78/* Main routine
79 Arguments: list of DATE raw data files
80*/
81int main(int argc, char **argv) {
ac940b58 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 }
bd955ed2 89 AliLog::SetClassDebugLevel("AliTPCRawStream",-5);
90 AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
91 AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
92 AliLog::SetModuleDebugLevel("RAW",-5);
ec2624ea 93
ac940b58 94 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
95 "*",
96 "TStreamerInfo",
97 "RIO",
98 "TStreamerInfo()");
ec2624ea 99
100
ac940b58 101 /* declare monitoring program */
ec2624ea 102 int i,status;
ac940b58 103 status=monitorDeclareMp( __FILE__ );
104 if (status!=0) {
105 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
106 return -1;
107 }
108
109 // variables
b401648b 110 AliTPCmapper *mapping = 0; // The TPC mapping
ac940b58 111 char localfile[255];
112 unsigned long32 runNb=0; //run number
113 // configuration options
114 Bool_t fastDecoding = kFALSE;
b401648b 115 // if test setup get parameters from $DAQDA_TEST_DIR
5d694e7e 116
b401648b 117 if (!mapping){
118 /* copy locally the mapping file from daq detector config db */
ac940b58 119 sprintf(localfile,"./%s",MAPPING_FILE);
120 status = daqDA_DB_getFile(MAPPING_FILE,localfile);
b401648b 121 if (status) {
122 printf("Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
ac940b58 123 return -1;
b401648b 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;
04049c81 130 }
131
04049c81 132 if (mapping == 0) {
b401648b 133 printf("Failed to get mapping object from %s. ...\n", MAPPING_FILE);
ac940b58 134 return -1;
04049c81 135 } else {
136 printf("Got mapping object from %s\n", MAPPING_FILE);
137 }
138
ac940b58 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);
ec2624ea 147 return -1;
148 }
ac940b58 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;
ec2624ea 154 }
155
ac940b58 156 // create calibration object
157 AliTPCCalibPulser calibPulser(config.GetConfigurationMap()); // pulser calibration algorithm
158 calibPulser.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
ec2624ea 159
ac940b58 160 //===========================//
161 // loop over RAW data files //
162 //==========================//
ec2624ea 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++;
ac940b58 198 // get the run number
199 runNb = event->eventRunNb;
ec2624ea 200 // Pulser calibration
5312f439 201 calibPulser.ProcessEvent(event);
ec2624ea 202
203 /* free resources */
204 free(event);
205 }
206 }
207
ac940b58 208 //
209 // Analyse pulser data and write them to rootfile
210 //
211 calibPulser.Analyse();
ec2624ea 212 printf ("%d events processed\n",nevents);
213
214 TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
e73181c9 215 calibPulser.Write("tpcCalibPulser");
ec2624ea 216 delete fileTPC;
217 printf("Wrote %s\n",RESULT_FILE);
218
f2c72763 219 /* store the result file on FES */
220
bd955ed2 221 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
f2c72763 222 if (status) {
223 status = -2;
224 }
ac940b58 225 //
226 //Send objects to the AMORE DB
227 //
228 printf ("AMORE part\n");
229 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
230 //cheet a little -- temporary solution (hopefully)
231 //
232 //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
233 //table in which the calib objects are stored. This table is dropped each time AmoreDA
234 //is initialised. This of course makes a problem if we would like to store different
235 //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
236 //the AMORE_DA_NAME env variable is overwritten.
6a02fd57 237
238 //find processed sector
239 Char_t sideName='A';
ffcfd6fa 240 Int_t sector = -1;
6a02fd57 241 for ( Int_t roc = 0; roc < 72; roc++ ) {
242 if ( !calibPulser.GetCalRocT0(roc) ) continue;
243 if (mapping->GetSideFromRoc(roc)==1) sideName='C';
244 sector = mapping->GetSectorFromRoc(roc);
245 }
246 gSystem->Setenv("AMORE_DA_NAME",Form("TPC-%c%02d-%s",sideName,sector,FILE_ID));
ac940b58 247 //
248 // end cheet
ffcfd6fa 249 if (sector>-1){
250 TDatime time;
251 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString()));
ac940b58 252
ffcfd6fa 253 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
254 Int_t statusDA=0;
255 statusDA+=amoreDA.Send("PulserT0",calibPulser.GetCalPadT0());
256 statusDA+=amoreDA.Send("PulserQ",calibPulser.GetCalPadQ());
257 statusDA+=amoreDA.Send("PulserRMS",calibPulser.GetCalPadRMS());
258 statusDA+=amoreDA.Send("arrayTmean",calibPulser.GetMeanTimeSectorArray());
259 statusDA+=amoreDA.Send("Info",&info);
260 if ( statusDA!=0 )
261 printf("Waring: Failed to write one of the calib objects to the AMORE database\n");
262 } else {
263 printf("Waring: No data found!\n");
264 }
265 // reset env var
6a02fd57 266 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);
f2c72763 267
ec2624ea 268 return status;
269}