Revision of AliTRDmcmSim + coding rule violations
[u/mrichter/AliRoot.git] / TPC / AliTPCPreprocessor.cxx
CommitLineData
54472e4f 1/**************************************************************************
2 * Copyright(c) 2007, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
72df5829 16
54472e4f 17#include "AliTPCPreprocessor.h"
a7dce0bc 18#include "AliShuttleInterface.h"
54472e4f 19
20#include "AliCDBMetaData.h"
21#include "AliDCSValue.h"
22#include "AliLog.h"
23#include "AliTPCSensorTempArray.h"
a7dce0bc 24#include "AliTPCROC.h"
25#include "AliTPCCalROC.h"
26#include "AliTPCCalPad.h"
27#include "AliTPCCalibPedestal.h"
9f016d99 28#include "AliTPCCalibPulser.h"
29#include "AliTPCCalibCE.h"
dca91b3f 30#include "AliTPCdataQA.h"
9e66a8dd 31#include "TFile.h"
7b54c8e9 32#include "TTree.h"
bb30a935 33#include "TGraph.h"
7b54c8e9 34#include "TEnv.h"
bb30a935 35#include "TParameter.h"
54472e4f 36
37#include <TTimeStamp.h>
38
a7dce0bc 39const Int_t kValCutTemp = 100; // discard temperatures > 100 degrees
40const Int_t kDiffCutTemp = 5; // discard temperature differences > 5 degrees
bb30a935 41const TString kPedestalRunType = "PEDESTAL"; // pedestal run identifier
9054511b 42const TString kPulserRunType = "PULSER"; // pulser run identifier
bdffc5fb 43const TString kPhysicsRunType = "PHYSICS"; // physics run identifier
9054511b 44const TString kCosmicRunType = "COSMIC"; // cosmic run identifier
45const TString kLaserRunType = "LASER"; // laser run identifier
9c754ce7 46const TString kDaqRunType = "DAQ"; // DAQ run identifier
87d77b35 47const TString kAmandaTemp = "TPC_PT_%d_TEMPERATURE"; // Amanda string for temperature entries
bee89eeb 48//const Double_t kFitFraction = 0.7; // Fraction of DCS sensor fits required
68b512ca 49const Double_t kFitFraction = -1.0; // Don't require minimum number of fits in commissioning run
72df5829 50
54472e4f 51//
52// This class is the SHUTTLE preprocessor for the TPC detector.
54472e4f 53//
54
55ClassImp(AliTPCPreprocessor)
56
57//______________________________________________________________________________________________
6d07bf74 58AliTPCPreprocessor::AliTPCPreprocessor(AliShuttleInterface* shuttle) :
59 AliPreprocessor("TPC",shuttle),
b6e9fd45 60 fConfEnv(0), fTemp(0), fHighVoltage(0), fHighVoltageStat(0), fGoofie(0), fConfigOK(kTRUE), fROC(0)
54472e4f 61{
62 // constructor
a7dce0bc 63 fROC = AliTPCROC::Instance();
72534123 64
65 // define run types to be processed
66
67 AddRunType(kPedestalRunType);
68 AddRunType(kPulserRunType);
69 AddRunType(kPhysicsRunType);
72534123 70 AddRunType(kCosmicRunType);
71 AddRunType(kLaserRunType);
72 AddRunType(kDaqRunType);
73
54472e4f 74}
72df5829 75//______________________________________________________________________________________________
f4a89669 76 AliTPCPreprocessor::AliTPCPreprocessor(const AliTPCPreprocessor& ) :
77 AliPreprocessor("TPC",0),
b6e9fd45 78 fConfEnv(0), fTemp(0), fHighVoltage(0), fHighVoltageStat(0), fGoofie(0), fConfigOK(kTRUE), fROC(0)
f4a89669 79 {
80
81 Fatal("AliTPCPreprocessor", "copy constructor not implemented");
f7f602cc 82//
83// // fTemp = new AliTPCSensorTempArray(*(org.fTemp));
f4a89669 84 }
54472e4f 85
86//______________________________________________________________________________________________
87AliTPCPreprocessor::~AliTPCPreprocessor()
88{
89 // destructor
a7dce0bc 90
54472e4f 91 delete fTemp;
bdffc5fb 92 delete fHighVoltage;
54472e4f 93}
72df5829 94//______________________________________________________________________________________________
95AliTPCPreprocessor& AliTPCPreprocessor::operator = (const AliTPCPreprocessor& )
96{
97 Fatal("operator =", "assignment operator not implemented");
98 return *this;
99}
100
54472e4f 101
102//______________________________________________________________________________________________
103void AliTPCPreprocessor::Initialize(Int_t run, UInt_t startTime,
104 UInt_t endTime)
105{
bb30a935 106 // Creates AliTestDataDCS object -- start maps half an hour beforre actual run start
54472e4f 107
dca91b3f 108 UInt_t startTimeLocal = startTime-3600;
109 UInt_t endTimeLocal = endTime+1800;
bb30a935 110
dca91b3f 111 AliPreprocessor::Initialize(run, startTimeLocal, endTimeLocal);
54472e4f 112
113 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
f4a89669 114 TTimeStamp((time_t)startTime,0).AsString(),
115 TTimeStamp((time_t)endTime,0).AsString()));
54472e4f 116
7b54c8e9 117 // Preprocessor configuration
118
37092b2b 119 AliCDBEntry* entry = GetFromOCDB("Config", "Preprocessor");
7b54c8e9 120 if (entry) fConfEnv = (TEnv*) entry->GetObject();
121 if ( fConfEnv==0 ) {
7b54c8e9 122 Log("AliTPCPreprocsessor: Preprocessor Config OCDB entry missing.\n");
37092b2b 123 fConfigOK = kFALSE;
124 return;
7b54c8e9 125 }
126
18eade96 127 // Temperature sensors
128
136e44f7 129 TTree *confTree = 0;
130
131 TString tempConf = fConfEnv->GetValue("Temperature","ON");
132 tempConf.ToUpper();
133 if (tempConf != "OFF" ) {
7b54c8e9 134 entry = GetFromOCDB("Config", "Temperature");
f7f602cc 135 if (entry) confTree = (TTree*) entry->GetObject();
18eade96 136 if ( confTree==0 ) {
18eade96 137 Log("AliTPCPreprocsessor: Temperature Config OCDB entry missing.\n");
138 fConfigOK = kFALSE;
f7f602cc 139 return;
18eade96 140 }
dca91b3f 141 fTemp = new AliTPCSensorTempArray(startTimeLocal, endTimeLocal, confTree, kAmandaTemp);
18eade96 142 fTemp->SetValCut(kValCutTemp);
143 fTemp->SetDiffCut(kDiffCutTemp);
136e44f7 144 }
18eade96 145
bdffc5fb 146 // High voltage measurements
147
136e44f7 148 TString hvConf = fConfEnv->GetValue("HighVoltage","ON");
149 hvConf.ToUpper();
150 if (hvConf != "OFF" ) {
bdffc5fb 151 confTree=0;
152 entry=0;
153 entry = GetFromOCDB("Config", "HighVoltage");
154 if (entry) confTree = (TTree*) entry->GetObject();
155 if ( confTree==0 ) {
156 Log("AliTPCPreprocsessor: High Voltage Config OCDB entry missing.\n");
157 fConfigOK = kFALSE;
158 return;
159 }
dca91b3f 160 fHighVoltage = new AliDCSSensorArray(startTimeLocal, endTimeLocal, confTree);
bff20895 161 }
9d2ce539 162
163 // High voltage status values
164
bff20895 165 TString hvStatConf = fConfEnv->GetValue("HighVoltageStat","ON");
166 hvStatConf.ToUpper();
167 if (hvStatConf != "OFF" ) {
9d2ce539 168 confTree=0;
169 entry=0;
170 entry = GetFromOCDB("Config", "HighVoltageStat");
171 if (entry) confTree = (TTree*) entry->GetObject();
172 if ( confTree==0 ) {
173 Log("AliTPCPreprocsessor: High Voltage Status Config OCDB entry missing.\n");
174 fConfigOK = kFALSE;
175 return;
176 }
dca91b3f 177 fHighVoltageStat = new AliDCSSensorArray(startTimeLocal, endTimeLocal, confTree);
bdffc5fb 178 }
b6e9fd45 179
180 // Goofie values
181
182 TString goofieConf = fConfEnv->GetValue("Goofie","ON");
183 goofieConf.ToUpper();
184 if (goofieConf != "OFF" ) {
185 confTree=0;
186 entry=0;
187 entry = GetFromOCDB("Config", "Goofie");
188 if (entry) confTree = (TTree*) entry->GetObject();
189 if ( confTree==0 ) {
190 Log("AliTPCPreprocsessor: Goofie Config OCDB entry missing.\n");
191 fConfigOK = kFALSE;
192 return;
193 }
194 fGoofie = new AliDCSSensorArray(startTimeLocal, endTimeLocal, confTree);
195 }
196
197
54472e4f 198}
199
200//______________________________________________________________________________________________
201UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
202{
203 // Fills data into TPC calibrations objects
204
54472e4f 205 // Amanda servers provide information directly through dcsAliasMap
206
bb30a935 207
a7dce0bc 208 if (!fConfigOK) return 9;
136e44f7 209 UInt_t result = 0;
bb30a935 210 TObjArray *resultArray = new TObjArray();
211 TString errorHandling = fConfEnv->GetValue("ErrorHandling","ON");
212 errorHandling.ToUpper();
213 TObject * status;
214
215 UInt_t dcsResult=0;
216 if (errorHandling == "OFF" ) {
217 if (!dcsAliasMap) dcsResult=1;
218 if (dcsAliasMap->GetEntries() == 0 ) dcsResult=1;
219 status = new TParameter<int>("dcsResult",dcsResult);
220 resultArray->Add(status);
221 } else {
222 if (!dcsAliasMap) return 9;
223 if (dcsAliasMap->GetEntries() == 0 ) return 9;
224 }
225
226
227
a7dce0bc 228
229 TString runType = GetRunType();
230
54472e4f 231 // Temperature sensors are processed by AliTPCCalTemp
72df5829 232
136e44f7 233 TString tempConf = fConfEnv->GetValue("Temperature","ON");
234 tempConf.ToUpper();
235 if (tempConf != "OFF" ) {
236 UInt_t tempResult = MapTemperature(dcsAliasMap);
237 result=tempResult;
bb30a935 238 status = new TParameter<int>("tempResult",tempResult);
239 resultArray->Add(status);
136e44f7 240 }
18eade96 241
bdffc5fb 242 // High Voltage recordings
243
244
136e44f7 245 TString hvConf = fConfEnv->GetValue("HighVoltage","ON");
246 hvConf.ToUpper();
247 if (hvConf != "OFF" ) {
248 UInt_t hvResult = MapHighVoltage(dcsAliasMap);
249 result+=hvResult;
bb30a935 250 status = new TParameter<int>("hvResult",hvResult);
251 resultArray->Add(status);
bdffc5fb 252 }
f7f602cc 253
b6e9fd45 254 // Goofie values
255
256
257 TString goofieConf = fConfEnv->GetValue("Goofie","ON");
258 goofieConf.ToUpper();
259 if (goofieConf != "OFF" ) {
260 UInt_t goofieResult = MapGoofie(dcsAliasMap);
261 result+=goofieResult;
262 status = new TParameter<int>("goofieResult",goofieResult);
263 resultArray->Add(status);
264 }
265
54472e4f 266 // Other calibration information will be retrieved through FXS files
a7dce0bc 267 // examples:
54472e4f 268 // TList* fileSourcesDAQ = GetFile(AliShuttleInterface::kDAQ, "pedestals");
269 // const char* fileNamePed = GetFile(AliShuttleInterface::kDAQ, "pedestals", "LDC1");
270 //
271 // TList* fileSourcesHLT = GetFile(AliShuttleInterface::kHLT, "calib");
272 // const char* fileNameHLT = GetFile(AliShuttleInterface::kHLT, "calib", "LDC1");
273
9f016d99 274 // pedestal entries
54472e4f 275
a7dce0bc 276 if(runType == kPedestalRunType) {
68b512ca 277 Int_t numSources = 1;
278 Int_t pedestalSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
7b54c8e9 279 TString source = fConfEnv->GetValue("Pedestal","DAQ");
280 source.ToUpper();
136e44f7 281 if (source != "OFF" ) {
282 if ( source == "HLT") pedestalSource[0] = AliShuttleInterface::kHLT;
283 if (!GetHLTStatus()) pedestalSource[0] = AliShuttleInterface::kDAQ;
284 if (source == "HLTDAQ" ) {
285 numSources=2;
286 pedestalSource[0] = AliShuttleInterface::kHLT;
287 pedestalSource[1] = AliShuttleInterface::kDAQ;
288 }
289 if (source == "DAQHLT" ) numSources=2;
290 UInt_t pedestalResult=0;
291 for (Int_t i=0; i<numSources; i++ ) {
453bd596 292 pedestalResult = ExtractPedestals(pedestalSource[i]);
136e44f7 293 if ( pedestalResult == 0 ) break;
294 }
295 result += pedestalResult;
bb30a935 296 status = new TParameter<int>("pedestalResult",pedestalResult);
297 resultArray->Add(status);
68b512ca 298 }
a7dce0bc 299 }
300
9f016d99 301 // pulser trigger processing
302
68b512ca 303 if(runType == kPulserRunType) {
304 Int_t numSources = 1;
305 Int_t pulserSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
9f016d99 306 TString source = fConfEnv->GetValue("Pulser","DAQ");
307 source.ToUpper();
136e44f7 308 if ( source != "OFF") {
309 if ( source == "HLT") pulserSource[0] = AliShuttleInterface::kHLT;
310 if (!GetHLTStatus()) pulserSource[0] = AliShuttleInterface::kDAQ;
311 if (source == "HLTDAQ" ) {
312 numSources=2;
313 pulserSource[0] = AliShuttleInterface::kHLT;
314 pulserSource[1] = AliShuttleInterface::kDAQ;
315 }
316 if (source == "DAQHLT" ) numSources=2;
317 UInt_t pulserResult=0;
318 for (Int_t i=0; i<numSources; i++ ) {
319 pulserResult = ExtractPulser(pulserSource[i]);
320 if ( pulserResult == 0 ) break;
321 }
322 result += pulserResult;
bb30a935 323 status = new TParameter<int>("pulserResult",pulserResult);
324 resultArray->Add(status);
68b512ca 325 }
9f016d99 326 }
327
9054511b 328 // Altro configuration
329
330
331 TString altroConf = fConfEnv->GetValue("AltroConf","ON");
332 goofieConf.ToUpper();
333 if (altroConf != "OFF" ) {
db9ef692 334 UInt_t altroResult = ExtractAltro(AliShuttleInterface::kDCS);
9054511b 335 result+=altroResult;
336 status = new TParameter<int>("altroResult",altroResult);
337 resultArray->Add(status);
338 }
68b512ca 339
340
9f016d99 341 // Central Electrode processing
342
9054511b 343 if( runType == kPhysicsRunType ||
9d2ce539 344 runType == kDaqRunType ) {
68b512ca 345
9d2ce539 346// if (true) { // do CE processing for all run types
68b512ca 347 Int_t numSources = 1;
348 Int_t ceSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
9f016d99 349 TString source = fConfEnv->GetValue("CE","DAQ");
350 source.ToUpper();
136e44f7 351 if ( source != "OFF" ) {
352 if ( source == "HLT") ceSource[0] = AliShuttleInterface::kHLT;
353 if (!GetHLTStatus()) ceSource[0] = AliShuttleInterface::kDAQ;
354 if (source == "HLTDAQ" ) {
68b512ca 355 numSources=2;
356 ceSource[0] = AliShuttleInterface::kHLT;
357 ceSource[1] = AliShuttleInterface::kDAQ;
136e44f7 358 }
359 if (source == "DAQHLT" ) numSources=2;
360 UInt_t ceResult=0;
361 for (Int_t i=0; i<numSources; i++ ) {
362 ceResult = ExtractCE(ceSource[i]);
363 if ( ceResult == 0 ) break;
364 }
365 result += ceResult;
bb30a935 366 status = new TParameter<int>("ceResult",ceResult);
367 resultArray->Add(status);
dca91b3f 368
369 numSources = 1;
370 Int_t qaSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
5e5c1e83 371 source = fConfEnv->GetValue("QA","DAQ");
dca91b3f 372 source.ToUpper();
373 if ( source != "OFF" ) {
374 if ( source == "HLT") qaSource[0] = AliShuttleInterface::kHLT;
375 if (!GetHLTStatus()) qaSource[0] = AliShuttleInterface::kDAQ;
376 if (source == "HLTDAQ" ) {
377 numSources=2;
378 qaSource[0] = AliShuttleInterface::kHLT;
379 qaSource[1] = AliShuttleInterface::kDAQ;
380 }
381 if (source == "DAQHLT" ) numSources=2;
382 UInt_t qaResult=0;
383 for (Int_t i=0; i<numSources; i++ ) {
384 qaResult = ExtractQA(qaSource[i]);
385 if ( qaResult == 0 ) break;
386 }
387// result += qaResult;
388 if ( qaResult !=0 ) Log ("ExtractQA failed, no QA entry available.");
389 status = new TParameter<int>("qaResult",qaResult);
390 resultArray->Add(status);
68b512ca 391 }
dca91b3f 392 }
9f016d99 393 }
136e44f7 394
136e44f7 395 if (errorHandling == "OFF" ) {
bb30a935 396 AliCDBMetaData metaData;
397 metaData.SetBeamPeriod(0);
398 metaData.SetResponsible("Haavard Helstrup");
399 metaData.SetComment("Preprocessor AliTPC status.");
400 Store("Calib", "PreprocStatus", resultArray, &metaData, 0, kFALSE);
401 resultArray->Delete();
402 return 0;
136e44f7 403 } else {
bb30a935 404 return result;
136e44f7 405 }
54472e4f 406}
407//______________________________________________________________________________________________
408UInt_t AliTPCPreprocessor::MapTemperature(TMap* dcsAliasMap)
409{
410
411 // extract DCS temperature maps. Perform fits to save space
412
72df5829 413 UInt_t result=0;
54472e4f 414 TMap *map = fTemp->ExtractDCS(dcsAliasMap);
415 if (map) {
416 fTemp->MakeSplineFit(map);
68b512ca 417 Double_t fitFraction = 1.0*fTemp->NumFits()/fTemp->NumSensors();
67a165ed 418 if (fitFraction > kFitFraction ) {
419 AliInfo(Form("Temperature values extracted, fits performed.\n"));
420 } else {
421 Log ("Too few temperature maps fitted. \n");
422 result = 9;
423 }
54472e4f 424 } else {
67a165ed 425 Log("No temperature map extracted. \n");
72df5829 426 result=9;
54472e4f 427 }
428 delete map;
429 // Now store the final CDB file
a7dce0bc 430
431 if ( result == 0 ) {
72df5829 432 AliCDBMetaData metaData;
54472e4f 433 metaData.SetBeamPeriod(0);
434 metaData.SetResponsible("Haavard Helstrup");
435 metaData.SetComment("Preprocessor AliTPC data base entries.");
436
a7dce0bc 437 Bool_t storeOK = Store("Calib", "Temperature", fTemp, &metaData, 0, kFALSE);
438 if ( !storeOK ) result=1;
439
72df5829 440 }
54472e4f 441
442 return result;
7b54c8e9 443
54472e4f 444}
7b54c8e9 445
bdffc5fb 446//______________________________________________________________________________________________
447UInt_t AliTPCPreprocessor::MapHighVoltage(TMap* dcsAliasMap)
448{
449
450 // extract DCS HV maps. Perform fits to save space
451
452 UInt_t result=0;
453 TMap *map = fHighVoltage->ExtractDCS(dcsAliasMap);
454 if (map) {
455 fHighVoltage->MakeSplineFit(map);
68b512ca 456 Double_t fitFraction = 1.0*fHighVoltage->NumFits()/fHighVoltage->NumSensors();
bdffc5fb 457 if (fitFraction > kFitFraction ) {
136e44f7 458 AliInfo(Form("High voltage recordings extracted, fits performed.\n"));
bdffc5fb 459 } else {
460 Log ("Too few high voltage recordings fitted. \n");
461 result = 9;
462 }
463 } else {
464 Log("No high voltage recordings extracted. \n");
465 result=9;
466 }
467 delete map;
9d2ce539 468
bff20895 469 TString hvStatConf = fConfEnv->GetValue("HighVoltageStat","ON");
470 hvStatConf.ToUpper();
471 if (hvStatConf != "OFF" ) {
472 TMap *map2 = fHighVoltageStat->ExtractDCS(dcsAliasMap);
473 if (map2) {
dca91b3f 474 fHighVoltageStat->ClearFit();
475 fHighVoltageStat->SetGraph(map2);
bff20895 476 } else {
477 Log("No high voltage status recordings extracted. \n");
478 result=9;
479 }
480 delete map2;
9d2ce539 481
bff20895 482 // add status maps to high voltage sensor array
9d2ce539 483
bff20895 484 fHighVoltage->AddSensors(fHighVoltageStat);
485 }
bdffc5fb 486 // Now store the final CDB file
487
488 if ( result == 0 ) {
489 AliCDBMetaData metaData;
490 metaData.SetBeamPeriod(0);
491 metaData.SetResponsible("Haavard Helstrup");
492 metaData.SetComment("Preprocessor AliTPC data base entries.");
493
494 Bool_t storeOK = Store("Calib", "HighVoltage", fHighVoltage, &metaData, 0, kFALSE);
495 if ( !storeOK ) result=1;
496
497 }
498
499 return result;
500
501}
502
b6e9fd45 503//______________________________________________________________________________________________
504UInt_t AliTPCPreprocessor::MapGoofie(TMap* dcsAliasMap)
505{
506
507 // extract DCS Goofie maps. Do not perform fits (low update rate)
508
509 UInt_t result=0;
510
511 TMap *map = fGoofie->ExtractDCS(dcsAliasMap);
512 if (map) {
513 fGoofie->ClearFit();
514 fGoofie->SetGraph(map);
515 } else {
516 Log("No Goofie recordings extracted. \n");
517 result=9;
518 }
519 delete map;
520
521 // Now store the final CDB file
522
523 if ( result == 0 ) {
524 AliCDBMetaData metaData;
525 metaData.SetBeamPeriod(0);
526 metaData.SetResponsible("Haavard Helstrup");
527 metaData.SetComment("Preprocessor AliTPC data base entries.");
528
529 Bool_t storeOK = Store("Calib", "Goofie", fGoofie, &metaData, 0, kFALSE);
530 if ( !storeOK ) result=1;
531
532 }
533
534 return result;
535
536}
537
7b54c8e9 538
a7dce0bc 539//______________________________________________________________________________________________
7b54c8e9 540
541UInt_t AliTPCPreprocessor::ExtractPedestals(Int_t sourceFXS)
a7dce0bc 542{
543 //
544 // Read pedestal file from file exchage server
545 // Keep original entry from OCDB in case no new pedestals are available
546 //
547 AliTPCCalPad *calPadPed=0;
548 AliCDBEntry* entry = GetFromOCDB("Calib", "Pedestals");
549 if (entry) calPadPed = (AliTPCCalPad*)entry->GetObject();
550 if ( calPadPed==NULL ) {
a7dce0bc 551 Log("AliTPCPreprocsessor: No previous TPC pedestal entry available.\n");
7b54c8e9 552 calPadPed = new AliTPCCalPad("PedestalsMean","PedestalsMean");
553 }
554
555 AliTPCCalPad *calPadRMS=0;
d63b9ad7 556 entry = GetFromOCDB("Calib", "PadNoise");
7b54c8e9 557 if (entry) calPadRMS = (AliTPCCalPad*)entry->GetObject();
558 if ( calPadRMS==NULL ) {
7b54c8e9 559 Log("AliTPCPreprocsessor: No previous TPC noise entry available.\n");
560 calPadRMS = new AliTPCCalPad("PedestalsRMS","PedestalsRMS");
a7dce0bc 561 }
562
7b54c8e9 563
a7dce0bc 564 UInt_t result=0;
565
566 Int_t nSectors = fROC->GetNSectors();
7b54c8e9 567 TList* list = GetFileSources(sourceFXS,"pedestals");
9f016d99 568
569 if (list && list->GetEntries()>0) {
a7dce0bc 570
571// loop through all files from LDCs
572
bdffc5fb 573 Bool_t changed=false;
a7dce0bc 574 UInt_t index = 0;
575 while (list->At(index)!=NULL) {
576 TObjString* fileNameEntry = (TObjString*) list->At(index);
577 if (fileNameEntry!=NULL) {
7b54c8e9 578 TString fileName = GetFile(sourceFXS, "pedestals",
a7dce0bc 579 fileNameEntry->GetString().Data());
580 TFile *f = TFile::Open(fileName);
9f016d99 581 if (!f) {
582 Log ("Error opening pedestal file.");
583 result =2;
584 break;
585 }
a7dce0bc 586 AliTPCCalibPedestal *calPed;
e73181c9 587 f->GetObject("tpcCalibPedestal",calPed);
67a165ed 588 if ( !calPed ) {
589 Log ("No pedestal calibration object in file.");
590 result = 2;
591 break;
592 }
a7dce0bc 593
594 // replace entries for the sectors available in the present file
595
bdffc5fb 596 changed=true;
c9c23d80 597 for (Int_t sector=0; sector<nSectors; sector++) {
7b54c8e9 598 AliTPCCalROC *rocPed=calPed->GetCalRocPedestal(sector, kFALSE);
599 if ( rocPed ) calPadPed->SetCalROC(rocPed,sector);
600 AliTPCCalROC *rocRMS=calPed->GetCalRocRMS(sector, kFALSE);
601 if ( rocRMS ) calPadRMS->SetCalROC(rocRMS,sector);
a7dce0bc 602 }
a480de15 603 delete calPed;
342d3b42 604 f->Close();
a7dce0bc 605 }
606 ++index;
607 } // while(list)
608//
609// Store updated pedestal entry to OCDB
610//
bdffc5fb 611 if (changed) {
612 AliCDBMetaData metaData;
613 metaData.SetBeamPeriod(0);
614 metaData.SetResponsible("Haavard Helstrup");
615 metaData.SetComment("Preprocessor AliTPC data base entries.");
616
617 Bool_t storeOK = Store("Calib", "Pedestals", calPadPed, &metaData, 0, kTRUE);
618 if ( !storeOK ) ++result;
619 storeOK = Store("Calib", "PadNoise", calPadRMS, &metaData, 0, kTRUE);
620 if ( !storeOK ) ++result;
621 }
9f016d99 622 } else {
67a165ed 623 Log ("Error: no entries in input file list!");
9f016d99 624 result = 1;
7b54c8e9 625 }
a7dce0bc 626
a7dce0bc 627 return result;
628}
7b54c8e9 629
630//______________________________________________________________________________________________
631
632
9f016d99 633UInt_t AliTPCPreprocessor::ExtractPulser(Int_t sourceFXS)
634{
635 //
636 // Read pulser calibration file from file exchage server
637 // Keep original entry from OCDB in case no new pulser calibration is available
638 //
639 TObjArray *pulserObjects=0;
640 AliTPCCalPad *pulserTmean=0;
641 AliTPCCalPad *pulserTrms=0;
642 AliTPCCalPad *pulserQmean=0;
643 AliCDBEntry* entry = GetFromOCDB("Calib", "Pulser");
644 if (entry) pulserObjects = (TObjArray*)entry->GetObject();
645 if ( pulserObjects==NULL ) {
646 Log("AliTPCPreprocsessor: No previous TPC pulser entry available.\n");
647 pulserObjects = new TObjArray;
648 }
649
650 pulserTmean = (AliTPCCalPad*)pulserObjects->FindObject("PulserTmean");
651 if ( !pulserTmean ) {
652 pulserTmean = new AliTPCCalPad("PulserTmean","PulserTmean");
653 pulserObjects->Add(pulserTmean);
654 }
655 pulserTrms = (AliTPCCalPad*)pulserObjects->FindObject("PulserTrms");
656 if ( !pulserTrms ) {
657 pulserTrms = new AliTPCCalPad("PulserTrms","PulserTrms");
658 pulserObjects->Add(pulserTrms);
659 }
660 pulserQmean = (AliTPCCalPad*)pulserObjects->FindObject("PulserQmean");
661 if ( !pulserQmean ) {
662 pulserQmean = new AliTPCCalPad("PulserQmean","PulserQmean");
663 pulserObjects->Add(pulserQmean);
664 }
665
666
667 UInt_t result=0;
668
669 Int_t nSectors = fROC->GetNSectors();
670 TList* list = GetFileSources(sourceFXS,"pulser");
671
672 if (list && list->GetEntries()>0) {
673
674// loop through all files from LDCs
675
bdffc5fb 676 Bool_t changed=false;
9f016d99 677 UInt_t index = 0;
678 while (list->At(index)!=NULL) {
679 TObjString* fileNameEntry = (TObjString*) list->At(index);
680 if (fileNameEntry!=NULL) {
681 TString fileName = GetFile(sourceFXS, "pulser",
682 fileNameEntry->GetString().Data());
683 TFile *f = TFile::Open(fileName);
684 if (!f) {
685 Log ("Error opening pulser file.");
686 result =2;
687 break;
688 }
689 AliTPCCalibPulser *calPulser;
e73181c9 690 f->GetObject("tpcCalibPulser",calPulser);
67a165ed 691 if ( !calPulser ) {
692 Log ("No pulser calibration object in file.");
693 result = 2;
694 break;
695 }
9f016d99 696
697 // replace entries for the sectors available in the present file
698
bdffc5fb 699 changed=true;
9f016d99 700 for (Int_t sector=0; sector<nSectors; sector++) {
701 AliTPCCalROC *rocTmean=calPulser->GetCalRocT0(sector);
702 if ( rocTmean ) pulserTmean->SetCalROC(rocTmean,sector);
703 AliTPCCalROC *rocTrms=calPulser->GetCalRocRMS(sector);
704 if ( rocTrms ) pulserTrms->SetCalROC(rocTrms,sector);
705 AliTPCCalROC *rocQmean=calPulser->GetCalRocQ(sector);
706 if ( rocQmean ) pulserQmean->SetCalROC(rocQmean,sector);
707 }
a480de15 708 delete calPulser;
342d3b42 709 f->Close();
9f016d99 710 }
711 ++index;
712 } // while(list)
713//
714// Store updated pedestal entry to OCDB
715//
bdffc5fb 716 if (changed) {
717 AliCDBMetaData metaData;
718 metaData.SetBeamPeriod(0);
719 metaData.SetResponsible("Haavard Helstrup");
720 metaData.SetComment("Preprocessor AliTPC data base entries.");
721
722 Bool_t storeOK = Store("Calib", "Pulser", pulserObjects, &metaData, 0, kTRUE);
723 if ( !storeOK ) ++result;
724 }
9f016d99 725 } else {
67a165ed 726 Log ("Error: no entries in input file list!");
9f016d99 727 result = 1;
728 }
729
730 return result;
731}
732
733UInt_t AliTPCPreprocessor::ExtractCE(Int_t sourceFXS)
734{
735 //
736 // Read Central Electrode file from file exchage server
737 // Keep original entry from OCDB in case no new CE calibration is available
738 //
739 TObjArray *ceObjects=0;
740 AliTPCCalPad *ceTmean=0;
741 AliTPCCalPad *ceTrms=0;
742 AliTPCCalPad *ceQmean=0;
bb30a935 743 TObjArray *rocTtime=0;
744 TObjArray *rocQtime=0;
745
9f016d99 746 AliCDBEntry* entry = GetFromOCDB("Calib", "CE");
747 if (entry) ceObjects = (TObjArray*)entry->GetObject();
748 if ( ceObjects==NULL ) {
749 Log("AliTPCPreprocsessor: No previous TPC central electrode entry available.\n");
750 ceObjects = new TObjArray;
751 }
752
bb30a935 753 Int_t nSectors = fROC->GetNSectors();
754
9f016d99 755 ceTmean = (AliTPCCalPad*)ceObjects->FindObject("CETmean");
756 if ( !ceTmean ) {
757 ceTmean = new AliTPCCalPad("CETmean","CETmean");
758 ceObjects->Add(ceTmean);
759 }
760 ceTrms = (AliTPCCalPad*)ceObjects->FindObject("CETrms");
761 if ( !ceTrms ) {
762 ceTrms = new AliTPCCalPad("CETrms","CETrms");
763 ceObjects->Add(ceTrms);
764 }
765 ceQmean = (AliTPCCalPad*)ceObjects->FindObject("CEQmean");
766 if ( !ceQmean ) {
767 ceQmean = new AliTPCCalPad("CEQmean","CEQmean");
768 ceObjects->Add(ceQmean);
769 }
38fcad6d 770 //!new from here please have a look!!!
771 rocTtime = (TObjArray*)ceObjects->FindObject("rocTtime");
772 if ( !rocTtime ) {
bb30a935 773 rocTtime = new TObjArray(nSectors);
38fcad6d 774 rocTtime->SetName("rocTtime");
775 ceObjects->Add(rocTtime);
776 }
bb30a935 777
778 rocQtime = (TObjArray*)ceObjects->FindObject("rocQtime");
38fcad6d 779 if ( !rocQtime ) {
bb30a935 780 rocQtime = new TObjArray(nSectors);
38fcad6d 781 rocQtime->SetName("rocQtime");
782 ceObjects->Add(rocQtime);
783 }
9f016d99 784
785
786 UInt_t result=0;
787
9f016d99 788 TList* list = GetFileSources(sourceFXS,"CE");
789
790 if (list && list->GetEntries()>0) {
791
792// loop through all files from LDCs
793
794 UInt_t index = 0;
795 while (list->At(index)!=NULL) {
796 TObjString* fileNameEntry = (TObjString*) list->At(index);
797 if (fileNameEntry!=NULL) {
798 TString fileName = GetFile(sourceFXS, "CE",
799 fileNameEntry->GetString().Data());
800 TFile *f = TFile::Open(fileName);
801 if (!f) {
802 Log ("Error opening central electrode file.");
803 result =2;
804 break;
805 }
806 AliTPCCalibCE *calCE;
e73181c9 807 f->GetObject("tpcCalibCE",calCE);
9f016d99 808
7c2575c4 809 if (!calCE) {
810 Log ("No valid calibCE object.");
811 result=2;
812 break;
813 }
9f016d99 814 // replace entries for the sectors available in the present file
815
816 for (Int_t sector=0; sector<nSectors; sector++) {
817 AliTPCCalROC *rocTmean=calCE->GetCalRocT0(sector);
818 if ( rocTmean ) ceTmean->SetCalROC(rocTmean,sector);
819 AliTPCCalROC *rocTrms=calCE->GetCalRocRMS(sector);
820 if ( rocTrms ) ceTrms->SetCalROC(rocTrms,sector);
821 AliTPCCalROC *rocQmean=calCE->GetCalRocQ(sector);
38fcad6d 822 if ( rocQmean ) ceQmean->SetCalROC(rocQmean,sector);
bb30a935 823 TGraph *grT=calCE->MakeGraphTimeCE(sector,0,2); // T time graph
824 if ( grT ) rocTtime->AddAt(grT,sector);
825 TGraph *grQ=calCE->MakeGraphTimeCE(sector,0,3); // Q time graph
826 if ( grQ ) rocTtime->AddAt(grQ,sector);
9f016d99 827 }
a480de15 828 delete calCE;
342d3b42 829 f->Close();
9f016d99 830 }
831 ++index;
832 } // while(list)
833//
834// Store updated pedestal entry to OCDB
835//
836 AliCDBMetaData metaData;
837 metaData.SetBeamPeriod(0);
838 metaData.SetResponsible("Haavard Helstrup");
839 metaData.SetComment("Preprocessor AliTPC data base entries.");
840
841 Bool_t storeOK = Store("Calib", "CE", ceObjects, &metaData, 0, kTRUE);
842 if ( !storeOK ) ++result;
843
844 } else {
845 Log ("Error: no entries!");
846 result = 1;
847 }
848
849 return result;
850}
dca91b3f 851//______________________________________________________________________________________________
852
853UInt_t AliTPCPreprocessor::ExtractQA(Int_t sourceFXS)
854{
855 //
856 // Read Quality Assurance file from file exchage server
857 //
858
859 UInt_t result=0;
860
861 TList* list = GetFileSources(sourceFXS,"QA");
862
863 if (list && list->GetEntries()>0) {
864
865// only one QA objetc should be available!
866
867 AliTPCdataQA *calQA;
868
869 UInt_t nentries = list->GetEntries();
870 UInt_t index=0;
871 if ( nentries > 1) Log ( "More than one QA entry. First one processed");
872 TObjString* fileNameEntry = (TObjString*) list->At(index);
873 if (fileNameEntry!=NULL) {
874 TString fileName = GetFile(sourceFXS, "QA",
875 fileNameEntry->GetString().Data());
876 TFile *f = TFile::Open(fileName);
877 if (!f) {
878 Log ("Error opening QA file.");
a2465b54 879 result =2;
880 } else {
881 f->GetObject("tpcCalibQA",calQA);
7c2575c4 882 if ( calQA ) {
dca91b3f 883//
884// Store updated pedestal entry to OCDB
885//
7c2575c4 886 AliCDBMetaData metaData;
887 metaData.SetBeamPeriod(0);
888 metaData.SetResponsible("Haavard Helstrup");
889 metaData.SetComment("Preprocessor AliTPC data base entries.");
890
891 Bool_t storeOK = Store("Calib", "QA", calQA, &metaData, 0, kTRUE);
892 if ( !storeOK ) ++result;
893 }
a2465b54 894 }
895 } else {
896 Log ("Error: no QA files on FXS!");
897 result = 2;
898 }
dca91b3f 899 } else {
a2465b54 900 Log ("Error: no QA entries in FXS list!");
dca91b3f 901 result = 1;
902 }
dca91b3f 903 return result;
904}
905
9054511b 906//______________________________________________________________________________________________
907
908
909UInt_t AliTPCPreprocessor::ExtractAltro(Int_t sourceFXS)
910{
911 //
912 // Read pulser calibration file from file exchage server
913 // Keep original entry from OCDB in case no new pulser calibration is available
914 //
915 TObjArray *altroObjects=0;
916 AliTPCCalPad *acqStart=0;
917 AliTPCCalPad *zsThr=0;
918 AliTPCCalPad *acqStop=0;
919 AliTPCCalPad *FPED=0;
920 AliTPCCalPad *masked=0;
921
922 AliCDBEntry* entry = GetFromOCDB("Calib", "Altro");
923 if (entry) altroObjects = (TObjArray*)entry->GetObject();
924 if ( altroObjects==NULL ) {
925 Log("AliTPCPreprocsessor: No previous TPC altro calibration entry available.\n");
926 altroObjects = new TObjArray;
927 }
928
929 acqStart = (AliTPCCalPad*)altroObjects->FindObject("AcqStart");
930 if ( !acqStart ) {
931 acqStart = new AliTPCCalPad("AcqStart","AcqStart");
932 altroObjects->Add(acqStart);
933 }
934 zsThr = (AliTPCCalPad*)altroObjects->FindObject("ZsThr");
935 if ( !zsThr ) {
936 zsThr = new AliTPCCalPad("ZsThr","ZsThr");
937 altroObjects->Add(zsThr);
938 }
939 FPED = (AliTPCCalPad*)altroObjects->FindObject("FPED");
940 if ( !FPED ) {
941 FPED = new AliTPCCalPad("FPED","FPED");
942 altroObjects->Add(FPED);
943 }
944 acqStop = (AliTPCCalPad*)altroObjects->FindObject("AcqStop");
945 if ( !acqStop ) {
946 acqStop = new AliTPCCalPad("AcqStop","AcqStop");
947 altroObjects->Add(acqStop);
948 }
949 masked = (AliTPCCalPad*)altroObjects->FindObject("Masked");
950 if ( !masked ) {
951 masked = new AliTPCCalPad("Masked","Masked");
952 altroObjects->Add(masked);
953 }
954
955
956
957 UInt_t result=0;
958 TString idFXS[2]={"AltroConfigA","AltroConfigC"};
959
960 Int_t nSectors = fROC->GetNSectors();
961 Bool_t changed=false;
962 for ( Int_t id=0; id<2; id++) {
963 TList* list = GetFileSources(sourceFXS,idFXS[id].Data());
964
965 if (list && list->GetEntries()>0) {
966 if (altroObjects == 0 ) altroObjects = new TObjArray;
967
968// loop through all files from LDCs
969
970 UInt_t index = 0;
971 while (list->At(index)!=NULL) {
972 TObjString* fileNameEntry = (TObjString*) list->At(index);
973 if (fileNameEntry!=NULL) {
974 TString fileName = GetFile(sourceFXS, idFXS[id].Data(),
975 fileNameEntry->GetString().Data());
976 TFile *f = TFile::Open(fileName);
977 if (!f) {
978 char message[40];
979 sprintf(message,"Error opening Altro configuration file, id = %d",id);
980 Log (message);
981 result =2;
982 break;
983 }
984 TObjArray *altroFXS;
985 f->GetObject("AltroConfig",altroFXS);
986 if ( !altroFXS ) {
987 Log ("No Altro configuration object in file.");
988 result = 2;
989 break;
990 }
991
992 // replace entries for the sectors available in the present file
993 AliTPCCalPad *acqStartFXS=(AliTPCCalPad*)altroFXS->FindObject("AcqStart");
994 AliTPCCalPad *zsThrFXS=(AliTPCCalPad*)altroFXS->FindObject("ZsThr");
995 AliTPCCalPad *acqStopFXS=(AliTPCCalPad*)altroFXS->FindObject("AcqStop");
996 AliTPCCalPad *FPEDFXS=(AliTPCCalPad*)altroFXS->FindObject("FPED");
997 AliTPCCalPad *maskedFXS=(AliTPCCalPad*)altroFXS->FindObject("Masked");
998
999 changed=true;
1000 for (Int_t sector=0; sector<nSectors; sector++) {
1001
1002 if (acqStartFXS) {
1003 AliTPCCalROC *rocAcqStart=acqStartFXS->GetCalROC(sector);
1004 if ( rocAcqStart ) acqStart->SetCalROC(rocAcqStart,sector);
1005 }
1006 if (zsThrFXS ) {
1007 AliTPCCalROC *rocZsThr=zsThrFXS->GetCalROC(sector);
1008 if ( rocZsThr ) zsThr->SetCalROC(rocZsThr,sector);
1009 }
1010 if (acqStopFXS) {
1011 AliTPCCalROC *rocAcqStop=acqStopFXS->GetCalROC(sector);
1012 if ( rocAcqStop ) acqStop->SetCalROC(rocAcqStop,sector);
1013 }
1014 if (FPEDFXS ) {
1015 AliTPCCalROC *rocFPED=FPEDFXS->GetCalROC(sector);
1016 if ( FPEDFXS ) FPED->SetCalROC(rocFPED,sector);
1017 }
1018 if (maskedFXS) {
1019 AliTPCCalROC *rocMasked=maskedFXS->GetCalROC(sector);
1020 if ( rocMasked ) masked->SetCalROC(rocMasked,sector);
1021 }
1022 }
1023 delete altroFXS;
1024 f->Close();
1025 }
1026 ++index;
1027 } // while(list)
1028 } else {
1029 Log ("Error: no entries in input file list!");
1030 result = 1;
1031 }
1032
1033 } // for - id
1034//
1035// Store updated pedestal entry to OCDB
1036//
1037 if (changed) {
1038 AliCDBMetaData metaData;
1039 metaData.SetBeamPeriod(0);
1040 metaData.SetResponsible("Haavard Helstrup");
1041 metaData.SetComment("Preprocessor AliTPC data base entries.");
1042
1043 Bool_t storeOK = Store("Calib", "AltroConfig", altroObjects, &metaData, 0, kTRUE);
1044 if ( !storeOK ) ++result;
1045 }
1046
1047 return result;
1048}