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