]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/TPCCEda.cxx
Fixes for cmake
[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
5312f439 209 calibCE.ProcessEvent(event);
5312f439 210
5a3a40fa 211 /* free resources */
212 free(event);
213 }
214 }
215
ac940b58 216 //
217 // Analyse CE data and write them to rootfile
218 //
219 calibCE.Analyse();
5a3a40fa 220 printf ("%d events processed\n",nevents);
221
222 TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
e73181c9 223 calibCE.Write("tpcCalibCE");
5a3a40fa 224 delete fileTPC;
225 printf("Wrote %s\n",RESULT_FILE);
226
f2c72763 227 /* store the result file on FES */
228
bd955ed2 229 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
f2c72763 230 if (status) {
231 status = -2;
232 }
233
ac940b58 234 //
235 //Send objects to the AMORE DB
236 //
237 printf ("AMORE part\n");
238 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
239 //cheet a little -- temporary solution (hopefully)
240 //
241 //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
242 //table in which the calib objects are stored. This table is dropped each time AmoreDA
243 //is initialised. This of course makes a problem if we would like to store different
244 //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
245 //the AMORE_DA_NAME env variable is overwritten.
6a02fd57 246 gSystem->Setenv("AMORE_DA_NAME",Form("TPC-%s",FILE_ID));
ac940b58 247 //
248 // end cheet
6a02fd57 249 TDatime time;
250 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsString()));
251 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
252 Int_t statusDA=0;
253 statusDA+=amoreDA.Send("CET0",calibCE.GetCalPadT0());
254 statusDA+=amoreDA.Send("CEQ",calibCE.GetCalPadQ());
255 statusDA+=amoreDA.Send("CERMS",calibCE.GetCalPadRMS());
256 statusDA+=amoreDA.Send("Info",&info);
257 if ( statusDA!=0 )
258 printf("Waring: Failed to write one of the calib objects to the AMORE database\n");
259 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);
ac940b58 260
5a3a40fa 261 return status;
262}