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