757a17fa3132543b88bc0a63d52def9e07e62c40
[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++) fHv[i]=0x0;
44         
45 }
46
47 //---------------------------------------------------------------
48 AliACORDEDataDCS::AliACORDEDataDCS(Int_t nRun, UInt_t startTime, UInt_t endTime):
49         TObject(),
50         fRun(nRun),
51         fStartTime(startTime),
52         fEndTime(endTime),
53         fGraphs("TGraph",kNGraphs),
54         fFunc(0),
55         fIsProcessed(kFALSE)
56 {
57 // Init of class AliACORDEDataDCS
58 // Gettin the TimeStamp an put it on a string
59
60         AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", nRun,
61         TTimeStamp(startTime).AsString(),
62         TTimeStamp(endTime).AsString()));
63
64        
65         Init();
66
67 }
68
69 //---------------------------------------------------------------
70 AliACORDEDataDCS::~AliACORDEDataDCS() {
71
72         for(int i=0;i<kNHistos;i++) {delete fHv[i]; fHv[i]=0;}
73         fGraphs.Clear("C");
74         fFunc=0;
75 }
76 //---------------------------------------------------------------
77
78 AliACORDEDataDCS::AliACORDEDataDCS(const AliACORDEDataDCS & data):
79 TObject(),
80 fRun(0),
81 fStartTime(0),
82 fEndTime(0),
83 fGraphs("TGraph",kNGraphs),
84 fFunc(0),
85 fIsProcessed(kFALSE)
86 {
87 // Setting the initial values
88 // fRUn, Start of Run, End of Run, IsProcessed
89
90         fRun=data.fRun;
91         fStartTime=data.fStartTime;
92         fEndTime=data.fEndTime;
93         fFunc=data.fFunc;
94         fIsProcessed=data.fIsProcessed;
95
96
97         for(int i=0;i<kNAliases;i++){fAliasNames[i] = data.fAliasNames[i];}
98
99         for(int i=0;i<kNHistos;i++){fHv[i]=data.fHv[i];}
100
101
102
103         
104 }
105 //--------------------------------------------------------------
106 AliACORDEDataDCS& AliACORDEDataDCS:: operator=(const AliACORDEDataDCS & data) { 
107
108         
109         this->fRun=data.fRun;
110         this->fStartTime=data.fStartTime;
111         this->fEndTime=data.fEndTime;
112         this->fFunc=data.fFunc;
113         this->fIsProcessed=data.fIsProcessed;
114
115
116         for(int i=0;i<kNAliases;i++){this->fAliasNames[i] = data.fAliasNames[i];}
117
118         for(int i=0;i<kNHistos;i++){this->fHv[i]=data.fHv[i];}
119
120         
121          return *this;
122  
123 }
124 //---------------------------------------------------------------
125 void AliACORDEDataDCS::ProcessData(TMap& aliasMap)
126 {
127 // Process of the data from the aliases DCS-data points
128
129         if(!(fHv[0])) Init();
130
131         TObjArray *aliasArr;
132         AliDCSValue* aValue;
133
134         for(int j=0; j<kNAliases; j++)
135         {
136                 aliasArr = (TObjArray*) aliasMap.GetValue(fAliasNames[j].Data());
137                 if(!aliasArr)
138                 {
139                         AliError(Form("Alias %s not found!", fAliasNames[j].Data()));
140                         continue;
141                 }
142                 Introduce(j, aliasArr);
143
144                 if(aliasArr->GetEntries()<2)
145                 {
146                         AliError(Form("Alias %s has just %d entries!",
147                                         fAliasNames[j].Data(),aliasArr->GetEntries()));
148                         continue;
149                 }
150
151                 TIter iterarray(aliasArr);
152
153                 Double_t *time = new Double_t[aliasArr->GetEntries()];
154                 Double_t *val  = new Double_t[aliasArr->GetEntries()];
155
156                 UInt_t ne=0;
157
158                 while ((aValue = (AliDCSValue*) iterarray.Next())) 
159                 {
160                 val[ne] = aValue->GetFloat();
161                 time[ne] = (Double_t) (aValue->GetTimeStamp());
162                 fHv[j]->Fill(val[ne]);
163                 ne++;
164                 }
165
166                
167                 
168                 CreateGraph(j, aliasArr->GetEntries(), time, val);
169                 delete[] val;
170                 delete[] time;
171         }
172
173
174         // calculate mean and rms of the first two histos
175         for(int i=0;i<kNHistos;i++)
176         {
177                 fMean[i] = fHv[i]->GetMean();
178                 fWidth[i] = fHv[i]->GetRMS();
179         }
180
181
182         fIsProcessed=kTRUE;
183
184
185 }
186
187 //---------------------------------------------------------------
188 void AliACORDEDataDCS::Init()
189 {
190 // Init of AliACORDEDatDCS procedure
191 // Loop over the aliases
192
193         TH1::AddDirectory(kFALSE);
194
195         fGraphs.SetOwner(1);
196
197         TString aliasName;
198
199         for(int i=0;i<kNAliases;i++){
200
201                 aliasName.Form("ACO_HV_MODULE%02d_VMON",i); 
202                 fAliasNames[i] = aliasName;
203         }
204
205         for(int i=0;i<kNHistos;i++)
206         {
207                 fHv[i] = new TH1F(fAliasNames[i].Data(),fAliasNames[i].Data(), 20, kHvMin, kHvMax);
208                 fHv[i]->GetXaxis()->SetTitle("Hv");
209         }
210 }
211
212 //---------------------------------------------------------------
213 void AliACORDEDataDCS::Introduce(UInt_t numAlias, const TObjArray* aliasArr)
214 {
215
216         int entries=aliasArr->GetEntries();
217         AliInfo(Form("************ Alias: %s **********",fAliasNames[numAlias].Data()));
218         AliInfo(Form("          %d DP values collected",entries));
219
220 }
221
222 //---------------------------------------------------------------
223 void AliACORDEDataDCS::CreateGraph(int i, int dim, const Double_t *x, const Double_t *y)
224 {
225 // Create the plots for the ACORDE DCS 
226
227         TGraph *gr = new(fGraphs[fGraphs.GetEntriesFast()]) TGraph(dim, x, y);
228
229         gr->GetXaxis()->SetTimeDisplay(1);
230         gr->SetTitle(fAliasNames[i].Data());
231
232         AliInfo(Form("Array entries: %d",fGraphs.GetEntriesFast()));
233
234
235 }
236
237 //---------------------------------------------------------------
238 void AliACORDEDataDCS::Draw(const Option_t* /*option*/)
239 {
240 // Draw all histos and graphs
241
242   if(!fIsProcessed) return;
243
244   TString canvasHistoName;
245   TCanvas *ch[10];
246   
247   for (int i=0;i<10;i++)
248   {
249   canvasHistoName.Form("ACO_HV_MODULE");
250   ch[i]=new TCanvas(canvasHistoName,canvasHistoName,20,20,600,600);
251   ch[i]->Divide(2,3);
252
253     for(int j=0;j<6;j++)
254     { 
255     ch[i]->cd(j+1);
256     ((TGraph*) fGraphs.UncheckedAt(i*6+j))->SetMarkerStyle(20);
257     ((TGraph*) fGraphs.UncheckedAt(i*6+j))->Draw("alp");
258     }
259
260   }
261
262  
263 }
264