1 /// \file TPCPULSERda.cxx
2 /// \brief TPC DA for online calibration
4 /// Contact: Haavard.Helstrup@cern.ch
6 /// Run Type: CALIBRATION_PULSER
8 /// Number of events needed: 100
10 /// Output Files: tpcPulser.root, to be exported to the DAQ FXS
12 /// Trigger types used: CALIBRATION_EVENT
14 /// TPCda_pulser.cxx - calibration algorithm for TPC pulser events
16 /// 10/06/2007 sylvain.chapeland@cern.ch : first version - clean skeleton based on DAQ DA case1
17 /// 30/09/2007 haavard.helstrup@cern.ch : created pulser DA based on pedestal code
18 /// 19/09/2008 J.Wiechula@gsi.de: Added export of the calibration data to the AMORE data base.
19 /// Added support for configuration files.
20 /// 23/04/2011 Christian.Lippmann@cern.ch : Added output of acsii files for online
21 /// 26/09/2014 Christian.Lippmann@cern.ch : CHange for new DAQ setup with one CRORC per LDC
22 /// 26/09/2014 Jens.Wiechula@cern.ch : comment out obsolete AliTPCRawStream
24 /// \author marian.ivanov@cern.ch
26 /// This process reads RAW data from the files provided as command line arguments
27 /// and save results in a file (named from RESULT_FILE define - see below).
29 #define RESULT_FILE "tpcPulser.root"
30 #define FILE_ID "pulser"
31 #define MAPPING_FILE "tpcMapping.root"
32 #define CONFIG_FILE "TPCPULSERda.conf"
33 #define Q_FILE "tpcPulserQ.data"
34 #define DEAD_FILE "tpcDeadChannelsPulser.data"
35 #define AliDebugLevel() -1
49 #include "TPluginManager.h"
51 #include "TObjString.h"
56 #include "AliRawReader.h"
57 #include "AliRawReaderDate.h"
58 #include "AliTPCmapper.h"
59 //#include "AliTPCRawStreamV3.h"
60 #include "AliTPCROC.h"
61 #include "AliTPCCalROC.h"
62 #include "AliTPCCalPad.h"
63 #include "AliMathBase.h"
64 #include "TTreeStream.h"
67 #include "AliTPCConfigDA.h"
73 // TPC calibration algorithm includes
75 #include "AliTPCCalibPulser.h"
77 int main(int argc, char **argv) {
79 /// Arguments: list of DATE raw data files
81 // log start of process
82 printf("TPC Pulser DA started - %s\n",__FILE__);
85 printf("Wrong number of arguments\n");
88 //AliLog::SetClassDebugLevel("AliTPCRawStreamV3",-5);
89 AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
90 AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
91 AliLog::SetModuleDebugLevel("RAW",-5);
93 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
100 TString daterolename(gSystem->Getenv("DATE_ROLE_NAME"));
101 if ( daterolename == "" ) {
102 printf("Error: Variable DATE_ROLE_NAME not defined! Exiting ...\n");
106 if ( daterolename.EndsWith("-0") ) inner = true;
107 else if ( daterolename.EndsWith("-1") ) inner = false;
109 printf("Error: Variable DATE_ROLE_NAME neither ends with -0 nor -1 (E.g. ldc-TPC-C12-1)! Exiting ...\n");
114 /* declare monitoring program */
116 status=monitorDeclareMp( __FILE__ );
118 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
123 AliTPCmapper *mapping = 0; // The TPC mapping
125 unsigned long32 runNb=0; //run number
126 // configuration options
127 // if test setup get parameters from $DAQDA_TEST_DIR
130 /* copy locally the mapping file from daq detector config db */
131 sprintf(localfile,"./%s",MAPPING_FILE);
132 status = daqDA_DB_getFile(MAPPING_FILE,localfile);
134 printf("Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
138 /* open the mapping file and retrieve mapping object */
139 TFile *fileMapping = new TFile(MAPPING_FILE, "read");
140 mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
145 printf("Failed to get mapping object from %s. ...\n", MAPPING_FILE);
148 printf("Got mapping object from %s\n", MAPPING_FILE);
152 // DA configuration from configuration file
154 //retrieve configuration file
155 sprintf(localfile,"./%s",CONFIG_FILE);
156 status = daqDA_DB_getFile(CONFIG_FILE,localfile);
158 printf("Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status);
161 AliTPCConfigDA config(CONFIG_FILE);
162 // check configuration options
163 Bool_t skipAmore=kFALSE;
165 //skip the amore part
166 if ( config.GetConfigurationMap()->GetValue("SkipAmore") ) {
167 skipAmore=((TObjString*)config.GetConfigurationMap()->GetValue("SkipAmore"))->GetString().Atoi();
168 printf("TPCPULSERda: Skip Amore set in config\n");
171 // create calibration object
172 AliTPCCalibPulser calibPulser(config.GetConfigurationMap()); // pulser calibration algorithm
173 calibPulser.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
175 //===========================//
176 // loop over RAW data files //
177 //==========================//
179 for(i=1;i<argc;i++) {
181 /* define data source : this is argument i */
182 printf("Processing file %s\n", argv[i]);
183 status=monitorSetDataSource( argv[i] );
185 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
191 struct eventHeaderStruct *event;
193 /* check shutdown condition */
194 if (daqDA_checkShutdown()) {break;}
196 /* get next event (blocking call until timeout) */
197 status=monitorGetEventDynamic((void **)&event);
198 if (status==MON_ERR_EOF) {
199 printf ("End of File %d detected\n",i);
200 break; /* end of monitoring file has been reached */
204 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
208 /* retry if got no event */
213 // get the run number
214 runNb = event->eventRunNb;
215 // Pulser calibration
216 calibPulser.ProcessEvent(event);
224 // Analyse pulser data and write them to rootfile
226 calibPulser.Analyse();
227 printf ("%d events processed\n",nevents);
229 TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
230 calibPulser.Write("tpcCalibPulser");
232 printf("Wrote %s\n",RESULT_FILE);
234 /* store the result file on FES */
236 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
241 //Send objects to the AMORE DB
244 printf ("AMORE part\n");
245 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
246 //cheet a little -- temporary solution (hopefully)
248 //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
249 //table in which the calib objects are stored. This table is dropped each time AmoreDA
250 //is initialised. This of course makes a problem if we would like to store different
251 //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
252 //the AMORE_DA_NAME env variable is overwritten.
254 //find processed sector
257 for ( Int_t roc = 0; roc < 72; roc++ ) {
258 if ( !calibPulser.GetCalRocT0(roc) ) continue;
259 if (mapping->GetSideFromRoc(roc)==1) sideName='C';
260 sector = mapping->GetSectorFromRoc(roc);
262 //gSystem->Setenv("AMORE_DA_NAME",Form("TPC-%c%02d-%s",sideName,sector,FILE_ID));
263 gSystem->Setenv("AMORE_DA_NAME",Form("%s-%s", gSystem->Getenv("DATE_ROLE_NAME"), FILE_ID));
268 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString()));
270 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
272 statusDA+=amoreDA.Send("PulserT0",calibPulser.GetCalPadT0());
273 statusDA+=amoreDA.Send("PulserQ",calibPulser.GetCalPadQ());
274 statusDA+=amoreDA.Send("PulserRMS",calibPulser.GetCalPadRMS());
275 statusDA+=amoreDA.Send("arrayTmean",calibPulser.GetMeanTimeSectorArray());
276 statusDA+=amoreDA.Send("Info",&info);
278 printf("Waring: Failed to write one of the calib objects to the AMORE database\n");
280 printf("Waring: No data found!\n");
283 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);
287 // Now prepare ASCII files for local ALTRO configuration through DDL.
289 ofstream deadchannelfile;
293 deadchannelfile.open(DEAD_FILE);
295 qfile << 19 << std::endl; // Pulser Q
296 deadchannelfile << 14 << std::endl; // Mark file to contain NOISY or DEAD CHANNELS
298 Int_t ctr_channel = 0;
301 // inner==true : calROC from ldc-0 contains: rcus 0,1 for IROC and rcu 2 for OROC
302 // inner==false: calROC from ldc-1 contains: nothingfor IROC and rcus 3,4,5 for OROC
303 for ( Int_t roc = 0; roc < 72; roc++ ) {
304 if ( !calibPulser.GetCalRocQ(roc) ) continue;
305 bool isIROC= mapping->IsIROC(roc);
306 Int_t side = mapping->GetSideFromRoc(roc);
307 Int_t sec= mapping->GetSectorFromRoc(roc);
308 Int_t minrcu, maxrcu;
309 if( isIROC ) { minrcu=0; maxrcu=1; }
310 //else if ( inner) { minrcu=2; maxrcu=2; }
311 //else { minrcu=3; maxrcu=5; }
312 else { minrcu=2; maxrcu=5; }
313 for ( int rcu = minrcu; rcu <= maxrcu; rcu++ ) {
314 //Int_t patch = mapping->IsIROC(roc) ? rcu : rcu+2;
315 for ( int branch = 0; branch < 2; branch++ ) {
316 for ( int fec = 0; fec < mapping->GetNfec(rcu, branch); fec++ ) {
317 for ( int altro = 0; altro < 8; altro++ ) {
318 for ( int channel = 0; channel < 16; channel++ ) {
319 Int_t hwadd = mapping->CodeHWAddress(branch, fec, altro, channel);
320 Int_t row = mapping->GetPadRow(rcu, hwadd); // row in a ROC
321 Int_t globalrow = mapping->GetGlobalPadRow(rcu, hwadd); // row in full sector
322 Int_t pad = mapping->GetPad(rcu, hwadd);
324 if ( (pad<1) || (pad>mapping->GetNpads(globalrow)-2) ) continue;
325 Float_t Q = calibPulser.GetCalRocQ(roc)->GetValue(row,pad);
326 qfile << ctr_channel++ << "\t" << side << "\t" << sec << "\t" << rcu << "\t" << hwadd << "\t" << Q << std::endl;
327 if ( fabs(Q) < 2) { // dead channel
328 deadchannelfile << ctr_dead++ << "\t" << side << "\t" << sec << "\t"
329 << rcu << "\t" << hwadd << "\t" << Q << std::endl;
331 } // end channel for loop
332 } // end altro for loop
333 } // end fec for loop
334 } // end branch for loop
335 } // end rcu for loop
339 deadchannelfile.close();
341 printf("Wrote ASCII file. Found %d dead channels.\n", ctr_dead);