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