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