]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - TPC/TPCCEda.cxx
RESET detector function implemented
[u/mrichter/AliRoot.git] / TPC / TPCCEda.cxx
... / ...
CommitLineData
1/*
2TPC DA for online calibration
3
4Contact: Haavard.Helstrup@cern.ch
5Link:
6Run Type: PHYSICS STANDALONE DAQ
7DA Type: MON
8Number of events needed: 500
9Input Files:
10Output Files: tpcCE.root, to be exported to the DAQ FXS
11fileId: CE
12Trigger types used: PHYSICS_EVENT
13
14*/
15
16/*
17
18TPCCEda.cxx - calibration algorithm for TPC Central Electrode events
19
2010/06/2007 sylvain.chapeland@cern.ch : first version - clean skeleton based on DAQ DA case1
2106/12/2007 haavard.helstrup@cern.ch : created CE DA based on pulser code
2219/09/2008 J.Wiechula@gsi.de: Added support for configuration files.
23
24contact: marian.ivanov@cern.ch
25
26
27This process reads RAW data from the files provided as command line arguments
28and save results in a file (named from RESULT_FILE define - see below).
29
30*/
31
32#define RESULT_FILE "tpcCE.root"
33#define FILE_ID "CE"
34#define MAPPING_FILE "tpcMapping.root"
35#define CONFIG_FILE "TPCCEda.conf"
36
37#include <daqDA.h>
38#include "event.h"
39#include "monitor.h"
40#include <stdio.h>
41#include <stdlib.h>
42#include <vector>
43//
44//Root includes
45//
46#include <TFile.h>
47#include "TROOT.h"
48#include "TPluginManager.h"
49#include "TSystem.h"
50#include "TString.h"
51#include "TObjString.h"
52#include "TDatime.h"
53#include "TStopwatch.h"
54#include "TMap.h"
55#include "TGraph.h"
56#include "TMath.h"
57//
58//AliRoot includes
59//
60#include "AliRawReader.h"
61#include "AliRawReaderDate.h"
62#include "AliTPCmapper.h"
63#include "AliTPCRawStream.h"
64#include "AliTPCROC.h"
65#include "AliTPCCalROC.h"
66#include "AliTPCCalPad.h"
67#include "AliMathBase.h"
68#include "TTreeStream.h"
69#include "AliLog.h"
70#include "AliTPCConfigDA.h"
71//
72//AMORE
73//
74#include <AmoreDA.h>
75//
76// TPC calibration algorithm includes
77//
78#include "AliTPCCalibCE.h"
79
80
81//functios, implementation below
82void SendToAmoreDB(AliTPCCalibCE &calibCE, unsigned long32 runNb);
83//for threaded processing
84
85
86/* Main routine
87 Arguments: list of DATE raw data files
88*/
89int main(int argc, char **argv) {
90 /* log start of process */
91 printf("TPC CE DA started - %s\n",__FILE__);
92
93 if (argc<2) {
94 printf("Wrong number of arguments\n");
95 return -1;
96 }
97
98 AliLog::SetClassDebugLevel("AliTPCRawStream",-5);
99 AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
100 AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
101 AliLog::SetModuleDebugLevel("RAW",-5);
102
103 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
104 "*",
105 "TStreamerInfo",
106 "RIO",
107 "TStreamerInfo()");
108
109 /* declare monitoring program */
110 int i,status;
111 status=monitorDeclareMp( __FILE__ );
112 if (status!=0) {
113 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
114 return -1;
115 }
116 monitorSetNowait();
117 monitorSetNoWaitNetworkTimeout(1000);
118
119 //variables
120 AliTPCmapper *mapping = 0; // The TPC mapping
121 char localfile[255];
122 unsigned long32 runNb=0; //run number
123
124
125 //
126 // DA configuration from configuration file
127 //
128 //retrieve configuration file
129 sprintf(localfile,"./%s",CONFIG_FILE);
130 status = daqDA_DB_getFile(CONFIG_FILE,localfile);
131 if (status) {
132 printf("Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status);
133 return -1;
134 }
135 AliTPCConfigDA config(CONFIG_FILE);
136 // check configuration options
137 TString laserTriggerName("C0LSR-ABCE-NOPF-CENT");
138 size_t bufferSize=30;
139 Int_t forceTriggerId=-1;
140 Int_t forceNeventsStandalone=-1;
141 Bool_t forceBufferEndsGlobal=kTRUE;
142// Bool_t forceBufferEndsGlobalDummy=kFALSE;
143 if ( config.GetConfigurationMap()->GetValue("LaserTriggerName") ) {
144 laserTriggerName=config.GetConfigurationMap()->GetValue("LaserTriggerName")->GetName();
145 printf("Laser trigger class name set to: %s.\n",laserTriggerName.Data());
146 }
147
148 if ( config.GetConfigurationMap()->GetValue("ForceTriggerId") ) {
149 forceTriggerId=TMath::Nint(config.GetValue("ForceTriggerId"));
150 printf("Only processing triggers with Id: %d.\n",forceTriggerId);
151 }
152
153
154 //subsribe to laser triggers only in physics partition
155 //if the trigger class is not available the return value is -1
156 //in this case we are most probably running as a standalone
157 // laser run and should request all events
158 unsigned char classIdptr=0;
159 int retClassId=daqDA_getClassIdFromName(laserTriggerName.Data(),&classIdptr);
160 if (retClassId==0){
161 //interleaved laser in physics runs
162 //select proper trigger class id
163 char c[5];
164 snprintf(c,sizeof(c),"%u",(unsigned int)classIdptr);
165 char *table[5] = {"PHY","Y","*",c,NULL};
166 monitorDeclareTableExtended(table);
167 printf("Using trigger class Id: %s\n",c);
168 } else if (retClassId==-1){
169 //global partition without laser triggered events
170 //the DA should exit properly without processing
171 printf("Laser trigger class '%s' was not found among trigger class names. Will stop processing.\n",laserTriggerName.Data());
172 return 0;
173 } else if (retClassId==-2){
174 //standalone case, accept all physics events
175 char *table[5] = {"PHY","Y","*","*",NULL};
176 monitorDeclareTableExtended(table);
177 printf("Using all trigger class Ids\n");
178 } else {
179 printf("Unknown return value of 'daqDA_getClassIdFromName': %d\n",retClassId);
180 return -2;
181 }
182
183 //see if we should force the trigger id
184 if (forceTriggerId>-1){
185 char c[5];
186 sprintf(c,"%d",forceTriggerId);
187 char *table[5] = {"PHY","Y","*",c,NULL};
188 monitorDeclareTableExtended(table);
189// forceBufferEndsGlobal=forceBufferEndsGlobalDummy;
190 }
191
192
193 // if test setup get parameters from $DAQDA_TEST_DIR
194 if (!mapping){
195 /* copy locally the mapping file from daq detector config db */
196 sprintf(localfile,"./%s",MAPPING_FILE);
197 status = daqDA_DB_getFile(MAPPING_FILE,localfile);
198 if (status) {
199 printf("Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
200 return -1;
201 }
202
203 /* open the mapping file and retrieve mapping object */
204 TFile *fileMapping = new TFile(MAPPING_FILE, "read");
205 mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
206 delete fileMapping;
207 }
208
209 if (mapping == 0) {
210 printf("Failed to get mapping object from %s. ...\n", MAPPING_FILE);
211 return -1;
212 } else {
213 printf("Got mapping object from %s\n", MAPPING_FILE);
214 }
215
216
217 //create calibration object
218 AliTPCCalibCE calibCE(config.GetConfigurationMap()); // central electrode calibration
219 calibCE.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
220
221 //amore update interval
222 Double_t updateInterval=300; //seconds
223 Double_t valConf=config.GetValue("AmoreUpdateInterval");
224 if ( valConf>0 ) updateInterval=valConf;
225 //timer
226 TStopwatch stopWatch;
227
228 //===========================//
229 // loop over RAW data files //
230 //==========================//
231 int nevents=0;
232 size_t counter=0;
233 for ( i=1; i<argc; i++) {
234
235 /* define data source : this is argument i */
236 printf("Processing file %s\n", argv[i]);
237 status=monitorSetDataSource( argv[i] );
238 if (status!=0) {
239 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
240 return -1;
241 }
242
243
244 /* read until EOF */
245 while (true) {
246 struct eventHeaderStruct *event;
247
248 /* check shutdown condition */
249 if (daqDA_checkShutdown()) {break;}
250
251 /* get next event (blocking call until timeout) */
252 status=monitorGetEventDynamic((void **)&event);
253 if (status==MON_ERR_EOF) {
254 printf ("End of File %d detected\n",i);
255 break; /* end of monitoring file has been reached */
256 }
257
258 if (status!=0) {
259 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
260 break;
261 }
262
263 /* retry if got no event */
264 if (event==NULL)
265 continue;
266
267 /* skip start/end of run events */
268 if ( (event->eventType != physicsEvent) && (event->eventType != calibrationEvent) ){
269 free(event);
270 continue;
271 }
272
273
274 // get the run number
275 runNb = event->eventRunNb;
276
277 // CE calibration
278 calibCE.ProcessEvent(event);
279
280 // sending to AMOREdb
281 if (stopWatch.RealTime()>updateInterval){
282 SendToAmoreDB(calibCE,runNb);
283 stopWatch.Start();
284 } else {
285 stopWatch.Continue();
286 }
287
288 /* free resources */
289 free(event);
290 ++nevents;
291 }
292 }
293
294 //
295 // Analyse CE data and write them to rootfile
296 //
297 calibCE.Analyse();
298 printf ("%d events processed, %d used\n",nevents,calibCE.GetNeventsProcessed());
299
300 TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
301 calibCE.Write("tpcCalibCE");
302 delete fileTPC;
303 printf("Wrote %s\n",RESULT_FILE);
304
305 /* store the result file on FES */
306
307 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
308 if (status) {
309 status = -2;
310 }
311
312 SendToAmoreDB(calibCE,runNb);
313
314 return status;
315}
316
317
318void SendToAmoreDB(AliTPCCalibCE &calibCE, unsigned long32 runNb)
319{
320 //AMORE
321// printf ("AMORE part\n");
322 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
323 //cheet a little -- temporary solution (hopefully)
324 //
325 //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
326 //table in which the calib objects are stored. This table is dropped each time AmoreDA
327 //is initialised. This of course makes a problem if we would like to store different
328 //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
329 //the AMORE_DA_NAME env variable is overwritten.
330 gSystem->Setenv("AMORE_DA_NAME",Form("TPC-%s",FILE_ID));
331 //
332 // end cheet
333 TGraph *grA=calibCE.MakeGraphTimeCE(-1,0,2);
334 TGraph *grC=calibCE.MakeGraphTimeCE(-2,0,2);
335 TDatime time;
336 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString()));
337 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
338 Int_t statusDA=0;
339 statusDA+=amoreDA.Send("CET0",calibCE.GetCalPadT0());
340 statusDA+=amoreDA.Send("CEQ",calibCE.GetCalPadQ());
341 statusDA+=amoreDA.Send("CERMS",calibCE.GetCalPadRMS());
342 statusDA+=amoreDA.Send("DriftA",grA);
343 statusDA+=amoreDA.Send("DriftC",grC);
344 statusDA+=amoreDA.Send("Info",&info);
345 if ( statusDA!=0 )
346 printf("Waring: Failed to write one of the calib objects to the AMORE database\n");
347 // reset env var
348 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);
349 if (grA) delete grA;
350 if (grC) delete grC;
351}
352
353