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