]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFPreprocessor.cxx
Correction.
[u/mrichter/AliRoot.git] / TOF / AliTOFPreprocessor.cxx
CommitLineData
c9fe8530 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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
9edefa04 16/* $Id$ */
9d883ed9 17
3aaf7a5f 18
a174d599 19//#include <Riostream.h>
20//#include <stdio.h>
21//#include <stdlib.h>
c9fe8530 22
9edefa04 23#include <TFile.h>
9edefa04 24#include <TH2S.h>
25#include <TMath.h>
26#include <TObjArray.h>
27#include <TObjString.h>
28#include <TTimeStamp.h>
c9fe8530 29
30#include "AliCDBMetaData.h"
7fffa85b 31#include "AliCDBEntry.h"
c9fe8530 32#include "AliLog.h"
17149e6b 33#include "AliTOFChannelOnlineArray.h"
34#include "AliTOFChannelOnlineStatusArray.h"
9edefa04 35#include "AliTOFDataDCS.h"
10056aa6 36#include "AliTOFGeometry.h"
9edefa04 37#include "AliTOFPreprocessor.h"
db83b789 38#include "AliTOFFEEReader.h"
3dda26a0 39#include "AliTOFRawStream.h"
40#include "AliTOFCableLengthMap.h"
b06d5296 41#include "AliTOFcalibHisto.h"
3dda26a0 42
c9fe8530 43
c9fe8530 44// TOF preprocessor class.
45// It takes data from DCS and passes them to the class AliTOFDataDCS, which
46// processes them. The result is then written to the CDB.
17149e6b 47// Analogously, it takes data form DAQ (both at Run level and inclusive -
c9fe8530 48// of all the runs - level, processes them, and stores both Reference Data
49// and Online Calibration files in the CDB.
17149e6b 50// Processing of Pulser/Noise Run data and of TOF FEE DCS map included also.
7fffa85b 51
52// return codes:
53// return=0 : all ok
54// return=1 : no DCS input data Map
55// return=2 : no DCS input data processing
56// return=3 : no DCS processed data was stored in Ref Data
57// return=4 : no DAQ input for Ref Data
58// return=5 : failed to store DAQ Ref Data
59// return=6 : failed to retrieve DAQ data for calibration
60// return=7 : problems in processing histos in the input DAQ file
61// return=8 : failed to store Online Delays
62// return=9 : failed to store Reference Data for Pulser
63// return=10: failed to retrieve Pulser data
64// return=11: failed to store Pulser map in OCDB
65// return=12: failed to store Reference Data for Noise
66// return=13: failed to retrieve Noise data
67// return=14: failed to store Noise map in OCDB
db83b789 68// return=15: failed to retrieve FEE data from FXS
69// return=16: failed to retrieve FEE data from OCDB
70// return=17: failed to store FEE data in OCDB
71// return=18: failed to store FEE reference data in OCDB
17149e6b 72// return=20: failed in retrieving status variable
c9fe8530 73
74ClassImp(AliTOFPreprocessor)
75
7fffa85b 76const Int_t AliTOFPreprocessor::fgkBinRangeAve = 13; // number of bins where to calculate the mean
77const Double_t AliTOFPreprocessor::fgkIntegralThr = 100; // min number of entries to perform computation of delay per channel
78const Double_t AliTOFPreprocessor::fgkThrPar = 0.013; // parameter used to trigger the calculation of the delay
c9fe8530 79
80//_____________________________________________________________________________
81
708db10b 82AliTOFPreprocessor::AliTOFPreprocessor(AliShuttleInterface* shuttle) :
83 AliPreprocessor("TOF", shuttle),
c9fe8530 84 fData(0),
c9fe8530 85 fCal(0),
10056aa6 86 fNChannels(0),
7fffa85b 87 fStoreRefData(kTRUE),
17149e6b 88 fFDRFlag(kFALSE),
013ac2dd 89 fStatus(0),
02ede0c4 90 fMatchingWindow(0),
91 fLatencyWindow(0)
c9fe8530 92{
93 // constructor
370aeff7 94 AddRunType("PHYSICS");
95 AddRunType("PULSER");
96 AddRunType("NOISE");
10056aa6 97
c9fe8530 98}
99
100//_____________________________________________________________________________
101
102AliTOFPreprocessor::~AliTOFPreprocessor()
103{
104 // destructor
105}
106
107//______________________________________________________________________________
108void AliTOFPreprocessor::Initialize(Int_t run, UInt_t startTime,
109 UInt_t endTime)
110{
111 // Creates AliTOFDataDCS object
112
113 AliPreprocessor::Initialize(run, startTime, endTime);
114
ff326f84 115 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s \n\tStartTime DCS Query %s \n\tEndTime DCS Query %s", run,
c9fe8530 116 TTimeStamp(startTime).AsString(),
ff326f84 117 TTimeStamp(endTime).AsString(), ((TTimeStamp)GetStartTimeDCSQuery()).AsString(), ((TTimeStamp)GetEndTimeDCSQuery()).AsString()));
c9fe8530 118
ff326f84 119 fData = new AliTOFDataDCS(fRun, fStartTime, fEndTime, GetStartTimeDCSQuery(), GetEndTimeDCSQuery());
10056aa6 120 fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
c9fe8530 121}
7fffa85b 122//_____________________________________________________________________________
123Bool_t AliTOFPreprocessor::ProcessDCS(){
124
125 // check whether DCS should be processed or not...
c9fe8530 126
7fffa85b 127 TString runType = GetRunType();
128 Log(Form("RunType %s",runType.Data()));
129
55454922 130 if (runType != "PHYSICS"){
7fffa85b 131 return kFALSE;
132 }
133
134 return kTRUE;
135}
c9fe8530 136//_____________________________________________________________________________
137
ee3e792b 138UInt_t AliTOFPreprocessor::ProcessDCSDataPoints(TMap* dcsAliasMap)
c9fe8530 139{
140 // Fills data into a AliTOFDataDCS object
141
7fffa85b 142
143 Log("Processing DCS DP");
708db10b 144 TH1::AddDirectory(0);
5936ab02 145
7885c291 146 Bool_t resultDCSMap=kFALSE;
147 Bool_t resultDCSStore=kFALSE;
c9fe8530 148
149 // processing DCS
150
4856f488 151 fData->SetFDRFlag(fFDRFlag);
152
c9fe8530 153 if (!dcsAliasMap){
5936ab02 154 Log("No DCS map found: TOF exiting from Shuttle");
e88f3330 155 if (fData){
156 delete fData;
157 fData = 0;
158 }
5936ab02 159 return 1;// return error Code for DCS input data not found
c9fe8530 160 }
161 else {
4856f488 162
c9fe8530 163 // The processing of the DCS input data is forwarded to AliTOFDataDCS
7885c291 164 resultDCSMap=fData->ProcessData(*dcsAliasMap);
165 if(!resultDCSMap){
166 Log("Some problems occurred while processing DCS data, TOF exiting from Shuttle");
e88f3330 167 if (fData){
168 delete fData;
169 fData = 0;
170 }
5936ab02 171 return 2;// return error Code for processed DCS data not stored
c9fe8530 172 }
7885c291 173 else{
174 AliCDBMetaData metaDataDCS;
175 metaDataDCS.SetBeamPeriod(0);
176 metaDataDCS.SetResponsible("Chiara Zampolli");
177 metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object.");
178 AliInfo("Storing DCS Data");
b0d8f3fc 179 resultDCSStore = StoreReferenceData("Calib","DCSData",fData, &metaDataDCS);
7885c291 180 if (!resultDCSStore){
b0d8f3fc 181 Log("Some problems occurred while storing DCS data results in Reference Data, TOF exiting from Shuttle");
e88f3330 182 if (fData){
183 delete fData;
184 fData = 0;
185 }
7885c291 186 return 3;// return error Code for processed DCS data not stored
b0d8f3fc 187 // in reference data
7885c291 188
189 }
190 }
c9fe8530 191 }
e88f3330 192 if (fData){
193 delete fData;
194 fData = 0;
195 }
196
ee3e792b 197 return 0;
198}
199//_____________________________________________________________________________
200
201UInt_t AliTOFPreprocessor::ProcessOnlineDelays()
202{
7fffa85b 203 // Processing data from DAQ for online calibration
204
965fa008 205 Bool_t updateOCDB = kFALSE;
7fffa85b 206 Log("Processing DAQ delays");
ee3e792b 207
17149e6b 208 // reading configuration map
209 TString compDelays = "kFALSE";
210 Int_t deltaStartingRun = fRun;
211 Int_t startingRun = fRun-deltaStartingRun;
212 Int_t binRangeAve = fgkBinRangeAve;
213 Double_t integralThr = fgkIntegralThr;
214 Double_t thrPar = fgkThrPar;
215
216 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Config");
217 if (!cdbEntry) {
218 Log(Form("No Configuration entry found in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
219 }
220 else {
221 TMap *configMap = (TMap*)cdbEntry->GetObject();
222 if (!configMap){
223 Log(Form("No map found in Config entry in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
224 }
225 else{
226 TObjString *strDelays = (TObjString*)configMap->GetValue("ComputingDelays");
227 if (strDelays) {
228 compDelays = (TString) strDelays->GetString();
229 }
230 else {
231 Log(Form("No ComputingDelays value found in Map from Config entry in CDB, using default value: ComputingDelays = %s",compDelays.Data()));
232 }
233 TObjString *strRun = (TObjString*)configMap->GetValue("StartingRun");
234 if (strRun) {
235 TString tmpstr = strRun->GetString();
236 startingRun = tmpstr.Atoi();
237 deltaStartingRun = fRun - startingRun;
238 }
239 else {
240 Log(Form("No StartingRun value found in Map from Config entry in CDB, using default value: StartingRun = %i",startingRun));
241 }
242 TObjString *strBinRangeAve = (TObjString*)configMap->GetValue("BinRangeAve");
243 if (strBinRangeAve) {
244 TString tmpstr = strBinRangeAve->GetString();
245 binRangeAve = tmpstr.Atoi();
246 }
247 else {
248 Log(Form("No BinRangeAve value found in Map from Config entry in CDB, using default value: BinRangeAve = %i",binRangeAve));
249 }
250 TObjString *strIntegralThr = (TObjString*)configMap->GetValue("IntegralThr");
251 if (strIntegralThr) {
252 TString tmpstr = strIntegralThr->GetString();
253 integralThr = tmpstr.Atof();
254 }
255 else {
256 Log(Form("No IntegralThr value found in Map from Config entry in CDB, using default value: IntegralThr = %i",integralThr));
257 }
258 TObjString *strThrPar = (TObjString*)configMap->GetValue("ThrPar");
259 if (strThrPar) {
260 TString tmpstr = strThrPar->GetString();
261 thrPar = tmpstr.Atof();
262 }
263 else {
264 Log(Form("No ThrPar value found in Map from Config entry in CDB, using default value: ThrPar = %i",thrPar));
265 }
266 }
267 }
268 if (compDelays == "kTRUE") fFDRFlag = kFALSE;
269 else fFDRFlag = kTRUE;
270
e88f3330 271 delete cdbEntry;
272 cdbEntry = 0x0;
273
17149e6b 274 Log(Form("ComputingDelays = %s, StartingRun = %i",compDelays.Data(),startingRun));
275
965fa008 276 /* init array with current calibration, if any */
277 fCal = new AliTOFChannelOnlineArray(fNChannels);
278 AliTOFChannelOnlineArray *curCal = NULL;
279
280 AliCDBEntry *cdbEntry2 = GetFromOCDB("Calib","ParOnlineDelay");
281 if (!cdbEntry2 || !cdbEntry2->GetObject()) {
282 /* no CDB entry found. set update flag */
283 Log(" ************ WARNING ************");
284 Log("No CDB ParOnlineDelay entry found, creating a new one!");
285 Log(" *********************************");
286 updateOCDB = kTRUE;
287 }
288 else {
289 Log("Found previous ParOnlineDelay entry. Using it to init calibration");
290 curCal = (AliTOFChannelOnlineArray *)cdbEntry2->GetObject();
291 for (Int_t i = 0; i < fNChannels; i++)
292 fCal->SetDelay(i, curCal->GetDelay(i));
293 }
294
17149e6b 295
ee3e792b 296 TH1::AddDirectory(0);
297
298 Bool_t resultDAQRef=kFALSE;
7fffa85b 299 Bool_t resultTOFPP=kFALSE;
e88f3330 300 TH2S *h2 = 0x0;
c9fe8530 301 // processing DAQ
7885c291 302
c9fe8530 303 TFile * daqFile=0x0;
7885c291 304
5936ab02 305 if(fStoreRefData){
306 //retrieving data at Run level
17149e6b 307 TList* list = GetFileSources(kDAQ, "RUNLevel");
308 if (list !=0x0 && list->GetEntries()!=0)
309 {
310 AliInfo("The following sources produced files with the id RUNLevel");
311 list->Print();
312 for (Int_t jj=0;jj<list->GetEntries();jj++){
313 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
314 AliInfo(Form("found source %s", str->String().Data()));
315 // file to be stored run per run
316 TString fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName());
317 if (fileNameRun.Length()>0){
318 AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun.Data()));
319 daqFile = new TFile(fileNameRun.Data(),"READ");
e88f3330 320 h2 = (TH2S*) daqFile->Get("htof");
17149e6b 321 AliCDBMetaData metaDataHisto;
322 metaDataHisto.SetBeamPeriod(0);
323 metaDataHisto.SetResponsible("Chiara Zampolli");
324 metaDataHisto.SetComment("This preprocessor stores the array of histos object as Reference Data.");
325 AliInfo("Storing Reference Data");
e88f3330 326 resultDAQRef = StoreReferenceData("Calib","DAQData",h2, &metaDataHisto);
17149e6b 327 if (!resultDAQRef){
328 Log("some problems occurred::No Reference Data stored, TOF exiting from Shuttle");
e88f3330 329 delete h2;
330 delete list;
331 delete fCal;
332 fCal=0x0;
17149e6b 333 return 5;//return error code for failure in storing Ref Data
334 }
335 daqFile->Close();
336 delete daqFile;
337 }
338
339 else{
340 Log("The input data file from DAQ (run-level) was not found, TOF exiting from Shuttle ");
e88f3330 341 delete list;
342 delete fCal;
343 fCal=0x0;
17149e6b 344 return 4;//return error code for failure in retrieving Ref Data
345 }
346 }
347 delete list;
348 }
5936ab02 349 else{
17149e6b 350 Log("The input data file list from DAQ (run-level) was not found, TOF exiting from Shuttle ");
e88f3330 351 delete fCal;
352 fCal=0x0;
17149e6b 353 return 4;//return error code for failure in retrieving Ref Data
354 }
9bc469d1 355 }
356
9bc469d1 357
17149e6b 358 //Total files, with cumulative histos
5936ab02 359
9bc469d1 360 TList* listTot = GetFileSources(kDAQ, "DELAYS");
bf76be9c 361 if (listTot !=0x0 && listTot->GetEntries()!=0)
17149e6b 362 {
363 AliInfo("The following sources produced files with the id DELAYS");
364 listTot->Print();
365 for (Int_t jj=0;jj<listTot->GetEntries();jj++){
366 TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj));
367 AliInfo(Form("found source %s", str->String().Data()));
368
369 // file with summed histos, to extract calib params
370 TString fileName = GetFile(kDAQ, "DELAYS", str->GetName());
371 if (fileName.Length()>0){
372 AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data()));
373
374 daqFile = new TFile(fileName.Data(),"READ");
e88f3330 375 if (h2) delete h2;
376 h2 = (TH2S*) daqFile->Get("htoftot");
377 if (!h2){
17149e6b 378 Log("some problems occurred:: No histo retrieved, TOF exiting from Shuttle");
e88f3330 379 delete listTot;
17149e6b 380 delete daqFile;
e88f3330 381 delete fCal;
382 fCal=0x0;
17149e6b 383 return 7; //return error code for histograms not existing/junky
384 }
385 else {
e88f3330 386 static const Int_t kSize=h2->GetNbinsX();
387 static const Int_t kNBins=h2->GetNbinsY();
388 static const Double_t kXBinmin=h2->GetYaxis()->GetBinLowEdge(1);
17149e6b 389 if (kSize != fNChannels){
390 Log(" number of bins along x different from number of pads, found only a subset of the histograms, TOF exiting from Shuttle");
e88f3330 391 delete listTot;
392 delete h2;
17149e6b 393 delete daqFile;
e88f3330 394 delete fCal;
395 fCal=0x0;
17149e6b 396 return 7; //return error code for histograms not existing/junky
397 }
398 Int_t nNotStatistics = 0; // number of channel with not enough statistics
3dda26a0 399
b06d5296 400 /* FDR flag set. do not compute delays, use nominal cable delays */
3dda26a0 401 if (fFDRFlag) {
402
403 Log(" Not computing delays according to flag set in Config entry in OCDB!");
b06d5296 404 FillWithCosmicCalibration(fCal);
965fa008 405
406 /* check whether the new calibration is different from the previous one */
407 if (curCal) { /* well, check also whether we have a previous calibration */
408 for (Int_t i = 0; i < fNChannels; i++) {
409 if (fCal->GetDelay(i) != curCal->GetDelay(i)) {
410 updateOCDB = kTRUE;
411 break;
412 }
413 }
414 }
415 else /* otherwise update OCDB */
416 updateOCDB = kTRUE;
417
3dda26a0 418 }
17149e6b 419
420 else { // computing delays if not in FDR runs
965fa008 421
422 updateOCDB = kTRUE; /* always update OCDB when computing delays */
423
17149e6b 424 for (Int_t ich=0;ich<kSize;ich++){
425 /* check whether channel has been read out during current run.
426 * if the status is bad it means it has not been read out.
427 * in this case skip channel in order to not affect the mean */
428 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad){
429 AliDebug(2,Form(" Channel %i found bad according to FEEmap, (HW status = %i), skipping from delay computing",ich, (Int_t)fStatus->GetHWStatus(ich)));
430 continue;
431 }
432 AliDebug(2,Form(" Channel %i found ok according to FEEmap, starting delay computing",ich));
433 TH1S *h1 = new TH1S("h1","h1",kNBins,kXBinmin-0.5,kNBins*1.+kXBinmin-0.5);
434 for (Int_t ibin=0;ibin<kNBins;ibin++){
e88f3330 435 h1->SetBinContent(ibin+1,h2->GetBinContent(ich+1,ibin+1));
17149e6b 436 }
437 if(h1->Integral()<integralThr) {
438 nNotStatistics++;
439 Log(Form(" Not enough statistics for bin %i, skipping this channel",ich)); // printing message only if not in FDR runs
440 delete h1;
441 h1=0x0;
442 continue;
443 }
444 Bool_t found=kFALSE;
445 Float_t minContent=h1->Integral()*thrPar;
446 Int_t nbinsX = h1->GetNbinsX();
447 Int_t startBin=1;
448 for (Int_t j=1; j<=nbinsX; j++){
449 if ((
450 h1->GetBinContent(j) +
451 h1->GetBinContent(j+1)+
452 h1->GetBinContent(j+2)+
453 h1->GetBinContent(j+3))>minContent){
454 found=kTRUE;
455 startBin=j;
456 break;
457 }
458 }
459 if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",ich));
460 // Now calculate the mean over the interval.
461 Double_t mean = 0;
462 Double_t sumw2 = 0;
463 Double_t nent = 0;
464 for(Int_t k=0;k<binRangeAve;k++){
465 mean=mean+h1->GetBinCenter(startBin+k)*h1->GetBinContent(startBin+k);
466 nent=nent+h1->GetBinContent(startBin+k);
467 sumw2=sumw2+(h1->GetBinCenter(startBin+k))*(h1->GetBinCenter(startBin+k))*(h1->GetBinContent(startBin+k));
468 }
469 mean= mean/nent; //<x>
470 sumw2=sumw2/nent; //<x^2>
471 Double_t rmsmean= 0;
472 rmsmean = TMath::Sqrt((sumw2-mean*mean)/nent);
473 if (ich<fNChannels) {
474 Float_t delay = mean*AliTOFGeometry::TdcBinWidth()*1.E-3; // delay in ns
475 fCal->SetDelay(ich,delay); // delay in ns
476 AliDebug(2,Form("Setting delay %f (ns) for channel %i",delay,ich));
477 }
478 delete h1;
479 h1=0x0;
480 }
481 }
482 if (nNotStatistics!=0) Log(Form("Too little statistics for %d channels!",nNotStatistics));
483 }
e88f3330 484 delete h2;
17149e6b 485 daqFile->Close();
486 delete daqFile;
487 }
488 else{
489 Log("The Cumulative data file from DAQ does not exist, TOF exiting from Shuttle");
e88f3330 490 delete listTot;
491 delete fCal;
492 fCal=0x0;
17149e6b 493 return 6;//return error code for problems in retrieving DAQ data
494 }
7fffa85b 495 }
17149e6b 496 delete listTot;
c9fe8530 497 }
c9fe8530 498 else{
9d883ed9 499 Log("Problem: no list for Cumulative data file from DAQ was found, TOF exiting from Shuttle");
e88f3330 500 delete fCal;
501 fCal=0x0;
7885c291 502 return 6; //return error code for problems in retrieving DAQ data
c9fe8530 503 }
504
965fa008 505 /* check whether we don't need to update OCDB.
506 * in this case we can return without errors and
507 * the current FEE is stored in the fStatus object. */
508 if (!updateOCDB) {
509 AliInfo("update OCDB flag not set. Do not overwrite stored file.");
510 return 0; /* return ok */
511 }
512
c9fe8530 513 daqFile=0;
7fffa85b 514 AliCDBMetaData metaData;
515 metaData.SetBeamPeriod(0);
516 metaData.SetResponsible("Chiara Zampolli");
17149e6b 517 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineArray object for online calibration - delays.");
7fffa85b 518 AliInfo("Storing Calibration Data");
17149e6b 519 resultTOFPP = Store("Calib","ParOnlineDelay",fCal, &metaData,deltaStartingRun,kTRUE);
7fffa85b 520 if(!resultTOFPP){
521 Log("Some problems occurred while storing online object resulting from DAQ data processing");
e88f3330 522 delete fCal;
523 fCal=0x0;
7fffa85b 524 return 8;//return error code for problems in storing DAQ data
525 }
9d883ed9 526
e88f3330 527 if (fCal){
528 delete fCal;
529 fCal = 0;
530 }
531
5936ab02 532 return 0;
c9fe8530 533}
ee3e792b 534//_____________________________________________________________________________
535
536UInt_t AliTOFPreprocessor::ProcessPulserData()
537{
7fffa85b 538 // Processing Pulser Run data for TOF channel status
539
540 Log("Processing Pulser");
ee3e792b 541
17149e6b 542 if (fStatus==0x0){
543 AliError("No valid fStatus found, some errors must have occurred!!");
544 return 20;
545 }
ee3e792b 546
17149e6b 547 TH1::AddDirectory(0);
548
ee3e792b 549 Bool_t resultPulserRef=kFALSE;
7fffa85b 550 Bool_t resultPulser=kFALSE;
17149e6b 551
a174d599 552 static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
553 TH1S * htofPulser = new TH1S("hTOFpulser","histo with signals on TOF during pulser", kSize,-0.5,kSize-0.5);
554 for (Int_t ibin =1;ibin<=kSize;ibin++){
17149e6b 555 htofPulser->SetBinContent(ibin,-1);
7fffa85b 556 }
17149e6b 557
ee3e792b 558 // processing pulser
559
560 TFile * daqFile=0x0;
561 TH1S *h1=0x0;
562
563 //retrieving Pulser data
564 TList* listPulser = GetFileSources(kDAQ, "PULSER");
bf76be9c 565 if (listPulser !=0x0 && listPulser->GetEntries()!=0)
e88f3330 566 {
567 AliInfo("The following sources produced files with the id PULSER");
568 listPulser->Print();
569 Int_t nPulser = 0;
570 for (Int_t jj=0;jj<listPulser->GetEntries();jj++){
571 Int_t nPulserSource = 0;
572 TObjString * str = dynamic_cast<TObjString*> (listPulser->At(jj));
573 AliInfo(Form("found source %s", str->String().Data()));
574 // file to be stored run per run
575 TString fileNamePulser = GetFile(kDAQ, "PULSER", str->GetName());
576 if (fileNamePulser.Length()>0){
577 // storing refernce data
578 AliInfo(Form("Got the file %s, now we can process pulser data.", fileNamePulser.Data()));
579 daqFile = new TFile(fileNamePulser.Data(),"READ");
580 h1 = (TH1S*) daqFile->Get("hTOFpulser");
581 for (Int_t ibin=0;ibin<kSize;ibin++){
582 if ((h1->GetBinContent(ibin+1))!=-1){
583 if ((htofPulser->GetBinContent(ibin+1))==-1){
584 htofPulser->SetBinContent(ibin+1,h1->GetBinContent(ibin+1));
585 }
586 else {
587 Log(Form("Something strange occurred during Pulser run, channel %i already read by another LDC, please check!",ibin));
588 }
589 }
590 }
591
592 // elaborating infos
593 Double_t mean =0;
594 Int_t nread=0;
595 Int_t nreadNotEmpty=0;
596 for (Int_t ientry=1;ientry<=h1->GetNbinsX();ientry++){
597
598 AliDebug(3,Form(" channel %i pulser status before pulser = %i, with global status = %i",ientry,(Int_t)fStatus->GetPulserStatus(ientry),(Int_t)fStatus->GetStatus(ientry)));
599 /* check whether channel has been read out during current run.
600 * if the status is bad it means it has not been read out.
601 * in this case skip channel in order to not affect the mean */
602 if (fStatus->GetHWStatus(ientry-1) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
603 continue;
604 nPulser++;
605 nPulserSource++;
606 if (h1->GetBinContent(ientry)==-1) continue;
607 else {
608 if (h1->GetBinContent(ientry)>0) {
609 nreadNotEmpty++;
610 AliDebug(2,Form(" channel %i is ok with entry = %f; so far %i channels added ",ientry-1,h1->GetBinContent(ientry),nreadNotEmpty));
611 }
612 mean+=h1->GetBinContent(ientry);
613 nread++;
614 }
615 }
616 if (nread!=0) {
617 mean/=nread;
618 AliDebug(2,Form(" nread = %i , nreadNotEmpty = %i, mean = %f",nread,nreadNotEmpty,mean));
619 for (Int_t ich =0;ich<fNChannels;ich++){
620 if (h1->GetBinContent(ich+1)==-1) continue;
621 AliDebug(3,Form(" channel %i pulser status before pulser = %i",ich,(Int_t)fStatus->GetPulserStatus(ich)));
622
623 /* check whether channel has been read out during current run.
624 * if the status is bad it means it has not been read out.
625 * in this case skip channel in order to leave its status
626 * unchanged */
627 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
628 continue;
629
630 if (h1->GetBinContent(ich+1)<0.05*mean){
631 fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserBad); // bad status for pulser
632 AliDebug(2,Form( " channel %i pulser status after pulser = %i (bad, content = %f), with global status = %i",ich,(Int_t)fStatus->GetPulserStatus(ich),h1->GetBinContent(ich+1),(Int_t)fStatus->GetStatus(ich)));
633 }
634 else {
635 fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserOk); // good status for pulser
636 AliDebug(2,Form( " channel %i pulser status after pulser = %i (good), with global status = %i",ich,(Int_t)fStatus->GetPulserStatus(ich),(Int_t)fStatus->GetStatus(ich)));
637 }
638 }
639 }
640 else {
641 Log("No channels read!! No action taken, keeping old status");
642 }
643
644 daqFile->Close();
645 delete daqFile;
646 delete h1;
17149e6b 647 }
1a1486e7 648
e88f3330 649 else{
650 Log("The input data file from DAQ (pulser) was not found, TOF exiting from Shuttle ");
651 delete listPulser;
652 delete htofPulser;
653 htofPulser = 0x0;
654 if (fStatus){
655 delete fStatus;
656 fStatus = 0;
657 }
658 return 10;//return error code for failure in retrieving Ref Data
1a1486e7 659 }
e88f3330 660 AliDebug(2,Form(" Number of channels processed during pulser run from source %i = %i",jj, nPulserSource));
1a1486e7 661 }
e88f3330 662 AliDebug(2,Form(" Number of channels processed during pulser run = %i",nPulser));
663 delete listPulser;
ee3e792b 664 }
7fffa85b 665
ee3e792b 666 else{
17149e6b 667 Log("The input data file list from DAQ (pulser) was not found, TOF exiting from Shuttle ");
e88f3330 668 delete htofPulser;
669 htofPulser = 0x0;
670 if (fStatus){
671 delete fStatus;
672 fStatus = 0;
673 }
17149e6b 674 return 10;//return error code for failure in retrieving Ref Data
ee3e792b 675 }
17149e6b 676
7fffa85b 677 //storing in OCDB
17149e6b 678
7fffa85b 679 AliCDBMetaData metaData;
680 metaData.SetBeamPeriod(0);
681 metaData.SetResponsible("Chiara Zampolli");
17149e6b 682 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Pulser run.");
7fffa85b 683 AliInfo("Storing Calibration Data from Pulser Run");
17149e6b 684 resultPulser = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
7fffa85b 685 if(!resultPulser){
686 Log("Some problems occurred while storing online object resulting from Pulser data processing");
e88f3330 687 delete htofPulser;
688 htofPulser = 0x0;
689 if (fStatus){
690 delete fStatus;
691 fStatus = 0;
692 }
7fffa85b 693 return 11;//return error code for problems in storing Pulser data
694 }
695
ee3e792b 696 if(fStoreRefData){
697
698 AliCDBMetaData metaDataHisto;
699 metaDataHisto.SetBeamPeriod(0);
700 metaDataHisto.SetResponsible("Chiara Zampolli");
701 char comment[200];
17149e6b 702 sprintf(comment,"This preprocessor stores the Ref data from a pulser run.");
ee3e792b 703 metaDataHisto.SetComment(comment);
704 AliInfo("Storing Reference Data");
db83b789 705 resultPulserRef = StoreReferenceData("Calib","PulserData",htofPulser, &metaDataHisto);
ee3e792b 706 if (!resultPulserRef){
7fffa85b 707 Log("some problems occurred::No Reference Data for pulser stored, TOF exiting from Shuttle");
e88f3330 708 delete htofPulser;
709 htofPulser = 0x0;
710 if (fStatus){
711 delete fStatus;
712 fStatus = 0;
713 }
7fffa85b 714 return 9;//return error code for failure in storing Ref Data
ee3e792b 715 }
716 }
717
718 daqFile=0;
719
e88f3330 720 delete htofPulser;
721 htofPulser = 0x0;
722
723 if (fStatus){
724 delete fStatus;
725 fStatus = 0;
726 }
727
ee3e792b 728 return 0;
729}
730//_____________________________________________________________________________
731
732UInt_t AliTOFPreprocessor::ProcessNoiseData()
733{
7fffa85b 734
735 // Processing Noise Run data for TOF channel status
736
737 Log("Processing Noise");
ee3e792b 738
17149e6b 739 if (fStatus==0x0){
740 AliError("No valid fStatus found, some errors must have occurred!!");
741 return 20;
742 }
743
013ac2dd 744 Float_t noiseThr = 1; // setting default threshold for noise to 1 Hz
745 // reading config map
746 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","ConfigNoise");
747 if (!cdbEntry) {
748 Log(Form("No Configuration entry found in CDB, using default values: NoiseThr = %d",noiseThr));
749 }
750 else {
751 TMap *configMap = (TMap*)cdbEntry->GetObject();
752 if (!configMap){
753 Log(Form("No map found in Config entry in CDB, using default values: NoiseThr = %d", noiseThr));
754 }
755 else{
756 TObjString *strNoiseThr = (TObjString*)configMap->GetValue("NoiseThr");
757 if (strNoiseThr) {
758 TString tmpstr = strNoiseThr->GetString();
759 noiseThr = tmpstr.Atoi();
760 }
761 else {
762 Log(Form("No NoiseThr value found in Map from ConfigNoise entry in CDB, using default value: NoiseThr = %i",noiseThr));
763 }
764 }
765 }
766
767 delete cdbEntry;
768 cdbEntry = 0x0;
769
ee3e792b 770 TH1::AddDirectory(0);
771
772 Bool_t resultNoiseRef=kFALSE;
7fffa85b 773 Bool_t resultNoise=kFALSE;
ee3e792b 774
a174d599 775 static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
17149e6b 776 TH1F * htofNoise = new TH1F("hTOFnoise","histo with signals on TOF during noise", kSize,-0.5,kSize-0.5);
a174d599 777 for (Int_t ibin =1;ibin<=kSize;ibin++){
17149e6b 778 htofNoise->SetBinContent(ibin,-1);
ee3e792b 779 }
17149e6b 780
ee3e792b 781 // processing noise
782
783 TFile * daqFile=0x0;
784 TH1F * h1=0x0;
785
013ac2dd 786 // useful counters
787 Int_t nNoise = 0;
788 Int_t nNoisyChannels = 0;
789 Int_t nNotNoisyChannels = 0;
790 Int_t nChannelsFromDA = 0;
791 Int_t nMatchingWindowNullNonZero = 0;
792 Int_t nMatchingWindowNullEqualZero = 0;
793
794 // retrieving Noise data
ee3e792b 795 TList* listNoise = GetFileSources(kDAQ, "NOISE");
bf76be9c 796 if (listNoise !=0x0 && listNoise->GetEntries()!=0)
e88f3330 797 {
798 AliInfo("The following sources produced files with the id NOISE");
799 listNoise->Print();
e88f3330 800 for (Int_t jj=0;jj<listNoise->GetEntries();jj++){
801 Int_t nNoiseSource = 0;
802 TObjString * str = dynamic_cast<TObjString*> (listNoise->At(jj));
803 AliInfo(Form("found source %s", str->String().Data()));
804 // file to be stored run per run
805 TString fileNameNoise = GetFile(kDAQ, "NOISE", str->GetName());
806 if (fileNameNoise.Length()>0){
807 // storing reference data
808 AliInfo(Form("Got the file %s, now we can process noise data.", fileNameNoise.Data()));
809 daqFile = new TFile(fileNameNoise.Data(),"READ");
810 h1 = (TH1F*) daqFile->Get("hTOFnoise");
811 for (Int_t ibin=0;ibin<kSize;ibin++){
812 if ((h1->GetBinContent(ibin+1))!=-1){
013ac2dd 813 nNoiseSource++;
814 // checking the matching window for current channel
815 if (fMatchingWindow[ibin] == 0){
fc143ab2 816 Log(Form("Matching window for channel %i null, but the channel was read by the LDC! skipping channel, BUT Please check!",ibin));
013ac2dd 817 if ((h1->GetBinContent(ibin+1))!=0) nMatchingWindowNullNonZero++;
818 if ((h1->GetBinContent(ibin+1))==0) nMatchingWindowNullEqualZero++;
819 continue;
820 }
e88f3330 821 if ((htofNoise->GetBinContent(ibin+1))==-1){
013ac2dd 822 htofNoise->SetBinContent(ibin+1,h1->GetBinContent(ibin+1)/(fMatchingWindow[ibin]*1.E-9));
823 if ((h1->GetBinContent(ibin+1))!= 0) AliDebug(2,Form("Channel = %i, Matching window = %i, Content = %f", ibin, fMatchingWindow[ibin], htofNoise->GetBinContent(ibin+1)));
e88f3330 824 }
825 else {
826 Log(Form("Something strange occurred during Noise run, channel %i already read by another LDC, please check!",ibin));
827 }
828 }
829 }
013ac2dd 830
831 Log(Form(" Number of channels processed during noise run from source %i = %i",jj, nNoiseSource));
e88f3330 832 daqFile->Close();
833 delete daqFile;
834 delete h1;
013ac2dd 835 daqFile = 0x0;
836 h1 = 0x0;
837
e88f3330 838 }
e88f3330 839 else{
840 Log("The input data file from DAQ (noise) was not found, TOF exiting from Shuttle ");
841 delete listNoise;
013ac2dd 842 listNoise = 0x0;
e88f3330 843 delete htofNoise;
844 htofNoise = 0x0;
845 if (fStatus){
846 delete fStatus;
847 fStatus = 0;
848 }
013ac2dd 849 if (fMatchingWindow){
850 delete [] fMatchingWindow;
851 fMatchingWindow = 0;
852 }
e88f3330 853 return 13;//return error code for failure in retrieving Ref Data
854 }
013ac2dd 855 }
ee3e792b 856 }
013ac2dd 857
e88f3330 858 else{
859 Log("The input data file list from DAQ (noise) was not found, TOF exiting from Shuttle ");
860 delete htofNoise;
861 htofNoise = 0x0;
862 if (fStatus){
863 delete fStatus;
864 fStatus = 0;
ee3e792b 865 }
013ac2dd 866 if (fMatchingWindow){
867 delete [] fMatchingWindow;
868 fMatchingWindow = 0;
869 }
7fffa85b 870 return 13;//return error code for failure in retrieving Ref Data
ee3e792b 871 }
872
013ac2dd 873 // elaborating infos to set NOISE status
874 for (Int_t ich =0;ich<fNChannels;ich++){
875 if (htofNoise->GetBinContent(ich+1)== -1) continue;
876
877 nChannelsFromDA++;
878
879 AliDebug(3,Form(" channel %i noise status before noise = %i, with global status = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich),(Int_t)fStatus->GetStatus(ich)));
880 //AliDebug(2,Form( " channel %i status before noise = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich)));
881
882 /* check whether channel has been read out during current run.
883 * if the status is bad it means it has not been read out.
884 * in this case skip channel in order to leave its status
885 * unchanged */
886
887 if ((fStatus->GetHWStatus(ich)) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
888 continue;
889
890 nNoise++;
891 if (htofNoise->GetBinContent(ich+1) >= noiseThr){
892 fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseBad); // bad status for noise
893 AliDebug(3,Form( " channel %i noise status after noise = %i, with global status = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich),(Int_t)fStatus->GetStatus(ich)));
894 nNoisyChannels++;
895 }
896 else {
897 fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseOk); // good status for noise
898 AliDebug(3,Form(" channel %i noise status after noise = %i, with global status = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich),(Int_t)fStatus->GetStatus(ich)));
899 nNotNoisyChannels++;
900 }
901 }
902
903 Log(Form(" Number of channels processed by DA during noise run, independetly from TOFFEE = %i",nChannelsFromDA));
904 Log(Form(" Number of channels processed during noise run (that were ON according to TOFFEE) = %i",nNoise));
905 Log(Form(" Number of noisy channels found during noise run = %i",nNoisyChannels));
906 Log(Form(" Number of not noisy channels found during noise run = %i",nNotNoisyChannels));
907 Log(Form(" Number of channels with matching window NULL (so skipped), but Non Zero content = %i",nMatchingWindowNullNonZero));
908 Log(Form(" Number of channels with matching window NULL (so skipped), and Zero content = %i",nMatchingWindowNullEqualZero));
909
910 delete listNoise;
911
912 //daqFile=0;
e88f3330 913
7fffa85b 914 //storing in OCDB
e88f3330 915
7fffa85b 916 AliCDBMetaData metaData;
917 metaData.SetBeamPeriod(0);
918 metaData.SetResponsible("Chiara Zampolli");
17149e6b 919 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Noise run.");
7fffa85b 920 AliInfo("Storing Calibration Data from Noise Run");
17149e6b 921 resultNoise = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
7fffa85b 922 if(!resultNoise){
923 Log("Some problems occurred while storing online object resulting from Noise data processing");
e88f3330 924 delete htofNoise;
925 htofNoise = 0x0;
926 if (fStatus){
927 delete fStatus;
928 fStatus = 0;
929 }
013ac2dd 930 if (fMatchingWindow){
931 delete [] fMatchingWindow;
932 fMatchingWindow = 0;
933 }
7fffa85b 934 return 14;//return error code for problems in storing Noise data
935 }
936
ee3e792b 937 if(fStoreRefData){
938
939 AliCDBMetaData metaDataHisto;
940 metaDataHisto.SetBeamPeriod(0);
941 metaDataHisto.SetResponsible("Chiara Zampolli");
942 char comment[200];
17149e6b 943 sprintf(comment,"This preprocessor stores the Ref data from a noise run. ");
ee3e792b 944 metaDataHisto.SetComment(comment);
945 AliInfo("Storing Reference Data");
db83b789 946 resultNoiseRef = StoreReferenceData("Calib","NoiseData",htofNoise, &metaDataHisto);
ee3e792b 947 if (!resultNoiseRef){
948 Log("some problems occurred::No Reference Data for noise stored");
e88f3330 949 delete htofNoise;
950 htofNoise = 0x0;
951 if (fStatus){
952 delete fStatus;
953 fStatus = 0;
954 }
013ac2dd 955 if (fMatchingWindow){
956 delete [] fMatchingWindow;
957 fMatchingWindow = 0;
958 }
7fffa85b 959 return 12;//return error code for failure in storing Ref Data
ee3e792b 960 }
961 }
962
e88f3330 963 delete htofNoise;
964 htofNoise = 0x0;
965
966 if (fStatus){
967 delete fStatus;
968 fStatus = 0;
969 }
970
013ac2dd 971 if (fMatchingWindow){
972 delete [] fMatchingWindow;
973 fMatchingWindow = 0;
974 }
975
ee3e792b 976 return 0;
977}
978//_____________________________________________________________________________
979
db83b789 980UInt_t AliTOFPreprocessor::ProcessFEEData()
ee3e792b 981{
7fffa85b 982 // Processing Pulser Run data for TOF channel status
983 // dummy for the time being
ee3e792b 984
db83b789 985 Log("Processing FEE");
986
987 Bool_t updateOCDB = kFALSE;
988 AliTOFFEEReader feeReader;
17149e6b 989
db83b789 990 TH1C hCurrentFEE("hCurrentFEE","histo with current FEE channel status", fNChannels, 0, fNChannels);
991
992 /* load current TOF FEE config from DCS FXS, parse,
993 * fill current FEE histogram and set FEE status */
994
fceb731d 995 const char * nameFile = GetFile(kDCS,"TofFeeLightMap","");
db83b789 996 AliInfo(Form("nameFile = %s",nameFile));
997 if (nameFile == NULL) {
998 return 15;
999 }
fceb731d 1000 feeReader.LoadFEElightConfig(nameFile);
1001 Int_t parseFee = feeReader.ParseFEElightConfig();
1002 AliDebug(2,Form("%i enabled channels found in FEElight configuration",parseFee));
db83b789 1003 /* load stored TOF FEE from OCDB and compare it with current FEE.
1004 * if stored FEE is different from current FEE set update flag.
1005 * if there is no stored FEE in OCDB set update flag */
1006
013ac2dd 1007 fMatchingWindow = new Int_t[fNChannels];
02ede0c4 1008 fLatencyWindow = new Int_t[fNChannels];
1009
17149e6b 1010 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Status");
1011 if (!cdbEntry) {
1012 /* no CDB entry found. set update flag */
1013 Log(" ************ WARNING ************");
1014 Log("No CDB Status entry found, creating a new one!");
1015 Log(" *********************************");
1016 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
1017 updateOCDB = kTRUE;
db83b789 1018 }
db83b789 1019 else {
e88f3330 1020 if (cdbEntry) cdbEntry->SetOwner(kFALSE);
17149e6b 1021 /* CDB entry OK. loop over channels */
1022 fStatus = (AliTOFChannelOnlineStatusArray*) cdbEntry->GetObject();
e88f3330 1023 delete cdbEntry;
1024 cdbEntry = 0x0;
db83b789 1025 }
17149e6b 1026 for (Int_t iChannel = 0; iChannel < fNChannels; iChannel++){
1027 //AliDebug(2,Form("********** channel %i",iChannel));
1028 /* compare current FEE channel status with stored one
1029 * if different set update flag and break loop */
1030 //AliDebug(2,Form( " channel %i status before FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
013ac2dd 1031 fMatchingWindow[iChannel] = feeReader.GetMatchingWindow(iChannel);
02ede0c4 1032 fLatencyWindow[iChannel] = feeReader.GetLatencyWindow(iChannel);
17149e6b 1033 if (feeReader.IsChannelEnabled(iChannel)) {
1034 hCurrentFEE.SetBinContent(iChannel + 1, 1);
1035 if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWOk){
1036 updateOCDB = kTRUE;
1037 fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWOk);
013ac2dd 1038 AliDebug(3,Form( " changed into enabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
17149e6b 1039 }
02ede0c4 1040 if (fStatus->GetLatencyWindow(iChannel)!=fLatencyWindow[iChannel]){
1041 updateOCDB = kTRUE;
1042 fStatus->SetLatencyWindow(iChannel,fLatencyWindow[iChannel]);
1043 AliDebug(3,Form( " changed latency window: channel %i latency window after FEE = %i",iChannel,fStatus->GetLatencyWindow(iChannel)));
1044 }
17149e6b 1045 }
1046 else {
1047 if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWBad){
1048 updateOCDB = kTRUE;
1049 fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWBad);
013ac2dd 1050 AliDebug(3,Form( " changed into disabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
17149e6b 1051 }
1052 }
1053 }
1054
db83b789 1055
1056 /* check whether we don't have to store reference data.
1057 * in this case we return without errors. */
1058 if (fStoreRefData) {
1059 /* store reference data */
1060 AliCDBMetaData metaDataHisto;
1061 metaDataHisto.SetBeamPeriod(0);
1062 metaDataHisto.SetResponsible("Roberto Preghenella");
17149e6b 1063 metaDataHisto.SetComment("This preprocessor stores the FEE Ref data of the current run.");
db83b789 1064 AliInfo("Storing FEE reference data");
1065 /* store FEE reference data */
1066 if (!StoreReferenceData("Calib", "FEEData", &hCurrentFEE, &metaDataHisto)) {
1067 /* failed */
1068 Log("problems while storing FEE reference data");
e88f3330 1069 if (fStatus){
1070 delete fStatus;
1071 fStatus = 0;
1072 }
db83b789 1073 return 18; /* error return code for problems while storing FEE reference data */
1074 }
1075 }
1076
1077 /* check whether we don't need to update OCDB.
1078 * in this case we can return without errors and
17149e6b 1079 * the current FEE is stored in the fStatus object. */
db83b789 1080 if (!updateOCDB) {
1081 AliInfo("TOF FEE config has not changed. Do not overwrite stored file.");
1082 return 0; /* return ok */
1083 }
1084
17149e6b 1085 TString runType = GetRunType();
1086 if (runType != "PHYSICS") {
1087 AliInfo(Form("Run Type = %s, waiting to store status map",GetRunType()));
1088 return 0; /* return ok */
1089 }
1090
db83b789 1091 /* update the OCDB with the current FEE since even
1092 * a little difference has been detected. */
1093
1094 AliCDBMetaData metaData;
1095 metaData.SetBeamPeriod(0);
1096 metaData.SetResponsible("Roberto Preghenella");
17149e6b 1097 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object from FEE data.");
1098 AliInfo("Storing Status data from current run after FEE parsing");
db83b789 1099 /* store FEE data */
17149e6b 1100 if (!Store("Calib", "Status", fStatus, &metaData, 0, kTRUE)) {
db83b789 1101 /* failed */
1102 Log("problems while storing FEE data object");
e88f3330 1103 if (fStatus){
1104 delete fStatus;
1105 fStatus = 0;
1106 }
db83b789 1107 return 17; /* return error code for problems while storing FEE data */
1108 }
1109
1110 /* everything fine. return */
ee3e792b 1111
e88f3330 1112 if (fStatus){
1113 delete fStatus;
1114 fStatus = 0;
1115 }
1116
7fffa85b 1117 return 0;
1118
1119}
1120
1121//_____________________________________________________________________________
1122
1123UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap)
1124{
a174d599 1125 //
1126 //
1127 //
7fffa85b 1128
1129 TString runType = GetRunType();
1130 Log(Form("RunType %s",runType.Data()));
bf76be9c 1131
ee3e792b 1132 // processing
1133
db83b789 1134 /* always process FEE data */
1135 Int_t iresultFEE = ProcessFEEData();
1136 if (iresultFEE != 0)
1137 return iresultFEE;
1138
7fffa85b 1139 if (runType == "PULSER") {
1140 Int_t iresultPulser = ProcessPulserData();
1141 return iresultPulser;
1142 }
17149e6b 1143
7fffa85b 1144 if (runType == "NOISE") { // for the time being associating noise runs with pedestal runs; proper run type to be defined
1145 Int_t iresultNoise = ProcessNoiseData();
1146 return iresultNoise;
1147 }
1148
1149 if (runType == "PHYSICS") {
4856f488 1150 Int_t iresultDAQ = ProcessOnlineDelays();
1151 if (iresultDAQ != 0) {
7fffa85b 1152 return iresultDAQ;
1153 }
4856f488 1154 else {
1155 Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);
1156 return iresultDCS;
1157 }
ee3e792b 1158 }
1159
7fffa85b 1160 // storing
ee3e792b 1161 return 0;
1162}
c9fe8530 1163
1164
b06d5296 1165//_____________________________________________________________________________
1166
1167void
1168AliTOFPreprocessor::FillWithCosmicCalibration(AliTOFChannelOnlineArray *cal)
1169{
1170 /*
1171 * fill with cosmic calibration
1172 */
1173
1174 Log(" Using cosmic-ray calibration.");
1175
1176 AliTOFcalibHisto calibHisto;
97a29b32 1177 calibHisto.SetFullCorrectionFlag(AliTOFcalibHisto::kTimeSlewingCorr, kFALSE);
1178 Log(Form(" loading calibration histograms from %s", calibHisto.GetCalibHistoFileName()));
b06d5296 1179 Log(Form(" loading calibration parameters from %s", calibHisto.GetCalibParFileName()));
1180 calibHisto.LoadCalibPar();
1181
1182 /* loop over channel index */
1183 for (Int_t iIndex = 0; iIndex < fNChannels; iIndex++) {
9155334b 1184 cal->SetDelay(iIndex, calibHisto.GetFullCorrection(iIndex));
b06d5296 1185 }
1186
1187}
1188
b06d5296 1189//_____________________________________________________________________________
1190
1191void
1192AliTOFPreprocessor::FillWithCableLengthMap(AliTOFChannelOnlineArray *cal)
1193{
1194 /*
1195 * fill with cosmic calibration
1196 */
1197
1198 Log(" Using cable-length map.");
1199 AliTOFRawStream tofrs;
1200 Int_t det[5], dummy, index;
1201 Float_t cableTimeShift;
1202
1203 /* temporarly disable warnings */
1204 AliLog::EType_t logLevel = (AliLog::EType_t)AliLog::GetGlobalLogLevel();
1205 AliLog::SetGlobalLogLevel(AliLog::kError);
1206
1207 /* loop over EO indeces */
1208 for (Int_t iddl = 0; iddl < 72; iddl++)
1209 for (Int_t islot = 3; islot <= 12; islot++)
1210 for (Int_t ichain = 0; ichain < 2; ichain++)
1211 for (Int_t itdc = 0; itdc < 15; itdc++)
1212 for (Int_t ichannel = 0; ichannel < 8; ichannel++) {
1213
1214 /* get DO index */
1215 tofrs.EquipmentId2VolumeId(iddl, islot, ichain, itdc, ichannel, det);
1216
1217 /* swap det[3] and det[4] indeces (needed to obtain correct channel index) */
1218 dummy = det[3];
1219 det[3] = det[4];
1220 det[4] = dummy;
1221
1222 /* check DO index */
1223 if (det[0] < 0 || det[0] > 17 ||
1224 det[1] < 0 || det[1] > 4 ||
1225 det[2] < 0 || det[2] > 18 ||
1226 det[3] < 0 || det[3] > 1 ||
1227 det[4] < 0 || det[4] > 47)
1228 continue;
1229
1230 /* get channel index */
1231 index = AliTOFGeometry::GetIndex(det);
1232
1233 /* get cable time shift */
1234 cableTimeShift = AliTOFCableLengthMap::GetCableTimeShift(iddl, islot, ichain, itdc);
1235
1236 /* set delay */
1237 if (index<fNChannels) {
1238 cal->SetDelay(index,cableTimeShift); // delay in ns
1239 AliDebug(2,Form("Setting delay %f (ns) for channel %i",cableTimeShift,index));
1240 }
1241
1242 } /* loop over EO indeces */
1243
1244 /* re-enable warnings */
1245 AliLog::SetGlobalLogLevel(logLevel);
1246
1247}
1248
1249