2 TPC DA for online calibration
4 Contact: Haavard.Helstrup@cern.ch
6 Run Type: PHYSICS STANDALONE DAQ
8 Number of events needed: 500
10 Output Files: tpcCE.root, to be exported to the DAQ FXS
12 Trigger types used: PHYSICS_EVENT
18 TPCCEda.cxx - calibration algorithm for TPC Central Electrode events
20 10/06/2007 sylvain.chapeland@cern.ch : first version - clean skeleton based on DAQ DA case1
21 06/12/2007 haavard.helstrup@cern.ch : created CE DA based on pulser code
22 19/09/2008 J.Wiechula@gsi.de: 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 "tpcCE.root"
34 #define MAPPING_FILE "tpcMapping.root"
35 #define CONFIG_FILE "TPCCEda.conf"
49 #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"
67 #include "AliTPCConfigDA.h"
73 // TPC calibration algorithm includes
75 #include "AliTPCCalibCE.h"
81 Arguments: list of DATE raw data files
83 int main(int argc, char **argv) {
84 /* log start of process */
85 printf("TPC CE DA started - %s\n",__FILE__);
88 printf("Wrong number of arguments\n");
92 AliLog::SetClassDebugLevel("AliTPCRawStream",-5);
93 AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
94 AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
95 AliLog::SetModuleDebugLevel("RAW",-5);
97 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
103 /* declare monitoring program */
105 status=monitorDeclareMp( __FILE__ );
107 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
111 monitorSetNoWaitNetworkTimeout(1000);
114 AliTPCmapper *mapping = 0; // The TPC mapping
116 unsigned long32 runNb=0; //run number
117 // configuration options
118 Bool_t fastDecoding = kFALSE;
120 // if test setup get parameters from $DAQDA_TEST_DIR
122 /* copy locally the mapping file from daq detector config db */
123 sprintf(localfile,"./%s",MAPPING_FILE);
124 status = daqDA_DB_getFile(MAPPING_FILE,localfile);
126 printf("Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
130 /* open the mapping file and retrieve mapping object */
131 TFile *fileMapping = new TFile(MAPPING_FILE, "read");
132 mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
137 printf("Failed to get mapping object from %s. ...\n", MAPPING_FILE);
140 printf("Got mapping object from %s\n", MAPPING_FILE);
144 // DA configuration from configuration file
146 //retrieve configuration file
147 sprintf(localfile,"./%s",CONFIG_FILE);
148 status = daqDA_DB_getFile(CONFIG_FILE,localfile);
150 printf("Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status);
153 AliTPCConfigDA config(CONFIG_FILE);
154 // check configuration
155 if ( (Int_t)config.GetValue("UseFastDecoder") == 1 ){
156 printf("Info: The fast decoder will be used for the processing.\n");
160 //create calibration object
161 AliTPCCalibCE calibCE(config.GetConfigurationMap()); // central electrode calibration
162 calibCE.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
164 //===========================//
165 // loop over RAW data files //
166 //==========================//
168 for ( i=1; i<argc; i++) {
170 /* define data source : this is argument i */
171 printf("Processing file %s\n", argv[i]);
172 status=monitorSetDataSource( argv[i] );
174 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
180 struct eventHeaderStruct *event;
182 /* check shutdown condition */
183 if (daqDA_checkShutdown()) {break;}
185 /* get next event (blocking call until timeout) */
186 status=monitorGetEventDynamic((void **)&event);
187 if (status==MON_ERR_EOF) {
188 printf ("End of File %d detected\n",i);
189 break; /* end of monitoring file has been reached */
193 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
197 /* skip start/end of run events */
198 if ( (event->eventType != physicsEvent) && (event->eventType != calibrationEvent) )
201 /* retry if got no event */
206 // get the run number
207 runNb = event->eventRunNb;
209 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
210 if ( fastDecoding ) calibCE.ProcessEventFast(rawReader);
211 else calibCE.ProcessEvent(rawReader);
220 // Analyse CE data and write them to rootfile
223 printf ("%d events processed\n",nevents);
225 TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
226 calibCE.Write("tpcCalibCE");
228 printf("Wrote %s\n",RESULT_FILE);
230 /* store the result file on FES */
232 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
238 //Send objects to the AMORE DB
240 printf ("AMORE part\n");
241 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
242 //cheet a little -- temporary solution (hopefully)
244 //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
245 //table in which the calib objects are stored. This table is dropped each time AmoreDA
246 //is initialised. This of course makes a problem if we would like to store different
247 //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
248 //the AMORE_DA_NAME env variable is overwritten.
249 gSystem->Setenv("AMORE_DA_NAME",Form("TPC-%s",FILE_ID));
253 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsString()));
254 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
256 statusDA+=amoreDA.Send("CET0",calibCE.GetCalPadT0());
257 statusDA+=amoreDA.Send("CEQ",calibCE.GetCalPadQ());
258 statusDA+=amoreDA.Send("CERMS",calibCE.GetCalPadRMS());
259 statusDA+=amoreDA.Send("Info",&info);
261 printf("Waring: Failed to write one of the calib objects to the AMORE database\n");
262 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);