]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/TPCCEda.cxx
Possibility to include ARVersion.h
[u/mrichter/AliRoot.git] / TPC / TPCCEda.cxx
CommitLineData
9c754ce7 1/*
2TPC DA for online calibration
3
4Contact: Haavard.Helstrup@cern.ch
5Link:
1b37fc95 6Run Type: PHYSICS STANDALONE DAQ
9c754ce7 7DA Type: MON
8Number of events needed: 500
9Input Files:
10Output Files: tpcCE.root, to be exported to the DAQ FXS
bd955ed2 11fileId: CE
9c754ce7 12Trigger types used: PHYSICS_EVENT
13
14*/
15
5a3a40fa 16/*
17
18TPCCEda.cxx - calibration algorithm for TPC Central Electrode events
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
ac940b58 2219/09/2008 J.Wiechula@gsi.de: Added support for configuration files.
5a3a40fa 23
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
9c754ce7 32#define RESULT_FILE "tpcCE.root"
bd955ed2 33#define FILE_ID "CE"
04049c81 34#define MAPPING_FILE "tpcMapping.root"
ac940b58 35#define CONFIG_FILE "TPCCEda.conf"
5a3a40fa 36
37
38#include <daqDA.h>
39#include "event.h"
40#include "monitor.h"
41#include <stdio.h>
42#include <stdlib.h>
43
44//
45//Root includes
46//
47#include <TFile.h>
48#include "TROOT.h"
49#include "TPluginManager.h"
ac940b58 50#include "TSystem.h"
51#include "TString.h"
52#include "TObjString.h"
53#include "TDatime.h"
5a3a40fa 54//
55//AliRoot includes
56//
57#include "AliRawReader.h"
58#include "AliRawReaderDate.h"
97b609ee 59#include "AliTPCmapper.h"
5a3a40fa 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"
ac940b58 67#include "AliTPCConfigDA.h"
68//
69//AMORE
70//
71#include <AmoreDA.h>
5a3a40fa 72//
73// TPC calibration algorithm includes
74//
75#include "AliTPCCalibCE.h"
76
77
78
79
80/* Main routine
81 Arguments: list of DATE raw data files
82*/
83int main(int argc, char **argv) {
ac940b58 84 /* log start of process */
85 printf("TPC CE DA started - %s\n",__FILE__);
86
87 if (argc<2) {
88 printf("Wrong number of arguments\n");
89 return -1;
90 }
91
92 AliLog::SetClassDebugLevel("AliTPCRawStream",-5);
93 AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
94 AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
95 AliLog::SetModuleDebugLevel("RAW",-5);
5a3a40fa 96
97 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
98 "*",
99 "TStreamerInfo",
100 "RIO",
101 "TStreamerInfo()");
102
ac940b58 103 /* declare monitoring program */
104 int i,status;
105 status=monitorDeclareMp( __FILE__ );
106 if (status!=0) {
107 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
108 return -1;
109 }
110 monitorSetNowait();
111 monitorSetNoWaitNetworkTimeout(1000);
112
113 //variables
b401648b 114 AliTPCmapper *mapping = 0; // The TPC mapping
ac940b58 115 char localfile[255];
116 unsigned long32 runNb=0; //run number
117 // configuration options
118 Bool_t fastDecoding = kFALSE;
119
b401648b 120 // if test setup get parameters from $DAQDA_TEST_DIR
b401648b 121 if (!mapping){
122 /* copy locally the mapping file from daq detector config db */
ac940b58 123 sprintf(localfile,"./%s",MAPPING_FILE);
124 status = daqDA_DB_getFile(MAPPING_FILE,localfile);
b401648b 125 if (status) {
126 printf("Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
ac940b58 127 return -1;
b401648b 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;
04049c81 134 }
135
04049c81 136 if (mapping == 0) {
b401648b 137 printf("Failed to get mapping object from %s. ...\n", MAPPING_FILE);
ac940b58 138 return -1;
04049c81 139 } else {
140 printf("Got mapping object from %s\n", MAPPING_FILE);
141 }
ac940b58 142
143 //
144 // DA configuration from configuration file
145 //
146 //retrieve configuration file
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);
5a3a40fa 151 return -1;
152 }
ac940b58 153 AliTPCConfigDA config(CONFIG_FILE);
154 // check configuration
155 if ( (Int_t)config.GetValue("UseFastDecoder") == 1 ){
156 printf("Info: The fast decoder will be used for the processing.\n");
157 fastDecoding=kTRUE;
5a3a40fa 158 }
159
ac940b58 160 //create calibration object
161 AliTPCCalibCE calibCE(config.GetConfigurationMap()); // central electrode calibration
162 calibCE.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
5a3a40fa 163
ac940b58 164 //===========================//
165 // loop over RAW data files //
166 //==========================//
5a3a40fa 167 int nevents=0;
ac940b58 168 for ( i=1; i<argc; i++) {
5a3a40fa 169
170 /* define data source : this is argument i */
171 printf("Processing file %s\n", argv[i]);
172 status=monitorSetDataSource( argv[i] );
173 if (status!=0) {
174 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
175 return -1;
176 }
177
178 /* read until EOF */
179 while (true) {
180 struct eventHeaderStruct *event;
181
182 /* check shutdown condition */
183 if (daqDA_checkShutdown()) {break;}
184
185 /* get next event (blocking call until timeout) */
186 status=monitorGetEventDynamic((void **)&event);
187 if (status==MON_ERR_EOF) {
188 printf ("End of File %d detected\n",i);
189 break; /* end of monitoring file has been reached */
190 }
191
192 if (status!=0) {
193 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
194 break;
195 }
ac940b58 196
197 /* skip start/end of run events */
198 if ( (event->eventType != physicsEvent) && (event->eventType != calibrationEvent) )
199 continue;
5a3a40fa 200
201 /* retry if got no event */
ac940b58 202 if (event==NULL)
5a3a40fa 203 continue;
ac940b58 204
5a3a40fa 205 nevents++;
ac940b58 206 // get the run number
207 runNb = event->eventRunNb;
208 // CE calibration
5a3a40fa 209 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
ac940b58 210 if ( fastDecoding ) calibCE.ProcessEventFast(rawReader);
211 else calibCE.ProcessEvent(rawReader);
5a3a40fa 212 delete rawReader;
213
214 /* free resources */
215 free(event);
216 }
217 }
218
ac940b58 219 //
220 // Analyse CE data and write them to rootfile
221 //
222 calibCE.Analyse();
5a3a40fa 223 printf ("%d events processed\n",nevents);
224
225 TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
e73181c9 226 calibCE.Write("tpcCalibCE");
5a3a40fa 227 delete fileTPC;
228 printf("Wrote %s\n",RESULT_FILE);
229
f2c72763 230 /* store the result file on FES */
231
bd955ed2 232 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
f2c72763 233 if (status) {
234 status = -2;
235 }
236
ac940b58 237 //
238 //Send objects to the AMORE DB
239 //
240 printf ("AMORE part\n");
241 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
242 //cheet a little -- temporary solution (hopefully)
243 //
244 //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
245 //table in which the calib objects are stored. This table is dropped each time AmoreDA
246 //is initialised. This of course makes a problem if we would like to store different
247 //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
248 //the AMORE_DA_NAME env variable is overwritten.
6a02fd57 249 gSystem->Setenv("AMORE_DA_NAME",Form("TPC-%s",FILE_ID));
ac940b58 250 //
251 // end cheet
6a02fd57 252 TDatime time;
253 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsString()));
254 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
255 Int_t statusDA=0;
256 statusDA+=amoreDA.Send("CET0",calibCE.GetCalPadT0());
257 statusDA+=amoreDA.Send("CEQ",calibCE.GetCalPadQ());
258 statusDA+=amoreDA.Send("CERMS",calibCE.GetCalPadRMS());
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 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);
ac940b58 263
5a3a40fa 264 return status;
265}