preliminary update of the rec-hlt-tpc.C macro: adding the CA tracker and merger
[u/mrichter/AliRoot.git] / TPC / AliTPCPreprocessor.cxx
... / ...
CommitLineData
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
16
17#include "AliTPCPreprocessor.h"
18#include "AliShuttleInterface.h"
19
20#include "AliCDBMetaData.h"
21#include "AliDCSValue.h"
22#include "AliLog.h"
23#include "AliTPCSensorTempArray.h"
24#include "AliTPCROC.h"
25#include "AliTPCCalROC.h"
26#include "AliTPCCalPad.h"
27#include "AliTPCCalibPedestal.h"
28#include "AliTPCCalibPulser.h"
29#include "AliTPCCalibCE.h"
30#include "AliTPCCalibRaw.h"
31#include "AliTPCdataQA.h"
32#include "ARVersion.h"
33#include "TFile.h"
34#include "TTree.h"
35#include "TGraph.h"
36#include "TEnv.h"
37#include "TParameter.h"
38
39#include <TTimeStamp.h>
40
41const Int_t kValCutTemp = 100; // discard temperatures > 100 degrees
42const Int_t kDiffCutTemp = 5; // discard temperature differences > 5 degrees
43const TString kPedestalRunType = "PEDESTAL"; // pedestal run identifier
44const TString kPulserRunType = "PULSER"; // pulser run identifier
45const TString kPhysicsRunType = "PHYSICS"; // physics run identifier
46const TString kCosmicRunType = "COSMIC"; // cosmic run identifier
47const TString kLaserRunType = "LASER"; // laser run identifier
48const TString kDaqRunType = "DAQ"; // DAQ run identifier
49const TString kAmandaTemp = "TPC_PT_%d_TEMPERATURE"; // Amanda string for temperature entries
50//const Double_t kFitFraction = 0.7; // Fraction of DCS sensor fits required
51const Double_t kFitFraction = -1.0; // Don't require minimum number of fits in commissioning run
52
53//
54// This class is the SHUTTLE preprocessor for the TPC detector.
55//
56
57ClassImp(AliTPCPreprocessor)
58
59//______________________________________________________________________________________________
60AliTPCPreprocessor::AliTPCPreprocessor(AliShuttleInterface* shuttle) :
61 AliPreprocessor("TPC",shuttle),
62 fConfEnv(0), fTemp(0), fHighVoltage(0), fHighVoltageStat(0), fGoofie(0), fConfigOK(kTRUE), fROC(0)
63{
64 // constructor
65 fROC = AliTPCROC::Instance();
66
67 // define run types to be processed
68
69 AddRunType(kPedestalRunType);
70 AddRunType(kPulserRunType);
71 AddRunType(kPhysicsRunType);
72 AddRunType(kCosmicRunType);
73 AddRunType(kLaserRunType);
74 AddRunType(kDaqRunType);
75
76}
77//______________________________________________________________________________________________
78 AliTPCPreprocessor::AliTPCPreprocessor(const AliTPCPreprocessor& ) :
79 AliPreprocessor("TPC",0),
80 fConfEnv(0), fTemp(0), fHighVoltage(0), fHighVoltageStat(0), fGoofie(0), fConfigOK(kTRUE), fROC(0)
81 {
82
83 Fatal("AliTPCPreprocessor", "copy constructor not implemented");
84//
85// // fTemp = new AliTPCSensorTempArray(*(org.fTemp));
86 }
87
88//______________________________________________________________________________________________
89AliTPCPreprocessor::~AliTPCPreprocessor()
90{
91 // destructor
92
93 delete fTemp;
94 delete fHighVoltage;
95}
96//______________________________________________________________________________________________
97AliTPCPreprocessor& AliTPCPreprocessor::operator = (const AliTPCPreprocessor& )
98{
99 Fatal("operator =", "assignment operator not implemented");
100 return *this;
101}
102
103
104//______________________________________________________________________________________________
105void AliTPCPreprocessor::Initialize(Int_t run, UInt_t startTime,
106 UInt_t endTime)
107{
108 // Creates AliTestDataDCS object -- start maps half an hour beforre actual run start
109
110 UInt_t startTimeLocal = startTime-3600;
111 UInt_t endTimeLocal = endTime+1800;
112
113 AliPreprocessor::Initialize(run, startTimeLocal, endTimeLocal);
114
115 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
116 TTimeStamp((time_t)startTime,0).AsString(),
117 TTimeStamp((time_t)endTime,0).AsString()));
118
119 // Preprocessor configuration
120
121 AliCDBEntry* entry = GetFromOCDB("Config", "Preprocessor");
122 if (entry) fConfEnv = (TEnv*) entry->GetObject();
123 if ( fConfEnv==0 ) {
124 Log("AliTPCPreprocsessor: Preprocessor Config OCDB entry missing.\n");
125 fConfigOK = kFALSE;
126 return;
127 }
128
129 // Temperature sensors
130
131 TTree *confTree = 0;
132
133 TString tempConf = fConfEnv->GetValue("Temperature","ON");
134 tempConf.ToUpper();
135 if (tempConf != "OFF" ) {
136 entry = GetFromOCDB("Config", "Temperature");
137 if (entry) confTree = (TTree*) entry->GetObject();
138 if ( confTree==0 ) {
139 Log("AliTPCPreprocsessor: Temperature Config OCDB entry missing.\n");
140 fConfigOK = kFALSE;
141 return;
142 }
143 fTemp = new AliTPCSensorTempArray(startTimeLocal, endTimeLocal, confTree, kAmandaTemp);
144 fTemp->SetValCut(kValCutTemp);
145 fTemp->SetDiffCut(kDiffCutTemp);
146 }
147
148 // High voltage measurements
149
150 TString hvConf = fConfEnv->GetValue("HighVoltage","ON");
151 hvConf.ToUpper();
152 if (hvConf != "OFF" ) {
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 }
162 fHighVoltage = new AliDCSSensorArray(startTimeLocal, endTimeLocal, confTree);
163 }
164
165 // High voltage status values
166
167 TString hvStatConf = fConfEnv->GetValue("HighVoltageStat","ON");
168 hvStatConf.ToUpper();
169 if (hvStatConf != "OFF" ) {
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 }
179 fHighVoltageStat = new AliDCSSensorArray(startTimeLocal, endTimeLocal, confTree);
180 }
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
200}
201
202//______________________________________________________________________________________________
203UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
204{
205 // Fills data into TPC calibrations objects
206
207 // Amanda servers provide information directly through dcsAliasMap
208
209
210 if (!fConfigOK) return 9;
211 UInt_t result = 0;
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
230
231 TString runType = GetRunType();
232
233 // Temperature sensors are processed by AliTPCCalTemp
234
235 TString tempConf = fConfEnv->GetValue("Temperature","ON");
236 tempConf.ToUpper();
237 if (tempConf != "OFF" ) {
238 UInt_t tempResult = MapTemperature(dcsAliasMap);
239 result=tempResult;
240 status = new TParameter<int>("tempResult",tempResult);
241 resultArray->Add(status);
242 }
243
244 // High Voltage recordings
245
246
247 TString hvConf = fConfEnv->GetValue("HighVoltage","ON");
248 hvConf.ToUpper();
249 if (hvConf != "OFF" ) {
250 UInt_t hvResult = MapHighVoltage(dcsAliasMap);
251 result+=hvResult;
252 status = new TParameter<int>("hvResult",hvResult);
253 resultArray->Add(status);
254 }
255
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
268 // Other calibration information will be retrieved through FXS files
269 // examples:
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
276 // pedestal entries
277
278 if(runType == kPedestalRunType) {
279 Int_t numSources = 1;
280 Int_t pedestalSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
281 TString source = fConfEnv->GetValue("Pedestal","DAQ");
282 source.ToUpper();
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++ ) {
294 pedestalResult = ExtractPedestals(pedestalSource[i]);
295 if ( pedestalResult == 0 ) break;
296 }
297 result += pedestalResult;
298 status = new TParameter<int>("pedestalResult",pedestalResult);
299 resultArray->Add(status);
300 }
301 }
302
303 // pulser trigger processing
304
305 if(runType == kPulserRunType) {
306 Int_t numSources = 1;
307 Int_t pulserSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
308 TString source = fConfEnv->GetValue("Pulser","DAQ");
309 source.ToUpper();
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;
325 status = new TParameter<int>("pulserResult",pulserResult);
326 resultArray->Add(status);
327 }
328 }
329
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
359 // Altro configuration
360
361
362 TString altroConf = fConfEnv->GetValue("AltroConf","ON");
363 goofieConf.ToUpper();
364 if (altroConf != "OFF" ) {
365 UInt_t altroResult = ExtractAltro(AliShuttleInterface::kDCS);
366 result+=altroResult;
367 status = new TParameter<int>("altroResult",altroResult);
368 resultArray->Add(status);
369 }
370
371
372 // Central Electrode processing
373
374 if( runType == kPhysicsRunType ||
375 runType == kLaserRunType ) {
376
377 Int_t numSources = 1;
378 Int_t ceSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
379 TString source = fConfEnv->GetValue("CE","DAQ");
380 source.ToUpper();
381 if ( source != "OFF" ) {
382 if ( source == "HLT") ceSource[0] = AliShuttleInterface::kHLT;
383 if (!GetHLTStatus()) ceSource[0] = AliShuttleInterface::kDAQ;
384 if (source == "HLTDAQ" ) {
385 numSources=2;
386 ceSource[0] = AliShuttleInterface::kHLT;
387 ceSource[1] = AliShuttleInterface::kDAQ;
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 }
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;
400 status = new TParameter<int>("ceResult",ceResult);
401 resultArray->Add(status);
402
403 numSources = 1;
404 Int_t qaSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
405 source = fConfEnv->GetValue("QA","DAQ");
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);
425 }
426 }
427 }
428
429 if (errorHandling == "OFF" ) {
430 AliCDBMetaData metaData;
431 metaData.SetBeamPeriod(0);
432 metaData.SetResponsible("Haavard Helstrup");
433 metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
434 metaData.SetComment("Preprocessor AliTPC status.");
435 Store("Calib", "PreprocStatus", resultArray, &metaData, 0, kFALSE);
436 resultArray->Delete();
437 return 0;
438 } else {
439 return result;
440 }
441}
442//______________________________________________________________________________________________
443UInt_t AliTPCPreprocessor::MapTemperature(TMap* dcsAliasMap)
444{
445
446 // extract DCS temperature maps. Perform fits to save space
447
448 UInt_t result=0;
449 TMap *map = fTemp->ExtractDCS(dcsAliasMap);
450 if (map) {
451 fTemp->MakeSplineFit(map);
452 Double_t fitFraction = 1.0*fTemp->NumFits()/fTemp->NumSensors();
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 }
459 } else {
460 Log("No temperature map extracted. \n");
461 result=9;
462 }
463 delete map;
464 // Now store the final CDB file
465
466 if ( result == 0 ) {
467 AliCDBMetaData metaData;
468 metaData.SetBeamPeriod(0);
469 metaData.SetResponsible("Haavard Helstrup");
470 metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
471 metaData.SetComment("Preprocessor AliTPC data base entries.");
472
473 Bool_t storeOK = Store("Calib", "Temperature", fTemp, &metaData, 0, kFALSE);
474 if ( !storeOK ) result=1;
475
476 }
477
478 return result;
479
480}
481
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);
492 Double_t fitFraction = 1.0*fHighVoltage->NumFits()/fHighVoltage->NumSensors();
493 if (fitFraction > kFitFraction ) {
494 AliInfo(Form("High voltage recordings extracted, fits performed.\n"));
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;
504
505 TString hvStatConf = fConfEnv->GetValue("HighVoltageStat","ON");
506 hvStatConf.ToUpper();
507 if (hvStatConf != "OFF" ) {
508 TMap *map2 = fHighVoltageStat->ExtractDCS(dcsAliasMap);
509 if (map2) {
510 fHighVoltageStat->ClearFit();
511 fHighVoltageStat->SetGraph(map2);
512 } else {
513 Log("No high voltage status recordings extracted. \n");
514 result=9;
515 }
516 delete map2;
517
518 // add status maps to high voltage sensor array
519
520 fHighVoltage->AddSensors(fHighVoltageStat);
521 }
522 // Now store the final CDB file
523
524 if ( result == 0 ) {
525 AliCDBMetaData metaData;
526 metaData.SetBeamPeriod(0);
527 metaData.SetResponsible("Haavard Helstrup");
528 metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
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
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");
564 metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
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
576
577//______________________________________________________________________________________________
578
579UInt_t AliTPCPreprocessor::ExtractPedestals(Int_t sourceFXS)
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 ) {
589 Log("AliTPCPreprocsessor: No previous TPC pedestal entry available.\n");
590 calPadPed = new AliTPCCalPad("PedestalsMean","PedestalsMean");
591 }
592
593 AliTPCCalPad *calPadRMS=0;
594 entry = GetFromOCDB("Calib", "PadNoise");
595 if (entry) calPadRMS = (AliTPCCalPad*)entry->GetObject();
596 if ( calPadRMS==NULL ) {
597 Log("AliTPCPreprocsessor: No previous TPC noise entry available.\n");
598 calPadRMS = new AliTPCCalPad("PedestalsRMS","PedestalsRMS");
599 }
600
601
602 UInt_t result=0;
603
604 Int_t nSectors = fROC->GetNSectors();
605 TList* list = GetFileSources(sourceFXS,"pedestals");
606
607 if (list && list->GetEntries()>0) {
608
609// loop through all files from LDCs
610
611 Bool_t changed=false;
612 UInt_t index = 0;
613 while (list->At(index)!=NULL) {
614 TObjString* fileNameEntry = (TObjString*) list->At(index);
615 if (fileNameEntry!=NULL) {
616 TString fileName = GetFile(sourceFXS, "pedestals",
617 fileNameEntry->GetString().Data());
618 TFile *f = TFile::Open(fileName);
619 if (!f) {
620 Log ("Error opening pedestal file.");
621 result =2;
622 break;
623 }
624 AliTPCCalibPedestal *calPed;
625 f->GetObject("tpcCalibPedestal",calPed);
626 if ( !calPed ) {
627 Log ("No pedestal calibration object in file.");
628 result = 2;
629 break;
630 }
631
632 // replace entries for the sectors available in the present file
633
634 changed=true;
635 for (Int_t sector=0; sector<nSectors; sector++) {
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);
640 }
641 delete calPed;
642 f->Close();
643 }
644 ++index;
645 } // while(list)
646//
647// Store updated pedestal entry to OCDB
648//
649 if (changed) {
650 AliCDBMetaData metaData;
651 metaData.SetBeamPeriod(0);
652 metaData.SetResponsible("Haavard Helstrup");
653 metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
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 }
661 } else {
662 Log ("Error: no entries in input file list!");
663 result = 1;
664 }
665
666 return result;
667}
668
669//______________________________________________________________________________________________
670
671
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
715 Bool_t changed=false;
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;
729 f->GetObject("tpcCalibPulser",calPulser);
730 if ( !calPulser ) {
731 Log ("No pulser calibration object in file.");
732 result = 2;
733 break;
734 }
735
736 // replace entries for the sectors available in the present file
737
738 changed=true;
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 }
747 delete calPulser;
748 f->Close();
749 }
750 ++index;
751 } // while(list)
752//
753// Store updated pedestal entry to OCDB
754//
755 if (changed) {
756 AliCDBMetaData metaData;
757 metaData.SetBeamPeriod(0);
758 metaData.SetResponsible("Haavard Helstrup");
759 metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
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 }
765 } else {
766 Log ("Error: no entries in input file list!");
767 result = 1;
768 }
769
770 return result;
771}
772
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;
783 TObjArray* rawArray = new TObjArray;
784
785 TList* list = GetFileSources(sourceFXS,"tpcCalibRaw");
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 }
803 AliTPCCalibRaw *calRaw;
804 f->GetObject("tpcCalibRaw",calRaw);
805 if ( !calRaw ) {
806 Log ("No raw calibration object in file.");
807 result = 2;
808 break;
809 }
810 rawArray->Add(calRaw);
811 f->Close();
812 }
813 ++index;
814 } // while(list)
815//
816// Store updated pedestal entry to OCDB
817//
818 AliCDBMetaData metaData;
819 metaData.SetBeamPeriod(0);
820 metaData.SetResponsible("Haavard Helstrup");
821 metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
822 metaData.SetComment("Preprocessor AliTPC data base entries.");
823
824 Bool_t storeOK = Store("Calib", "Raw", rawArray, &metaData, 0, kTRUE);
825 if ( !storeOK ) ++result;
826 } else {
827 Log ("Error: no entries in input file list!");
828 result = 1;
829 }
830
831 return result;
832}
833//______________________________________________________________________________________________
834
835UInt_t AliTPCPreprocessor::ExtractCE(Int_t sourceFXS)
836{
837 //
838 // Read Central Electrode file from file exchage server
839 //
840 //
841 AliTPCCalPad *ceTmean=0;
842 AliTPCCalPad *ceTrms=0;
843 AliTPCCalPad *ceQmean=0;
844 TObjArray *rocTtime=0;
845 TObjArray *rocQtime=0;
846
847 TObjArray *ceObjects= new TObjArray;
848
849
850 Int_t nSectors = fROC->GetNSectors();
851
852 ceTmean = new AliTPCCalPad("CETmean","CETmean");
853 ceObjects->Add(ceTmean);
854
855 ceTrms = new AliTPCCalPad("CETrms","CETrms");
856 ceObjects->Add(ceTrms);
857
858 ceQmean = new AliTPCCalPad("CEQmean","CEQmean");
859 ceObjects->Add(ceQmean);
860
861 rocTtime = new TObjArray(nSectors+2); // also make room for A and C side average
862 rocTtime->SetName("rocTtime");
863 ceObjects->Add(rocTtime);
864
865 rocQtime = new TObjArray(nSectors);
866 rocQtime->SetName("rocQtime");
867 ceObjects->Add(rocQtime);
868
869
870 UInt_t result=0;
871
872 TList* list = GetFileSources(sourceFXS,"CE");
873
874 if (list && list->GetEntries()>0) {
875
876// loop through all files from LDCs
877
878 UInt_t index = 0;
879 while (list->At(index)!=NULL) {
880 TObjString* fileNameEntry = (TObjString*) list->At(index);
881 if (fileNameEntry!=NULL) {
882 TString fileName = GetFile(sourceFXS, "CE",
883 fileNameEntry->GetString().Data());
884 TFile *f = TFile::Open(fileName);
885 if (!f) {
886 Log ("Error opening central electrode file.");
887 result =2;
888 break;
889 }
890 AliTPCCalibCE *calCE;
891 f->GetObject("tpcCalibCE",calCE);
892
893 if (!calCE) {
894 Log ("No valid calibCE object.");
895 result=2;
896 break;
897 }
898 // replace entries for the sectors available in the present file
899
900 for (Int_t sector=0; sector<nSectors; sector++) {
901 AliTPCCalROC *rocTmean=calCE->GetCalRocT0(sector);
902 if ( rocTmean ) ceTmean->SetCalROC(rocTmean,sector);
903 AliTPCCalROC *rocTrms=calCE->GetCalRocRMS(sector);
904 if ( rocTrms ) ceTrms->SetCalROC(rocTrms,sector);
905 AliTPCCalROC *rocQmean=calCE->GetCalRocQ(sector);
906 if ( rocQmean ) ceQmean->SetCalROC(rocQmean,sector);
907 TGraph *grT=calCE->MakeGraphTimeCE(sector,0,2); // T time graph
908 if ( grT ) rocTtime->AddAt(grT,sector);
909 TGraph *grQ=calCE->MakeGraphTimeCE(sector,0,3); // Q time graph
910 if ( grQ ) rocTtime->AddAt(grQ,sector);
911 }
912
913 TGraph *grT=calCE->MakeGraphTimeCE(-1,0,2); // A side average
914 if ( grT ) rocTtime->AddAt(grT,nSectors);
915 grT=calCE->MakeGraphTimeCE(-2,0,2); // C side average
916 if ( grT ) rocTtime->AddAt(grT,nSectors+1);
917
918
919 delete calCE;
920 f->Close();
921 }
922 ++index;
923 } // while(list)
924//
925// Store updated pedestal entry to OCDB
926//
927 AliCDBMetaData metaData;
928 metaData.SetBeamPeriod(0);
929 metaData.SetResponsible("Haavard Helstrup");
930 metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
931 metaData.SetComment("Preprocessor AliTPC data base entries.");
932
933 Bool_t storeOK = Store("Calib", "CE", ceObjects, &metaData, 0, kTRUE);
934 if ( !storeOK ) ++result;
935
936 } else {
937 Log ("Error: no entries!");
938 result = 1;
939 }
940
941 return result;
942}
943//______________________________________________________________________________________________
944
945UInt_t AliTPCPreprocessor::ExtractQA(Int_t sourceFXS)
946{
947 //
948 // Read Quality Assurance file from file exchage server
949 //
950
951 UInt_t result=0;
952
953 TList* list = GetFileSources(sourceFXS,"QA");
954
955 if (list && list->GetEntries()>0) {
956
957// only one QA objetc should be available!
958
959 AliTPCdataQA *calQA;
960
961 UInt_t nentries = list->GetEntries();
962 UInt_t index=0;
963 if ( nentries > 1) Log ( "More than one QA entry. First one processed");
964 TObjString* fileNameEntry = (TObjString*) list->At(index);
965 if (fileNameEntry!=NULL) {
966 TString fileName = GetFile(sourceFXS, "QA",
967 fileNameEntry->GetString().Data());
968 TFile *f = TFile::Open(fileName);
969 if (!f) {
970 Log ("Error opening QA file.");
971 result =2;
972 } else {
973 f->GetObject("tpcCalibQA",calQA);
974 if ( calQA ) {
975//
976// Store updated pedestal entry to OCDB
977//
978 AliCDBMetaData metaData;
979 metaData.SetBeamPeriod(0);
980 metaData.SetResponsible("Haavard Helstrup");
981 metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
982 metaData.SetComment("Preprocessor AliTPC data base entries.");
983
984 Bool_t storeOK = Store("Calib", "QA", calQA, &metaData, 0, kTRUE);
985 if ( !storeOK ) ++result;
986 }
987 }
988 } else {
989 Log ("Error: no QA files on FXS!");
990 result = 2;
991 }
992 } else {
993 Log ("Error: no QA entries in FXS list!");
994 result = 1;
995 }
996 return result;
997}
998
999//______________________________________________________________________________________________
1000
1001
1002UInt_t AliTPCPreprocessor::ExtractAltro(Int_t sourceFXS)
1003{
1004 //
1005 // Read pulser calibration file from file exchage server
1006 // Keep original entry from OCDB in case no new pulser calibration is available
1007 //
1008 TObjArray *altroObjects=0;
1009 AliTPCCalPad *acqStart=0;
1010 AliTPCCalPad *zsThr=0;
1011 AliTPCCalPad *acqStop=0;
1012 AliTPCCalPad *FPED=0;
1013 AliTPCCalPad *masked=0;
1014
1015 AliCDBEntry* entry = GetFromOCDB("Calib", "Altro");
1016 if (entry) altroObjects = (TObjArray*)entry->GetObject();
1017 if ( altroObjects==NULL ) {
1018 Log("AliTPCPreprocsessor: No previous TPC altro calibration entry available.\n");
1019 altroObjects = new TObjArray;
1020 }
1021
1022 acqStart = (AliTPCCalPad*)altroObjects->FindObject("AcqStart");
1023 if ( !acqStart ) {
1024 acqStart = new AliTPCCalPad("AcqStart","AcqStart");
1025 altroObjects->Add(acqStart);
1026 }
1027 zsThr = (AliTPCCalPad*)altroObjects->FindObject("ZsThr");
1028 if ( !zsThr ) {
1029 zsThr = new AliTPCCalPad("ZsThr","ZsThr");
1030 altroObjects->Add(zsThr);
1031 }
1032 FPED = (AliTPCCalPad*)altroObjects->FindObject("FPED");
1033 if ( !FPED ) {
1034 FPED = new AliTPCCalPad("FPED","FPED");
1035 altroObjects->Add(FPED);
1036 }
1037 acqStop = (AliTPCCalPad*)altroObjects->FindObject("AcqStop");
1038 if ( !acqStop ) {
1039 acqStop = new AliTPCCalPad("AcqStop","AcqStop");
1040 altroObjects->Add(acqStop);
1041 }
1042 masked = (AliTPCCalPad*)altroObjects->FindObject("Masked");
1043 if ( !masked ) {
1044 masked = new AliTPCCalPad("Masked","Masked");
1045 altroObjects->Add(masked);
1046 }
1047
1048
1049
1050 UInt_t result=0;
1051 TString idFXS[2]={"AltroConfigA","AltroConfigC"};
1052
1053 Int_t nSectors = fROC->GetNSectors();
1054 Bool_t changed=false;
1055 for ( Int_t id=0; id<2; id++) {
1056 TList* list = GetFileSources(sourceFXS,idFXS[id].Data());
1057
1058 if (list && list->GetEntries()>0) {
1059 if (altroObjects == 0 ) altroObjects = new TObjArray;
1060
1061// loop through all files from LDCs
1062
1063 UInt_t index = 0;
1064 while (list->At(index)!=NULL) {
1065 TObjString* fileNameEntry = (TObjString*) list->At(index);
1066 if (fileNameEntry!=NULL) {
1067 TString fileName = GetFile(sourceFXS, idFXS[id].Data(),
1068 fileNameEntry->GetString().Data());
1069 TFile *f = TFile::Open(fileName);
1070 if (!f) {
1071 char message[40];
1072 sprintf(message,"Error opening Altro configuration file, id = %d",id);
1073 Log (message);
1074 result =2;
1075 break;
1076 }
1077 TObjArray *altroFXS;
1078 f->GetObject("AltroConfig",altroFXS);
1079 if ( !altroFXS ) {
1080 Log ("No Altro configuration object in file.");
1081 result = 2;
1082 break;
1083 }
1084
1085 // replace entries for the sectors available in the present file
1086 AliTPCCalPad *acqStartFXS=(AliTPCCalPad*)altroFXS->FindObject("AcqStart");
1087 AliTPCCalPad *zsThrFXS=(AliTPCCalPad*)altroFXS->FindObject("ZsThr");
1088 AliTPCCalPad *acqStopFXS=(AliTPCCalPad*)altroFXS->FindObject("AcqStop");
1089 AliTPCCalPad *FPEDFXS=(AliTPCCalPad*)altroFXS->FindObject("FPED");
1090 AliTPCCalPad *maskedFXS=(AliTPCCalPad*)altroFXS->FindObject("Masked");
1091
1092 changed=true;
1093 for (Int_t sector=0; sector<nSectors; sector++) {
1094
1095 if (acqStartFXS) {
1096 AliTPCCalROC *rocAcqStart=acqStartFXS->GetCalROC(sector);
1097 if ( rocAcqStart ) acqStart->SetCalROC(rocAcqStart,sector);
1098 }
1099 if (zsThrFXS ) {
1100 AliTPCCalROC *rocZsThr=zsThrFXS->GetCalROC(sector);
1101 if ( rocZsThr ) zsThr->SetCalROC(rocZsThr,sector);
1102 }
1103 if (acqStopFXS) {
1104 AliTPCCalROC *rocAcqStop=acqStopFXS->GetCalROC(sector);
1105 if ( rocAcqStop ) acqStop->SetCalROC(rocAcqStop,sector);
1106 }
1107 if (FPEDFXS ) {
1108 AliTPCCalROC *rocFPED=FPEDFXS->GetCalROC(sector);
1109 if ( rocFPED ) FPED->SetCalROC(rocFPED,sector);
1110 }
1111 if (maskedFXS) {
1112 AliTPCCalROC *rocMasked=maskedFXS->GetCalROC(sector);
1113 if ( rocMasked ) masked->SetCalROC(rocMasked,sector);
1114 }
1115 }
1116 delete altroFXS;
1117 f->Close();
1118 }
1119 ++index;
1120 } // while(list)
1121 } else {
1122 Log ("Error: no entries in input file list!");
1123 result = 1;
1124 }
1125
1126 } // for - id
1127//
1128// Store updated pedestal entry to OCDB
1129//
1130 if (changed) {
1131 AliCDBMetaData metaData;
1132 metaData.SetBeamPeriod(0);
1133 metaData.SetResponsible("Haavard Helstrup");
1134 metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
1135 metaData.SetComment("Preprocessor AliTPC data base entries.");
1136
1137 Bool_t storeOK = Store("Calib", "AltroConfig", altroObjects, &metaData, 0, kTRUE);
1138 if ( !storeOK ) ++result;
1139 }
1140
1141 return result;
1142}