2 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 /// \file TPCPULSERda.cxx
15 /// \brief TPC DA for online calibration
17 /// Contact: Haavard.Helstrup@cern.ch
19 /// Run Type: CALIBRATION_PULSER
21 /// Number of events needed: 100
23 /// Output Files: tpcPulser.root, to be exported to the DAQ FXS
25 /// Trigger types used: CALIBRATION_EVENT
27 /// TPCda_pulser.cxx - calibration algorithm for TPC pulser events
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
37 /// \author marian.ivanov@cern.ch
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).
42 #define RESULT_FILE "tpcPulser.root"
43 #define FILE_ID "pulser"
44 #define MAPPING_FILE "tpcMapping.root"
45 #define CONFIG_FILE "TPCPULSERda.conf"
46 #define Q_FILE "tpcPulserQ.data"
47 #define DEAD_FILE "tpcDeadChannelsPulser.data"
48 #define AliDebugLevel() -1
62 #include "TPluginManager.h"
64 #include "TObjString.h"
69 #include "AliRawReader.h"
70 #include "AliRawReaderDate.h"
71 #include "AliTPCmapper.h"
72 //#include "AliTPCRawStreamV3.h"
73 #include "AliTPCROC.h"
74 #include "AliTPCCalROC.h"
75 #include "AliTPCCalPad.h"
76 #include "AliMathBase.h"
77 #include "TTreeStream.h"
80 #include "AliTPCConfigDA.h"
86 // TPC calibration algorithm includes
88 #include "AliTPCCalibPulser.h"
90 int main(int argc, char **argv) {
92 /// Arguments: list of DATE raw data files
94 // log start of process
95 printf("TPC Pulser DA started - %s\n",__FILE__);
98 printf("Wrong number of arguments\n");
101 //AliLog::SetClassDebugLevel("AliTPCRawStreamV3",-5);
102 AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
103 AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
104 AliLog::SetModuleDebugLevel("RAW",-5);
106 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
113 TString daterolename(gSystem->Getenv("DATE_ROLE_NAME"));
114 if ( daterolename == "" ) {
115 printf("Error: Variable DATE_ROLE_NAME not defined! Exiting ...\n");
119 if ( daterolename.EndsWith("-0") ) inner = true;
120 else if ( daterolename.EndsWith("-1") ) inner = false;
122 printf("Error: Variable DATE_ROLE_NAME neither ends with -0 nor -1 (E.g. ldc-TPC-C12-1)! Exiting ...\n");
127 /* declare monitoring program */
129 status=monitorDeclareMp( __FILE__ );
131 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
136 AliTPCmapper *mapping = 0; // The TPC mapping
138 unsigned long32 runNb=0; //run number
139 // configuration options
140 // if test setup get parameters from $DAQDA_TEST_DIR
143 /* copy locally the mapping file from daq detector config db */
144 sprintf(localfile,"./%s",MAPPING_FILE);
145 status = daqDA_DB_getFile(MAPPING_FILE,localfile);
147 printf("Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
151 /* open the mapping file and retrieve mapping object */
152 TFile *fileMapping = new TFile(MAPPING_FILE, "read");
153 mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
158 printf("Failed to get mapping object from %s. ...\n", MAPPING_FILE);
161 printf("Got mapping object from %s\n", MAPPING_FILE);
165 // DA configuration from configuration file
167 //retrieve configuration file
168 sprintf(localfile,"./%s",CONFIG_FILE);
169 status = daqDA_DB_getFile(CONFIG_FILE,localfile);
171 printf("Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status);
174 AliTPCConfigDA config(CONFIG_FILE);
175 // check configuration options
176 Bool_t skipAmore=kFALSE;
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");
184 // create calibration object
185 AliTPCCalibPulser calibPulser(config.GetConfigurationMap()); // pulser calibration algorithm
186 calibPulser.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
188 //===========================//
189 // loop over RAW data files //
190 //==========================//
192 for(i=1;i<argc;i++) {
194 /* define data source : this is argument i */
195 printf("Processing file %s\n", argv[i]);
196 status=monitorSetDataSource( argv[i] );
198 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
204 struct eventHeaderStruct *event;
206 /* check shutdown condition */
207 if (daqDA_checkShutdown()) {break;}
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 */
217 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
221 /* retry if got no event */
226 // get the run number
227 runNb = event->eventRunNb;
228 // Pulser calibration
229 calibPulser.ProcessEvent(event);
237 // Analyse pulser data and write them to rootfile
239 calibPulser.Analyse();
240 printf ("%d events processed\n",nevents);
242 TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
243 calibPulser.Write("tpcCalibPulser");
245 printf("Wrote %s\n",RESULT_FILE);
247 /* store the result file on FES */
249 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
254 //Send objects to the AMORE DB
257 printf ("AMORE part\n");
258 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
259 //cheet a little -- temporary solution (hopefully)
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.
267 //find processed sector
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);
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));
281 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString()));
283 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
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);
291 printf("Waring: Failed to write one of the calib objects to the AMORE database\n");
293 printf("Waring: No data found!\n");
296 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);
300 // Now prepare ASCII files for local ALTRO configuration through DDL.
302 ofstream deadchannelfile;
306 deadchannelfile.open(DEAD_FILE);
308 qfile << 19 << std::endl; // Pulser Q
309 deadchannelfile << 14 << std::endl; // Mark file to contain NOISY or DEAD CHANNELS
311 Int_t ctr_channel = 0;
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;
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; }
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);
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;
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
352 deadchannelfile.close();
354 printf("Wrote ASCII file. Found %d dead channels.\n", ctr_dead);