Bug fix discovered by coverity. Had no impact on raw data, because it affects a metho...
[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"
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;
cf4216a3 252 if (!dcsAliasMap) dcsResult=1;
253 if (dcsAliasMap->GetEntries() == 0 ) dcsResult=1;
254 status = new TParameter<int>("dcsResult",dcsResult);
255 resultArray->Add(status);
bb30a935 256
257
a7dce0bc 258 TString runType = GetRunType();
259
cf4216a3 260 if ( dcsResult == 0 ) {
261
54472e4f 262 // Temperature sensors are processed by AliTPCCalTemp
72df5829 263
cf4216a3 264 TString tempConf = fConfEnv->GetValue("Temperature","ON");
265 tempConf.ToUpper();
266 if (tempConf != "OFF" ) {
267 UInt_t tempResult = MapTemperature(dcsAliasMap);
c589a949 268 if ( tempConf != "TRY") result+=tempResult;
cf4216a3 269 status = new TParameter<int>("tempResult",tempResult);
270 resultArray->Add(status);
271 }
18eade96 272
bdffc5fb 273 // High Voltage recordings
274
275
cf4216a3 276 TString hvConf = fConfEnv->GetValue("HighVoltage","ON");
277 hvConf.ToUpper();
278 if (hvConf != "OFF" ) {
279 UInt_t hvResult = MapHighVoltage(dcsAliasMap);
c589a949 280 if (hvConf != "TRY") result+=hvResult;
cf4216a3 281 status = new TParameter<int>("hvResult",hvResult);
282 resultArray->Add(status);
283 }
f7f602cc 284
cf4216a3 285 // Goofie values
b6e9fd45 286
287
cf4216a3 288 TString goofieConf = fConfEnv->GetValue("Goofie","ON");
289 goofieConf.ToUpper();
290 if (goofieConf != "OFF" ) {
291 UInt_t goofieResult = MapGoofie(dcsAliasMap);
c589a949 292 if (goofieConf != "TRY") result+=goofieResult;
cf4216a3 293 status = new TParameter<int>("goofieResult",goofieResult);
294 resultArray->Add(status);
295 }
09a746c5 296
297 // Pressure values
298
299 if( runType == kPhysicsRunType ||
300 runType == kLaserRunType ) {
301
302 TString pressureConf = fConfEnv->GetValue("Pressure","ON");
303 pressureConf.ToUpper();
304 if (pressureConf != "OFF" ) {
305 UInt_t pressureResult = MapPressure(dcsAliasMap);
306 status = new TParameter<int>("pressureResult",pressureResult);
307 resultArray->Add(status);
308 }
309 }
cf4216a3 310 }
54472e4f 311 // Other calibration information will be retrieved through FXS files
a7dce0bc 312 // examples:
54472e4f 313 // TList* fileSourcesDAQ = GetFile(AliShuttleInterface::kDAQ, "pedestals");
314 // const char* fileNamePed = GetFile(AliShuttleInterface::kDAQ, "pedestals", "LDC1");
315 //
316 // TList* fileSourcesHLT = GetFile(AliShuttleInterface::kHLT, "calib");
317 // const char* fileNameHLT = GetFile(AliShuttleInterface::kHLT, "calib", "LDC1");
318
9f016d99 319 // pedestal entries
54472e4f 320
a7dce0bc 321 if(runType == kPedestalRunType) {
68b512ca 322 Int_t numSources = 1;
323 Int_t pedestalSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
7b54c8e9 324 TString source = fConfEnv->GetValue("Pedestal","DAQ");
325 source.ToUpper();
136e44f7 326 if (source != "OFF" ) {
327 if ( source == "HLT") pedestalSource[0] = AliShuttleInterface::kHLT;
328 if (!GetHLTStatus()) pedestalSource[0] = AliShuttleInterface::kDAQ;
329 if (source == "HLTDAQ" ) {
330 numSources=2;
331 pedestalSource[0] = AliShuttleInterface::kHLT;
332 pedestalSource[1] = AliShuttleInterface::kDAQ;
333 }
334 if (source == "DAQHLT" ) numSources=2;
335 UInt_t pedestalResult=0;
336 for (Int_t i=0; i<numSources; i++ ) {
453bd596 337 pedestalResult = ExtractPedestals(pedestalSource[i]);
136e44f7 338 if ( pedestalResult == 0 ) break;
339 }
340 result += pedestalResult;
bb30a935 341 status = new TParameter<int>("pedestalResult",pedestalResult);
342 resultArray->Add(status);
68b512ca 343 }
a7dce0bc 344 }
345
9f016d99 346 // pulser trigger processing
347
68b512ca 348 if(runType == kPulserRunType) {
349 Int_t numSources = 1;
350 Int_t pulserSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
9f016d99 351 TString source = fConfEnv->GetValue("Pulser","DAQ");
352 source.ToUpper();
136e44f7 353 if ( source != "OFF") {
354 if ( source == "HLT") pulserSource[0] = AliShuttleInterface::kHLT;
355 if (!GetHLTStatus()) pulserSource[0] = AliShuttleInterface::kDAQ;
356 if (source == "HLTDAQ" ) {
357 numSources=2;
358 pulserSource[0] = AliShuttleInterface::kHLT;
359 pulserSource[1] = AliShuttleInterface::kDAQ;
360 }
361 if (source == "DAQHLT" ) numSources=2;
c589a949 362 if (source == "TRY" ) numSources=2;
136e44f7 363 UInt_t pulserResult=0;
364 for (Int_t i=0; i<numSources; i++ ) {
365 pulserResult = ExtractPulser(pulserSource[i]);
366 if ( pulserResult == 0 ) break;
367 }
c589a949 368 if (source != "TRY") result += pulserResult;
bb30a935 369 status = new TParameter<int>("pulserResult",pulserResult);
370 resultArray->Add(status);
68b512ca 371 }
9f016d99 372 }
373
70f224dd 374
375// raw calibration processing
376
377 if(runType == kPhysicsRunType) {
378 Int_t numSources = 1;
379 Int_t rawSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
380 TString source = fConfEnv->GetValue("Raw","DAQ");
381 source.ToUpper();
382 if ( source != "OFF") {
383 if ( source == "HLT") rawSource[0] = AliShuttleInterface::kHLT;
384 if (!GetHLTStatus()) rawSource[0] = AliShuttleInterface::kDAQ;
385 if (source == "HLTDAQ" ) {
386 numSources=2;
387 rawSource[0] = AliShuttleInterface::kHLT;
388 rawSource[1] = AliShuttleInterface::kDAQ;
389 }
390 if (source == "DAQHLT" ) numSources=2;
c589a949 391 if (source == "TRY" ) numSources=2;
70f224dd 392 UInt_t rawResult=0;
393 for (Int_t i=0; i<numSources; i++ ) {
394 rawResult = ExtractRaw(rawSource[i]);
395 if ( rawResult == 0 ) break;
396 }
c589a949 397 if (source != "TRY" )result += rawResult;
70f224dd 398 status = new TParameter<int>("rawResult",rawResult);
399 resultArray->Add(status);
400 }
401 }
402
403
9054511b 404 // Altro configuration
405
406
407 TString altroConf = fConfEnv->GetValue("AltroConf","ON");
cf4216a3 408 altroConf.ToUpper();
9054511b 409 if (altroConf != "OFF" ) {
f6b5fa33 410 UInt_t altroResult = ExtractAltro(AliShuttleInterface::kDCS,dcsAliasMap);
c589a949 411 if (altroConf != "TRY" ) result+=altroResult;
9054511b 412 status = new TParameter<int>("altroResult",altroResult);
413 resultArray->Add(status);
414 }
68b512ca 415
416
9f016d99 417 // Central Electrode processing
418
9054511b 419 if( runType == kPhysicsRunType ||
6f3699dd 420 runType == kLaserRunType ) {
68b512ca 421
422 Int_t numSources = 1;
423 Int_t ceSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
9f016d99 424 TString source = fConfEnv->GetValue("CE","DAQ");
425 source.ToUpper();
136e44f7 426 if ( source != "OFF" ) {
427 if ( source == "HLT") ceSource[0] = AliShuttleInterface::kHLT;
428 if (!GetHLTStatus()) ceSource[0] = AliShuttleInterface::kDAQ;
429 if (source == "HLTDAQ" ) {
68b512ca 430 numSources=2;
431 ceSource[0] = AliShuttleInterface::kHLT;
432 ceSource[1] = AliShuttleInterface::kDAQ;
136e44f7 433 }
434 if (source == "DAQHLT" ) numSources=2;
c589a949 435 if (source == "TRY" ) numSources=2;
136e44f7 436 UInt_t ceResult=0;
437 for (Int_t i=0; i<numSources; i++ ) {
438 ceResult = ExtractCE(ceSource[i]);
439 if ( ceResult == 0 ) break;
440 }
6f3699dd 441
442 // only flag error if CE result is missing from LASER runs
443 // -- for PHYSICS run do CE processing if data available
444
dee76880 445 if ( runType == kLaserRunType && source != "TRY" && ceResult<10 ) result += ceResult;
bb30a935 446 status = new TParameter<int>("ceResult",ceResult);
447 resultArray->Add(status);
dca91b3f 448
449 numSources = 1;
450 Int_t qaSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
5e5c1e83 451 source = fConfEnv->GetValue("QA","DAQ");
dca91b3f 452 source.ToUpper();
453 if ( source != "OFF" ) {
454 if ( source == "HLT") qaSource[0] = AliShuttleInterface::kHLT;
455 if (!GetHLTStatus()) qaSource[0] = AliShuttleInterface::kDAQ;
456 if (source == "HLTDAQ" ) {
457 numSources=2;
458 qaSource[0] = AliShuttleInterface::kHLT;
459 qaSource[1] = AliShuttleInterface::kDAQ;
460 }
461 if (source == "DAQHLT" ) numSources=2;
c589a949 462 if (source == "TRY" ) numSources=2;
dca91b3f 463 UInt_t qaResult=0;
464 for (Int_t i=0; i<numSources; i++ ) {
465 qaResult = ExtractQA(qaSource[i]);
466 if ( qaResult == 0 ) break;
467 }
468// result += qaResult;
469 if ( qaResult !=0 ) Log ("ExtractQA failed, no QA entry available.");
470 status = new TParameter<int>("qaResult",qaResult);
471 resultArray->Add(status);
68b512ca 472 }
dca91b3f 473 }
9f016d99 474 }
136e44f7 475
c589a949 476// Store component status to OCDB
477
478 AliCDBMetaData metaData;
479 metaData.SetBeamPeriod(0);
480 metaData.SetResponsible("Haavard Helstrup");
481 metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
482 metaData.SetComment("Preprocessor AliTPC status.");
483 Store("Calib", "PreprocStatus", resultArray, &metaData, 0, kFALSE);
484 resultArray->Delete();
485 delete resultArray;
486
487 if (errorHandling == "OFF" ) return 0;
488 return result;
489
54472e4f 490}
491//______________________________________________________________________________________________
492UInt_t AliTPCPreprocessor::MapTemperature(TMap* dcsAliasMap)
493{
494
495 // extract DCS temperature maps. Perform fits to save space
496
72df5829 497 UInt_t result=0;
54472e4f 498 TMap *map = fTemp->ExtractDCS(dcsAliasMap);
499 if (map) {
500 fTemp->MakeSplineFit(map);
68b512ca 501 Double_t fitFraction = 1.0*fTemp->NumFits()/fTemp->NumSensors();
67a165ed 502 if (fitFraction > kFitFraction ) {
503 AliInfo(Form("Temperature values extracted, fits performed.\n"));
504 } else {
505 Log ("Too few temperature maps fitted. \n");
506 result = 9;
507 }
54472e4f 508 } else {
67a165ed 509 Log("No temperature map extracted. \n");
72df5829 510 result=9;
54472e4f 511 }
512 delete map;
513 // Now store the final CDB file
a7dce0bc 514
515 if ( result == 0 ) {
72df5829 516 AliCDBMetaData metaData;
54472e4f 517 metaData.SetBeamPeriod(0);
518 metaData.SetResponsible("Haavard Helstrup");
eeeac1b2 519 metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
54472e4f 520 metaData.SetComment("Preprocessor AliTPC data base entries.");
521
a7dce0bc 522 Bool_t storeOK = Store("Calib", "Temperature", fTemp, &metaData, 0, kFALSE);
523 if ( !storeOK ) result=1;
524
72df5829 525 }
54472e4f 526
527 return result;
7b54c8e9 528
54472e4f 529}
09a746c5 530//______________________________________________________________________________________________
531UInt_t AliTPCPreprocessor::MapPressure(TMap* dcsAliasMap)
532{
533
534 // extract DCS pressure maps. Perform fits to save space
535
536 UInt_t result=0;
537 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
538 if (map) {
539 fPressure->MakeSplineFit(map);
540 Double_t fitFraction = 1.0*fPressure->NumFits()/fPressure->NumSensors();
541 if (fitFraction > kFitFraction ) {
1a63b1b0 542 AliInfo(Form("Pressure values extracted, fits performed.\n"));
09a746c5 543 } else {
544 Log ("Too few pressure maps fitted. \n");
545 result = 9;
546 }
547 } else {
548 Log("No pressure map extracted. \n");
549 result=9;
550 }
551 delete map;
552 return result;
553}
7b54c8e9 554
bdffc5fb 555//______________________________________________________________________________________________
556UInt_t AliTPCPreprocessor::MapHighVoltage(TMap* dcsAliasMap)
557{
558
559 // extract DCS HV maps. Perform fits to save space
560
561 UInt_t result=0;
562 TMap *map = fHighVoltage->ExtractDCS(dcsAliasMap);
563 if (map) {
379fc89a 564 fHighVoltage->ClearFit();
2b00f997 565 fHighVoltage->RemoveGraphDuplicates(kHighVoltageDifference);
566 // don't keep new point if too similar to previous one
379fc89a 567 fHighVoltage->SetGraph(map);
bdffc5fb 568 } else {
569 Log("No high voltage recordings extracted. \n");
570 result=9;
571 }
572 delete map;
9d2ce539 573
bff20895 574 TString hvStatConf = fConfEnv->GetValue("HighVoltageStat","ON");
575 hvStatConf.ToUpper();
576 if (hvStatConf != "OFF" ) {
577 TMap *map2 = fHighVoltageStat->ExtractDCS(dcsAliasMap);
578 if (map2) {
dca91b3f 579 fHighVoltageStat->ClearFit();
580 fHighVoltageStat->SetGraph(map2);
bff20895 581 } else {
582 Log("No high voltage status recordings extracted. \n");
583 result=9;
584 }
585 delete map2;
9d2ce539 586
bff20895 587 // add status maps to high voltage sensor array
9d2ce539 588
bff20895 589 fHighVoltage->AddSensors(fHighVoltageStat);
590 }
bdffc5fb 591 // Now store the final CDB file
592
593 if ( result == 0 ) {
594 AliCDBMetaData metaData;
595 metaData.SetBeamPeriod(0);
596 metaData.SetResponsible("Haavard Helstrup");
eeeac1b2 597 metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
bdffc5fb 598 metaData.SetComment("Preprocessor AliTPC data base entries.");
599
600 Bool_t storeOK = Store("Calib", "HighVoltage", fHighVoltage, &metaData, 0, kFALSE);
601 if ( !storeOK ) result=1;
602
603 }
604
605 return result;
606
607}
608
b6e9fd45 609//______________________________________________________________________________________________
610UInt_t AliTPCPreprocessor::MapGoofie(TMap* dcsAliasMap)
611{
612
613 // extract DCS Goofie maps. Do not perform fits (low update rate)
614
615 UInt_t result=0;
616
617 TMap *map = fGoofie->ExtractDCS(dcsAliasMap);
618 if (map) {
619 fGoofie->ClearFit();
620 fGoofie->SetGraph(map);
621 } else {
622 Log("No Goofie recordings extracted. \n");
623 result=9;
624 }
625 delete map;
626
627 // Now store the final CDB file
628
629 if ( result == 0 ) {
630 AliCDBMetaData metaData;
631 metaData.SetBeamPeriod(0);
632 metaData.SetResponsible("Haavard Helstrup");
eeeac1b2 633 metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
b6e9fd45 634 metaData.SetComment("Preprocessor AliTPC data base entries.");
635
636 Bool_t storeOK = Store("Calib", "Goofie", fGoofie, &metaData, 0, kFALSE);
637 if ( !storeOK ) result=1;
638
639 }
640
641 return result;
642
643}
644
7b54c8e9 645
a7dce0bc 646//______________________________________________________________________________________________
7b54c8e9 647
648UInt_t AliTPCPreprocessor::ExtractPedestals(Int_t sourceFXS)
a7dce0bc 649{
650 //
651 // Read pedestal file from file exchage server
652 // Keep original entry from OCDB in case no new pedestals are available
653 //
654 AliTPCCalPad *calPadPed=0;
655 AliCDBEntry* entry = GetFromOCDB("Calib", "Pedestals");
656 if (entry) calPadPed = (AliTPCCalPad*)entry->GetObject();
657 if ( calPadPed==NULL ) {
a7dce0bc 658 Log("AliTPCPreprocsessor: No previous TPC pedestal entry available.\n");
7b54c8e9 659 calPadPed = new AliTPCCalPad("PedestalsMean","PedestalsMean");
660 }
661
662 AliTPCCalPad *calPadRMS=0;
d63b9ad7 663 entry = GetFromOCDB("Calib", "PadNoise");
7b54c8e9 664 if (entry) calPadRMS = (AliTPCCalPad*)entry->GetObject();
665 if ( calPadRMS==NULL ) {
7b54c8e9 666 Log("AliTPCPreprocsessor: No previous TPC noise entry available.\n");
667 calPadRMS = new AliTPCCalPad("PedestalsRMS","PedestalsRMS");
a7dce0bc 668 }
669
7b54c8e9 670
a7dce0bc 671 UInt_t result=0;
672
673 Int_t nSectors = fROC->GetNSectors();
7b54c8e9 674 TList* list = GetFileSources(sourceFXS,"pedestals");
9f016d99 675
676 if (list && list->GetEntries()>0) {
a7dce0bc 677
678// loop through all files from LDCs
679
bdffc5fb 680 Bool_t changed=false;
a7dce0bc 681 UInt_t index = 0;
682 while (list->At(index)!=NULL) {
683 TObjString* fileNameEntry = (TObjString*) list->At(index);
684 if (fileNameEntry!=NULL) {
7b54c8e9 685 TString fileName = GetFile(sourceFXS, "pedestals",
a7dce0bc 686 fileNameEntry->GetString().Data());
687 TFile *f = TFile::Open(fileName);
9f016d99 688 if (!f) {
689 Log ("Error opening pedestal file.");
690 result =2;
691 break;
692 }
a7dce0bc 693 AliTPCCalibPedestal *calPed;
e73181c9 694 f->GetObject("tpcCalibPedestal",calPed);
67a165ed 695 if ( !calPed ) {
696 Log ("No pedestal calibration object in file.");
697 result = 2;
698 break;
699 }
a7dce0bc 700
701 // replace entries for the sectors available in the present file
702
bdffc5fb 703 changed=true;
c9c23d80 704 for (Int_t sector=0; sector<nSectors; sector++) {
7b54c8e9 705 AliTPCCalROC *rocPed=calPed->GetCalRocPedestal(sector, kFALSE);
706 if ( rocPed ) calPadPed->SetCalROC(rocPed,sector);
707 AliTPCCalROC *rocRMS=calPed->GetCalRocRMS(sector, kFALSE);
708 if ( rocRMS ) calPadRMS->SetCalROC(rocRMS,sector);
a7dce0bc 709 }
a480de15 710 delete calPed;
342d3b42 711 f->Close();
a7dce0bc 712 }
713 ++index;
714 } // while(list)
715//
716// Store updated pedestal entry to OCDB
717//
bdffc5fb 718 if (changed) {
719 AliCDBMetaData metaData;
720 metaData.SetBeamPeriod(0);
721 metaData.SetResponsible("Haavard Helstrup");
eeeac1b2 722 metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
bdffc5fb 723 metaData.SetComment("Preprocessor AliTPC data base entries.");
724
725 Bool_t storeOK = Store("Calib", "Pedestals", calPadPed, &metaData, 0, kTRUE);
726 if ( !storeOK ) ++result;
727 storeOK = Store("Calib", "PadNoise", calPadRMS, &metaData, 0, kTRUE);
728 if ( !storeOK ) ++result;
729 }
9f016d99 730 } else {
cf4216a3 731 Log ("Error: no entries in pedestal file list!");
9f016d99 732 result = 1;
7b54c8e9 733 }
a7dce0bc 734
795dbd3b 735 delete calPadPed;
736 delete calPadRMS;
737
a7dce0bc 738 return result;
739}
7b54c8e9 740
741//______________________________________________________________________________________________
742
743
9f016d99 744UInt_t AliTPCPreprocessor::ExtractPulser(Int_t sourceFXS)
745{
746 //
747 // Read pulser calibration file from file exchage server
748 // Keep original entry from OCDB in case no new pulser calibration is available
749 //
750 TObjArray *pulserObjects=0;
751 AliTPCCalPad *pulserTmean=0;
752 AliTPCCalPad *pulserTrms=0;
753 AliTPCCalPad *pulserQmean=0;
754 AliCDBEntry* entry = GetFromOCDB("Calib", "Pulser");
755 if (entry) pulserObjects = (TObjArray*)entry->GetObject();
756 if ( pulserObjects==NULL ) {
757 Log("AliTPCPreprocsessor: No previous TPC pulser entry available.\n");
758 pulserObjects = new TObjArray;
759 }
760
761 pulserTmean = (AliTPCCalPad*)pulserObjects->FindObject("PulserTmean");
762 if ( !pulserTmean ) {
763 pulserTmean = new AliTPCCalPad("PulserTmean","PulserTmean");
764 pulserObjects->Add(pulserTmean);
765 }
766 pulserTrms = (AliTPCCalPad*)pulserObjects->FindObject("PulserTrms");
767 if ( !pulserTrms ) {
768 pulserTrms = new AliTPCCalPad("PulserTrms","PulserTrms");
769 pulserObjects->Add(pulserTrms);
770 }
771 pulserQmean = (AliTPCCalPad*)pulserObjects->FindObject("PulserQmean");
772 if ( !pulserQmean ) {
773 pulserQmean = new AliTPCCalPad("PulserQmean","PulserQmean");
774 pulserObjects->Add(pulserQmean);
775 }
776
777
778 UInt_t result=0;
779
780 Int_t nSectors = fROC->GetNSectors();
781 TList* list = GetFileSources(sourceFXS,"pulser");
782
783 if (list && list->GetEntries()>0) {
784
785// loop through all files from LDCs
786
bdffc5fb 787 Bool_t changed=false;
9f016d99 788 UInt_t index = 0;
789 while (list->At(index)!=NULL) {
790 TObjString* fileNameEntry = (TObjString*) list->At(index);
791 if (fileNameEntry!=NULL) {
792 TString fileName = GetFile(sourceFXS, "pulser",
793 fileNameEntry->GetString().Data());
794 TFile *f = TFile::Open(fileName);
795 if (!f) {
796 Log ("Error opening pulser file.");
797 result =2;
798 break;
799 }
800 AliTPCCalibPulser *calPulser;
e73181c9 801 f->GetObject("tpcCalibPulser",calPulser);
67a165ed 802 if ( !calPulser ) {
803 Log ("No pulser calibration object in file.");
804 result = 2;
805 break;
806 }
9f016d99 807
808 // replace entries for the sectors available in the present file
809
bdffc5fb 810 changed=true;
9f016d99 811 for (Int_t sector=0; sector<nSectors; sector++) {
812 AliTPCCalROC *rocTmean=calPulser->GetCalRocT0(sector);
813 if ( rocTmean ) pulserTmean->SetCalROC(rocTmean,sector);
814 AliTPCCalROC *rocTrms=calPulser->GetCalRocRMS(sector);
815 if ( rocTrms ) pulserTrms->SetCalROC(rocTrms,sector);
816 AliTPCCalROC *rocQmean=calPulser->GetCalRocQ(sector);
817 if ( rocQmean ) pulserQmean->SetCalROC(rocQmean,sector);
818 }
a480de15 819 delete calPulser;
342d3b42 820 f->Close();
9f016d99 821 }
822 ++index;
823 } // while(list)
824//
825// Store updated pedestal entry to OCDB
826//
bdffc5fb 827 if (changed) {
828 AliCDBMetaData metaData;
829 metaData.SetBeamPeriod(0);
830 metaData.SetResponsible("Haavard Helstrup");
eeeac1b2 831 metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
bdffc5fb 832 metaData.SetComment("Preprocessor AliTPC data base entries.");
833
834 Bool_t storeOK = Store("Calib", "Pulser", pulserObjects, &metaData, 0, kTRUE);
835 if ( !storeOK ) ++result;
836 }
9f016d99 837 } else {
cf4216a3 838 Log ("Error: no entries in pulser file list!");
9f016d99 839 result = 1;
840 }
795dbd3b 841 pulserObjects->Delete();
842 delete pulserObjects;
9f016d99 843
844 return result;
845}
846
70f224dd 847//______________________________________________________________________________________________
848
849
850UInt_t AliTPCPreprocessor::ExtractRaw(Int_t sourceFXS)
851{
852 //
853 // Read Raw calibration file from file exchage server
854 //
855
856 UInt_t result=0;
90581ff1 857 TObjArray* rawArray = new TObjArray;
70f224dd 858
9b1478f9 859 TList* list = GetFileSources(sourceFXS,"tpcCalibRaw");
70f224dd 860
861 if (list && list->GetEntries()>0) {
862
863// loop through all files
864
865 UInt_t index = 0;
866 while (list->At(index)!=NULL) {
867 TObjString* fileNameEntry = (TObjString*) list->At(index);
868 if (fileNameEntry!=NULL) {
869 TString fileName = GetFile(sourceFXS, "tpcCalibRaw",
870 fileNameEntry->GetString().Data());
871 TFile *f = TFile::Open(fileName);
872 if (!f) {
873 Log ("Error opening raw file.");
874 result =2;
875 break;
876 }
90581ff1 877 AliTPCCalibRaw *calRaw;
70f224dd 878 f->GetObject("tpcCalibRaw",calRaw);
879 if ( !calRaw ) {
880 Log ("No raw calibration object in file.");
881 result = 2;
882 break;
883 }
90581ff1 884 rawArray->Add(calRaw);
70f224dd 885 f->Close();
886 }
887 ++index;
888 } // while(list)
889//
890// Store updated pedestal entry to OCDB
891//
892 AliCDBMetaData metaData;
893 metaData.SetBeamPeriod(0);
894 metaData.SetResponsible("Haavard Helstrup");
895 metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
896 metaData.SetComment("Preprocessor AliTPC data base entries.");
897
90581ff1 898 Bool_t storeOK = Store("Calib", "Raw", rawArray, &metaData, 0, kTRUE);
70f224dd 899 if ( !storeOK ) ++result;
900 } else {
cf4216a3 901 Log ("Error: no entries in raw file list!");
70f224dd 902 result = 1;
903 }
795dbd3b 904
905 rawArray->Delete();
906 delete rawArray;
70f224dd 907
908 return result;
909}
910//______________________________________________________________________________________________
911
9f016d99 912UInt_t AliTPCPreprocessor::ExtractCE(Int_t sourceFXS)
913{
914 //
915 // Read Central Electrode file from file exchage server
9f016d99 916 //
e2d642a2 917 //
918 AliTPCCalPad *ceTmean=0;
919 AliTPCCalPad *ceTrms=0;
920 AliTPCCalPad *ceQmean=0;
921 TObjArray *rocTtime=0;
922 TObjArray *rocQtime=0;
923
924 TObjArray *ceObjects= new TObjArray;
925
926
927 Int_t nSectors = fROC->GetNSectors();
928
929 ceTmean = new AliTPCCalPad("CETmean","CETmean");
930 ceObjects->Add(ceTmean);
931
932 ceTrms = new AliTPCCalPad("CETrms","CETrms");
933 ceObjects->Add(ceTrms);
934
935 ceQmean = new AliTPCCalPad("CEQmean","CEQmean");
936 ceObjects->Add(ceQmean);
937
938 rocTtime = new TObjArray(nSectors+2); // also make room for A and C side average
939 rocTtime->SetName("rocTtime");
940 ceObjects->Add(rocTtime);
941
942 rocQtime = new TObjArray(nSectors);
943 rocQtime->SetName("rocQtime");
944 ceObjects->Add(rocQtime);
945
946 //=== new part
947 TObjArray *arrFitGraphs=new TObjArray;
948 arrFitGraphs->SetName("ceFitsDrift");
949 ceObjects->Add(arrFitGraphs);
70f224dd 950
09a746c5 951// Temperature maps
e2d642a2 952
953 if (fTemp) {
df8595b9 954 AliTPCSensorTempArray *tempMap = new AliTPCSensorTempArray(*fTemp);
955 tempMap->SetNameTitle("TempMap","TempMap");
956 ceObjects->Add(tempMap);
e2d642a2 957 }
958
09a746c5 959// Pressure maps
e2d642a2 960
961 if (fPressure) {
962 AliDCSSensor *sensor=0, *sensorCopy=0;
963 for (Int_t isensor=0; isensor<kNumPressureSensors; ++isensor ) {
09a746c5 964 sensor = fPressure->GetSensor(kPressureSensorNames[isensor]);
b5886f0f 965 if (sensor) {
e2d642a2 966 sensorCopy = new AliDCSSensor(*sensor);
967 sensorCopy->SetNameTitle(kPressureSensorNames[isensor],kPressureSensorNames[isensor]);
968 ceObjects->Add(sensorCopy);
b5886f0f 969 }
e2d642a2 970 }
971 }
972
973 UInt_t result=0;
974
975 TList* list = GetFileSources(sourceFXS,"CE");
976
977 if (list && list->GetEntries()>0) {
978
9f016d99 979// loop through all files from LDCs
e2d642a2 980
9f016d99 981 UInt_t index = 0;
982 while (list->At(index)!=NULL) {
e2d642a2 983 TObjString* fileNameEntry = (TObjString*) list->At(index);
984 if (fileNameEntry!=NULL) {
9f016d99 985 TString fileName = GetFile(sourceFXS, "CE",
e2d642a2 986 fileNameEntry->GetString().Data());
6d3584e9 987 AliTPCCalibCE *calCE=AliTPCCalibCE::ReadFromFile(fileName.Data());
e2d642a2 988
7c2575c4 989 if (!calCE) {
e2d642a2 990 Log ("No valid calibCE object.");
991 result=2;
992 break;
993 }
9f016d99 994 // replace entries for the sectors available in the present file
e2d642a2 995
9f016d99 996 for (Int_t sector=0; sector<nSectors; sector++) {
e2d642a2 997 AliTPCCalROC *rocTmean=calCE->GetCalRocT0(sector);
998 if ( rocTmean ) ceTmean->SetCalROC(rocTmean,sector);
999 AliTPCCalROC *rocTrms=calCE->GetCalRocRMS(sector);
1000 if ( rocTrms ) ceTrms->SetCalROC(rocTrms,sector);
1001 AliTPCCalROC *rocQmean=calCE->GetCalRocQ(sector);
1002 if ( rocQmean ) ceQmean->SetCalROC(rocQmean,sector);
1003 TGraph *grT=calCE->MakeGraphTimeCE(sector,0,2); // T time graph
1004 if ( grT ) rocTtime->AddAt(grT,sector);
1005 TGraph *grQ=calCE->MakeGraphTimeCE(sector,0,3); // Q time graph
1006 if ( grQ ) rocQtime->AddAt(grQ,sector);
9f016d99 1007 }
e2d642a2 1008
1009 TGraph *grT=calCE->MakeGraphTimeCE(-1,0,2); // A side average
1010 if ( grT ) {
1011 rocTtime->AddAt(grT,nSectors);
1012 } else {
31c50f68 1013 result=10;
e2d642a2 1014 }
1015 grT=calCE->MakeGraphTimeCE(-2,0,2); // C side average
1016 if ( grT ) {
1017 rocTtime->AddAt(grT,nSectors+1);
1018 } else {
31c50f68 1019 result=10;
e2d642a2 1020 }
1fc96a8a 1021
e2d642a2 1022 delete calCE;
9f016d99 1023 }
e2d642a2 1024 ++index;
9f016d99 1025 } // while(list)
1fc96a8a 1026//
1027// Check number of calibrated sectors per side
1028//
1029 Int_t aside=0, cside=0;
1030 for (Int_t ind=0; ind<nSectors/4; ind++ ) {
1031 TGraph *grT=(TGraph*)rocTtime->At(ind);
1032 if (grT) aside++;
1033 grT=(TGraph*)rocTtime->At(ind+nSectors/2);
1034 if (grT) aside++;
1035 grT=(TGraph*)rocTtime->At(ind+nSectors/4);
1036 if (grT) cside++;
1037 grT=(TGraph*)rocTtime->At(ind+3*nSectors/4);
1038 if (grT) cside++;
1039 }
1040 if ( (aside<kMinCESectors) && (cside<kMinCESectors) ) result=10;
e2d642a2 1041
1042 //
1043 //=== New CE part
1044 // if it is validated this part needs to be modified again
1045 // currently its only processed if there is a valid standard CE object
1046 //
1047 list = GetFileSources(sourceFXS,"CEnew");
1048
1049 if (result==0 && list && list->GetEntries()>0) {
1050
1051// loop through all files from LDCs
1052
1053 UInt_t index2 = 0;
1054 while (list->At(index2)!=NULL) {
1055 TObjString* fileNameEntry = (TObjString*) list->At(index2);
1056 if (fileNameEntry!=NULL) {
1057 TString fileName = GetFile(sourceFXS, "CEnew",
1058 fileNameEntry->GetString().Data());
1059 TFile *f = TFile::Open(fileName);
1060 if (!f) {
1061 Log ("Error opening new central electrode file.");
1062// result =2;
1063 break;
1064 }
1065 AliTPCCalibCE *calCE;
1066 f->GetObject("tpcCalibCE",calCE);
1067
1068 if (!calCE) {
1069 Log ("No valid new calibCE object.");
1070// result=2;
1071 break;
1072 }
1073
1074 TIter nextObj(calCE->GetArrFitGraphs());
1075 TObject *obj=0x0;
1076 while ( (obj=nextObj()) ){
1077 arrFitGraphs->Add(obj->Clone());
1078 }
1079 delete calCE;
1080 f->Close();
1081 }
1082 ++index2;
1083 }
1084 }
1085
9f016d99 1086//
1087// Store updated pedestal entry to OCDB
1088//
1089 AliCDBMetaData metaData;
1090 metaData.SetBeamPeriod(0);
1091 metaData.SetResponsible("Haavard Helstrup");
eeeac1b2 1092 metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
9f016d99 1093 metaData.SetComment("Preprocessor AliTPC data base entries.");
e2d642a2 1094
31c50f68 1095 if ( result == 0 ) {
e2d642a2 1096 Bool_t storeOK = Store("Calib", "CE", ceObjects, &metaData, 0, kTRUE);
1097 if ( !storeOK ) ++result;
31c50f68 1098 } else {
e2d642a2 1099 Log ("Warning: Average time graphs not available - no OCDB entry written");
1100 }
9f016d99 1101 } else {
cf4216a3 1102 Log ("Error: no CE entries available from FXS!");
9f016d99 1103 result = 1;
1104 }
e2d642a2 1105
795dbd3b 1106 ceObjects->Delete();
1107 delete ceObjects;
1108
9f016d99 1109 return result;
1110}
dca91b3f 1111//______________________________________________________________________________________________
1112
1113UInt_t AliTPCPreprocessor::ExtractQA(Int_t sourceFXS)
1114{
1115 //
1116 // Read Quality Assurance file from file exchage server
1117 //
1118
1119 UInt_t result=0;
1120
1121 TList* list = GetFileSources(sourceFXS,"QA");
1122
1123 if (list && list->GetEntries()>0) {
1124
1125// only one QA objetc should be available!
1126
1127 AliTPCdataQA *calQA;
1128
1129 UInt_t nentries = list->GetEntries();
1130 UInt_t index=0;
1131 if ( nentries > 1) Log ( "More than one QA entry. First one processed");
1132 TObjString* fileNameEntry = (TObjString*) list->At(index);
1133 if (fileNameEntry!=NULL) {
1134 TString fileName = GetFile(sourceFXS, "QA",
1135 fileNameEntry->GetString().Data());
1136 TFile *f = TFile::Open(fileName);
1137 if (!f) {
1138 Log ("Error opening QA file.");
a2465b54 1139 result =2;
1140 } else {
1141 f->GetObject("tpcCalibQA",calQA);
7c2575c4 1142 if ( calQA ) {
dca91b3f 1143//
1144// Store updated pedestal entry to OCDB
1145//
7c2575c4 1146 AliCDBMetaData metaData;
1147 metaData.SetBeamPeriod(0);
1148 metaData.SetResponsible("Haavard Helstrup");
eeeac1b2 1149 metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
7c2575c4 1150 metaData.SetComment("Preprocessor AliTPC data base entries.");
1151
cf4216a3 1152 Bool_t storeOK = Store("Calib", "QA", calQA, &metaData, 0, kFALSE);
7c2575c4 1153 if ( !storeOK ) ++result;
795dbd3b 1154
1155 delete calQA;
7c2575c4 1156 }
a2465b54 1157 }
1158 } else {
1159 Log ("Error: no QA files on FXS!");
1160 result = 2;
1161 }
dca91b3f 1162 } else {
a2465b54 1163 Log ("Error: no QA entries in FXS list!");
dca91b3f 1164 result = 1;
1165 }
dca91b3f 1166 return result;
1167}
1168
9054511b 1169//______________________________________________________________________________________________
1170
1171
f6b5fa33 1172UInt_t AliTPCPreprocessor::ExtractAltro(Int_t sourceFXS, TMap* dcsMap)
9054511b 1173{
1174 //
f6b5fa33 1175 // Read Altro configuration file from file exchage server
9054511b 1176 // Keep original entry from OCDB in case no new pulser calibration is available
1177 //
1178 TObjArray *altroObjects=0;
1179 AliTPCCalPad *acqStart=0;
1180 AliTPCCalPad *zsThr=0;
1181 AliTPCCalPad *acqStop=0;
1182 AliTPCCalPad *FPED=0;
1183 AliTPCCalPad *masked=0;
cf4216a3 1184 AliTPCCalPad *k1=0, *k2=0, *k3=0;
1185 AliTPCCalPad *l1=0, *l2=0, *l3=0;
1186 TMap *mapRCUconfig=0;
9054511b 1187
14ae505e 1188 AliCDBEntry* entry = GetFromOCDB("Calib", "AltroConfig");
9054511b 1189 if (entry) altroObjects = (TObjArray*)entry->GetObject();
1190 if ( altroObjects==NULL ) {
1191 Log("AliTPCPreprocsessor: No previous TPC altro calibration entry available.\n");
1192 altroObjects = new TObjArray;
1193 }
1194
1195 acqStart = (AliTPCCalPad*)altroObjects->FindObject("AcqStart");
1196 if ( !acqStart ) {
1197 acqStart = new AliTPCCalPad("AcqStart","AcqStart");
1198 altroObjects->Add(acqStart);
1199 }
1200 zsThr = (AliTPCCalPad*)altroObjects->FindObject("ZsThr");
1201 if ( !zsThr ) {
1202 zsThr = new AliTPCCalPad("ZsThr","ZsThr");
1203 altroObjects->Add(zsThr);
1204 }
1205 FPED = (AliTPCCalPad*)altroObjects->FindObject("FPED");
1206 if ( !FPED ) {
1207 FPED = new AliTPCCalPad("FPED","FPED");
1208 altroObjects->Add(FPED);
1209 }
1210 acqStop = (AliTPCCalPad*)altroObjects->FindObject("AcqStop");
1211 if ( !acqStop ) {
1212 acqStop = new AliTPCCalPad("AcqStop","AcqStop");
1213 altroObjects->Add(acqStop);
1214 }
1215 masked = (AliTPCCalPad*)altroObjects->FindObject("Masked");
1216 if ( !masked ) {
1217 masked = new AliTPCCalPad("Masked","Masked");
1218 altroObjects->Add(masked);
1219 }
cf4216a3 1220 k1 = (AliTPCCalPad*)altroObjects->FindObject("K1");
1221 if ( !k1 ) {
1222 k1 = new AliTPCCalPad("K1","K1");
1223 altroObjects->Add(k1);
1224 }
1225 k2 = (AliTPCCalPad*)altroObjects->FindObject("K2");
1226 if ( !k2 ) {
1227 k2 = new AliTPCCalPad("K2","K2");
1228 altroObjects->Add(k2);
1229 }
1230 k3 = (AliTPCCalPad*)altroObjects->FindObject("K3");
1231 if ( !k3 ) {
1232 k3 = new AliTPCCalPad("K3","K3");
1233 altroObjects->Add(k3);
1234 }
1235 l1 = (AliTPCCalPad*)altroObjects->FindObject("L1");
1236 if ( !l1 ) {
1237 l1 = new AliTPCCalPad("L1","L1");
1238 altroObjects->Add(l1);
1239 }
1240 l2 = (AliTPCCalPad*)altroObjects->FindObject("L2");
1241 if ( !l2 ) {
1242 l2 = new AliTPCCalPad("L2","L2");
1243 altroObjects->Add(l2);
1244 }
1245 l3 = (AliTPCCalPad*)altroObjects->FindObject("L3");
1246 if ( !l3 ) {
1247 l3 = new AliTPCCalPad("L3","L3");
1248 altroObjects->Add(l3);
1249 }
1250 mapRCUconfig = (TMap*)altroObjects->FindObject("RCUconfig");
1251 if (!mapRCUconfig) {
1252 mapRCUconfig = new TMap();
1253 mapRCUconfig->SetName("RCUconfig");
1254 altroObjects->Add(mapRCUconfig);
1255 }
9054511b 1256
1257
1258 UInt_t result=0;
1259 TString idFXS[2]={"AltroConfigA","AltroConfigC"};
1260
1261 Int_t nSectors = fROC->GetNSectors();
1262 Bool_t changed=false;
f6b5fa33 1263 if (altroObjects == 0 ) altroObjects = new TObjArray;
1264
1265// extract list of active DDLs
1266
1267 Bool_t found;
1268 TString arrDDL(kNumDDL);
2b00f997 1269 arrDDL.Append('x',kNumDDL);
f6b5fa33 1270 for ( Int_t iDDL = 0; iDDL<kNumDDL; iDDL++ ) {
1271 TString stringID = Form (kAmandaDDL.Data(),iDDL+kFirstDDL);
1272 TPair *pair = (TPair*)dcsMap->FindObject(stringID.Data());
1273 found = false;
1274 if ( pair ) {
1275 TObjArray *valueSet=(TObjArray*)pair->Value();
1276 if ( valueSet) {
1277 AliDCSValue *val = (AliDCSValue*)valueSet->At(0);
2b00f997 1278 if (val) {
1279 found = val->GetBool();
1280 if (found){
1281 arrDDL[iDDL] = '1';
1282 } else {
1283 arrDDL[iDDL] = '0';
1284 }
1285 }
f6b5fa33 1286 }
1287 }
f6b5fa33 1288 }
1289 TObjString *ddlArray = new TObjString;
1290 ddlArray->SetString(arrDDL);
1291 TMap *activeDDL = new TMap;
1292 activeDDL->SetName("DDLArray");
1293 TObjString *key = new TObjString("DDLArray");
1294 activeDDL->Add(key,ddlArray);
1295 altroObjects->Add(activeDDL);
1296 changed=true;
1297
1298
1299// extract Altro configuration files
1300
9054511b 1301 for ( Int_t id=0; id<2; id++) {
1302 TList* list = GetFileSources(sourceFXS,idFXS[id].Data());
1303
1304 if (list && list->GetEntries()>0) {
9054511b 1305
1306// loop through all files from LDCs
1307
1308 UInt_t index = 0;
1309 while (list->At(index)!=NULL) {
1310 TObjString* fileNameEntry = (TObjString*) list->At(index);
1311 if (fileNameEntry!=NULL) {
1312 TString fileName = GetFile(sourceFXS, idFXS[id].Data(),
1313 fileNameEntry->GetString().Data());
1314 TFile *f = TFile::Open(fileName);
1315 if (!f) {
1316 char message[40];
1317 sprintf(message,"Error opening Altro configuration file, id = %d",id);
1318 Log (message);
1319 result =2;
1320 break;
1321 }
1322 TObjArray *altroFXS;
1323 f->GetObject("AltroConfig",altroFXS);
1324 if ( !altroFXS ) {
1325 Log ("No Altro configuration object in file.");
1326 result = 2;
1327 break;
1328 }
1329
1330 // replace entries for the sectors available in the present file
1331 AliTPCCalPad *acqStartFXS=(AliTPCCalPad*)altroFXS->FindObject("AcqStart");
1332 AliTPCCalPad *zsThrFXS=(AliTPCCalPad*)altroFXS->FindObject("ZsThr");
1333 AliTPCCalPad *acqStopFXS=(AliTPCCalPad*)altroFXS->FindObject("AcqStop");
1334 AliTPCCalPad *FPEDFXS=(AliTPCCalPad*)altroFXS->FindObject("FPED");
1335 AliTPCCalPad *maskedFXS=(AliTPCCalPad*)altroFXS->FindObject("Masked");
cf4216a3 1336 AliTPCCalPad *k1FXS=(AliTPCCalPad*)altroFXS->FindObject("K1");
1337 AliTPCCalPad *k2FXS=(AliTPCCalPad*)altroFXS->FindObject("K2");
1338 AliTPCCalPad *k3FXS=(AliTPCCalPad*)altroFXS->FindObject("K3");
1339 AliTPCCalPad *l1FXS=(AliTPCCalPad*)altroFXS->FindObject("L1");
1340 AliTPCCalPad *l2FXS=(AliTPCCalPad*)altroFXS->FindObject("L2");
1341 AliTPCCalPad *l3FXS=(AliTPCCalPad*)altroFXS->FindObject("L3");
1342 TMap *mapRCUconfigFXS = (TMap*)altroFXS->FindObject("RCUconfig");
1343 TIterator *mapFXSiter = mapRCUconfigFXS->MakeIterator();
1344
9054511b 1345 changed=true;
1346 for (Int_t sector=0; sector<nSectors; sector++) {
1347
1348 if (acqStartFXS) {
1349 AliTPCCalROC *rocAcqStart=acqStartFXS->GetCalROC(sector);
1350 if ( rocAcqStart ) acqStart->SetCalROC(rocAcqStart,sector);
1351 }
1352 if (zsThrFXS ) {
1353 AliTPCCalROC *rocZsThr=zsThrFXS->GetCalROC(sector);
1354 if ( rocZsThr ) zsThr->SetCalROC(rocZsThr,sector);
1355 }
1356 if (acqStopFXS) {
1357 AliTPCCalROC *rocAcqStop=acqStopFXS->GetCalROC(sector);
1358 if ( rocAcqStop ) acqStop->SetCalROC(rocAcqStop,sector);
1359 }
1360 if (FPEDFXS ) {
1361 AliTPCCalROC *rocFPED=FPEDFXS->GetCalROC(sector);
2d47cfd4 1362 if ( rocFPED ) FPED->SetCalROC(rocFPED,sector);
9054511b 1363 }
1364 if (maskedFXS) {
1365 AliTPCCalROC *rocMasked=maskedFXS->GetCalROC(sector);
1366 if ( rocMasked ) masked->SetCalROC(rocMasked,sector);
1367 }
cf4216a3 1368 if (k1FXS) {
1369 AliTPCCalROC *rocK1=k1FXS->GetCalROC(sector);
1370 if ( rocK1 ) k1->SetCalROC(rocK1,sector);
1371 }
1372 if (k2FXS) {
1373 AliTPCCalROC *rocK2=k2FXS->GetCalROC(sector);
1374 if ( rocK2 ) k2->SetCalROC(rocK2,sector);
1375 }
1376 if (k3FXS) {
1377 AliTPCCalROC *rocK3=k3FXS->GetCalROC(sector);
1378 if ( rocK3 ) k3->SetCalROC(rocK3,sector);
1379 }
1380 if (l1FXS) {
1381 AliTPCCalROC *rocL1=l1FXS->GetCalROC(sector);
1382 if ( rocL1 ) l1->SetCalROC(rocL1,sector);
1383 }
1384 if (l2FXS) {
1385 AliTPCCalROC *rocL2=l2FXS->GetCalROC(sector);
1386 if ( rocL2 ) l2->SetCalROC(rocL2,sector);
1387 }
1388 if (l3FXS) {
1389 AliTPCCalROC *rocL3=l3FXS->GetCalROC(sector);
1390 if ( rocL3 ) l3->SetCalROC(rocL3,sector);
1391 }
1392 }
1393 if (mapRCUconfigFXS) {
1394 Int_t mapEntries = mapRCUconfigFXS->GetEntries();
1395 TObjString* keyFXS;
1396 TVectorF* vecFXS;
1397 TVectorF* vec; // nSectors = 72 (total number of inner/outer sectors)
1398 for (Int_t i=0; i<mapEntries; ++i) {
1399 keyFXS=(TObjString*)mapFXSiter->Next();
1400 vecFXS=(TVectorF*)mapRCUconfigFXS->GetValue(keyFXS);
1401 vec=(TVectorF*)mapRCUconfig->GetValue(keyFXS);
1402 if (!vec) {
1403 vec = new TVectorF(3*nSectors);
1404 *vec = -1;
1405 mapRCUconfig->Add(keyFXS,vec);
1406 }
1407 if (vec->GetNoElements() != 3*nSectors ) {
1408 vec->ResizeTo(3*nSectors);
1409 }
1410 if (id==0) { // A side
1411 vec->SetSub(0,vecFXS->GetSub(0,nSectors/2-1));
1412 vec->SetSub(nSectors,vecFXS->GetSub(nSectors,2*nSectors-1));
1413 } else { // C side
1414 vec->SetSub(nSectors/2,vecFXS->GetSub(nSectors/2,nSectors-1));
1415 vec->SetSub(2*nSectors,vecFXS->GetSub(2*nSectors,3*nSectors-1));
1416 }
1417 }
9054511b 1418 }
1419 delete altroFXS;
1420 f->Close();
1421 }
1422 ++index;
1423 } // while(list)
1424 } else {
cf4216a3 1425 Log ("Error: no entries in AltroConfig file list!");
9054511b 1426 result = 1;
1427 }
1428
1429 } // for - id
1430//
1431// Store updated pedestal entry to OCDB
1432//
1433 if (changed) {
1434 AliCDBMetaData metaData;
1435 metaData.SetBeamPeriod(0);
1436 metaData.SetResponsible("Haavard Helstrup");
eeeac1b2 1437 metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
9054511b 1438 metaData.SetComment("Preprocessor AliTPC data base entries.");
1439
dbc10140 1440 Bool_t storeOK = Store("Calib", "AltroConfig", altroObjects, &metaData, 0, kFALSE);
9054511b 1441 if ( !storeOK ) ++result;
1442 }
1443
795dbd3b 1444 altroObjects->Delete();
1445 delete altroObjects;
1446
9054511b 1447 return result;
1448}