Updated calibration object to use by triggger simulator and simulator itself
[u/mrichter/AliRoot.git] / AD / ADbase / AliADDataDCS.cxx
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
16
17 #include "AliADDataDCS.h"
18
19 #include "AliDCSValue.h"
20 #include "AliLog.h"
21
22 #include <TGraph.h>
23 #include <TAxis.h>
24 #include <TCanvas.h>
25 #include <TTimeStamp.h>
26 #include <TMap.h>
27 #include <TString.h>
28 #include <TObjString.h>
29 #include <TH1F.h>
30
31 class TH2;
32 class AliCDBMetaData;
33 class TDatime;
34
35 // AliADDataDCS class
36 // main aim to introduce the aliases for the AD DCS
37 // data points to be then
38 // stored in the OCDB, and to process them. 
39 // ProcessData() method called by ADPreprocessor
40
41 ClassImp(AliADDataDCS)
42
43 //_____________________________________________________________________________
44 AliADDataDCS::AliADDataDCS():
45         TObject(),
46         fRun(0),
47         fStartTime(0),
48         fEndTime(0),
49         fDaqStartTime(0),
50         fDaqEndTime(0),
51         fCtpStartTime(0),
52         fCtpEndTime(0),
53     fGraphs("TGraph",kNGraphs),
54         fFEEParameters(NULL),
55         fIsProcessed(kFALSE)
56
57 {
58   // Default constructor
59         for(int i=0;i<kNHvChannel;i++) {
60                 fDeadChannel[i] = kFALSE;
61                 fMeanHV[i]      = 100.0;
62                 fWidthHV[i]     = 0.0; 
63                 fHv[i]          = NULL;
64         }
65 }
66
67 //_____________________________________________________________________________
68 AliADDataDCS::AliADDataDCS(Int_t nRun, UInt_t startTime, UInt_t endTime, UInt_t daqStartTime, UInt_t daqEndTime, UInt_t ctpStartTime, UInt_t ctpEndTime):
69         TObject(),
70         fRun(nRun),
71         fStartTime(startTime),
72         fEndTime(endTime),
73         fDaqStartTime(daqStartTime),
74         fDaqEndTime(daqEndTime),
75         fCtpStartTime(ctpStartTime),
76         fCtpEndTime(ctpEndTime),
77         fGraphs("TGraph",kNGraphs),
78         fFEEParameters(new TMap()),
79         fIsProcessed(kFALSE)
80
81 {
82
83   // constructor with arguments
84         for(int i=0;i<kNHvChannel;i++) {
85          fDeadChannel[i] = kFALSE;        
86          fMeanHV[i]      = 100.0;
87      fWidthHV[i]     = 0.0; 
88         }
89         AliInfo(Form("\n\tRun %d \n\tTime Created %s \n\tTime Completed %s \n\tDAQ start %s \n\tDAQ end %s \n\tCTP start %s \n\tCTP end %s   ", nRun,
90                 TTimeStamp(startTime).AsString(),
91                 TTimeStamp(endTime).AsString(),
92                 TTimeStamp(daqStartTime).AsString(),
93                 TTimeStamp(daqEndTime).AsString(),
94                 TTimeStamp(ctpStartTime).AsString(),
95                 TTimeStamp(ctpEndTime).AsString()
96                 ));
97         
98         fFEEParameters->SetOwnerValue();
99         Init();
100
101 }
102
103 //_____________________________________________________________________________
104 AliADDataDCS::~AliADDataDCS() {
105
106   // destructor
107   fGraphs.Clear("C");
108   delete fFEEParameters;
109
110 }
111
112 //_____________________________________________________________________________
113 Bool_t AliADDataDCS::ProcessData(TMap& aliasMap){
114
115   // method to process the data
116   Bool_t success = kTRUE;
117
118   if(!(fAliasNames[0])) Init();
119
120   TObjArray *aliasArr;
121   AliDCSValue* aValue;
122
123   // starting loop on aliases
124   for(int iAlias=0; iAlias<kNAliases; iAlias++){
125
126     aliasArr = (TObjArray*) aliasMap.GetValue(fAliasNames[iAlias].Data());
127     if(!aliasArr){
128       AliError(Form("Alias %s not found!", fAliasNames[iAlias].Data()));
129       success = kFALSE;
130       continue;
131     }
132
133     //Introduce(iAlias, aliasArr);
134     
135     if(aliasArr->GetEntries()<2){
136       AliWarning(Form("Alias %s has just %d entries!",
137                     fAliasNames[iAlias].Data(),aliasArr->GetEntries()));
138     }
139     
140     TIter iterarray(aliasArr);
141         
142     if(iAlias<kNHvChannel){ // Treating HV values
143         Int_t nentries = aliasArr->GetEntries();
144
145         Double_t *times = new Double_t[nentries];
146         Double_t *values = new Double_t[nentries];
147
148         UInt_t iValue=0;
149         Float_t variation = 0.0;
150
151         while((aValue = (AliDCSValue*) iterarray.Next())) {
152                         UInt_t currentTime = aValue->GetTimeStamp();
153                         //if(currentTime>fCtpEndTime) break; //What is this for?
154
155                         values[iValue] = aValue->GetFloat();
156                         times[iValue] = (Double_t) (currentTime);
157                         
158                         if(iValue>0) {
159                                 if(values[iValue-1]>0.) variation = TMath::Abs(values[iValue]-values[iValue-1])/values[iValue-1];
160                                 if(variation > 0.01) fDeadChannel[GetOfflineChannel(iAlias)] = kTRUE;
161                         }
162                         fHv[iAlias]->Fill(values[iValue]);
163                         printf("%s : %s : %f Dead=%d\n",fAliasNames[iAlias].Data(),TTimeStamp(currentTime).AsString(),values[iValue],fDeadChannel[GetOfflineChannel(iAlias)]);
164                         iValue++;
165         }      
166         CreateGraph(iAlias, aliasArr->GetEntries(), times, values); // fill graphs 
167
168         // calculate mean and rms of the first two histos
169         // and convert index to aliroot channel
170         Int_t iChannel     = GetOfflineChannel(iAlias); 
171         fMeanHV[iChannel]  = fHv[iAlias]->GetMean();
172         fWidthHV[iChannel] = fHv[iAlias]->GetRMS();
173
174         delete[] values;
175         delete[] times; 
176         } else { // Treating FEE Parameters
177                 AliDCSValue * lastVal = NULL;
178                 while((aValue = (AliDCSValue*) iterarray.Next())) lastVal = aValue; // Take only the last value
179                 fFEEParameters->Add(new TObjString(fAliasNames[iAlias].Data()),lastVal);
180         }      
181   }
182   
183   fIsProcessed=kTRUE;
184
185   return success;
186 }
187
188 //_____________________________________________________________________________
189 void AliADDataDCS::Init(){
190
191   // initialization of aliases and DCS data
192
193   TString sindex;
194   int iAlias = 0;
195   
196   for(int iPM = 0; iPM<16 ; iPM++){
197                 fAliasNames[iAlias] = Form("AD0/HV/PM%d",iPM);
198                         
199                 fHv[iAlias] = new TH1F(fAliasNames[iAlias].Data(),fAliasNames[iAlias].Data(), 3000, kHvMin, kHvMax);
200                 fHv[iAlias]->GetXaxis()->SetTitle("Hv");
201                 iAlias++;
202   }
203   // CCIU Parameters
204         
205   fAliasNames[iAlias++] = "AD0/FEE/CCIU/BBAThreshold";
206   fAliasNames[iAlias++] = "AD0/FEE/CCIU/BBCThreshold";
207   fAliasNames[iAlias++] = "AD0/FEE/CCIU/BGAThreshold";
208   fAliasNames[iAlias++] = "AD0/FEE/CCIU/BGCThreshold";
209   fAliasNames[iAlias++] = "AD0/FEE/CCIU/BBAForBGThreshold";
210   fAliasNames[iAlias++] = "AD0/FEE/CCIU/BBCForBGThreshold";
211   fAliasNames[iAlias++] = "AD0/FEE/CCIU/MultADAThrLow";
212   fAliasNames[iAlias++] = "AD0/FEE/CCIU/MultADAThrHigh";
213   fAliasNames[iAlias++] = "AD0/FEE/CCIU/MultADCThrLow";
214   fAliasNames[iAlias++] = "AD0/FEE/CCIU/MultADCThrHigh";
215   for(int i=1;i<=5;i++) {
216         fAliasNames[iAlias] = "AD0/FEE/CCIU/TriggerSelect";
217         fAliasNames[iAlias++] += Form("%d",i);
218   }
219   //Trigger parameters
220   for(int iCIU = 0; iCIU<2 ; iCIU++){
221                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/Clk1Win1",iCIU);
222                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/Clk1Win2",iCIU);
223                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/Clk2Win1",iCIU);
224                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/Clk2Win2",iCIU);
225                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/DelayClk1Win1",iCIU);
226                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/DelayClk1Win2",iCIU);
227                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/DelayClk2Win1",iCIU);
228                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/DelayClk2Win2",iCIU);
229                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/LatchWin1",iCIU);
230                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/LatchWin2",iCIU);
231                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/ResetWin1",iCIU);
232                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/ResetWin2",iCIU);
233                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/PedestalSubtraction",iCIU);
234   }
235   for(int iCIU = 0; iCIU<2 ; iCIU++){
236           for(int iCh=1;iCh<=8;iCh++){
237                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/EnableCharge%d",iCIU,iCh);
238                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/EnableTiming%d",iCIU,iCh);
239                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/PedEven%d",iCIU,iCh);
240                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/PedOdd%d",iCIU,iCh);
241                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/PedCutEven%d",iCIU,iCh);
242                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/PedCutOdd%d",iCIU,iCh);
243           }
244   }
245  // Time Resolution Parameters  
246   for(int iCIU = 0; iCIU<2 ; iCIU++){
247                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/TimeResolution",iCIU);
248                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/WidthResolution",iCIU);
249   }
250   // HPTDC parameters
251   for(int iCIU = 0; iCIU<2 ; iCIU++){
252                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/MatchWindow",iCIU);
253                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/SearchWindow",iCIU);
254                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/TriggerCountOffset",iCIU);
255                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/RollOver",iCIU);
256   }
257
258   for(int iCIU = 0; iCIU<2 ; iCIU++){
259           for(int iCh=1;iCh<=8;iCh++){
260                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/DelayHit%d",iCIU,iCh);
261           }
262   }
263
264   for(int iCIU = 0; iCIU<2 ; iCIU++){
265           for(int iCh=1;iCh<=8;iCh++){
266                 fAliasNames[iAlias++] = Form("AD0/FEE/CIU%d/DiscriThr%d",iCIU,iCh);
267           }
268   }
269
270   if(iAlias!=kNAliases) 
271               AliError(Form("Number of DCS Aliases defined not correct"));
272
273 }
274
275 //_____________________________________________________________________________
276 void AliADDataDCS::Introduce(UInt_t numAlias, const TObjArray* aliasArr)const
277 {
278
279   // method to introduce new aliases
280
281   int entries=aliasArr->GetEntries();
282   AliInfo(Form("************ Alias: %s **********",fAliasNames[numAlias].Data()));
283   AliInfo(Form("        %d DP values collected",entries));
284
285 }
286
287 //_____________________________________________________________________________
288 void AliADDataDCS::CreateGraph(int i, int dim, const Double_t *x, const Double_t *y)
289 {
290
291    // Create graphics
292    
293    TGraph *gr = new(fGraphs[fGraphs.GetEntriesFast()]) TGraph(dim, x, y);
294
295    gr->GetXaxis()->SetTimeDisplay(1);
296    gr->SetTitle(fAliasNames[i].Data());
297
298    AliInfo(Form("Array entries: %d",fGraphs.GetEntriesFast()));
299
300 }
301
302
303 //_____________________________________________________________________________
304 void AliADDataDCS::Draw(const Option_t* /*option*/)
305 {
306 // Draw all histos and graphs
307
308   if(!fIsProcessed) return;
309
310   if(fGraphs.GetEntries()==0)  return;
311   
312   TCanvas *cHV = new TCanvas("AD0_HV","AD0_HV");
313   cHV->Divide(4,4);
314   
315   for(int iPM = 0; iPM<16 ; iPM++){
316         cHV->cd(iPM+1);
317         ((TGraph*) fGraphs.UncheckedAt(iPM))->SetMarkerStyle(20);
318         ((TGraph*) fGraphs.UncheckedAt(iPM))->Draw("ALP");                      
319         }
320 }
321