a737dcce37a840f686d6e6bc8d21aa7c29ac9f85
[u/mrichter/AliRoot.git] / ACORDE / AliACORDEDataDCS.cxx
1 /****************************************************
2         
3   AliACORDEDataDCS class
4   create to make a pointer to the
5   ACORDE data DCS points
6
7   Author: Pedro Gonzalez (CIEMAT, Madrid)
8   ACORDE-DCS creator: Mario Ivan Martinez Hdez
9                         <mim@fcfm.buap.mx>
10
11   Last update: Fix of coding violations
12   Mario Rodriguez C. (FCFM-BUAP)
13   <mrodrigu@mail.cern.ch>
14
15 *****************************************************/
16 #include "AliACORDEDataDCS.h"
17
18 #include "AliCDBMetaData.h"
19 #include "AliDCSValue.h"
20 #include "AliLog.h"
21
22 #include <TTimeStamp.h>
23 #include <TObjString.h>
24 #include <TH2F.h>
25 #include <TProfile.h>
26 #include <TGraph.h>
27 #include <TDatime.h>
28 #include <TStyle.h>
29 #include <TCanvas.h>
30
31 ClassImp(AliACORDEDataDCS)
32
33 //---------------------------------------------------------------
34 AliACORDEDataDCS::AliACORDEDataDCS():
35         TObject(),
36         fRun(0),
37         fStartTime(0),
38         fEndTime(0),
39         fGraphs("TGraph",kNGraphs),
40         fFunc(0),
41         fIsProcessed(kFALSE)
42 {
43         for(int i=0;i<kNHistos;i++) 
44         {
45                 fHv[i]=0x0;
46                 fMean[i] = fWidth[i] = 0.0;
47         }
48         
49 }
50
51 //---------------------------------------------------------------
52 AliACORDEDataDCS::AliACORDEDataDCS(Int_t nRun, UInt_t startTime, UInt_t endTime):
53         TObject(),
54         fRun(nRun),
55         fStartTime(startTime),
56         fEndTime(endTime),
57         fGraphs("TGraph",kNGraphs),
58         fFunc(0),
59         fIsProcessed(kFALSE)
60 {
61 // Init of class AliACORDEDataDCS
62 // Gettin the TimeStamp an put it on a string
63
64         AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", nRun,
65         TTimeStamp(startTime).AsString(),
66         TTimeStamp(endTime).AsString()));
67
68        
69         Init();
70
71 }
72
73 //---------------------------------------------------------------
74 AliACORDEDataDCS::~AliACORDEDataDCS() {
75
76         for(int i=0;i<kNHistos;i++) 
77         {
78                 delete fHv[i]; fHv[i]=0;
79         }
80         fGraphs.Clear("C");
81         fFunc=0;
82 }
83 //---------------------------------------------------------------
84
85 AliACORDEDataDCS::AliACORDEDataDCS(const AliACORDEDataDCS & data):
86 TObject(),
87 fRun(0),
88 fStartTime(0),
89 fEndTime(0),
90 fGraphs("TGraph",kNGraphs),
91 fFunc(0),
92 fIsProcessed(kFALSE)
93 {
94 // Setting the initial values
95 // fRUn, Start of Run, End of Run, IsProcessed
96
97         fRun=data.fRun;
98         fStartTime=data.fStartTime;
99         fEndTime=data.fEndTime;
100         fFunc=data.fFunc;
101         fIsProcessed=data.fIsProcessed;
102
103
104         for(int i=0;i<kNAliases;i++){fAliasNames[i] = data.fAliasNames[i];}
105
106         for(int i=0;i<kNHistos;i++)
107         {
108                 fHv[i]=data.fHv[i];
109                 fMean[i]=data.fMean[i];
110                 fWidth[i]=data.fWidth[i];
111         }
112
113
114
115         
116 }
117 //--------------------------------------------------------------
118 AliACORDEDataDCS& AliACORDEDataDCS:: operator=(const AliACORDEDataDCS & data) { 
119
120         
121         this->fRun=data.fRun;
122         this->fStartTime=data.fStartTime;
123         this->fEndTime=data.fEndTime;
124         this->fFunc=data.fFunc;
125         this->fIsProcessed=data.fIsProcessed;
126
127
128         for(int i=0;i<kNAliases;i++){this->fAliasNames[i] = data.fAliasNames[i];}
129
130         for(int i=0;i<kNHistos;i++)
131         {
132                 this->fHv[i]=data.fHv[i];
133         }
134
135         
136          return *this;
137  
138 }
139 //---------------------------------------------------------------
140 void AliACORDEDataDCS::ProcessData(TMap& aliasMap)
141 {
142 // Process of the data from the aliases DCS-data points
143
144         if(!(fHv[0])) Init();
145
146         TObjArray *aliasArr;
147         AliDCSValue* aValue;
148
149         for(int j=0; j<kNAliases; j++)
150         {
151                 aliasArr = (TObjArray*) aliasMap.GetValue(fAliasNames[j].Data());
152                 if(!aliasArr)
153                 {
154                         AliError(Form("Alias %s not found!", fAliasNames[j].Data()));
155                         continue;
156                 }
157                 Introduce(j, aliasArr);
158
159                 if(aliasArr->GetEntries()<2)
160                 {
161                 AliError(Form("Alias %s has just %d entries!",
162                                         fAliasNames[j].Data(),aliasArr->GetEntries()));
163                         continue;
164                 }
165
166                 TIter iterarray(aliasArr);
167
168                 Double_t *time = new Double_t[aliasArr->GetEntries()];
169                 Double_t *val  = new Double_t[aliasArr->GetEntries()];
170
171                 UInt_t ne=0;
172
173                 while ((aValue = (AliDCSValue*) iterarray.Next())) 
174                 {
175                 val[ne] = aValue->GetFloat();
176                 time[ne] = (Double_t) (aValue->GetTimeStamp());
177                 fHv[j]->Fill(val[ne]);
178                 ne++;
179                 }
180
181                
182                 
183                 CreateGraph(j, aliasArr->GetEntries(), time, val);
184                 delete[] val;
185                 delete[] time;
186         }
187
188
189         // calculate mean and rms of the first two histos
190         for(int i=0;i<kNHistos;i++)
191         {
192                 fMean[i] = fHv[i]->GetMean();
193                 fWidth[i] = fHv[i]->GetRMS();
194         }
195
196
197         fIsProcessed=kTRUE;
198
199
200 }
201
202 //---------------------------------------------------------------
203 void AliACORDEDataDCS::Init()
204 {
205 // Init of AliACORDEDatDCS procedure
206 // Loop over the aliases
207
208         TH1::AddDirectory(kFALSE);
209
210         fGraphs.SetOwner(1);
211
212         TString aliasName;
213
214         for(int i=0;i<kNAliases;i++){
215
216                 aliasName.Form("ACO_HV_MODULE%02d_VMON",i); 
217                 fAliasNames[i] = aliasName;
218         }
219
220         for(int i=0;i<kNHistos;i++)
221         {
222                 fHv[i] = new TH1F(fAliasNames[i].Data(),fAliasNames[i].Data(), 20, kHvMin, kHvMax);
223                 fHv[i]->GetXaxis()->SetTitle("Hv");
224         }
225 }
226
227 //---------------------------------------------------------------
228 void AliACORDEDataDCS::Introduce(UInt_t numAlias, const TObjArray* aliasArr)
229 {
230
231         int entries=aliasArr->GetEntries();
232         AliInfo(Form("************ Alias: %s **********",fAliasNames[numAlias].Data()));
233         AliInfo(Form("          %d DP values collected",entries));
234
235 }
236
237 //---------------------------------------------------------------
238 void AliACORDEDataDCS::CreateGraph(int i, int dim, const Double_t *x, const Double_t *y)
239 {
240 // Create the plots for the ACORDE DCS 
241
242         TGraph *gr = new(fGraphs[fGraphs.GetEntriesFast()]) TGraph(dim, x, y);
243
244         gr->GetXaxis()->SetTimeDisplay(1);
245         gr->SetTitle(fAliasNames[i].Data());
246
247         AliInfo(Form("Array entries: %d",fGraphs.GetEntriesFast()));
248
249
250 }
251
252 //---------------------------------------------------------------
253 void AliACORDEDataDCS::Draw(const Option_t* /*option*/)
254 {
255 // Draw all histos and graphs
256
257   if(!fIsProcessed) return;
258
259   TString canvasHistoName;
260   TCanvas *ch[10];
261   
262   for (int i=0;i<10;i++)
263   {
264   canvasHistoName.Form("ACO_HV_MODULE");
265   ch[i]=new TCanvas(canvasHistoName,canvasHistoName,20,20,600,600);
266   ch[i]->Divide(2,3);
267
268     for(int j=0;j<6;j++)
269     { 
270     ch[i]->cd(j+1);
271     ((TGraph*) fGraphs.UncheckedAt(i*6+j))->SetMarkerStyle(20);
272     ((TGraph*) fGraphs.UncheckedAt(i*6+j))->Draw("alp");
273     }
274
275   }
276
277  
278 }
279