]>
Commit | Line | Data |
---|---|---|
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 | |
a174d599 | 18 | //#include <Riostream.h> |
19 | //#include <stdio.h> | |
20 | //#include <stdlib.h> | |
c9fe8530 | 21 | |
9edefa04 | 22 | #include <TFile.h> |
a174d599 | 23 | //#include <TH1.h> |
24 | //#include <TH1F.h> | |
25 | //#include <TH1S.h> | |
9edefa04 | 26 | #include <TH2S.h> |
27 | #include <TMath.h> | |
28 | #include <TObjArray.h> | |
29 | #include <TObjString.h> | |
30 | #include <TTimeStamp.h> | |
c9fe8530 | 31 | |
32 | #include "AliCDBMetaData.h" | |
7fffa85b | 33 | #include "AliCDBEntry.h" |
c9fe8530 | 34 | #include "AliLog.h" |
c9fe8530 | 35 | #include "AliTOFChannelOnline.h" |
7fffa85b | 36 | #include "AliTOFChannelOnlineStatus.h" |
9edefa04 | 37 | #include "AliTOFDataDCS.h" |
10056aa6 | 38 | #include "AliTOFGeometry.h" |
9edefa04 | 39 | #include "AliTOFPreprocessor.h" |
db83b789 | 40 | #include "AliTOFFEEReader.h" |
c9fe8530 | 41 | |
a174d599 | 42 | //class TF1; |
43 | //class AliDCSValue; | |
44 | //class AliTOFGeometry; | |
c9fe8530 | 45 | |
46 | // TOF preprocessor class. | |
47 | // It takes data from DCS and passes them to the class AliTOFDataDCS, which | |
48 | // processes them. The result is then written to the CDB. | |
49 | // analogously, it takes data form DAQ (both at Run level and inclusive - | |
50 | // of all the runs - level, processes them, and stores both Reference Data | |
51 | // and Online Calibration files in the CDB. | |
7fffa85b | 52 | // Processing of Pulser/Noise Run data and of TOF FEE DCS map |
53 | ||
54 | // return codes: | |
55 | // return=0 : all ok | |
56 | // return=1 : no DCS input data Map | |
57 | // return=2 : no DCS input data processing | |
58 | // return=3 : no DCS processed data was stored in Ref Data | |
59 | // return=4 : no DAQ input for Ref Data | |
60 | // return=5 : failed to store DAQ Ref Data | |
61 | // return=6 : failed to retrieve DAQ data for calibration | |
62 | // return=7 : problems in processing histos in the input DAQ file | |
63 | // return=8 : failed to store Online Delays | |
64 | // return=9 : failed to store Reference Data for Pulser | |
65 | // return=10: failed to retrieve Pulser data | |
66 | // return=11: failed to store Pulser map in OCDB | |
67 | // return=12: failed to store Reference Data for Noise | |
68 | // return=13: failed to retrieve Noise data | |
69 | // return=14: failed to store Noise map in OCDB | |
db83b789 | 70 | // return=15: failed to retrieve FEE data from FXS |
71 | // return=16: failed to retrieve FEE data from OCDB | |
72 | // return=17: failed to store FEE data in OCDB | |
73 | // return=18: failed to store FEE reference data in OCDB | |
c9fe8530 | 74 | |
75 | ClassImp(AliTOFPreprocessor) | |
76 | ||
7fffa85b | 77 | const Int_t AliTOFPreprocessor::fgkBinRangeAve = 13; // number of bins where to calculate the mean |
78 | const Double_t AliTOFPreprocessor::fgkIntegralThr = 100; // min number of entries to perform computation of delay per channel | |
79 | const Double_t AliTOFPreprocessor::fgkThrPar = 0.013; // parameter used to trigger the calculation of the delay | |
c9fe8530 | 80 | |
81 | //_____________________________________________________________________________ | |
82 | ||
708db10b | 83 | AliTOFPreprocessor::AliTOFPreprocessor(AliShuttleInterface* shuttle) : |
84 | AliPreprocessor("TOF", shuttle), | |
c9fe8530 | 85 | fData(0), |
708db10b | 86 | fh2(0), |
c9fe8530 | 87 | fCal(0), |
7fffa85b | 88 | fCalStatus(0), |
db83b789 | 89 | fFEEStatus(0), |
10056aa6 | 90 | fNChannels(0), |
7fffa85b | 91 | fStoreRefData(kTRUE), |
92 | fFDRFlag(kTRUE) | |
c9fe8530 | 93 | { |
94 | // constructor | |
370aeff7 | 95 | AddRunType("PHYSICS"); |
96 | AddRunType("PULSER"); | |
97 | AddRunType("NOISE"); | |
10056aa6 | 98 | |
c9fe8530 | 99 | } |
100 | ||
101 | //_____________________________________________________________________________ | |
102 | ||
103 | AliTOFPreprocessor::~AliTOFPreprocessor() | |
104 | { | |
105 | // destructor | |
7981612d | 106 | if (fData){ |
107 | delete fData; | |
108 | fData = 0; | |
109 | } | |
110 | if (fh2){ | |
111 | delete fh2; | |
112 | fh2 = 0; | |
113 | } | |
114 | if (fCal){ | |
64f2148a | 115 | // fCal->Clear(); |
7981612d | 116 | delete fCal; |
117 | fCal = 0; | |
118 | } | |
7fffa85b | 119 | if (fCalStatus){ |
120 | delete fCalStatus; | |
121 | fCalStatus = 0; | |
122 | } | |
db83b789 | 123 | if (fFEEStatus){ |
124 | delete fFEEStatus; | |
125 | fFEEStatus = 0; | |
126 | } | |
c9fe8530 | 127 | } |
128 | ||
129 | //______________________________________________________________________________ | |
130 | void AliTOFPreprocessor::Initialize(Int_t run, UInt_t startTime, | |
131 | UInt_t endTime) | |
132 | { | |
133 | // Creates AliTOFDataDCS object | |
134 | ||
135 | AliPreprocessor::Initialize(run, startTime, endTime); | |
136 | ||
137 | AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run, | |
138 | TTimeStamp(startTime).AsString(), | |
139 | TTimeStamp(endTime).AsString())); | |
140 | ||
141 | fData = new AliTOFDataDCS(fRun, fStartTime, fEndTime); | |
7fffa85b | 142 | fData->SetFDRFlag(fFDRFlag); |
708db10b | 143 | fh2 = 0x0; |
10056aa6 | 144 | fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX(); |
145 | fCal = new TObjArray(fNChannels); | |
146 | fCal->SetOwner(); | |
147 | for (Int_t ich = 0; ich<fNChannels; ich ++){ | |
148 | AliTOFChannelOnline * calChOnline = new AliTOFChannelOnline(); | |
149 | fCal->AddAt(calChOnline,ich); | |
150 | } | |
7fffa85b | 151 | fCalStatus = new TObjArray(fNChannels); |
152 | fCalStatus->SetOwner(); | |
153 | for (Int_t ich = 0; ich<fNChannels; ich ++){ | |
154 | AliTOFChannelOnlineStatus * calChOnlineStatus = new AliTOFChannelOnlineStatus(); | |
155 | fCalStatus->AddAt(calChOnlineStatus,ich); | |
156 | } | |
db83b789 | 157 | fFEEStatus = new TObjArray(fNChannels); |
158 | fFEEStatus->SetOwner(); | |
159 | for (Int_t ich = 0; ich<fNChannels; ich ++){ | |
160 | AliTOFChannelOnlineStatus * calChOnlineStatus = new AliTOFChannelOnlineStatus(); | |
161 | fFEEStatus->AddAt(calChOnlineStatus,ich); | |
162 | } | |
c9fe8530 | 163 | } |
7fffa85b | 164 | //_____________________________________________________________________________ |
165 | Bool_t AliTOFPreprocessor::ProcessDCS(){ | |
166 | ||
167 | // check whether DCS should be processed or not... | |
c9fe8530 | 168 | |
7fffa85b | 169 | TString runType = GetRunType(); |
170 | Log(Form("RunType %s",runType.Data())); | |
171 | ||
55454922 | 172 | if (runType != "PHYSICS"){ |
7fffa85b | 173 | return kFALSE; |
174 | } | |
175 | ||
176 | return kTRUE; | |
177 | } | |
c9fe8530 | 178 | //_____________________________________________________________________________ |
179 | ||
ee3e792b | 180 | UInt_t AliTOFPreprocessor::ProcessDCSDataPoints(TMap* dcsAliasMap) |
c9fe8530 | 181 | { |
182 | // Fills data into a AliTOFDataDCS object | |
183 | ||
7fffa85b | 184 | |
185 | Log("Processing DCS DP"); | |
708db10b | 186 | TH1::AddDirectory(0); |
5936ab02 | 187 | |
7885c291 | 188 | Bool_t resultDCSMap=kFALSE; |
189 | Bool_t resultDCSStore=kFALSE; | |
c9fe8530 | 190 | |
191 | // processing DCS | |
192 | ||
193 | if (!dcsAliasMap){ | |
5936ab02 | 194 | Log("No DCS map found: TOF exiting from Shuttle"); |
195 | return 1;// return error Code for DCS input data not found | |
c9fe8530 | 196 | } |
197 | else { | |
198 | // The processing of the DCS input data is forwarded to AliTOFDataDCS | |
7885c291 | 199 | resultDCSMap=fData->ProcessData(*dcsAliasMap); |
200 | if(!resultDCSMap){ | |
201 | Log("Some problems occurred while processing DCS data, TOF exiting from Shuttle"); | |
5936ab02 | 202 | return 2;// return error Code for processed DCS data not stored |
c9fe8530 | 203 | } |
7885c291 | 204 | else{ |
205 | AliCDBMetaData metaDataDCS; | |
206 | metaDataDCS.SetBeamPeriod(0); | |
207 | metaDataDCS.SetResponsible("Chiara Zampolli"); | |
208 | metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object."); | |
209 | AliInfo("Storing DCS Data"); | |
b0d8f3fc | 210 | resultDCSStore = StoreReferenceData("Calib","DCSData",fData, &metaDataDCS); |
7885c291 | 211 | if (!resultDCSStore){ |
b0d8f3fc | 212 | Log("Some problems occurred while storing DCS data results in Reference Data, TOF exiting from Shuttle"); |
7885c291 | 213 | return 3;// return error Code for processed DCS data not stored |
b0d8f3fc | 214 | // in reference data |
7885c291 | 215 | |
216 | } | |
217 | } | |
c9fe8530 | 218 | } |
ee3e792b | 219 | return 0; |
220 | } | |
221 | //_____________________________________________________________________________ | |
222 | ||
223 | UInt_t AliTOFPreprocessor::ProcessOnlineDelays() | |
224 | { | |
7fffa85b | 225 | // Processing data from DAQ for online calibration |
226 | ||
227 | Log("Processing DAQ delays"); | |
ee3e792b | 228 | |
229 | TH1::AddDirectory(0); | |
230 | ||
231 | Bool_t resultDAQRef=kFALSE; | |
7fffa85b | 232 | Bool_t resultTOFPP=kFALSE; |
c9fe8530 | 233 | // processing DAQ |
7885c291 | 234 | |
c9fe8530 | 235 | TFile * daqFile=0x0; |
7885c291 | 236 | |
5936ab02 | 237 | if(fStoreRefData){ |
238 | //retrieving data at Run level | |
239 | TList* list = GetFileSources(kDAQ, "RUNLevel"); | |
bf76be9c | 240 | if (list !=0x0 && list->GetEntries()!=0) |
5936ab02 | 241 | { |
242 | AliInfo("The following sources produced files with the id RUNLevel"); | |
243 | list->Print(); | |
244 | for (Int_t jj=0;jj<list->GetEntries();jj++){ | |
245 | TObjString * str = dynamic_cast<TObjString*> (list->At(jj)); | |
246 | AliInfo(Form("found source %s", str->String().Data())); | |
247 | // file to be stored run per run | |
248 | TString fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName()); | |
249 | if (fileNameRun.Length()>0){ | |
250 | AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun.Data())); | |
251 | daqFile = new TFile(fileNameRun.Data(),"READ"); | |
252 | fh2 = (TH2S*) daqFile->Get("htof"); | |
253 | AliCDBMetaData metaDataHisto; | |
254 | metaDataHisto.SetBeamPeriod(0); | |
255 | metaDataHisto.SetResponsible("Chiara Zampolli"); | |
256 | metaDataHisto.SetComment("This preprocessor stores the array of histos object as Reference Data."); | |
257 | AliInfo("Storing Reference Data"); | |
258 | resultDAQRef = StoreReferenceData("Calib","DAQData",fh2, &metaDataHisto); | |
259 | if (!resultDAQRef){ | |
260 | Log("some problems occurred::No Reference Data stored, TOF exiting from Shuttle"); | |
7885c291 | 261 | return 5;//return error code for failure in storing Ref Data |
5936ab02 | 262 | } |
263 | daqFile->Close(); | |
264 | delete daqFile; | |
265 | } | |
266 | ||
267 | else{ | |
268 | Log("The input data file from DAQ (run-level) was not found, TOF exiting from Shuttle "); | |
7885c291 | 269 | return 4;//return error code for failure in retrieving Ref Data |
c9fe8530 | 270 | } |
c9fe8530 | 271 | } |
ee3e792b | 272 | delete list; |
9bc469d1 | 273 | } |
5936ab02 | 274 | else{ |
275 | Log("The input data file list from DAQ (run-level) was not found, TOF exiting from Shuttle "); | |
7885c291 | 276 | return 4;//return error code for failure in retrieving Ref Data |
5936ab02 | 277 | } |
9bc469d1 | 278 | } |
279 | ||
9bc469d1 | 280 | |
5936ab02 | 281 | //Total files, with cumulative histos |
282 | ||
9bc469d1 | 283 | TList* listTot = GetFileSources(kDAQ, "DELAYS"); |
bf76be9c | 284 | if (listTot !=0x0 && listTot->GetEntries()!=0) |
9bc469d1 | 285 | { |
286 | AliInfo("The following sources produced files with the id DELAYS"); | |
287 | listTot->Print(); | |
288 | for (Int_t jj=0;jj<listTot->GetEntries();jj++){ | |
289 | TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj)); | |
290 | AliInfo(Form("found source %s", str->String().Data())); | |
291 | ||
c9fe8530 | 292 | // file with summed histos, to extract calib params |
9bc469d1 | 293 | TString fileName = GetFile(kDAQ, "DELAYS", str->GetName()); |
294 | if (fileName.Length()>0){ | |
295 | AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data())); | |
c9fe8530 | 296 | |
9bc469d1 | 297 | daqFile = new TFile(fileName.Data(),"READ"); |
64f2148a | 298 | if (fh2) delete fh2; |
708db10b | 299 | fh2 = (TH2S*) daqFile->Get("htoftot"); |
300 | if (!fh2){ | |
9d883ed9 | 301 | Log("some problems occurred:: No histo retrieved, TOF exiting from Shuttle"); |
302 | delete daqFile; | |
7885c291 | 303 | return 7; //return error code for histograms not existing/junky |
c9fe8530 | 304 | } |
c9fe8530 | 305 | else { |
3a3ece53 | 306 | static const Int_t kSize=fh2->GetNbinsX(); |
307 | static const Int_t kNBins=fh2->GetNbinsY(); | |
308 | static const Double_t kXBinmin=fh2->GetYaxis()->GetBinLowEdge(1); | |
10056aa6 | 309 | if (kSize != fNChannels){ |
9d883ed9 | 310 | Log(" number of bins along x different from number of pads, found only a subset of the histograms, TOF exiting from Shuttle"); |
311 | delete daqFile; | |
7885c291 | 312 | return 7; //return error code for histograms not existing/junky |
9bc469d1 | 313 | } |
d9179e4b | 314 | Int_t nNotStatistics = 0; // number of channel with not enough statistics |
3a3ece53 | 315 | for (Int_t ich=0;ich<kSize;ich++){ |
316 | TH1S *h1 = new TH1S("h1","h1",kNBins,kXBinmin-0.5,kNBins*1.+kXBinmin-0.5); | |
317 | for (Int_t ibin=0;ibin<kNBins;ibin++){ | |
708db10b | 318 | h1->SetBinContent(ibin+1,fh2->GetBinContent(ich+1,ibin+1)); |
319 | } | |
7fffa85b | 320 | if(h1->Integral()<fgkIntegralThr) { |
d9179e4b | 321 | nNotStatistics++; |
322 | if (!fFDRFlag) Log(Form(" Not enough statistics for bin %i, skipping this channel",ich)); // printing message only if not in FDR runs | |
7fffa85b | 323 | delete h1; |
324 | h1=0x0; | |
325 | continue; | |
c9fe8530 | 326 | } |
7fffa85b | 327 | if (!fFDRFlag) { // not computing delays if in FDR runs |
328 | Bool_t found=kFALSE; | |
329 | Float_t minContent=h1->Integral()*fgkThrPar; | |
330 | Int_t nbinsX = h1->GetNbinsX(); | |
331 | Int_t startBin=1; | |
332 | for (Int_t j=1; j<=nbinsX; j++){ | |
333 | if (( | |
334 | h1->GetBinContent(j) + | |
335 | h1->GetBinContent(j+1)+ | |
336 | h1->GetBinContent(j+2)+ | |
337 | h1->GetBinContent(j+3))>minContent){ | |
338 | found=kTRUE; | |
339 | startBin=j; | |
340 | break; | |
341 | } | |
342 | } | |
343 | if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",ich)); | |
344 | // Now calculate the mean over the interval. | |
345 | Double_t mean = 0; | |
346 | Double_t sumw2 = 0; | |
347 | Double_t nent = 0; | |
348 | for(Int_t k=0;k<fgkBinRangeAve;k++){ | |
349 | mean=mean+h1->GetBinCenter(startBin+k)*h1->GetBinContent(startBin+k); | |
350 | nent=nent+h1->GetBinContent(startBin+k); | |
351 | sumw2=sumw2+(h1->GetBinCenter(startBin+k))*(h1->GetBinCenter(startBin+k))*(h1->GetBinContent(startBin+k)); | |
352 | } | |
353 | mean= mean/nent; //<x> | |
354 | sumw2=sumw2/nent; //<x^2> | |
355 | Double_t rmsmean= 0; | |
356 | rmsmean = TMath::Sqrt((sumw2-mean*mean)/nent); | |
357 | if (ich<fNChannels) { | |
358 | AliTOFChannelOnline * ch = (AliTOFChannelOnline *)fCal->At(ich); | |
359 | ch->SetDelay((Double_t)mean*AliTOFGeometry::TdcBinWidth()*1.E-3); // delay in ns | |
360 | // ch->SetStatus(1); // calibrated channel, removed for the time being from AliTOFChannelOnline | |
361 | } | |
c9fe8530 | 362 | } |
708db10b | 363 | delete h1; |
364 | h1=0x0; | |
c9fe8530 | 365 | } |
d9179e4b | 366 | if (nNotStatistics!=0) Log(Form("Too little statistics for %d channels!",nNotStatistics)); |
c9fe8530 | 367 | } |
368 | daqFile->Close(); | |
369 | delete daqFile; | |
c9fe8530 | 370 | } |
371 | else{ | |
9d883ed9 | 372 | Log("The Cumulative data file from DAQ does not exist, TOF exiting from Shuttle"); |
7885c291 | 373 | return 6;//return error code for problems in retrieving DAQ data |
c9fe8530 | 374 | } |
375 | } | |
ee3e792b | 376 | delete listTot; |
c9fe8530 | 377 | } |
378 | else{ | |
9d883ed9 | 379 | Log("Problem: no list for Cumulative data file from DAQ was found, TOF exiting from Shuttle"); |
7885c291 | 380 | return 6; //return error code for problems in retrieving DAQ data |
c9fe8530 | 381 | } |
382 | ||
c9fe8530 | 383 | daqFile=0; |
7fffa85b | 384 | AliCDBMetaData metaData; |
385 | metaData.SetBeamPeriod(0); | |
386 | metaData.SetResponsible("Chiara Zampolli"); | |
387 | metaData.SetComment("This preprocessor fills a TObjArray object."); | |
388 | AliInfo("Storing Calibration Data"); | |
389 | resultTOFPP = Store("Calib","ParOnline",fCal, &metaData,0,kTRUE); | |
390 | if(!resultTOFPP){ | |
391 | Log("Some problems occurred while storing online object resulting from DAQ data processing"); | |
392 | return 8;//return error code for problems in storing DAQ data | |
393 | } | |
9d883ed9 | 394 | |
5936ab02 | 395 | return 0; |
c9fe8530 | 396 | } |
ee3e792b | 397 | //_____________________________________________________________________________ |
398 | ||
399 | UInt_t AliTOFPreprocessor::ProcessPulserData() | |
400 | { | |
7fffa85b | 401 | // Processing Pulser Run data for TOF channel status |
402 | ||
403 | Log("Processing Pulser"); | |
ee3e792b | 404 | |
405 | TH1::AddDirectory(0); | |
406 | ||
407 | Bool_t resultPulserRef=kFALSE; | |
7fffa85b | 408 | Bool_t resultPulser=kFALSE; |
ee3e792b | 409 | |
a174d599 | 410 | static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors(); |
411 | TH1S * htofPulser = new TH1S("hTOFpulser","histo with signals on TOF during pulser", kSize,-0.5,kSize-0.5); | |
412 | for (Int_t ibin =1;ibin<=kSize;ibin++){ | |
ee3e792b | 413 | htofPulser->SetBinContent(ibin,-1); |
414 | } | |
415 | ||
7fffa85b | 416 | // retrieving last stored pulser object, and copying |
417 | ||
418 | AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Pulser"); | |
419 | if (cdbEntry!=0x0){ | |
420 | TObjArray *currentCalStatus = (TObjArray*)cdbEntry->GetObject(); | |
421 | for (Int_t ich = 0; ich<fNChannels; ich ++){ | |
422 | AliTOFChannelOnlineStatus * calChOnlineSt = (AliTOFChannelOnlineStatus*)fCalStatus->At(ich); | |
423 | calChOnlineSt->SetStatus(((AliTOFChannelOnlineStatus*)currentCalStatus->At(ich))->GetStatus()); | |
424 | } | |
425 | } | |
426 | ||
ee3e792b | 427 | // processing pulser |
428 | ||
429 | TFile * daqFile=0x0; | |
430 | TH1S *h1=0x0; | |
431 | ||
432 | //retrieving Pulser data | |
433 | TList* listPulser = GetFileSources(kDAQ, "PULSER"); | |
bf76be9c | 434 | if (listPulser !=0x0 && listPulser->GetEntries()!=0) |
ee3e792b | 435 | { |
436 | AliInfo("The following sources produced files with the id PULSER"); | |
437 | listPulser->Print(); | |
438 | for (Int_t jj=0;jj<listPulser->GetEntries();jj++){ | |
439 | TObjString * str = dynamic_cast<TObjString*> (listPulser->At(jj)); | |
440 | AliInfo(Form("found source %s", str->String().Data())); | |
441 | // file to be stored run per run | |
442 | TString fileNamePulser = GetFile(kDAQ, "PULSER", str->GetName()); | |
443 | if (fileNamePulser.Length()>0){ | |
444 | // storing refernce data | |
1a1486e7 | 445 | AliInfo(Form("Got the file %s, now we can process pulser data.", fileNamePulser.Data())); |
ee3e792b | 446 | daqFile = new TFile(fileNamePulser.Data(),"READ"); |
447 | h1 = (TH1S*) daqFile->Get("hTOFpulser"); | |
a174d599 | 448 | for (Int_t ibin=0;ibin<kSize;ibin++){ |
ee3e792b | 449 | if ((h1->GetBinContent(ibin+1))!=-1){ |
450 | if ((htofPulser->GetBinContent(ibin+1))==-1){ | |
451 | htofPulser->SetBinContent(ibin+1,h1->GetBinContent(ibin+1)); | |
452 | } | |
453 | else { | |
454 | Log(Form("Something strange occurred during Pulser run, channel %i already read by another LDC, please check!",ibin)); | |
455 | } | |
456 | } | |
457 | } | |
1a1486e7 | 458 | |
ee3e792b | 459 | // elaborating infos |
460 | Double_t mean =0; | |
461 | Int_t nread=0; | |
462 | Int_t nreadNotEmpty=0; | |
463 | for (Int_t ientry=1;ientry<=h1->GetNbinsX();ientry++){ | |
db83b789 | 464 | |
465 | /* check whether channel has been read out during current run. | |
466 | * if the status is bad it means it has not been read out. | |
467 | * in this case skip channel in order to not affect the mean */ | |
468 | if (((AliTOFChannelOnlineStatus *)fFEEStatus->At(ientry-1))->GetStatus() == AliTOFChannelOnlineStatus::kTOFHWBad) | |
1a1486e7 | 469 | continue; |
db83b789 | 470 | |
ee3e792b | 471 | if (h1->GetBinContent(ientry)==-1) continue; |
472 | else { | |
473 | if (h1->GetBinContent(ientry)>0) { | |
474 | nreadNotEmpty++; | |
475 | AliDebug(1,Form(" channel %i is ok with entry = %f; so far %i channels added ",ientry-1,h1->GetBinContent(ientry),nreadNotEmpty)); | |
476 | } | |
477 | mean+=h1->GetBinContent(ientry); | |
478 | nread++; | |
479 | } | |
480 | } | |
1a1486e7 | 481 | if (nread!=0) { |
482 | mean/=nread; | |
483 | AliDebug(1,Form(" nread = %i , mean = %f",nread,mean)); | |
484 | for (Int_t ich =0;ich<fNChannels;ich++){ | |
485 | AliTOFChannelOnlineStatus * chSt = (AliTOFChannelOnlineStatus *)fCalStatus->At(ich); | |
486 | if (h1->GetBinContent(ich+1)==-1) continue; | |
487 | AliDebug(1,Form(" channel %i ",ich)); | |
488 | AliDebug(1,Form(" channel status before pulser = %i",(Int_t)chSt->GetStatus())); | |
489 | ||
490 | /* check whether channel has been read out during current run. | |
491 | * if the status is bad it means it has not been read out. | |
492 | * in this case skip channel in order to leave its status | |
493 | * unchanged */ | |
494 | if (((AliTOFChannelOnlineStatus *)fFEEStatus->At(ich))->GetStatus() == AliTOFChannelOnlineStatus::kTOFHWBad) | |
495 | continue; | |
496 | ||
497 | if (h1->GetBinContent(ich+1)<0.05*mean){ | |
498 | chSt->SetStatus(chSt->GetStatus()|AliTOFChannelOnlineStatus::kTOFPulserBad); // bad status for pulser | |
499 | AliDebug(1,Form(" channel status after pulser = %i",(Int_t)chSt->GetStatus())); | |
500 | } | |
501 | else { | |
502 | chSt->SetStatus(chSt->GetStatus()|AliTOFChannelOnlineStatus::kTOFPulserOk); // bad status for pulser | |
503 | AliDebug(1,Form(" channel status after pulser = %i",(Int_t)chSt->GetStatus())); | |
504 | } | |
505 | } | |
ee3e792b | 506 | } |
1a1486e7 | 507 | else { |
508 | Log("No channels read!! No action taken, keeping old status"); | |
509 | } | |
510 | ||
ee3e792b | 511 | daqFile->Close(); |
512 | delete daqFile; | |
513 | delete h1; | |
514 | } | |
515 | ||
516 | else{ | |
7fffa85b | 517 | Log("The input data file from DAQ (pulser) was not found, TOF exiting from Shuttle "); |
518 | return 10;//return error code for failure in retrieving Ref Data | |
ee3e792b | 519 | } |
520 | ||
521 | } | |
522 | delete listPulser; | |
523 | } | |
7fffa85b | 524 | |
ee3e792b | 525 | else{ |
7fffa85b | 526 | Log("The input data file list from DAQ (pulser) was not found, TOF exiting from Shuttle "); |
527 | return 10;//return error code for failure in retrieving Ref Data | |
ee3e792b | 528 | } |
7fffa85b | 529 | |
530 | //storing in OCDB | |
531 | ||
532 | AliCDBMetaData metaData; | |
533 | metaData.SetBeamPeriod(0); | |
534 | metaData.SetResponsible("Chiara Zampolli"); | |
535 | metaData.SetComment("This preprocessor fills a TObjArray object for Pulser data."); | |
536 | AliInfo("Storing Calibration Data from Pulser Run"); | |
db83b789 | 537 | resultPulser = Store("Calib","Pulser",fCalStatus, &metaData,0,kTRUE); |
7fffa85b | 538 | if(!resultPulser){ |
539 | Log("Some problems occurred while storing online object resulting from Pulser data processing"); | |
540 | return 11;//return error code for problems in storing Pulser data | |
541 | } | |
542 | ||
ee3e792b | 543 | if(fStoreRefData){ |
544 | ||
545 | AliCDBMetaData metaDataHisto; | |
546 | metaDataHisto.SetBeamPeriod(0); | |
547 | metaDataHisto.SetResponsible("Chiara Zampolli"); | |
548 | char comment[200]; | |
549 | sprintf(comment,"This preprocessor stores the result of the pulser run"); | |
550 | metaDataHisto.SetComment(comment); | |
551 | AliInfo("Storing Reference Data"); | |
db83b789 | 552 | resultPulserRef = StoreReferenceData("Calib","PulserData",htofPulser, &metaDataHisto); |
ee3e792b | 553 | if (!resultPulserRef){ |
7fffa85b | 554 | Log("some problems occurred::No Reference Data for pulser stored, TOF exiting from Shuttle"); |
555 | return 9;//return error code for failure in storing Ref Data | |
ee3e792b | 556 | } |
557 | } | |
558 | ||
559 | daqFile=0; | |
560 | ||
561 | return 0; | |
562 | } | |
563 | //_____________________________________________________________________________ | |
564 | ||
565 | UInt_t AliTOFPreprocessor::ProcessNoiseData() | |
566 | { | |
7fffa85b | 567 | |
568 | // Processing Noise Run data for TOF channel status | |
569 | ||
570 | Log("Processing Noise"); | |
ee3e792b | 571 | |
572 | TH1::AddDirectory(0); | |
573 | ||
574 | Bool_t resultNoiseRef=kFALSE; | |
7fffa85b | 575 | Bool_t resultNoise=kFALSE; |
ee3e792b | 576 | |
a174d599 | 577 | static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors(); |
578 | TH1F * htofNoise = new TH1F("hTOFnoise","histo with signals on TOF during pulser", kSize,-0.5,kSize-0.5); | |
579 | for (Int_t ibin =1;ibin<=kSize;ibin++){ | |
ee3e792b | 580 | htofNoise->SetBinContent(ibin,-1); |
581 | } | |
582 | ||
7fffa85b | 583 | // retrieving last stored noise object, and copying |
584 | ||
585 | AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Noise"); | |
586 | if (cdbEntry!=0x0){ | |
587 | TObjArray *currentCalStatus = (TObjArray*)cdbEntry->GetObject(); | |
588 | for (Int_t ich = 0; ich<fNChannels; ich ++){ | |
589 | AliTOFChannelOnlineStatus * calChOnlineSt = (AliTOFChannelOnlineStatus*)fCalStatus->At(ich); | |
590 | calChOnlineSt->SetStatus(((AliTOFChannelOnlineStatus*)currentCalStatus->At(ich))->GetStatus()); | |
591 | } | |
592 | } | |
593 | ||
ee3e792b | 594 | // processing noise |
595 | ||
596 | TFile * daqFile=0x0; | |
597 | TH1F * h1=0x0; | |
598 | ||
599 | //retrieving Noise data | |
600 | TList* listNoise = GetFileSources(kDAQ, "NOISE"); | |
bf76be9c | 601 | if (listNoise !=0x0 && listNoise->GetEntries()!=0) |
ee3e792b | 602 | { |
603 | AliInfo("The following sources produced files with the id NOISE"); | |
604 | listNoise->Print(); | |
605 | for (Int_t jj=0;jj<listNoise->GetEntries();jj++){ | |
606 | TObjString * str = dynamic_cast<TObjString*> (listNoise->At(jj)); | |
607 | AliInfo(Form("found source %s", str->String().Data())); | |
608 | // file to be stored run per run | |
609 | TString fileNameNoise = GetFile(kDAQ, "NOISE", str->GetName()); | |
610 | if (fileNameNoise.Length()>0){ | |
611 | // storing refernce data | |
1a1486e7 | 612 | AliInfo(Form("Got the file %s, now we can process noise data.", fileNameNoise.Data())); |
ee3e792b | 613 | daqFile = new TFile(fileNameNoise.Data(),"READ"); |
614 | h1 = (TH1F*) daqFile->Get("hTOFnoise"); | |
a174d599 | 615 | for (Int_t ibin=0;ibin<kSize;ibin++){ |
ee3e792b | 616 | if ((h1->GetBinContent(ibin+1))!=-1){ |
617 | if ((htofNoise->GetBinContent(ibin+1))==-1){ | |
618 | htofNoise->SetBinContent(ibin+1,h1->GetBinContent(ibin+1)); | |
619 | } | |
620 | else { | |
621 | Log(Form("Something strange occurred during Noise run, channel %i already read by another LDC, please check!",ibin)); | |
622 | } | |
623 | } | |
624 | } | |
625 | // elaborating infos | |
626 | for (Int_t ich =0;ich<fNChannels;ich++){ | |
7fffa85b | 627 | AliTOFChannelOnlineStatus * chSt = (AliTOFChannelOnlineStatus *)fCalStatus->At(ich); |
ee3e792b | 628 | if (h1->GetBinContent(ich+1)==-1) continue; |
629 | AliDebug(1,Form( " channel %i",ich)); | |
7fffa85b | 630 | AliDebug(1,Form( " channel status before noise = %i",(Int_t)chSt->GetStatus())); |
db83b789 | 631 | |
632 | /* check whether channel has been read out during current run. | |
633 | * if the status is bad it means it has not been read out. | |
634 | * in this case skip channel in order to leave its status | |
635 | * unchanged */ | |
636 | if (((AliTOFChannelOnlineStatus *)fFEEStatus->At(ich))->GetStatus() == AliTOFChannelOnlineStatus::kTOFHWBad) | |
637 | continue; | |
638 | ||
ee3e792b | 639 | if (h1->GetBinContent(ich+1)>=1){ // setting limit for noise to 1 kHz |
7fffa85b | 640 | chSt->SetStatus(chSt->GetStatus()|AliTOFChannelOnlineStatus::kTOFNoiseBad); // bad status for noise |
641 | AliDebug(1,Form( " channel status after noise = %i",(Int_t)chSt->GetStatus())); | |
ee3e792b | 642 | } |
643 | else { | |
7fffa85b | 644 | chSt->SetStatus(chSt->GetStatus()|AliTOFChannelOnlineStatus::kTOFNoiseOk); // bad status for noise |
645 | AliDebug(1,Form(" channel status after noise = %i",(Int_t)chSt->GetStatus())); | |
ee3e792b | 646 | } |
647 | } | |
648 | ||
649 | daqFile->Close(); | |
650 | delete daqFile; | |
7fffa85b | 651 | delete h1; |
652 | ||
ee3e792b | 653 | } |
654 | ||
655 | else{ | |
7fffa85b | 656 | Log("The input data file from DAQ (noise) was not found, TOF exiting from Shuttle "); |
657 | return 13;//return error code for failure in retrieving Ref Data | |
ee3e792b | 658 | } |
659 | ||
660 | } | |
661 | delete listNoise; | |
662 | } | |
663 | else{ | |
7fffa85b | 664 | Log("The input data file list from DAQ (noise) was not found, TOF exiting from Shuttle "); |
665 | return 13;//return error code for failure in retrieving Ref Data | |
ee3e792b | 666 | } |
667 | ||
668 | daqFile=0; | |
669 | ||
7fffa85b | 670 | //storing in OCDB |
671 | ||
672 | AliCDBMetaData metaData; | |
673 | metaData.SetBeamPeriod(0); | |
674 | metaData.SetResponsible("Chiara Zampolli"); | |
675 | metaData.SetComment("This preprocessor fills a TObjArray object for Noise data."); | |
676 | AliInfo("Storing Calibration Data from Noise Run"); | |
db83b789 | 677 | resultNoise = Store("Calib","Noise",fCalStatus, &metaData,0,kTRUE); |
7fffa85b | 678 | if(!resultNoise){ |
679 | Log("Some problems occurred while storing online object resulting from Noise data processing"); | |
680 | return 14;//return error code for problems in storing Noise data | |
681 | } | |
682 | ||
ee3e792b | 683 | if(fStoreRefData){ |
684 | ||
685 | AliCDBMetaData metaDataHisto; | |
686 | metaDataHisto.SetBeamPeriod(0); | |
687 | metaDataHisto.SetResponsible("Chiara Zampolli"); | |
688 | char comment[200]; | |
7fffa85b | 689 | sprintf(comment,"This preprocessor stores the result of the noise run, TOF exiting from Shuttle "); |
ee3e792b | 690 | metaDataHisto.SetComment(comment); |
691 | AliInfo("Storing Reference Data"); | |
db83b789 | 692 | resultNoiseRef = StoreReferenceData("Calib","NoiseData",htofNoise, &metaDataHisto); |
ee3e792b | 693 | if (!resultNoiseRef){ |
694 | Log("some problems occurred::No Reference Data for noise stored"); | |
7fffa85b | 695 | return 12;//return error code for failure in storing Ref Data |
ee3e792b | 696 | } |
697 | } | |
698 | ||
699 | return 0; | |
700 | } | |
701 | //_____________________________________________________________________________ | |
702 | ||
db83b789 | 703 | UInt_t AliTOFPreprocessor::ProcessFEEData() |
ee3e792b | 704 | { |
7fffa85b | 705 | // Processing Pulser Run data for TOF channel status |
706 | // dummy for the time being | |
ee3e792b | 707 | |
db83b789 | 708 | Log("Processing FEE"); |
709 | ||
710 | Bool_t updateOCDB = kFALSE; | |
711 | AliTOFFEEReader feeReader; | |
712 | AliTOFChannelOnlineStatus *currentChannel = NULL, *storedChannel = NULL; | |
713 | TObjArray *currentFEE = fFEEStatus; | |
714 | ||
715 | TH1C hCurrentFEE("hCurrentFEE","histo with current FEE channel status", fNChannels, 0, fNChannels); | |
716 | ||
717 | /* load current TOF FEE config from DCS FXS, parse, | |
718 | * fill current FEE histogram and set FEE status */ | |
719 | ||
720 | const char * nameFile = GetFile(kDCS,"TofFeeMap",""); | |
721 | AliInfo(Form("nameFile = %s",nameFile)); | |
722 | if (nameFile == NULL) { | |
723 | return 15; | |
724 | } | |
725 | feeReader.LoadFEEConfig(nameFile); | |
726 | feeReader.ParseFEEConfig(); | |
727 | /* loop over channels */ | |
728 | for (Int_t iChannel = 0; iChannel < fNChannels; iChannel++) { | |
729 | currentChannel = (AliTOFChannelOnlineStatus *)currentFEE->At(iChannel); | |
730 | if (!currentChannel) | |
731 | continue; | |
732 | /* channel enabled. set FEE channel status ok */ | |
733 | if (feeReader.IsChannelEnabled(iChannel)) { | |
734 | currentChannel->SetStatus(AliTOFChannelOnlineStatus::kTOFHWOk); | |
735 | hCurrentFEE.SetBinContent(iChannel + 1, 1); | |
736 | } | |
737 | /* channel disabled. set FEE channel status bad */ | |
738 | else { | |
739 | currentChannel->SetStatus(AliTOFChannelOnlineStatus::kTOFHWBad); | |
740 | } | |
741 | } | |
742 | ||
743 | /* load stored TOF FEE from OCDB and compare it with current FEE. | |
744 | * if stored FEE is different from current FEE set update flag. | |
745 | * if there is no stored FEE in OCDB set update flag */ | |
746 | ||
747 | AliCDBEntry *cdbEntry = GetFromOCDB("Calib","FEE"); | |
748 | /* no CDB entry found. set update flag */ | |
749 | if (cdbEntry == NULL) { | |
750 | updateOCDB = kTRUE; | |
751 | } | |
752 | /* CDB entry OK. loop over channels */ | |
753 | else { | |
754 | TObjArray *storedFEE = (TObjArray *)cdbEntry->GetObject(); | |
755 | for (Int_t iChannel = 0; iChannel < fNChannels; iChannel++){ | |
756 | currentChannel = (AliTOFChannelOnlineStatus *)currentFEE->At(iChannel); | |
757 | storedChannel = (AliTOFChannelOnlineStatus *)storedFEE->At(iChannel); | |
758 | /* compare current FEE channel status with stored one | |
759 | * if different set update flag and break loop */ | |
760 | if (currentChannel->GetStatus() != storedChannel->GetStatus()) { | |
761 | updateOCDB = kTRUE; | |
762 | break; | |
763 | } | |
764 | } | |
765 | } | |
766 | ||
767 | /* check whether we don't have to store reference data. | |
768 | * in this case we return without errors. */ | |
769 | if (fStoreRefData) { | |
770 | /* store reference data */ | |
771 | AliCDBMetaData metaDataHisto; | |
772 | metaDataHisto.SetBeamPeriod(0); | |
773 | metaDataHisto.SetResponsible("Roberto Preghenella"); | |
774 | metaDataHisto.SetComment("This preprocessor stores the FEE referece data of the current run."); | |
775 | AliInfo("Storing FEE reference data"); | |
776 | /* store FEE reference data */ | |
777 | if (!StoreReferenceData("Calib", "FEEData", &hCurrentFEE, &metaDataHisto)) { | |
778 | /* failed */ | |
779 | Log("problems while storing FEE reference data"); | |
780 | return 18; /* error return code for problems while storing FEE reference data */ | |
781 | } | |
782 | } | |
783 | ||
784 | /* check whether we don't need to update OCDB. | |
785 | * in this case we can return without errors and | |
786 | * the current FEE is stored in the fFEEStatus TObjArray. */ | |
787 | if (!updateOCDB) { | |
788 | AliInfo("TOF FEE config has not changed. Do not overwrite stored file."); | |
789 | return 0; /* return ok */ | |
790 | } | |
791 | ||
792 | /* update the OCDB with the current FEE since even | |
793 | * a little difference has been detected. */ | |
794 | ||
795 | AliCDBMetaData metaData; | |
796 | metaData.SetBeamPeriod(0); | |
797 | metaData.SetResponsible("Roberto Preghenella"); | |
798 | metaData.SetComment("This preprocessor fills a TObjArray object for FEE data."); | |
799 | AliInfo("Storing FEE data from current run"); | |
800 | /* store FEE data */ | |
801 | if (!Store("Calib", "FEE", fFEEStatus, &metaData, 0, kTRUE)) { | |
802 | /* failed */ | |
803 | Log("problems while storing FEE data object"); | |
804 | return 17; /* return error code for problems while storing FEE data */ | |
805 | } | |
806 | ||
807 | /* everything fine. return */ | |
ee3e792b | 808 | |
7fffa85b | 809 | return 0; |
810 | ||
811 | } | |
812 | ||
813 | //_____________________________________________________________________________ | |
814 | ||
815 | UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap) | |
816 | { | |
a174d599 | 817 | // |
818 | // | |
819 | // | |
7fffa85b | 820 | |
821 | TString runType = GetRunType(); | |
822 | Log(Form("RunType %s",runType.Data())); | |
bf76be9c | 823 | |
ee3e792b | 824 | // processing |
825 | ||
db83b789 | 826 | /* always process FEE data */ |
827 | Int_t iresultFEE = ProcessFEEData(); | |
828 | if (iresultFEE != 0) | |
829 | return iresultFEE; | |
830 | ||
7fffa85b | 831 | if (runType == "PULSER") { |
832 | Int_t iresultPulser = ProcessPulserData(); | |
833 | return iresultPulser; | |
834 | } | |
ee3e792b | 835 | |
7fffa85b | 836 | if (runType == "NOISE") { // for the time being associating noise runs with pedestal runs; proper run type to be defined |
837 | Int_t iresultNoise = ProcessNoiseData(); | |
838 | return iresultNoise; | |
839 | } | |
840 | ||
841 | if (runType == "PHYSICS") { | |
842 | Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap); | |
843 | if (iresultDCS != 0) { | |
844 | return iresultDCS; | |
845 | } | |
846 | else { | |
847 | Int_t iresultDAQ = ProcessOnlineDelays(); | |
848 | return iresultDAQ; | |
849 | } | |
ee3e792b | 850 | } |
851 | ||
7fffa85b | 852 | // storing |
ee3e792b | 853 | return 0; |
854 | } | |
c9fe8530 | 855 | |
856 |