]>
Commit | Line | Data |
---|---|---|
14487e6a | 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 | $Log$ | |
18 | */ | |
19 | ||
20 | // | |
21 | // Class to simulate the | |
22 | // data coming from DCS | |
23 | // for a test preprocessor | |
24 | // | |
25 | ||
5c6b40ae | 26 | #include "AliTestDataDCS.h" |
27 | ||
5c6b40ae | 28 | #include "AliDCSValue.h" |
29 | #include "AliLog.h" | |
30 | ||
31 | #include <TTimeStamp.h> | |
5c6b40ae | 32 | #include <TGraph.h> |
5c6b40ae | 33 | #include <TCanvas.h> |
14487e6a | 34 | #include <TObjArray.h> |
35 | #include <TMap.h> | |
5c6b40ae | 36 | |
37 | ClassImp(AliTestDataDCS) | |
38 | ||
39 | //--------------------------------------------------------------- | |
40 | AliTestDataDCS::AliTestDataDCS(): | |
41 | TObject(), | |
42 | fRun(0), | |
43 | fStartTime(0), | |
44 | fEndTime(0), | |
45 | fGraphs("TGraph",kNGraphs), | |
46 | fIsProcessed(kFALSE) | |
47 | { | |
48 | for(int i=0;i<kNHistos;i++) fHv[i]=0x0; | |
49 | fFunc = 0; | |
50 | } | |
51 | ||
52 | //--------------------------------------------------------------- | |
53 | AliTestDataDCS::AliTestDataDCS(Int_t nRun, UInt_t startTime, UInt_t endTime): | |
54 | TObject(), | |
55 | fRun(nRun), | |
56 | fStartTime(startTime), | |
57 | fEndTime(endTime), | |
58 | fGraphs("TGraph",kNGraphs), | |
59 | fIsProcessed(kFALSE) | |
60 | { | |
14487e6a | 61 | |
62 | // | |
63 | // constructor | |
64 | // | |
65 | ||
5c6b40ae | 66 | AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", nRun, |
67 | TTimeStamp(startTime).AsString(), | |
68 | TTimeStamp(endTime).AsString())); | |
69 | ||
70 | fFunc = 0; | |
71 | Init(); | |
72 | ||
73 | } | |
74 | ||
75 | //--------------------------------------------------------------- | |
76 | AliTestDataDCS::~AliTestDataDCS() { | |
77 | ||
78 | for(int i=0;i<kNHistos;i++) {delete fHv[i]; fHv[i]=0;} | |
79 | fGraphs.Clear("C"); | |
80 | fFunc=0; | |
81 | } | |
82 | ||
83 | //--------------------------------------------------------------- | |
84 | void AliTestDataDCS::ProcessData(TMap& aliasMap){ | |
85 | ||
14487e6a | 86 | // |
87 | // processing the data | |
88 | // | |
89 | ||
5c6b40ae | 90 | if(!(fHv[0])) Init(); |
91 | ||
92 | TObjArray *aliasArr; | |
93 | AliDCSValue* aValue; | |
94 | for(int j=0; j<kNAliases; j++){ | |
95 | aliasArr = (TObjArray*) aliasMap.GetValue(fAliasNames[j].Data()); | |
96 | if(!aliasArr){ | |
97 | AliError(Form("Alias %s not found!", fAliasNames[j].Data())); | |
98 | continue; | |
99 | } | |
100 | Introduce(j, aliasArr); | |
101 | ||
102 | if(aliasArr->GetEntries()<2){ | |
103 | AliError(Form("Alias %s has just %d entries!", | |
104 | fAliasNames[j].Data(),aliasArr->GetEntries())); | |
105 | continue; | |
106 | } | |
107 | ||
108 | TIter iterarray(aliasArr); | |
109 | ||
110 | Double_t *time = new Double_t[aliasArr->GetEntries()]; | |
111 | Double_t *val = new Double_t[aliasArr->GetEntries()]; | |
112 | ||
113 | UInt_t ne=0; | |
114 | while ((aValue = (AliDCSValue*) iterarray.Next())) { | |
36137ac1 | 115 | |
45a493ce | 116 | val[ne] = aValue->GetFloat(); |
5c6b40ae | 117 | time[ne] = (Double_t) (aValue->GetTimeStamp()); |
118 | // fill histos (alias 0-2) | |
119 | if(j < 3) fHv[j]->Fill(val[ne]); | |
120 | ne++; | |
121 | } | |
122 | // fill graphs (alias 3-5) | |
123 | if(j >= 3) CreateGraph(j, aliasArr->GetEntries(), time, val); | |
124 | delete[] val; | |
125 | delete[] time; | |
126 | } | |
127 | ||
128 | // calculate mean and rms of the first two histos | |
129 | for(int i=0;i<kNHistos;i++){ | |
130 | fMean[i] = fHv[i]->GetMean(); | |
131 | fWidth[i] = fHv[i]->GetRMS(); | |
132 | } | |
133 | ||
134 | // pol1 fit of the first graph | |
135 | if(fGraphs.GetEntries() > 0){ | |
136 | ((TGraph*) fGraphs.UncheckedAt(0))->Fit("pol1"); | |
137 | fFunc = ((TGraph*) fGraphs.UncheckedAt(0))->GetFunction("pol1"); | |
138 | } | |
139 | ||
140 | fIsProcessed=kTRUE; | |
141 | ||
142 | ||
143 | } | |
144 | ||
145 | //--------------------------------------------------------------- | |
146 | void AliTestDataDCS::Init(){ | |
147 | ||
14487e6a | 148 | // |
149 | // initialization | |
150 | // | |
151 | ||
5c6b40ae | 152 | TH1::AddDirectory(kFALSE); |
153 | ||
154 | fGraphs.SetOwner(1); | |
155 | ||
156 | for(int i=0;i<kNAliases;i++){ | |
36137ac1 | 157 | fAliasNames[i] = "DCSAlias"; |
5c6b40ae | 158 | fAliasNames[i] += i; |
5c6b40ae | 159 | } |
160 | ||
161 | for(int i=0;i<kNHistos;i++){ | |
36137ac1 | 162 | fHv[i] = new TH1F(fAliasNames[i].Data(),fAliasNames[i].Data(), 20, kHvMin, kHvMax); |
5c6b40ae | 163 | fHv[i]->GetXaxis()->SetTitle("Hv"); |
164 | } | |
165 | } | |
166 | ||
167 | //--------------------------------------------------------------- | |
168 | void AliTestDataDCS::Introduce(UInt_t numAlias, const TObjArray* aliasArr){ | |
169 | ||
170 | int entries=aliasArr->GetEntries(); | |
171 | AliInfo(Form("************ Alias: %s **********",fAliasNames[numAlias].Data())); | |
172 | AliInfo(Form(" %d DP values collected",entries)); | |
173 | ||
174 | } | |
175 | ||
176 | //--------------------------------------------------------------- | |
177 | void AliTestDataDCS::CreateGraph(int i, int dim, const Double_t *x, const Double_t *y) | |
178 | { | |
179 | ||
180 | TGraph *gr = new(fGraphs[fGraphs.GetEntriesFast()]) TGraph(dim, x, y); | |
181 | ||
182 | gr->GetXaxis()->SetTimeDisplay(1); | |
183 | gr->SetTitle(fAliasNames[i].Data()); | |
184 | ||
185 | AliInfo(Form("Array entries: %d",fGraphs.GetEntriesFast())); | |
186 | ||
187 | ||
188 | } | |
189 | ||
190 | //--------------------------------------------------------------- | |
191 | void AliTestDataDCS::Draw(const Option_t* /*option*/) | |
192 | { | |
14487e6a | 193 | // |
194 | // Draw all histos and graphs | |
195 | // | |
5c6b40ae | 196 | |
197 | if(!fIsProcessed) return; | |
198 | ||
199 | TCanvas *ch; | |
200 | TString canvasHistoName="Histos"; | |
201 | ch=new TCanvas(canvasHistoName,canvasHistoName,20,20,600,600); | |
202 | ch->Divide(2,2); | |
203 | ch->cd(1); | |
204 | fHv[0]->Draw(); | |
205 | ch->cd(2); | |
206 | fHv[1]->Draw(); | |
207 | ch->cd(3); | |
208 | fHv[2]->Draw(); | |
209 | ||
210 | ||
211 | if(fGraphs.GetEntries() == 0) return; | |
212 | ||
213 | TCanvas *cg; | |
214 | TString canvasGraphName="Graphs"; | |
215 | cg=new TCanvas(canvasGraphName,canvasGraphName,40,40,600,600); | |
216 | cg->Divide(2,2); | |
217 | cg->cd(1); | |
218 | ((TGraph*) fGraphs.UncheckedAt(0))->Draw("alp"); | |
219 | ||
220 | cg->cd(2); | |
221 | ((TGraph*) fGraphs.UncheckedAt(1))->Draw("alp"); | |
222 | cg->cd(3); | |
223 | ((TGraph*) fGraphs.UncheckedAt(2))->Draw("alp"); | |
224 | ||
225 | if(fFunc){ | |
226 | cg->cd(4); | |
227 | fFunc->Draw("l"); | |
228 | } | |
229 | ||
230 | } | |
231 |