Fixes for wrong use of const causing PW.CAST_TO_QUALIFIED_TYPE defect in Coverity
[u/mrichter/AliRoot.git] / TPC / Base / 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"
70f224dd 30#include "AliTPCCalibRaw.h"
dca91b3f 31#include "AliTPCdataQA.h"
eeeac1b2 32#include "ARVersion.h"
9e66a8dd 33#include "TFile.h"
7b54c8e9 34#include "TTree.h"
bb30a935 35#include "TGraph.h"
7b54c8e9 36#include "TEnv.h"
bb30a935 37#include "TParameter.h"
54472e4f 38
39#include <TTimeStamp.h>
40
a7dce0bc 41const Int_t kValCutTemp = 100; // discard temperatures > 100 degrees
42const Int_t kDiffCutTemp = 5; // discard temperature differences > 5 degrees
2b00f997 43const Double_t kHighVoltageDifference = 1e-4; // don't record High Voltage points
44 // differing by less than 1e-4 from
45 // previous point.
bb30a935 46const TString kPedestalRunType = "PEDESTAL"; // pedestal run identifier
9054511b 47const TString kPulserRunType = "PULSER"; // pulser run identifier
bdffc5fb 48const TString kPhysicsRunType = "PHYSICS"; // physics run identifier
9054511b 49const TString kCosmicRunType = "COSMIC"; // cosmic run identifier
50const TString kLaserRunType = "LASER"; // laser run identifier
9c754ce7 51const TString kDaqRunType = "DAQ"; // DAQ run identifier
87d77b35 52const TString kAmandaTemp = "TPC_PT_%d_TEMPERATURE"; // Amanda string for temperature entries
f6b5fa33 53const TString kAmandaDDL = "DDL%d"; // Amanda string for list of active DDLs
54const Int_t kNumDDL = 216; // number of TPC DDLs
55const Int_t kFirstDDL = 768; // identifier of first DDL
bee89eeb 56//const Double_t kFitFraction = 0.7; // Fraction of DCS sensor fits required
68b512ca 57const Double_t kFitFraction = -1.0; // Don't require minimum number of fits in commissioning run
09a746c5 58const Int_t kNumPressureSensors = 3; // number of pressure sensors
59const char* kPressureSensorNames[kNumPressureSensors] = {
60 "CavernAtmosPressure",
61 "CavernAtmosPressure2",
62 "SurfaceAtmosPressure" };
1fc96a8a 63const Int_t kMinCESectors = 32; // minimum number of sectors (per side)
64 // to accept CE calibration
09a746c5 65
cf4216a3 66
54472e4f 67//
68// This class is the SHUTTLE preprocessor for the TPC detector.
54472e4f 69//
70
71ClassImp(AliTPCPreprocessor)
72
73//______________________________________________________________________________________________
6d07bf74 74AliTPCPreprocessor::AliTPCPreprocessor(AliShuttleInterface* shuttle) :
75 AliPreprocessor("TPC",shuttle),
09a746c5 76 fConfEnv(0), fTemp(0), fHighVoltage(0), fHighVoltageStat(0), fGoofie(0),
77 fPressure(0), fConfigOK(kTRUE), fROC(0)
54472e4f 78{
79 // constructor
a7dce0bc 80 fROC = AliTPCROC::Instance();
72534123 81
82 // define run types to be processed
83
84 AddRunType(kPedestalRunType);
85 AddRunType(kPulserRunType);
86 AddRunType(kPhysicsRunType);
72534123 87 AddRunType(kCosmicRunType);
88 AddRunType(kLaserRunType);
89 AddRunType(kDaqRunType);
90
54472e4f 91}
72df5829 92//______________________________________________________________________________________________
f4a89669 93 AliTPCPreprocessor::AliTPCPreprocessor(const AliTPCPreprocessor& ) :
94 AliPreprocessor("TPC",0),
09a746c5 95 fConfEnv(0), fTemp(0), fHighVoltage(0), fHighVoltageStat(0), fGoofie(0),
96 fPressure(0), fConfigOK(kTRUE), fROC(0)
f4a89669 97 {
98
99 Fatal("AliTPCPreprocessor", "copy constructor not implemented");
f7f602cc 100//
101// // fTemp = new AliTPCSensorTempArray(*(org.fTemp));
f4a89669 102 }
54472e4f 103
104//______________________________________________________________________________________________
105AliTPCPreprocessor::~AliTPCPreprocessor()
106{
107 // destructor
a7dce0bc 108
54472e4f 109 delete fTemp;
bdffc5fb 110 delete fHighVoltage;
795dbd3b 111 delete fHighVoltageStat;
112 delete fGoofie;
09a746c5 113 delete fPressure;
54472e4f 114}
72df5829 115//______________________________________________________________________________________________
116AliTPCPreprocessor& AliTPCPreprocessor::operator = (const AliTPCPreprocessor& )
117{
118 Fatal("operator =", "assignment operator not implemented");
119 return *this;
120}
121
54472e4f 122
123//______________________________________________________________________________________________
124void AliTPCPreprocessor::Initialize(Int_t run, UInt_t startTime,
125 UInt_t endTime)
126{
bb30a935 127
09a746c5 128 AliPreprocessor::Initialize(run, startTime, endTime);
54472e4f 129
130 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
f4a89669 131 TTimeStamp((time_t)startTime,0).AsString(),
132 TTimeStamp((time_t)endTime,0).AsString()));
54472e4f 133
7b54c8e9 134 // Preprocessor configuration
135
37092b2b 136 AliCDBEntry* entry = GetFromOCDB("Config", "Preprocessor");
7b54c8e9 137 if (entry) fConfEnv = (TEnv*) entry->GetObject();
138 if ( fConfEnv==0 ) {
7b54c8e9 139 Log("AliTPCPreprocsessor: Preprocessor Config OCDB entry missing.\n");
37092b2b 140 fConfigOK = kFALSE;
141 return;
7b54c8e9 142 }
143
18eade96 144 // Temperature sensors
145
136e44f7 146 TTree *confTree = 0;
147
148 TString tempConf = fConfEnv->GetValue("Temperature","ON");
149 tempConf.ToUpper();
150 if (tempConf != "OFF" ) {
7b54c8e9 151 entry = GetFromOCDB("Config", "Temperature");
f7f602cc 152 if (entry) confTree = (TTree*) entry->GetObject();
18eade96 153 if ( confTree==0 ) {
18eade96 154 Log("AliTPCPreprocsessor: Temperature Config OCDB entry missing.\n");
155 fConfigOK = kFALSE;
f7f602cc 156 return;
18eade96 157 }
09a746c5 158 fTemp = new AliTPCSensorTempArray(startTime, endTime, confTree, kAmandaTemp);
18eade96 159 fTemp->SetValCut(kValCutTemp);
160 fTemp->SetDiffCut(kDiffCutTemp);
136e44f7 161 }
18eade96 162
bdffc5fb 163 // High voltage measurements
164
136e44f7 165 TString hvConf = fConfEnv->GetValue("HighVoltage","ON");
166 hvConf.ToUpper();
167 if (hvConf != "OFF" ) {
bdffc5fb 168 confTree=0;
169 entry=0;
170 entry = GetFromOCDB("Config", "HighVoltage");
171 if (entry) confTree = (TTree*) entry->GetObject();
172 if ( confTree==0 ) {
173 Log("AliTPCPreprocsessor: High Voltage Config OCDB entry missing.\n");
174 fConfigOK = kFALSE;
175 return;
176 }
03d57022 177 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
178 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
179 fHighVoltage = new AliDCSSensorArray (UInt_t(timeStart),
180 UInt_t(timeEnd), confTree);
bff20895 181 }
9d2ce539 182
183 // High voltage status values
184
bff20895 185 TString hvStatConf = fConfEnv->GetValue("HighVoltageStat","ON");
186 hvStatConf.ToUpper();
187 if (hvStatConf != "OFF" ) {
9d2ce539 188 confTree=0;
189 entry=0;
190 entry = GetFromOCDB("Config", "HighVoltageStat");
191 if (entry) confTree = (TTree*) entry->GetObject();
192 if ( confTree==0 ) {
193 Log("AliTPCPreprocsessor: High Voltage Status Config OCDB entry missing.\n");
194 fConfigOK = kFALSE;
195 return;
196 }
fe7f3fe2 197 fHighVoltageStat = new AliDCSSensorArray(startTime, endTime, confTree);
bdffc5fb 198 }
b6e9fd45 199
200 // Goofie values
201
202 TString goofieConf = fConfEnv->GetValue("Goofie","ON");
203 goofieConf.ToUpper();
204 if (goofieConf != "OFF" ) {
205 confTree=0;
206 entry=0;
207 entry = GetFromOCDB("Config", "Goofie");
208 if (entry) confTree = (TTree*) entry->GetObject();
209 if ( confTree==0 ) {
210 Log("AliTPCPreprocsessor: Goofie Config OCDB entry missing.\n");
211 fConfigOK = kFALSE;
212 return;
213 }
09a746c5 214 fGoofie = new AliDCSSensorArray(startTime, endTime, confTree);
b6e9fd45 215 }
216
09a746c5 217 // Pressure values
218
219 TString runType = GetRunType();
220
221 if( runType == kPhysicsRunType ||
222 runType == kLaserRunType ) {
223 TString pressureConf = fConfEnv->GetValue("Pressure","ON");
224 pressureConf.ToUpper();
225 if (pressureConf != "OFF" ) {
226 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumPressureSensors);
227 for(Int_t j = 0; j < kNumPressureSensors; j++) {
228 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
229 sens->SetStringID(kPressureSensorNames[j]);
230 }
231 fPressure = new AliDCSSensorArray(startTime, endTime, array);
232 }
233 }
54472e4f 234}
235
236//______________________________________________________________________________________________
237UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
238{
239 // Fills data into TPC calibrations objects
240
54472e4f 241 // Amanda servers provide information directly through dcsAliasMap
242
bb30a935 243
a7dce0bc 244 if (!fConfigOK) return 9;
136e44f7 245 UInt_t result = 0;
bb30a935 246 TObjArray *resultArray = new TObjArray();
247 TString errorHandling = fConfEnv->GetValue("ErrorHandling","ON");
248 errorHandling.ToUpper();
249 TObject * status;
250
251 UInt_t dcsResult=0;
ff7d4b88 252 if (!dcsAliasMap) {
253 dcsResult=1;
254 } else {
255 if (dcsAliasMap->GetEntries() == 0 ) dcsResult=1;
256 }
cf4216a3 257 status = new TParameter<int>("dcsResult",dcsResult);
258 resultArray->Add(status);
bb30a935 259
260
a7dce0bc 261 TString runType = GetRunType();
262
cf4216a3 263 if ( dcsResult == 0 ) {
264
54472e4f 265 // Temperature sensors are processed by AliTPCCalTemp
72df5829 266
cf4216a3 267 TString tempConf = fConfEnv->GetValue("Temperature","ON");
268 tempConf.ToUpper();
269 if (tempConf != "OFF" ) {
270 UInt_t tempResult = MapTemperature(dcsAliasMap);
c589a949 271 if ( tempConf != "TRY") result+=tempResult;
cf4216a3 272 status = new TParameter<int>("tempResult",tempResult);
273 resultArray->Add(status);
274 }
18eade96 275
bdffc5fb 276 // High Voltage recordings
277
278
cf4216a3 279 TString hvConf = fConfEnv->GetValue("HighVoltage","ON");
280 hvConf.ToUpper();
281 if (hvConf != "OFF" ) {
282 UInt_t hvResult = MapHighVoltage(dcsAliasMap);
c589a949 283 if (hvConf != "TRY") result+=hvResult;
cf4216a3 284 status = new TParameter<int>("hvResult",hvResult);
285 resultArray->Add(status);
286 }
f7f602cc 287
cf4216a3 288 // Goofie values
b6e9fd45 289
290
cf4216a3 291 TString goofieConf = fConfEnv->GetValue("Goofie","ON");
292 goofieConf.ToUpper();
293 if (goofieConf != "OFF" ) {
294 UInt_t goofieResult = MapGoofie(dcsAliasMap);
c589a949 295 if (goofieConf != "TRY") result+=goofieResult;
cf4216a3 296 status = new TParameter<int>("goofieResult",goofieResult);
297 resultArray->Add(status);
298 }
09a746c5 299
300 // Pressure values
301
302 if( runType == kPhysicsRunType ||
303 runType == kLaserRunType ) {
304
305 TString pressureConf = fConfEnv->GetValue("Pressure","ON");
306 pressureConf.ToUpper();
307 if (pressureConf != "OFF" ) {
308 UInt_t pressureResult = MapPressure(dcsAliasMap);
309 status = new TParameter<int>("pressureResult",pressureResult);
310 resultArray->Add(status);
311 }
312 }
cf4216a3 313 }
54472e4f 314 // Other calibration information will be retrieved through FXS files
a7dce0bc 315 // examples:
54472e4f 316 // TList* fileSourcesDAQ = GetFile(AliShuttleInterface::kDAQ, "pedestals");
317 // const char* fileNamePed = GetFile(AliShuttleInterface::kDAQ, "pedestals", "LDC1");
318 //
319 // TList* fileSourcesHLT = GetFile(AliShuttleInterface::kHLT, "calib");
320 // const char* fileNameHLT = GetFile(AliShuttleInterface::kHLT, "calib", "LDC1");
321
9f016d99 322 // pedestal entries
54472e4f 323
a7dce0bc 324 if(runType == kPedestalRunType) {
68b512ca 325 Int_t numSources = 1;
326 Int_t pedestalSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
7b54c8e9 327 TString source = fConfEnv->GetValue("Pedestal","DAQ");
328 source.ToUpper();
136e44f7 329 if (source != "OFF" ) {
330 if ( source == "HLT") pedestalSource[0] = AliShuttleInterface::kHLT;
331 if (!GetHLTStatus()) pedestalSource[0] = AliShuttleInterface::kDAQ;
332 if (source == "HLTDAQ" ) {
333 numSources=2;
334 pedestalSource[0] = AliShuttleInterface::kHLT;
335 pedestalSource[1] = AliShuttleInterface::kDAQ;
336 }
337 if (source == "DAQHLT" ) numSources=2;
338 UInt_t pedestalResult=0;
339 for (Int_t i=0; i<numSources; i++ ) {
453bd596 340 pedestalResult = ExtractPedestals(pedestalSource[i]);
136e44f7 341 if ( pedestalResult == 0 ) break;
342 }
343 result += pedestalResult;
bb30a935 344 status = new TParameter<int>("pedestalResult",pedestalResult);
345 resultArray->Add(status);
68b512ca 346 }
a7dce0bc 347 }
348
9f016d99 349 // pulser trigger processing
350
68b512ca 351 if(runType == kPulserRunType) {
352 Int_t numSources = 1;
353 Int_t pulserSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
9f016d99 354 TString source = fConfEnv->GetValue("Pulser","DAQ");
355 source.ToUpper();
136e44f7 356 if ( source != "OFF") {
357 if ( source == "HLT") pulserSource[0] = AliShuttleInterface::kHLT;
358 if (!GetHLTStatus()) pulserSource[0] = AliShuttleInterface::kDAQ;
359 if (source == "HLTDAQ" ) {
360 numSources=2;
361 pulserSource[0] = AliShuttleInterface::kHLT;
362 pulserSource[1] = AliShuttleInterface::kDAQ;
363 }
364 if (source == "DAQHLT" ) numSources=2;
c589a949 365 if (source == "TRY" ) numSources=2;
136e44f7 366 UInt_t pulserResult=0;
367 for (Int_t i=0; i<numSources; i++ ) {
368 pulserResult = ExtractPulser(pulserSource[i]);
369 if ( pulserResult == 0 ) break;
370 }
c589a949 371 if (source != "TRY") result += pulserResult;
bb30a935 372 status = new TParameter<int>("pulserResult",pulserResult);
373 resultArray->Add(status);
68b512ca 374 }
9f016d99 375 }
376
70f224dd 377
378// raw calibration processing
379
380 if(runType == kPhysicsRunType) {
381 Int_t numSources = 1;
382 Int_t rawSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
383 TString source = fConfEnv->GetValue("Raw","DAQ");
384 source.ToUpper();
385 if ( source != "OFF") {
386 if ( source == "HLT") rawSource[0] = AliShuttleInterface::kHLT;
387 if (!GetHLTStatus()) rawSource[0] = AliShuttleInterface::kDAQ;
388 if (source == "HLTDAQ" ) {
389 numSources=2;
390 rawSource[0] = AliShuttleInterface::kHLT;
391 rawSource[1] = AliShuttleInterface::kDAQ;
392 }
393 if (source == "DAQHLT" ) numSources=2;
c589a949 394 if (source == "TRY" ) numSources=2;
70f224dd 395 UInt_t rawResult=0;
396 for (Int_t i=0; i<numSources; i++ ) {
397 rawResult = ExtractRaw(rawSource[i]);
398 if ( rawResult == 0 ) break;
399 }
c589a949 400 if (source != "TRY" )result += rawResult;
70f224dd 401 status = new TParameter<int>("rawResult",rawResult);
402 resultArray->Add(status);
403 }
404 }
405
406
9054511b 407 // Altro configuration
408
409
410 TString altroConf = fConfEnv->GetValue("AltroConf","ON");
cf4216a3 411 altroConf.ToUpper();
9054511b 412 if (altroConf != "OFF" ) {
f6b5fa33 413 UInt_t altroResult = ExtractAltro(AliShuttleInterface::kDCS,dcsAliasMap);
c589a949 414 if (altroConf != "TRY" ) result+=altroResult;
9054511b 415 status = new TParameter<int>("altroResult",altroResult);
416 resultArray->Add(status);
417 }
68b512ca 418
419
9f016d99 420 // Central Electrode processing
421
9054511b 422 if( runType == kPhysicsRunType ||
6f3699dd 423 runType == kLaserRunType ) {
68b512ca 424
425 Int_t numSources = 1;
426 Int_t ceSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
9f016d99 427 TString source = fConfEnv->GetValue("CE","DAQ");
428 source.ToUpper();
136e44f7 429 if ( source != "OFF" ) {
430 if ( source == "HLT") ceSource[0] = AliShuttleInterface::kHLT;
431 if (!GetHLTStatus()) ceSource[0] = AliShuttleInterface::kDAQ;
432 if (source == "HLTDAQ" ) {
68b512ca 433 numSources=2;
434 ceSource[0] = AliShuttleInterface::kHLT;
435 ceSource[1] = AliShuttleInterface::kDAQ;
136e44f7 436 }
437 if (source == "DAQHLT" ) numSources=2;
c589a949 438 if (source == "TRY" ) numSources=2;
136e44f7 439 UInt_t ceResult=0;
440 for (Int_t i=0; i<numSources; i++ ) {
441 ceResult = ExtractCE(ceSource[i]);
442 if ( ceResult == 0 ) break;
443 }
6f3699dd 444
445 // only flag error if CE result is missing from LASER runs
446 // -- for PHYSICS run do CE processing if data available
447
dee76880 448 if ( runType == kLaserRunType && source != "TRY" && ceResult<10 ) result += ceResult;
bb30a935 449 status = new TParameter<int>("ceResult",ceResult);
450 resultArray->Add(status);
dca91b3f 451
452 numSources = 1;
453 Int_t qaSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
5e5c1e83 454 source = fConfEnv->GetValue("QA","DAQ");
dca91b3f 455 source.ToUpper();
456 if ( source != "OFF" ) {
457 if ( source == "HLT") qaSource[0] = AliShuttleInterface::kHLT;
458 if (!GetHLTStatus()) qaSource[0] = AliShuttleInterface::kDAQ;
459 if (source == "HLTDAQ" ) {
460 numSources=2;
461 qaSource[0] = AliShuttleInterface::kHLT;
462 qaSource[1] = AliShuttleInterface::kDAQ;
463 }
464 if (source == "DAQHLT" ) numSources=2;
c589a949 465 if (source == "TRY" ) numSources=2;
dca91b3f 466 UInt_t qaResult=0;
467 for (Int_t i=0; i<numSources; i++ ) {
468 qaResult = ExtractQA(qaSource[i]);
469 if ( qaResult == 0 ) break;
470 }
471// result += qaResult;
472 if ( qaResult !=0 ) Log ("ExtractQA failed, no QA entry available.");
473 status = new TParameter<int>("qaResult",qaResult);
474 resultArray->Add(status);
68b512ca 475 }
dca91b3f 476 }
9f016d99 477 }
136e44f7 478
c589a949 479// Store component status to OCDB
480
481 AliCDBMetaData metaData;
482 metaData.SetBeamPeriod(0);
483 metaData.SetResponsible("Haavard Helstrup");
0492edf5 484 metaData.SetAliRootVersion(ALIROOT_BRANCH);
c589a949 485 metaData.SetComment("Preprocessor AliTPC status.");
f085dc93 486 Bool_t storeOK = Store("Calib", "PreprocStatus", resultArray, &metaData, 0, kFALSE);
487 if (!storeOK) Log ("Unable to store preprocessor status entry");
488
c589a949 489 resultArray->Delete();
490 delete resultArray;
491
492 if (errorHandling == "OFF" ) return 0;
493 return result;
494
54472e4f 495}
496//______________________________________________________________________________________________
497UInt_t AliTPCPreprocessor::MapTemperature(TMap* dcsAliasMap)
498{
499
500 // extract DCS temperature maps. Perform fits to save space
501
72df5829 502 UInt_t result=0;
54472e4f 503 TMap *map = fTemp->ExtractDCS(dcsAliasMap);
504 if (map) {
505 fTemp->MakeSplineFit(map);
68b512ca 506 Double_t fitFraction = 1.0*fTemp->NumFits()/fTemp->NumSensors();
67a165ed 507 if (fitFraction > kFitFraction ) {
508 AliInfo(Form("Temperature values extracted, fits performed.\n"));
509 } else {
510 Log ("Too few temperature maps fitted. \n");
511 result = 9;
512 }
54472e4f 513 } else {
67a165ed 514 Log("No temperature map extracted. \n");
72df5829 515 result=9;
54472e4f 516 }
517 delete map;
518 // Now store the final CDB file
a7dce0bc 519
520 if ( result == 0 ) {
72df5829 521 AliCDBMetaData metaData;
54472e4f 522 metaData.SetBeamPeriod(0);
523 metaData.SetResponsible("Haavard Helstrup");
0492edf5 524 metaData.SetAliRootVersion(ALIROOT_BRANCH);
54472e4f 525 metaData.SetComment("Preprocessor AliTPC data base entries.");
526
a7dce0bc 527 Bool_t storeOK = Store("Calib", "Temperature", fTemp, &metaData, 0, kFALSE);
528 if ( !storeOK ) result=1;
529
72df5829 530 }
54472e4f 531
532 return result;
7b54c8e9 533
54472e4f 534}
09a746c5 535//______________________________________________________________________________________________
536UInt_t AliTPCPreprocessor::MapPressure(TMap* dcsAliasMap)
537{
538
539 // extract DCS pressure maps. Perform fits to save space
540
541 UInt_t result=0;
542 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
543 if (map) {
544 fPressure->MakeSplineFit(map);
545 Double_t fitFraction = 1.0*fPressure->NumFits()/fPressure->NumSensors();
546 if (fitFraction > kFitFraction ) {
1a63b1b0 547 AliInfo(Form("Pressure values extracted, fits performed.\n"));
09a746c5 548 } else {
549 Log ("Too few pressure maps fitted. \n");
550 result = 9;
551 }
552 } else {
553 Log("No pressure map extracted. \n");
554 result=9;
555 }
556 delete map;
557 return result;
558}
7b54c8e9 559
bdffc5fb 560//______________________________________________________________________________________________
561UInt_t AliTPCPreprocessor::MapHighVoltage(TMap* dcsAliasMap)
562{
563
564 // extract DCS HV maps. Perform fits to save space
565
566 UInt_t result=0;
567 TMap *map = fHighVoltage->ExtractDCS(dcsAliasMap);
568 if (map) {
379fc89a 569 fHighVoltage->ClearFit();
2b00f997 570 fHighVoltage->RemoveGraphDuplicates(kHighVoltageDifference);
571 // don't keep new point if too similar to previous one
379fc89a 572 fHighVoltage->SetGraph(map);
bdffc5fb 573 } else {
574 Log("No high voltage recordings extracted. \n");
575 result=9;
576 }
577 delete map;
9d2ce539 578
bff20895 579 TString hvStatConf = fConfEnv->GetValue("HighVoltageStat","ON");
580 hvStatConf.ToUpper();
581 if (hvStatConf != "OFF" ) {
582 TMap *map2 = fHighVoltageStat->ExtractDCS(dcsAliasMap);
583 if (map2) {
dca91b3f 584 fHighVoltageStat->ClearFit();
585 fHighVoltageStat->SetGraph(map2);
bff20895 586 } else {
587 Log("No high voltage status recordings extracted. \n");
588 result=9;
589 }
590 delete map2;
9d2ce539 591
bff20895 592 // add status maps to high voltage sensor array
9d2ce539 593
bff20895 594 fHighVoltage->AddSensors(fHighVoltageStat);
595 }
bdffc5fb 596 // Now store the final CDB file
597
598 if ( result == 0 ) {
599 AliCDBMetaData metaData;
600 metaData.SetBeamPeriod(0);
601 metaData.SetResponsible("Haavard Helstrup");
0492edf5 602 metaData.SetAliRootVersion(ALIROOT_BRANCH);
bdffc5fb 603 metaData.SetComment("Preprocessor AliTPC data base entries.");
604
605 Bool_t storeOK = Store("Calib", "HighVoltage", fHighVoltage, &metaData, 0, kFALSE);
606 if ( !storeOK ) result=1;
607
608 }
609
610 return result;
611
612}
613
b6e9fd45 614//______________________________________________________________________________________________
615UInt_t AliTPCPreprocessor::MapGoofie(TMap* dcsAliasMap)
616{
617
618 // extract DCS Goofie maps. Do not perform fits (low update rate)
619
620 UInt_t result=0;
621
622 TMap *map = fGoofie->ExtractDCS(dcsAliasMap);
623 if (map) {
624 fGoofie->ClearFit();
625 fGoofie->SetGraph(map);
626 } else {
627 Log("No Goofie recordings extracted. \n");
628 result=9;
629 }
630 delete map;
631
632 // Now store the final CDB file
633
634 if ( result == 0 ) {
635 AliCDBMetaData metaData;
636 metaData.SetBeamPeriod(0);
637 metaData.SetResponsible("Haavard Helstrup");
0492edf5 638 metaData.SetAliRootVersion(ALIROOT_BRANCH);
b6e9fd45 639 metaData.SetComment("Preprocessor AliTPC data base entries.");
640
641 Bool_t storeOK = Store("Calib", "Goofie", fGoofie, &metaData, 0, kFALSE);
642 if ( !storeOK ) result=1;
643
644 }
645
646 return result;
647
648}
649
7b54c8e9 650
a7dce0bc 651//______________________________________________________________________________________________
7b54c8e9 652
653UInt_t AliTPCPreprocessor::ExtractPedestals(Int_t sourceFXS)
a7dce0bc 654{
655 //
656 // Read pedestal file from file exchage server
657 // Keep original entry from OCDB in case no new pedestals are available
658 //
ccf58a39 659 AliTPCCalPad *calPadPedOCDB=0;
a7dce0bc 660 AliCDBEntry* entry = GetFromOCDB("Calib", "Pedestals");
ccf58a39 661 if (entry) calPadPedOCDB = (AliTPCCalPad*)entry->GetObject();
662 if ( calPadPedOCDB==NULL ) {
a7dce0bc 663 Log("AliTPCPreprocsessor: No previous TPC pedestal entry available.\n");
7b54c8e9 664 }
665
ccf58a39 666 AliTPCCalPad *calPadRMSOCDB=0;
d63b9ad7 667 entry = GetFromOCDB("Calib", "PadNoise");
ccf58a39 668 if (entry) calPadRMSOCDB = (AliTPCCalPad*)entry->GetObject();
669 if ( calPadRMSOCDB==NULL ) {
7b54c8e9 670 Log("AliTPCPreprocsessor: No previous TPC noise entry available.\n");
a7dce0bc 671 }
672
ccf58a39 673 AliTPCCalPad* calPadPed = new AliTPCCalPad("PedestalsMean","PedestalsMean");
674 AliTPCCalPad* calPadRMS = new AliTPCCalPad("PedestalsRMS","PedestalsRMS");
675
7b54c8e9 676
a7dce0bc 677 UInt_t result=0;
678
679 Int_t nSectors = fROC->GetNSectors();
ccf58a39 680 TVectorD foundSectorsPed(nSectors);
681 foundSectorsPed=0;
682 TVectorD foundSectorsRMS(nSectors);
683 foundSectorsRMS=0;
684
7b54c8e9 685 TList* list = GetFileSources(sourceFXS,"pedestals");
9f016d99 686
687 if (list && list->GetEntries()>0) {
a7dce0bc 688
689// loop through all files from LDCs
690
bdffc5fb 691 Bool_t changed=false;
a7dce0bc 692 UInt_t index = 0;
693 while (list->At(index)!=NULL) {
694 TObjString* fileNameEntry = (TObjString*) list->At(index);
695 if (fileNameEntry!=NULL) {
7b54c8e9 696 TString fileName = GetFile(sourceFXS, "pedestals",
a7dce0bc 697 fileNameEntry->GetString().Data());
698 TFile *f = TFile::Open(fileName);
9f016d99 699 if (!f) {
700 Log ("Error opening pedestal file.");
701 result =2;
702 break;
703 }
a7dce0bc 704 AliTPCCalibPedestal *calPed;
e73181c9 705 f->GetObject("tpcCalibPedestal",calPed);
67a165ed 706 if ( !calPed ) {
707 Log ("No pedestal calibration object in file.");
708 result = 2;
709 break;
710 }
a7dce0bc 711
712 // replace entries for the sectors available in the present file
713
bdffc5fb 714 changed=true;
c9c23d80 715 for (Int_t sector=0; sector<nSectors; sector++) {
7b54c8e9 716 AliTPCCalROC *rocPed=calPed->GetCalRocPedestal(sector, kFALSE);
ccf58a39 717 if ( rocPed ) {
718 AliTPCCalROC* roc=calPadPed->GetCalROC(sector);
719 roc->Add(rocPed,1);
720 foundSectorsPed[sector]++;
721 }
7b54c8e9 722 AliTPCCalROC *rocRMS=calPed->GetCalRocRMS(sector, kFALSE);
ccf58a39 723 if ( rocRMS ) {
724 AliTPCCalROC* roc=calPadRMS->GetCalROC(sector);
725 roc->Add(rocRMS,1);
726 foundSectorsRMS[sector]++;
727 }
a7dce0bc 728 }
a480de15 729 delete calPed;
342d3b42 730 f->Close();
a7dce0bc 731 }
732 ++index;
733 } // while(list)
ccf58a39 734
735//
736// Check if calibration is complete -- otherwise take from old OCDB entry
737
738// inner sectors
739 for (Int_t sector=0; sector<nSectors/2; sector++) {
740 if (foundSectorsPed[sector] < 1 ) {
f3652e39 741 if (calPadPedOCDB) {
742 AliTPCCalROC *rocOCDB=calPadPedOCDB->GetCalROC(sector);
743 calPadPed->SetCalROC(rocOCDB,sector);
744 } else {
745 const int mess_length=100;
746 char message[mess_length];
747 snprintf(message,mess_length,"Missing pedestals for sector %d - also not available from previous OCDB entry.\n",
748 sector);
749 Log (message);
750 result = 2;
751 }
ccf58a39 752 }
753 if (foundSectorsRMS[sector] < 1 ) {
f3652e39 754 if (calPadRMSOCDB) {
755 AliTPCCalROC *rocOCDB=calPadRMSOCDB->GetCalROC(sector);
756 calPadRMS->SetCalROC(rocOCDB,sector);
757 } else {
758 const int mess_length=100;
759 char message[mess_length];
760 snprintf(message,mess_length,"Missing pedestal RMS for sector %d - also not available from previous OCDB entry.\n",
761 sector);
762 Log (message);
763 result = 2;
764 }
ccf58a39 765 }
766 }
f3652e39 767
ccf58a39 768// outer sectors -- two updates needed
f3652e39 769
ccf58a39 770 for (Int_t sector=nSectors/2; sector<nSectors; sector++) {
771 if (foundSectorsPed[sector] < 2 ) {
f3652e39 772 if (calPadPedOCDB) {
773 AliTPCCalROC *rocOCDB=calPadPedOCDB->GetCalROC(sector);
774 calPadPed->SetCalROC(rocOCDB,sector);
775 } else {
776 const int mess_length=100;
777 char message[mess_length];
778 snprintf(message,mess_length,"Missing pedestals for sector %d - also not available from previous OCDB entry.\n",
779 sector);
780 Log (message);
781 result = 2;
782 }
783
ccf58a39 784 }
785 if (foundSectorsRMS[sector] < 2 ) {
f3652e39 786 if (calPadRMSOCDB) {
787 AliTPCCalROC *rocOCDB=calPadRMSOCDB->GetCalROC(sector);
788 calPadRMS->SetCalROC(rocOCDB,sector);
789 } else {
790 const int mess_length=100;
791 char message[mess_length];
792 snprintf(message,mess_length,"Missing pedestal RMS for sector %d - also not available from previous OCDB entry.\n",
793 sector);
794 Log (message);
795 result = 2;
796 }
797
ccf58a39 798 }
799 }
800
801
a7dce0bc 802//
803// Store updated pedestal entry to OCDB
804//
bdffc5fb 805 if (changed) {
806 AliCDBMetaData metaData;
807 metaData.SetBeamPeriod(0);
808 metaData.SetResponsible("Haavard Helstrup");
0492edf5 809 metaData.SetAliRootVersion(ALIROOT_BRANCH);
bdffc5fb 810 metaData.SetComment("Preprocessor AliTPC data base entries.");
811
812 Bool_t storeOK = Store("Calib", "Pedestals", calPadPed, &metaData, 0, kTRUE);
813 if ( !storeOK ) ++result;
814 storeOK = Store("Calib", "PadNoise", calPadRMS, &metaData, 0, kTRUE);
815 if ( !storeOK ) ++result;
816 }
9f016d99 817 } else {
cf4216a3 818 Log ("Error: no entries in pedestal file list!");
9f016d99 819 result = 1;
7b54c8e9 820 }
a7dce0bc 821
795dbd3b 822 delete calPadPed;
823 delete calPadRMS;
ccf58a39 824 delete calPadPedOCDB;
825 delete calPadRMSOCDB;
795dbd3b 826
a7dce0bc 827 return result;
828}
7b54c8e9 829
830//______________________________________________________________________________________________
831
832
9f016d99 833UInt_t AliTPCPreprocessor::ExtractPulser(Int_t sourceFXS)
834{
835 //
836 // Read pulser calibration file from file exchage server
837 // Keep original entry from OCDB in case no new pulser calibration is available
838 //
ccf58a39 839
840 TObjArray *pulserObjects = new TObjArray;
841 TObjArray *pulserObjectsOCDB=0;
842
9f016d99 843 AliCDBEntry* entry = GetFromOCDB("Calib", "Pulser");
ccf58a39 844 if (entry) pulserObjectsOCDB = (TObjArray*)entry->GetObject();
845 if ( pulserObjectsOCDB==NULL ) {
9f016d99 846 Log("AliTPCPreprocsessor: No previous TPC pulser entry available.\n");
9f016d99 847 }
848
ccf58a39 849 AliTPCCalPad *pulserTmean = new AliTPCCalPad("PulserTmean","PulserTmean");
850 pulserObjects->Add(pulserTmean);
851
852 AliTPCCalPad *pulserTrms = new AliTPCCalPad("PulserTrms","PulserTrms");
853 pulserObjects->Add(pulserTrms);
854
855 AliTPCCalPad *pulserQmean = new AliTPCCalPad("PulserQmean","PulserQmean");
856 pulserObjects->Add(pulserQmean);
857
9f016d99 858
859
860 UInt_t result=0;
861
862 Int_t nSectors = fROC->GetNSectors();
ccf58a39 863 TVectorD foundTmean(nSectors);
864 foundTmean=0;
865 TVectorD foundTrms(nSectors);
866 foundTrms=0;
867 TVectorD foundQmean(nSectors);
868 foundQmean=0;
869
870
9f016d99 871 TList* list = GetFileSources(sourceFXS,"pulser");
872
873 if (list && list->GetEntries()>0) {
874
875// loop through all files from LDCs
876
bdffc5fb 877 Bool_t changed=false;
9f016d99 878 UInt_t index = 0;
879 while (list->At(index)!=NULL) {
880 TObjString* fileNameEntry = (TObjString*) list->At(index);
881 if (fileNameEntry!=NULL) {
882 TString fileName = GetFile(sourceFXS, "pulser",
883 fileNameEntry->GetString().Data());
884 TFile *f = TFile::Open(fileName);
885 if (!f) {
886 Log ("Error opening pulser file.");
887 result =2;
888 break;
889 }
890 AliTPCCalibPulser *calPulser;
e73181c9 891 f->GetObject("tpcCalibPulser",calPulser);
67a165ed 892 if ( !calPulser ) {
893 Log ("No pulser calibration object in file.");
894 result = 2;
895 break;
896 }
9f016d99 897
898 // replace entries for the sectors available in the present file
899
bdffc5fb 900 changed=true;
9f016d99 901 for (Int_t sector=0; sector<nSectors; sector++) {
902 AliTPCCalROC *rocTmean=calPulser->GetCalRocT0(sector);
ccf58a39 903 if ( rocTmean ) {
904 AliTPCCalROC* roc=pulserTmean->GetCalROC(sector);
905 roc->Add(rocTmean,1);
906 foundTmean[sector]++;
907 }
9f016d99 908 AliTPCCalROC *rocTrms=calPulser->GetCalRocRMS(sector);
ccf58a39 909 if ( rocTrms ) {
910 AliTPCCalROC* roc=pulserTrms->GetCalROC(sector);
911 roc->Add(rocTrms,1);
912 foundTrms[sector]++;
913 }
9f016d99 914 AliTPCCalROC *rocQmean=calPulser->GetCalRocQ(sector);
ccf58a39 915 if ( rocQmean ) {
916 AliTPCCalROC* roc=pulserQmean->GetCalROC(sector);
917 roc->Add(rocQmean,1);
918 foundQmean[sector]++;
919 }
9f016d99 920 }
a480de15 921 delete calPulser;
342d3b42 922 f->Close();
9f016d99 923 }
924 ++index;
925 } // while(list)
ccf58a39 926
927
928
929
930if (pulserObjectsOCDB) {
931 AliTPCCalPad* pulserTmeanOCDB = (AliTPCCalPad*)pulserObjectsOCDB->FindObject("PulserTmean");
932 AliTPCCalPad* pulserTrmsOCDB = (AliTPCCalPad*)pulserObjectsOCDB->FindObject("PulserTrms");
933 AliTPCCalPad* pulserQmeanOCDB = (AliTPCCalPad*)pulserObjectsOCDB->FindObject("PulserQmean");
934
935//
936// Check if calibration is complete -- otherwise take from old OCDB entry
937
938// inner sectors
939 for (Int_t sector=0; sector<nSectors/2; sector++) {
940 if (foundTmean[sector] < 1 ) {
941 if (pulserTmeanOCDB) {
942 AliTPCCalROC* rocOCDB = pulserTmeanOCDB->GetCalROC(sector);
943 if ( rocOCDB ) pulserTmean->SetCalROC(rocOCDB,sector);
944 }
945 }
946 if (foundTrms[sector] < 1 ) {
947 if (pulserTrmsOCDB) {
948 AliTPCCalROC* rocOCDB = pulserTrmsOCDB->GetCalROC(sector);
949 if ( rocOCDB ) pulserTrms->SetCalROC(rocOCDB,sector);
950 }
951 }
952 if (foundQmean[sector] < 1 ) {
953 if (pulserQmeanOCDB) {
954 AliTPCCalROC* rocOCDB = pulserQmeanOCDB->GetCalROC(sector);
955 if ( rocOCDB ) pulserQmean->SetCalROC(rocOCDB,sector);
956 }
957 }
958 }
959
960// outer sectors -- two updates needed
961
962 for (Int_t sector=0; sector<nSectors/2; sector++) {
963 if (foundTmean[sector] < 2 ) {
964 if (pulserTmeanOCDB) {
965 AliTPCCalROC* rocOCDB = pulserTmeanOCDB->GetCalROC(sector);
966 if ( rocOCDB ) pulserTmean->SetCalROC(rocOCDB,sector);
967 }
968 }
969 if (foundTrms[sector] < 2 ) {
970 if (pulserTrmsOCDB) {
971 AliTPCCalROC* rocOCDB = pulserTrmsOCDB->GetCalROC(sector);
972 if ( rocOCDB ) pulserTrms->SetCalROC(rocOCDB,sector);
973 }
974 }
975 if (foundQmean[sector] < 2 ) {
976 if (pulserQmeanOCDB) {
977 AliTPCCalROC* rocOCDB = pulserQmeanOCDB->GetCalROC(sector);
978 if ( rocOCDB ) pulserQmean->SetCalROC(rocOCDB,sector);
979 }
980 }
981
982 }
983}
984
9f016d99 985//
986// Store updated pedestal entry to OCDB
987//
bdffc5fb 988 if (changed) {
989 AliCDBMetaData metaData;
990 metaData.SetBeamPeriod(0);
991 metaData.SetResponsible("Haavard Helstrup");
0492edf5 992 metaData.SetAliRootVersion(ALIROOT_BRANCH);
bdffc5fb 993 metaData.SetComment("Preprocessor AliTPC data base entries.");
994
995 Bool_t storeOK = Store("Calib", "Pulser", pulserObjects, &metaData, 0, kTRUE);
996 if ( !storeOK ) ++result;
997 }
9f016d99 998 } else {
cf4216a3 999 Log ("Error: no entries in pulser file list!");
9f016d99 1000 result = 1;
1001 }
795dbd3b 1002 pulserObjects->Delete();
1003 delete pulserObjects;
f3652e39 1004 if (pulserObjectsOCDB) pulserObjectsOCDB->Delete();
ccf58a39 1005 delete pulserObjectsOCDB;
9f016d99 1006
1007 return result;
1008}
1009
70f224dd 1010//______________________________________________________________________________________________
1011
1012
1013UInt_t AliTPCPreprocessor::ExtractRaw(Int_t sourceFXS)
1014{
1015 //
1016 // Read Raw calibration file from file exchage server
1017 //
1018
1019 UInt_t result=0;
90581ff1 1020 TObjArray* rawArray = new TObjArray;
70f224dd 1021
9b1478f9 1022 TList* list = GetFileSources(sourceFXS,"tpcCalibRaw");
70f224dd 1023
1024 if (list && list->GetEntries()>0) {
1025
1026// loop through all files
1027
1028 UInt_t index = 0;
1029 while (list->At(index)!=NULL) {
1030 TObjString* fileNameEntry = (TObjString*) list->At(index);
1031 if (fileNameEntry!=NULL) {
1032 TString fileName = GetFile(sourceFXS, "tpcCalibRaw",
1033 fileNameEntry->GetString().Data());
1034 TFile *f = TFile::Open(fileName);
1035 if (!f) {
1036 Log ("Error opening raw file.");
1037 result =2;
1038 break;
1039 }
90581ff1 1040 AliTPCCalibRaw *calRaw;
70f224dd 1041 f->GetObject("tpcCalibRaw",calRaw);
1042 if ( !calRaw ) {
1043 Log ("No raw calibration object in file.");
1044 result = 2;
1045 break;
1046 }
90581ff1 1047 rawArray->Add(calRaw);
70f224dd 1048 f->Close();
1049 }
1050 ++index;
1051 } // while(list)
1052//
1053// Store updated pedestal entry to OCDB
1054//
1055 AliCDBMetaData metaData;
1056 metaData.SetBeamPeriod(0);
1057 metaData.SetResponsible("Haavard Helstrup");
0492edf5 1058 metaData.SetAliRootVersion(ALIROOT_BRANCH);
70f224dd 1059 metaData.SetComment("Preprocessor AliTPC data base entries.");
1060
90581ff1 1061 Bool_t storeOK = Store("Calib", "Raw", rawArray, &metaData, 0, kTRUE);
70f224dd 1062 if ( !storeOK ) ++result;
1063 } else {
cf4216a3 1064 Log ("Error: no entries in raw file list!");
70f224dd 1065 result = 1;
1066 }
795dbd3b 1067
1068 rawArray->Delete();
1069 delete rawArray;
70f224dd 1070
1071 return result;
1072}
1073//______________________________________________________________________________________________
1074
9f016d99 1075UInt_t AliTPCPreprocessor::ExtractCE(Int_t sourceFXS)
1076{
1077 //
1078 // Read Central Electrode file from file exchage server
9f016d99 1079 //
e2d642a2 1080 //
1081 AliTPCCalPad *ceTmean=0;
1082 AliTPCCalPad *ceTrms=0;
1083 AliTPCCalPad *ceQmean=0;
1084 TObjArray *rocTtime=0;
1085 TObjArray *rocQtime=0;
1086
1087 TObjArray *ceObjects= new TObjArray;
1088
1089
1090 Int_t nSectors = fROC->GetNSectors();
1091
1092 ceTmean = new AliTPCCalPad("CETmean","CETmean");
1093 ceObjects->Add(ceTmean);
1094
1095 ceTrms = new AliTPCCalPad("CETrms","CETrms");
1096 ceObjects->Add(ceTrms);
1097
1098 ceQmean = new AliTPCCalPad("CEQmean","CEQmean");
1099 ceObjects->Add(ceQmean);
1100
1101 rocTtime = new TObjArray(nSectors+2); // also make room for A and C side average
1102 rocTtime->SetName("rocTtime");
1103 ceObjects->Add(rocTtime);
1104
1105 rocQtime = new TObjArray(nSectors);
1106 rocQtime->SetName("rocQtime");
1107 ceObjects->Add(rocQtime);
1108
1109 //=== new part
1110 TObjArray *arrFitGraphs=new TObjArray;
1111 arrFitGraphs->SetName("ceFitsDrift");
1112 ceObjects->Add(arrFitGraphs);
70f224dd 1113
09a746c5 1114// Temperature maps
e2d642a2 1115
1116 if (fTemp) {
df8595b9 1117 AliTPCSensorTempArray *tempMap = new AliTPCSensorTempArray(*fTemp);
1118 tempMap->SetNameTitle("TempMap","TempMap");
1119 ceObjects->Add(tempMap);
e2d642a2 1120 }
1121
09a746c5 1122// Pressure maps
e2d642a2 1123
1124 if (fPressure) {
1125 AliDCSSensor *sensor=0, *sensorCopy=0;
1126 for (Int_t isensor=0; isensor<kNumPressureSensors; ++isensor ) {
09a746c5 1127 sensor = fPressure->GetSensor(kPressureSensorNames[isensor]);
b5886f0f 1128 if (sensor) {
e2d642a2 1129 sensorCopy = new AliDCSSensor(*sensor);
1130 sensorCopy->SetNameTitle(kPressureSensorNames[isensor],kPressureSensorNames[isensor]);
1131 ceObjects->Add(sensorCopy);
b5886f0f 1132 }
e2d642a2 1133 }
1134 }
1135
1136 UInt_t result=0;
1137
1138 TList* list = GetFileSources(sourceFXS,"CE");
1139
1140 if (list && list->GetEntries()>0) {
1141
9f016d99 1142// loop through all files from LDCs
e2d642a2 1143
9f016d99 1144 UInt_t index = 0;
1145 while (list->At(index)!=NULL) {
e2d642a2 1146 TObjString* fileNameEntry = (TObjString*) list->At(index);
1147 if (fileNameEntry!=NULL) {
9f016d99 1148 TString fileName = GetFile(sourceFXS, "CE",
e2d642a2 1149 fileNameEntry->GetString().Data());
6d3584e9 1150 AliTPCCalibCE *calCE=AliTPCCalibCE::ReadFromFile(fileName.Data());
e2d642a2 1151
7c2575c4 1152 if (!calCE) {
e2d642a2 1153 Log ("No valid calibCE object.");
1154 result=2;
1155 break;
1156 }
9f016d99 1157 // replace entries for the sectors available in the present file
e2d642a2 1158
9f016d99 1159 for (Int_t sector=0; sector<nSectors; sector++) {
e2d642a2 1160 AliTPCCalROC *rocTmean=calCE->GetCalRocT0(sector);
1161 if ( rocTmean ) ceTmean->SetCalROC(rocTmean,sector);
1162 AliTPCCalROC *rocTrms=calCE->GetCalRocRMS(sector);
1163 if ( rocTrms ) ceTrms->SetCalROC(rocTrms,sector);
1164 AliTPCCalROC *rocQmean=calCE->GetCalRocQ(sector);
1165 if ( rocQmean ) ceQmean->SetCalROC(rocQmean,sector);
1166 TGraph *grT=calCE->MakeGraphTimeCE(sector,0,2); // T time graph
1167 if ( grT ) rocTtime->AddAt(grT,sector);
1168 TGraph *grQ=calCE->MakeGraphTimeCE(sector,0,3); // Q time graph
1169 if ( grQ ) rocQtime->AddAt(grQ,sector);
9f016d99 1170 }
e2d642a2 1171
1172 TGraph *grT=calCE->MakeGraphTimeCE(-1,0,2); // A side average
1173 if ( grT ) {
1174 rocTtime->AddAt(grT,nSectors);
1175 } else {
31c50f68 1176 result=10;
e2d642a2 1177 }
1178 grT=calCE->MakeGraphTimeCE(-2,0,2); // C side average
1179 if ( grT ) {
1180 rocTtime->AddAt(grT,nSectors+1);
1181 } else {
31c50f68 1182 result=10;
e2d642a2 1183 }
1fc96a8a 1184
e2d642a2 1185 delete calCE;
9f016d99 1186 }
e2d642a2 1187 ++index;
9f016d99 1188 } // while(list)
1fc96a8a 1189//
1190// Check number of calibrated sectors per side
1191//
1192 Int_t aside=0, cside=0;
1193 for (Int_t ind=0; ind<nSectors/4; ind++ ) {
1194 TGraph *grT=(TGraph*)rocTtime->At(ind);
1195 if (grT) aside++;
1196 grT=(TGraph*)rocTtime->At(ind+nSectors/2);
1197 if (grT) aside++;
1198 grT=(TGraph*)rocTtime->At(ind+nSectors/4);
1199 if (grT) cside++;
1200 grT=(TGraph*)rocTtime->At(ind+3*nSectors/4);
1201 if (grT) cside++;
1202 }
f085dc93 1203 if ( (aside<kMinCESectors) && (cside<kMinCESectors) ) {
1204 Log (Form("ExtractCE: Too few fitted sectors: Aside =%d, Cside=%d\n",
1205 aside, cside)) ;
1206 result=10;
1207 }
e2d642a2 1208
1209 //
1210 //=== New CE part
1211 // if it is validated this part needs to be modified again
1212 // currently its only processed if there is a valid standard CE object
1213 //
1214 list = GetFileSources(sourceFXS,"CEnew");
1215
1216 if (result==0 && list && list->GetEntries()>0) {
1217
1218// loop through all files from LDCs
1219
1220 UInt_t index2 = 0;
1221 while (list->At(index2)!=NULL) {
1222 TObjString* fileNameEntry = (TObjString*) list->At(index2);
1223 if (fileNameEntry!=NULL) {
1224 TString fileName = GetFile(sourceFXS, "CEnew",
1225 fileNameEntry->GetString().Data());
82bf5037 1226 AliTPCCalibCE *calCE=AliTPCCalibCE::ReadFromFile(fileName.Data());
e2d642a2 1227
1228 if (!calCE) {
1229 Log ("No valid new calibCE object.");
1230// result=2;
1231 break;
1232 }
1233
1234 TIter nextObj(calCE->GetArrFitGraphs());
1235 TObject *obj=0x0;
1236 while ( (obj=nextObj()) ){
1237 arrFitGraphs->Add(obj->Clone());
1238 }
1239 delete calCE;
e2d642a2 1240 }
1241 ++index2;
1242 }
1243 }
1244
9f016d99 1245//
1246// Store updated pedestal entry to OCDB
1247//
1248 AliCDBMetaData metaData;
1249 metaData.SetBeamPeriod(0);
1250 metaData.SetResponsible("Haavard Helstrup");
0492edf5 1251 metaData.SetAliRootVersion(ALIROOT_BRANCH);
9f016d99 1252 metaData.SetComment("Preprocessor AliTPC data base entries.");
e2d642a2 1253
31c50f68 1254 if ( result == 0 ) {
e2d642a2 1255 Bool_t storeOK = Store("Calib", "CE", ceObjects, &metaData, 0, kTRUE);
1256 if ( !storeOK ) ++result;
31c50f68 1257 } else {
e2d642a2 1258 Log ("Warning: Average time graphs not available - no OCDB entry written");
1259 }
9f016d99 1260 } else {
cf4216a3 1261 Log ("Error: no CE entries available from FXS!");
9f016d99 1262 result = 1;
1263 }
e2d642a2 1264
795dbd3b 1265 ceObjects->Delete();
1266 delete ceObjects;
1267
9f016d99 1268 return result;
1269}
dca91b3f 1270//______________________________________________________________________________________________
1271
1272UInt_t AliTPCPreprocessor::ExtractQA(Int_t sourceFXS)
1273{
1274 //
1275 // Read Quality Assurance file from file exchage server
1276 //
1277
1278 UInt_t result=0;
1279
1280 TList* list = GetFileSources(sourceFXS,"QA");
1281
1282 if (list && list->GetEntries()>0) {
1283
ccf58a39 1284// only one QA object should be available!
dca91b3f 1285
1286 AliTPCdataQA *calQA;
1287
1288 UInt_t nentries = list->GetEntries();
1289 UInt_t index=0;
1290 if ( nentries > 1) Log ( "More than one QA entry. First one processed");
1291 TObjString* fileNameEntry = (TObjString*) list->At(index);
1292 if (fileNameEntry!=NULL) {
1293 TString fileName = GetFile(sourceFXS, "QA",
1294 fileNameEntry->GetString().Data());
1295 TFile *f = TFile::Open(fileName);
1296 if (!f) {
1297 Log ("Error opening QA file.");
a2465b54 1298 result =2;
1299 } else {
1300 f->GetObject("tpcCalibQA",calQA);
7c2575c4 1301 if ( calQA ) {
dca91b3f 1302//
1303// Store updated pedestal entry to OCDB
1304//
7c2575c4 1305 AliCDBMetaData metaData;
1306 metaData.SetBeamPeriod(0);
1307 metaData.SetResponsible("Haavard Helstrup");
0492edf5 1308 metaData.SetAliRootVersion(ALIROOT_BRANCH);
7c2575c4 1309 metaData.SetComment("Preprocessor AliTPC data base entries.");
1310
cf4216a3 1311 Bool_t storeOK = Store("Calib", "QA", calQA, &metaData, 0, kFALSE);
7c2575c4 1312 if ( !storeOK ) ++result;
795dbd3b 1313
1314 delete calQA;
7c2575c4 1315 }
a2465b54 1316 }
1317 } else {
1318 Log ("Error: no QA files on FXS!");
1319 result = 2;
1320 }
dca91b3f 1321 } else {
a2465b54 1322 Log ("Error: no QA entries in FXS list!");
dca91b3f 1323 result = 1;
1324 }
dca91b3f 1325 return result;
1326}
1327
9054511b 1328//______________________________________________________________________________________________
1329
1330
f6b5fa33 1331UInt_t AliTPCPreprocessor::ExtractAltro(Int_t sourceFXS, TMap* dcsMap)
9054511b 1332{
1333 //
f6b5fa33 1334 // Read Altro configuration file from file exchage server
9054511b 1335 // Keep original entry from OCDB in case no new pulser calibration is available
1336 //
1337 TObjArray *altroObjects=0;
1338 AliTPCCalPad *acqStart=0;
1339 AliTPCCalPad *zsThr=0;
1340 AliTPCCalPad *acqStop=0;
1341 AliTPCCalPad *FPED=0;
1342 AliTPCCalPad *masked=0;
cf4216a3 1343 AliTPCCalPad *k1=0, *k2=0, *k3=0;
1344 AliTPCCalPad *l1=0, *l2=0, *l3=0;
1345 TMap *mapRCUconfig=0;
9054511b 1346
14ae505e 1347 AliCDBEntry* entry = GetFromOCDB("Calib", "AltroConfig");
9054511b 1348 if (entry) altroObjects = (TObjArray*)entry->GetObject();
1349 if ( altroObjects==NULL ) {
1350 Log("AliTPCPreprocsessor: No previous TPC altro calibration entry available.\n");
1351 altroObjects = new TObjArray;
1352 }
1353
1354 acqStart = (AliTPCCalPad*)altroObjects->FindObject("AcqStart");
1355 if ( !acqStart ) {
1356 acqStart = new AliTPCCalPad("AcqStart","AcqStart");
1357 altroObjects->Add(acqStart);
1358 }
1359 zsThr = (AliTPCCalPad*)altroObjects->FindObject("ZsThr");
1360 if ( !zsThr ) {
1361 zsThr = new AliTPCCalPad("ZsThr","ZsThr");
1362 altroObjects->Add(zsThr);
1363 }
1364 FPED = (AliTPCCalPad*)altroObjects->FindObject("FPED");
1365 if ( !FPED ) {
1366 FPED = new AliTPCCalPad("FPED","FPED");
1367 altroObjects->Add(FPED);
1368 }
1369 acqStop = (AliTPCCalPad*)altroObjects->FindObject("AcqStop");
1370 if ( !acqStop ) {
1371 acqStop = new AliTPCCalPad("AcqStop","AcqStop");
1372 altroObjects->Add(acqStop);
1373 }
1374 masked = (AliTPCCalPad*)altroObjects->FindObject("Masked");
1375 if ( !masked ) {
1376 masked = new AliTPCCalPad("Masked","Masked");
1377 altroObjects->Add(masked);
1378 }
cf4216a3 1379 k1 = (AliTPCCalPad*)altroObjects->FindObject("K1");
1380 if ( !k1 ) {
1381 k1 = new AliTPCCalPad("K1","K1");
1382 altroObjects->Add(k1);
1383 }
1384 k2 = (AliTPCCalPad*)altroObjects->FindObject("K2");
1385 if ( !k2 ) {
1386 k2 = new AliTPCCalPad("K2","K2");
1387 altroObjects->Add(k2);
1388 }
1389 k3 = (AliTPCCalPad*)altroObjects->FindObject("K3");
1390 if ( !k3 ) {
1391 k3 = new AliTPCCalPad("K3","K3");
1392 altroObjects->Add(k3);
1393 }
1394 l1 = (AliTPCCalPad*)altroObjects->FindObject("L1");
1395 if ( !l1 ) {
1396 l1 = new AliTPCCalPad("L1","L1");
1397 altroObjects->Add(l1);
1398 }
1399 l2 = (AliTPCCalPad*)altroObjects->FindObject("L2");
1400 if ( !l2 ) {
1401 l2 = new AliTPCCalPad("L2","L2");
1402 altroObjects->Add(l2);
1403 }
1404 l3 = (AliTPCCalPad*)altroObjects->FindObject("L3");
1405 if ( !l3 ) {
1406 l3 = new AliTPCCalPad("L3","L3");
1407 altroObjects->Add(l3);
1408 }
1409 mapRCUconfig = (TMap*)altroObjects->FindObject("RCUconfig");
1410 if (!mapRCUconfig) {
1411 mapRCUconfig = new TMap();
1412 mapRCUconfig->SetName("RCUconfig");
1413 altroObjects->Add(mapRCUconfig);
1414 }
9054511b 1415
1416
1417 UInt_t result=0;
1418 TString idFXS[2]={"AltroConfigA","AltroConfigC"};
1419
1420 Int_t nSectors = fROC->GetNSectors();
1421 Bool_t changed=false;
f6b5fa33 1422 if (altroObjects == 0 ) altroObjects = new TObjArray;
1423
1424// extract list of active DDLs
1425
f3652e39 1426 if (dcsMap) {
f6b5fa33 1427 Bool_t found;
1428 TString arrDDL(kNumDDL);
2b00f997 1429 arrDDL.Append('x',kNumDDL);
f6b5fa33 1430 for ( Int_t iDDL = 0; iDDL<kNumDDL; iDDL++ ) {
1431 TString stringID = Form (kAmandaDDL.Data(),iDDL+kFirstDDL);
1432 TPair *pair = (TPair*)dcsMap->FindObject(stringID.Data());
1433 found = false;
1434 if ( pair ) {
1435 TObjArray *valueSet=(TObjArray*)pair->Value();
1436 if ( valueSet) {
1437 AliDCSValue *val = (AliDCSValue*)valueSet->At(0);
2b00f997 1438 if (val) {
1439 found = val->GetBool();
1440 if (found){
1441 arrDDL[iDDL] = '1';
1442 } else {
1443 arrDDL[iDDL] = '0';
1444 }
1445 }
f6b5fa33 1446 }
1447 }
f6b5fa33 1448 }
1449 TObjString *ddlArray = new TObjString;
1450 ddlArray->SetString(arrDDL);
1451 TMap *activeDDL = new TMap;
1452 activeDDL->SetName("DDLArray");
1453 TObjString *key = new TObjString("DDLArray");
1454 activeDDL->Add(key,ddlArray);
1455 altroObjects->Add(activeDDL);
1456 changed=true;
f3652e39 1457 } else {
1458 Log ("ExtractAltro: No DCS map available. Active DDL list cannot be obtained.");
1459 result = 3;
1460 }
f6b5fa33 1461
1462// extract Altro configuration files
1463
9054511b 1464 for ( Int_t id=0; id<2; id++) {
1465 TList* list = GetFileSources(sourceFXS,idFXS[id].Data());
1466
1467 if (list && list->GetEntries()>0) {
9054511b 1468
1469// loop through all files from LDCs
1470
1471 UInt_t index = 0;
1472 while (list->At(index)!=NULL) {
1473 TObjString* fileNameEntry = (TObjString*) list->At(index);
1474 if (fileNameEntry!=NULL) {
1475 TString fileName = GetFile(sourceFXS, idFXS[id].Data(),
1476 fileNameEntry->GetString().Data());
1477 TFile *f = TFile::Open(fileName);
1478 if (!f) {
ff7d4b88 1479 const int mess_length=40;
1480 char message[mess_length];
1481 snprintf(message,mess_length,"Error opening Altro configuration file, id = %d",id);
9054511b 1482 Log (message);
1483 result =2;
1484 break;
1485 }
1486 TObjArray *altroFXS;
1487 f->GetObject("AltroConfig",altroFXS);
1488 if ( !altroFXS ) {
1489 Log ("No Altro configuration object in file.");
1490 result = 2;
1491 break;
1492 }
1493
1494 // replace entries for the sectors available in the present file
1495 AliTPCCalPad *acqStartFXS=(AliTPCCalPad*)altroFXS->FindObject("AcqStart");
1496 AliTPCCalPad *zsThrFXS=(AliTPCCalPad*)altroFXS->FindObject("ZsThr");
1497 AliTPCCalPad *acqStopFXS=(AliTPCCalPad*)altroFXS->FindObject("AcqStop");
1498 AliTPCCalPad *FPEDFXS=(AliTPCCalPad*)altroFXS->FindObject("FPED");
1499 AliTPCCalPad *maskedFXS=(AliTPCCalPad*)altroFXS->FindObject("Masked");
cf4216a3 1500 AliTPCCalPad *k1FXS=(AliTPCCalPad*)altroFXS->FindObject("K1");
1501 AliTPCCalPad *k2FXS=(AliTPCCalPad*)altroFXS->FindObject("K2");
1502 AliTPCCalPad *k3FXS=(AliTPCCalPad*)altroFXS->FindObject("K3");
1503 AliTPCCalPad *l1FXS=(AliTPCCalPad*)altroFXS->FindObject("L1");
1504 AliTPCCalPad *l2FXS=(AliTPCCalPad*)altroFXS->FindObject("L2");
1505 AliTPCCalPad *l3FXS=(AliTPCCalPad*)altroFXS->FindObject("L3");
1506 TMap *mapRCUconfigFXS = (TMap*)altroFXS->FindObject("RCUconfig");
1507 TIterator *mapFXSiter = mapRCUconfigFXS->MakeIterator();
1508
9054511b 1509 changed=true;
1510 for (Int_t sector=0; sector<nSectors; sector++) {
1511
1512 if (acqStartFXS) {
1513 AliTPCCalROC *rocAcqStart=acqStartFXS->GetCalROC(sector);
1514 if ( rocAcqStart ) acqStart->SetCalROC(rocAcqStart,sector);
1515 }
1516 if (zsThrFXS ) {
1517 AliTPCCalROC *rocZsThr=zsThrFXS->GetCalROC(sector);
1518 if ( rocZsThr ) zsThr->SetCalROC(rocZsThr,sector);
1519 }
1520 if (acqStopFXS) {
1521 AliTPCCalROC *rocAcqStop=acqStopFXS->GetCalROC(sector);
1522 if ( rocAcqStop ) acqStop->SetCalROC(rocAcqStop,sector);
1523 }
1524 if (FPEDFXS ) {
1525 AliTPCCalROC *rocFPED=FPEDFXS->GetCalROC(sector);
2d47cfd4 1526 if ( rocFPED ) FPED->SetCalROC(rocFPED,sector);
9054511b 1527 }
1528 if (maskedFXS) {
1529 AliTPCCalROC *rocMasked=maskedFXS->GetCalROC(sector);
1530 if ( rocMasked ) masked->SetCalROC(rocMasked,sector);
1531 }
cf4216a3 1532 if (k1FXS) {
1533 AliTPCCalROC *rocK1=k1FXS->GetCalROC(sector);
1534 if ( rocK1 ) k1->SetCalROC(rocK1,sector);
1535 }
1536 if (k2FXS) {
1537 AliTPCCalROC *rocK2=k2FXS->GetCalROC(sector);
1538 if ( rocK2 ) k2->SetCalROC(rocK2,sector);
1539 }
1540 if (k3FXS) {
1541 AliTPCCalROC *rocK3=k3FXS->GetCalROC(sector);
1542 if ( rocK3 ) k3->SetCalROC(rocK3,sector);
1543 }
1544 if (l1FXS) {
1545 AliTPCCalROC *rocL1=l1FXS->GetCalROC(sector);
1546 if ( rocL1 ) l1->SetCalROC(rocL1,sector);
1547 }
1548 if (l2FXS) {
1549 AliTPCCalROC *rocL2=l2FXS->GetCalROC(sector);
1550 if ( rocL2 ) l2->SetCalROC(rocL2,sector);
1551 }
1552 if (l3FXS) {
1553 AliTPCCalROC *rocL3=l3FXS->GetCalROC(sector);
1554 if ( rocL3 ) l3->SetCalROC(rocL3,sector);
1555 }
1556 }
1557 if (mapRCUconfigFXS) {
1558 Int_t mapEntries = mapRCUconfigFXS->GetEntries();
1559 TObjString* keyFXS;
1560 TVectorF* vecFXS;
1561 TVectorF* vec; // nSectors = 72 (total number of inner/outer sectors)
1562 for (Int_t i=0; i<mapEntries; ++i) {
1563 keyFXS=(TObjString*)mapFXSiter->Next();
1564 vecFXS=(TVectorF*)mapRCUconfigFXS->GetValue(keyFXS);
1565 vec=(TVectorF*)mapRCUconfig->GetValue(keyFXS);
1566 if (!vec) {
1567 vec = new TVectorF(3*nSectors);
1568 *vec = -1;
1569 mapRCUconfig->Add(keyFXS,vec);
1570 }
1571 if (vec->GetNoElements() != 3*nSectors ) {
1572 vec->ResizeTo(3*nSectors);
1573 }
1574 if (id==0) { // A side
1575 vec->SetSub(0,vecFXS->GetSub(0,nSectors/2-1));
1576 vec->SetSub(nSectors,vecFXS->GetSub(nSectors,2*nSectors-1));
1577 } else { // C side
1578 vec->SetSub(nSectors/2,vecFXS->GetSub(nSectors/2,nSectors-1));
1579 vec->SetSub(2*nSectors,vecFXS->GetSub(2*nSectors,3*nSectors-1));
1580 }
1581 }
9054511b 1582 }
1583 delete altroFXS;
1584 f->Close();
1585 }
1586 ++index;
1587 } // while(list)
1588 } else {
cf4216a3 1589 Log ("Error: no entries in AltroConfig file list!");
9054511b 1590 result = 1;
1591 }
1592
1593 } // for - id
1594//
1595// Store updated pedestal entry to OCDB
1596//
1597 if (changed) {
1598 AliCDBMetaData metaData;
1599 metaData.SetBeamPeriod(0);
1600 metaData.SetResponsible("Haavard Helstrup");
0492edf5 1601 metaData.SetAliRootVersion(ALIROOT_BRANCH);
9054511b 1602 metaData.SetComment("Preprocessor AliTPC data base entries.");
1603
dbc10140 1604 Bool_t storeOK = Store("Calib", "AltroConfig", altroObjects, &metaData, 0, kFALSE);
9054511b 1605 if ( !storeOK ) ++result;
1606 }
1607
795dbd3b 1608 altroObjects->Delete();
1609 delete altroObjects;
1610
9054511b 1611 return result;
1612}