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