]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/TPCPULSERda.cxx
adding usage of vtx axis as a parameter in the addtask macro
[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
12f70d37 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.
12f70d37 2423/04/2011 Christian.Lippmann@cern.ch : Added output of acsii files for online
25
26 contact: marian.ivanov@cern.ch
ec2624ea 27
28
29This process reads RAW data from the files provided as command line arguments
30and save results in a file (named from RESULT_FILE define - see below).
31
32*/
33
34#define RESULT_FILE "tpcPulser.root"
bd955ed2 35#define FILE_ID "pulser"
04049c81 36#define MAPPING_FILE "tpcMapping.root"
ac940b58 37#define CONFIG_FILE "TPCPULSERda.conf"
12f70d37 38#define Q_FILE "tpcPulserQ.data"
39#define DEAD_FILE "tpcDeadChannelsPulser.data"
b401648b 40#define AliDebugLevel() -1
ec2624ea 41
42
43#include <daqDA.h>
44#include "event.h"
45#include "monitor.h"
46#include <stdio.h>
47#include <stdlib.h>
12f70d37 48#include <fstream>
ec2624ea 49
50//
51//Root includes
52//
53#include <TFile.h>
54#include "TROOT.h"
55#include "TPluginManager.h"
ac940b58 56#include "TString.h"
57#include "TObjString.h"
58#include "TDatime.h"
ec2624ea 59//
60//AliRoot includes
61//
62#include "AliRawReader.h"
63#include "AliRawReaderDate.h"
97b609ee 64#include "AliTPCmapper.h"
ec2624ea 65#include "AliTPCRawStream.h"
66#include "AliTPCROC.h"
67#include "AliTPCCalROC.h"
68#include "AliTPCCalPad.h"
69#include "AliMathBase.h"
70#include "TTreeStream.h"
b401648b 71#include "AliLog.h"
72#include "TSystem.h"
ac940b58 73#include "AliTPCConfigDA.h"
74//
75//AMORE
76//
77#include <AmoreDA.h>
ec2624ea 78//
79// TPC calibration algorithm includes
80//
81#include "AliTPCCalibPulser.h"
82
ec2624ea 83/* Main routine
84 Arguments: list of DATE raw data files
85*/
86int main(int argc, char **argv) {
ac940b58 87 /* log start of process */
88 printf("TPC Pulser DA started - %s\n",__FILE__);
89
90 if (argc<2) {
91 printf("Wrong number of arguments\n");
92 return -1;
93 }
bd955ed2 94 AliLog::SetClassDebugLevel("AliTPCRawStream",-5);
95 AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
96 AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
97 AliLog::SetModuleDebugLevel("RAW",-5);
ec2624ea 98
ac940b58 99 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
100 "*",
101 "TStreamerInfo",
102 "RIO",
103 "TStreamerInfo()");
ec2624ea 104
105
12f70d37 106 TString daterolename(gSystem->Getenv("DATE_ROLE_NAME"));
107 if ( daterolename == "" ) {
108 printf("Error: Variable DATE_ROLE_NAME not defined! Exiting ...\n");
109 return -1;
110 }
111 bool inner;
112 if ( daterolename.EndsWith("-0") ) inner = true;
113 else if ( daterolename.EndsWith("-1") ) inner = false;
114 else {
115 printf("Error: Variable DATE_ROLE_NAME neither ends with -0 nor -1 (E.g. ldc-TPC-C12-1)! Exiting ...\n");
116 return -1;
117 }
118
ac940b58 119 /* declare monitoring program */
ec2624ea 120 int i,status;
ac940b58 121 status=monitorDeclareMp( __FILE__ );
122 if (status!=0) {
123 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
124 return -1;
125 }
126
127 // variables
b401648b 128 AliTPCmapper *mapping = 0; // The TPC mapping
ac940b58 129 char localfile[255];
130 unsigned long32 runNb=0; //run number
131 // configuration options
132 Bool_t fastDecoding = kFALSE;
b401648b 133 // if test setup get parameters from $DAQDA_TEST_DIR
5d694e7e 134
b401648b 135 if (!mapping){
136 /* copy locally the mapping file from daq detector config db */
ac940b58 137 sprintf(localfile,"./%s",MAPPING_FILE);
138 status = daqDA_DB_getFile(MAPPING_FILE,localfile);
b401648b 139 if (status) {
140 printf("Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
ac940b58 141 return -1;
b401648b 142 }
143
144 /* open the mapping file and retrieve mapping object */
145 TFile *fileMapping = new TFile(MAPPING_FILE, "read");
146 mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
147 delete fileMapping;
04049c81 148 }
149
04049c81 150 if (mapping == 0) {
b401648b 151 printf("Failed to get mapping object from %s. ...\n", MAPPING_FILE);
ac940b58 152 return -1;
04049c81 153 } else {
154 printf("Got mapping object from %s\n", MAPPING_FILE);
155 }
156
ac940b58 157 //
158 // DA configuration from configuration file
159 //
160 //retrieve configuration file
161 sprintf(localfile,"./%s",CONFIG_FILE);
162 status = daqDA_DB_getFile(CONFIG_FILE,localfile);
163 if (status) {
164 printf("Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status);
ec2624ea 165 return -1;
166 }
ac940b58 167 AliTPCConfigDA config(CONFIG_FILE);
168 // check configuration options
169 if ( (Int_t)config.GetValue("UseFastDecoder") == 1 ) {
170 printf("Info: The fast decoder will be used for the processing.\n");
171 fastDecoding=kTRUE;
ec2624ea 172 }
173
ac940b58 174 // create calibration object
175 AliTPCCalibPulser calibPulser(config.GetConfigurationMap()); // pulser calibration algorithm
176 calibPulser.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
ec2624ea 177
ac940b58 178 //===========================//
179 // loop over RAW data files //
180 //==========================//
ec2624ea 181 int nevents=0;
182 for(i=1;i<argc;i++) {
183
184 /* define data source : this is argument i */
185 printf("Processing file %s\n", argv[i]);
186 status=monitorSetDataSource( argv[i] );
187 if (status!=0) {
188 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
189 return -1;
190 }
191
192 /* read until EOF */
193 while (true) {
194 struct eventHeaderStruct *event;
195
196 /* check shutdown condition */
197 if (daqDA_checkShutdown()) {break;}
198
199 /* get next event (blocking call until timeout) */
200 status=monitorGetEventDynamic((void **)&event);
201 if (status==MON_ERR_EOF) {
202 printf ("End of File %d detected\n",i);
203 break; /* end of monitoring file has been reached */
204 }
205
206 if (status!=0) {
207 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
208 break;
209 }
210
211 /* retry if got no event */
212 if (event==NULL) {
213 continue;
214 }
215 nevents++;
ac940b58 216 // get the run number
217 runNb = event->eventRunNb;
ec2624ea 218 // Pulser calibration
5312f439 219 calibPulser.ProcessEvent(event);
ec2624ea 220
221 /* free resources */
222 free(event);
223 }
224 }
225
ac940b58 226 //
227 // Analyse pulser data and write them to rootfile
228 //
229 calibPulser.Analyse();
ec2624ea 230 printf ("%d events processed\n",nevents);
231
232 TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
e73181c9 233 calibPulser.Write("tpcCalibPulser");
ec2624ea 234 delete fileTPC;
235 printf("Wrote %s\n",RESULT_FILE);
236
f2c72763 237 /* store the result file on FES */
238
bd955ed2 239 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
f2c72763 240 if (status) {
241 status = -2;
242 }
ac940b58 243 //
244 //Send objects to the AMORE DB
245 //
246 printf ("AMORE part\n");
247 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
248 //cheet a little -- temporary solution (hopefully)
249 //
250 //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
251 //table in which the calib objects are stored. This table is dropped each time AmoreDA
252 //is initialised. This of course makes a problem if we would like to store different
253 //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
254 //the AMORE_DA_NAME env variable is overwritten.
6a02fd57 255
256 //find processed sector
257 Char_t sideName='A';
ffcfd6fa 258 Int_t sector = -1;
6a02fd57 259 for ( Int_t roc = 0; roc < 72; roc++ ) {
260 if ( !calibPulser.GetCalRocT0(roc) ) continue;
261 if (mapping->GetSideFromRoc(roc)==1) sideName='C';
262 sector = mapping->GetSectorFromRoc(roc);
263 }
12f70d37 264 //gSystem->Setenv("AMORE_DA_NAME",Form("TPC-%c%02d-%s",sideName,sector,FILE_ID));
265 gSystem->Setenv("AMORE_DA_NAME",Form("%s-%s", gSystem->Getenv("DATE_ROLE_NAME"), FILE_ID));
e9d80afd 266
ac940b58 267 //
268 // end cheet
ffcfd6fa 269 if (sector>-1){
270 TDatime time;
271 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString()));
ac940b58 272
ffcfd6fa 273 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
274 Int_t statusDA=0;
275 statusDA+=amoreDA.Send("PulserT0",calibPulser.GetCalPadT0());
276 statusDA+=amoreDA.Send("PulserQ",calibPulser.GetCalPadQ());
277 statusDA+=amoreDA.Send("PulserRMS",calibPulser.GetCalPadRMS());
278 statusDA+=amoreDA.Send("arrayTmean",calibPulser.GetMeanTimeSectorArray());
279 statusDA+=amoreDA.Send("Info",&info);
280 if ( statusDA!=0 )
281 printf("Waring: Failed to write one of the calib objects to the AMORE database\n");
282 } else {
283 printf("Waring: No data found!\n");
284 }
285 // reset env var
6a02fd57 286 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);
f2c72763 287
12f70d37 288 //
289 // Now prepare ASCII files for local ALTRO configuration through DDL.
290 //
291 ofstream deadchannelfile;
292 ofstream qfile;
293
294 qfile.open(Q_FILE);
295 deadchannelfile.open(DEAD_FILE);
296
297 qfile << 19 << std::endl; // Pulser Q
298 deadchannelfile << 14 << std::endl; // Mark file to contain NOISY or DEAD CHANNELS
299
300 Int_t ctr_channel = 0;
301 Int_t ctr_dead= 0;
302
303 // inner==true : calROC from ldc-0 contains: rcus 0,1 for IROC and rcu 2 for OROC
304 // inner==false: calROC from ldc-1 contains: nothingfor IROC and rcus 3,4,5 for OROC
305 for ( Int_t roc = 0; roc < 72; roc++ ) {
306 if ( !calibPulser.GetCalRocQ(roc) ) continue;
307 bool isIROC= mapping->IsIROC(roc);
308 Int_t side = mapping->GetSideFromRoc(roc);
309 Int_t sec= mapping->GetSectorFromRoc(roc);
310 Int_t minrcu, maxrcu;
311 if( isIROC ) { minrcu=0; maxrcu=1; }
312 else if ( inner) { minrcu=2; maxrcu=2; }
313 else { minrcu=3; maxrcu=5; }
314 for ( int rcu = minrcu; rcu <= maxrcu; rcu++ ) {
315 //Int_t patch = mapping->IsIROC(roc) ? rcu : rcu+2;
316 for ( int branch = 0; branch < 2; branch++ ) {
317 for ( int fec = 0; fec < mapping->GetNfec(rcu, branch); fec++ ) {
318 for ( int altro = 0; altro < 8; altro++ ) {
319 for ( int channel = 0; channel < 16; channel++ ) {
320 Int_t hwadd = mapping->CodeHWAddress(branch, fec, altro, channel);
321 Int_t row = mapping->GetPadRow(rcu, hwadd); // row in a ROC
322 Int_t globalrow = mapping->GetGlobalPadRow(rcu, hwadd); // row in full sector
323 Int_t pad = mapping->GetPad(rcu, hwadd);
324 // skip edge pads
325 if ( (pad<1) || (pad>mapping->GetNpads(globalrow)-2) ) continue;
326 Float_t Q = calibPulser.GetCalRocQ(roc)->GetValue(row,pad);
327 qfile << ctr_channel++ << "\t" << side << "\t" << sec << "\t" << rcu << "\t" << hwadd << "\t" << Q << std::endl;
328 if ( fabs(Q) < 2) { // dead channel
329 deadchannelfile << ctr_dead++ << "\t" << side << "\t" << sec << "\t"
330 << rcu << "\t" << hwadd << "\t" << Q << std::endl;
331 }
332 } // end channel for loop
333 } // end altro for loop
334 } // end fec for loop
335 } // end branch for loop
336 } // end rcu for loop
337 } // end roc loop
338
339 qfile.close();
340 deadchannelfile.close();
341
342 printf("Wrote ASCII file. Found %d dead channels.\n", ctr_dead);
343
344return status;
ec2624ea 345}