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