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
18 TPCda_pulser.cxx - calibration algorithm for TPC pulser events
20 10/06/2007 sylvain.chapeland@cern.ch : first version - clean skeleton based on DAQ DA case1
21 30/09/2007 haavard.helstrup@cern.ch : created pulser DA based on pedestal code
22 19/09/2008 J.Wiechula@gsi.de: Added export of the calibration data to the AMORE data base.
23 Added support for configuration files.
24 contact: marian.ivanov@cern.ch
27 This process reads RAW data from the files provided as command line arguments
28 and save results in a file (named from RESULT_FILE define - see below).
32 #define RESULT_FILE "tpcPulser.root"
33 #define FILE_ID "pulser"
34 #define MAPPING_FILE "tpcMapping.root"
35 #define CONFIG_FILE "TPCPULSERda.conf"
36 #define AliDebugLevel() -1
50 #include "TPluginManager.h"
52 #include "TObjString.h"
57 #include "AliRawReader.h"
58 #include "AliRawReaderDate.h"
59 #include "AliTPCmapper.h"
60 #include "AliTPCRawStream.h"
61 #include "AliTPCROC.h"
62 #include "AliTPCCalROC.h"
63 #include "AliTPCCalPad.h"
64 #include "AliMathBase.h"
65 #include "TTreeStream.h"
68 #include "AliTPCConfigDA.h"
74 // TPC calibration algorithm includes
76 #include "AliTPCCalibPulser.h"
79 Arguments: list of DATE raw data files
81 int main(int argc, char **argv) {
82 /* log start of process */
83 printf("TPC Pulser DA started - %s\n",__FILE__);
86 printf("Wrong number of arguments\n");
89 AliLog::SetClassDebugLevel("AliTPCRawStream",-5);
90 AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
91 AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
92 AliLog::SetModuleDebugLevel("RAW",-5);
94 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
101 /* declare monitoring program */
103 status=monitorDeclareMp( __FILE__ );
105 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
110 AliTPCmapper *mapping = 0; // The TPC mapping
112 unsigned long32 runNb=0; //run number
113 // configuration options
114 Bool_t fastDecoding = kFALSE;
115 // if test setup get parameters from $DAQDA_TEST_DIR
118 /* copy locally the mapping file from daq detector config db */
119 sprintf(localfile,"./%s",MAPPING_FILE);
120 status = daqDA_DB_getFile(MAPPING_FILE,localfile);
122 printf("Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
126 /* open the mapping file and retrieve mapping object */
127 TFile *fileMapping = new TFile(MAPPING_FILE, "read");
128 mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
133 printf("Failed to get mapping object from %s. ...\n", MAPPING_FILE);
136 printf("Got mapping object from %s\n", MAPPING_FILE);
140 // DA configuration from configuration file
142 //retrieve configuration file
143 sprintf(localfile,"./%s",CONFIG_FILE);
144 status = daqDA_DB_getFile(CONFIG_FILE,localfile);
146 printf("Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status);
149 AliTPCConfigDA config(CONFIG_FILE);
150 // check configuration options
151 if ( (Int_t)config.GetValue("UseFastDecoder") == 1 ) {
152 printf("Info: The fast decoder will be used for the processing.\n");
156 // create calibration object
157 AliTPCCalibPulser calibPulser(config.GetConfigurationMap()); // pulser calibration algorithm
158 calibPulser.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
160 //===========================//
161 // loop over RAW data files //
162 //==========================//
164 for(i=1;i<argc;i++) {
166 /* define data source : this is argument i */
167 printf("Processing file %s\n", argv[i]);
168 status=monitorSetDataSource( argv[i] );
170 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
176 struct eventHeaderStruct *event;
178 /* check shutdown condition */
179 if (daqDA_checkShutdown()) {break;}
181 /* get next event (blocking call until timeout) */
182 status=monitorGetEventDynamic((void **)&event);
183 if (status==MON_ERR_EOF) {
184 printf ("End of File %d detected\n",i);
185 break; /* end of monitoring file has been reached */
189 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
193 /* retry if got no event */
198 // get the run number
199 runNb = event->eventRunNb;
200 // Pulser calibration
201 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
202 if ( fastDecoding ) calibPulser.ProcessEventFast(rawReader);
203 else calibPulser.ProcessEvent(rawReader);
212 // Analyse pulser data and write them to rootfile
214 calibPulser.Analyse();
215 printf ("%d events processed\n",nevents);
217 TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
218 calibPulser.Write("tpcCalibPulser");
220 printf("Wrote %s\n",RESULT_FILE);
222 /* store the result file on FES */
224 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
229 //Send objects to the AMORE DB
231 printf ("AMORE part\n");
232 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
233 //cheet a little -- temporary solution (hopefully)
235 //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
236 //table in which the calib objects are stored. This table is dropped each time AmoreDA
237 //is initialised. This of course makes a problem if we would like to store different
238 //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
239 //the AMORE_DA_NAME env variable is overwritten.
241 //find processed sector
244 for ( Int_t roc = 0; roc < 72; roc++ ) {
245 if ( !calibPulser.GetCalRocT0(roc) ) continue;
246 if (mapping->GetSideFromRoc(roc)==1) sideName='C';
247 sector = mapping->GetSectorFromRoc(roc);
249 gSystem->Setenv("AMORE_DA_NAME",Form("TPC-%c%02d-%s",sideName,sector,FILE_ID));
253 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsString()));
255 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
257 statusDA+=amoreDA.Send("PulserT0",calibPulser.GetCalPadT0());
258 statusDA+=amoreDA.Send("PulserQ",calibPulser.GetCalPadQ());
259 statusDA+=amoreDA.Send("PulserRMS",calibPulser.GetCalPadRMS());
260 statusDA+=amoreDA.Send("arrayTmean",calibPulser.GetMeanTimeSectorArray());
261 statusDA+=amoreDA.Send("Info",&info);
263 printf("Waring: Failed to write one of the calib objects to the AMORE database\n");
265 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);