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