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