]> git.uio.no Git - u/mrichter/AliRoot.git/blob - VZERO/AliVZERODataDCS.cxx
Fix Coverity
[u/mrichter/AliRoot.git] / VZERO / AliVZERODataDCS.cxx
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 #include "AliVZERODataDCS.h"
18
19 #include "AliDCSValue.h"
20 #include "AliLog.h"
21
22 #include <TGraph.h>
23 #include <TAxis.h>
24 #include <TCanvas.h>
25 #include <TTimeStamp.h>
26 #include <TMap.h>
27 #include <TString.h>
28 #include <TObjString.h>
29 #include <TH1F.h>
30
31 class TH2;
32 class AliCDBMetaData;
33 class TDatime;
34
35 // AliVZERODataDCS class
36 // main aim to introduce the aliases for the VZERO DCS
37 // data points to be then
38 // stored in the OCDB, and to process them. 
39 // ProcessData() method called by VZEROPreprocessor
40
41 ClassImp(AliVZERODataDCS)
42
43 //_____________________________________________________________________________
44 AliVZERODataDCS::AliVZERODataDCS():
45         TObject(),
46         fRun(0),
47         fStartTime(0),
48         fEndTime(0),
49         fDaqStartTime(0),
50         fDaqEndTime(0),
51         fCtpStartTime(0),
52         fCtpEndTime(0),
53     fGraphs("TGraph",kNGraphs),
54         fFEEParameters(NULL),
55         fIsProcessed(kFALSE)
56
57 {
58   // Default constructor
59         for(int i=0;i<kNHvChannel;i++) {
60                 fDeadChannel[i] = kFALSE;
61                 fMeanHV[i]      = 100.0;
62                 fWidthHV[i]     = 0.0; 
63                 fHv[i]          = NULL;
64         }
65 }
66
67 //_____________________________________________________________________________
68 AliVZERODataDCS::AliVZERODataDCS(Int_t nRun, UInt_t startTime, UInt_t endTime, UInt_t daqStartTime, UInt_t daqEndTime, UInt_t ctpStartTime, UInt_t ctpEndTime):
69         TObject(),
70         fRun(nRun),
71         fStartTime(startTime),
72         fEndTime(endTime),
73         fDaqStartTime(daqStartTime),
74         fDaqEndTime(daqEndTime),
75         fCtpStartTime(ctpStartTime),
76         fCtpEndTime(ctpEndTime),
77         fGraphs("TGraph",kNGraphs),
78         fFEEParameters(new TMap()),
79         fIsProcessed(kFALSE)
80
81 {
82
83   // constructor with arguments
84         for(int i=0;i<kNHvChannel;i++) {
85          fDeadChannel[i] = kFALSE;        
86          fMeanHV[i]      = 100.0;
87      fWidthHV[i]     = 0.0; 
88         }
89         AliInfo(Form("\n\tRun %d \n\tTime Created %s \n\tTime Completed %s \n\tDAQ start %s \n\tDAQ end %s \n\tCTP start %s \n\tCTP end %s   ", nRun,
90                 TTimeStamp(startTime).AsString(),
91                 TTimeStamp(endTime).AsString(),
92                 TTimeStamp(daqStartTime).AsString(),
93                 TTimeStamp(daqEndTime).AsString(),
94                 TTimeStamp(ctpStartTime).AsString(),
95                 TTimeStamp(ctpEndTime).AsString()
96                 ));
97         
98         fFEEParameters->SetOwnerValue();
99         Init();
100
101 }
102
103 //_____________________________________________________________________________
104 AliVZERODataDCS::~AliVZERODataDCS() {
105
106   // destructor
107   fGraphs.Clear("C");
108   delete fFEEParameters;
109
110 }
111
112 //_____________________________________________________________________________
113 Bool_t AliVZERODataDCS::ProcessData(TMap& aliasMap){
114
115   // method to process the data
116   Bool_t success = kTRUE;
117
118   if(!(fAliasNames[0])) Init();
119
120   TObjArray *aliasArr;
121   AliDCSValue* aValue;
122
123   // starting loop on aliases
124   for(int iAlias=0; iAlias<kNAliases; iAlias++){
125
126     aliasArr = (TObjArray*) aliasMap.GetValue(fAliasNames[iAlias].Data());
127     if(!aliasArr){
128       AliError(Form("Alias %s not found!", fAliasNames[iAlias].Data()));
129       success = kFALSE;
130       continue;
131     }
132
133     //Introduce(iAlias, aliasArr);
134     
135     if(aliasArr->GetEntries()<2){
136       AliWarning(Form("Alias %s has just %d entries!",
137                     fAliasNames[iAlias].Data(),aliasArr->GetEntries()));
138     }
139     
140     TIter iterarray(aliasArr);
141         
142     if(iAlias<kNHvChannel){ // Treating HV values
143         Int_t nentries = aliasArr->GetEntries();
144
145         Double_t *times = new Double_t[nentries];
146         Double_t *values = new Double_t[nentries];
147
148         UInt_t iValue=0;
149         Float_t variation = 0.0;
150
151         while((aValue = (AliDCSValue*) iterarray.Next())) {
152                         UInt_t currentTime = aValue->GetTimeStamp();
153                         if(currentTime>fCtpEndTime) break;
154
155                         values[iValue] = aValue->GetFloat();
156                         times[iValue] = (Double_t) (currentTime);
157                         
158                         if(iValue>0) {
159                                 if(values[iValue-1]>0.) variation = TMath::Abs(values[iValue]-values[iValue-1])/values[iValue-1];
160                                 if(variation > 0.01) fDeadChannel[GetOfflineChannel(iAlias)] = kTRUE;
161                         }
162                         fHv[iAlias]->Fill(values[iValue]);
163                         printf("%s : %s : %f Dead=%d\n",fAliasNames[iAlias].Data(),TTimeStamp(currentTime).AsString(),values[iValue],fDeadChannel[GetOfflineChannel(iAlias)]);
164                         iValue++;
165         }      
166         CreateGraph(iAlias, aliasArr->GetEntries(), times, values); // fill graphs 
167
168         // calculate mean and rms of the first two histos
169         // and convert index to aliroot channel
170         Int_t iChannel     = GetOfflineChannel(iAlias); 
171         fMeanHV[iChannel]  = fHv[iAlias]->GetMean();
172         fWidthHV[iChannel] = fHv[iAlias]->GetRMS();
173
174         delete[] values;
175         delete[] times; 
176         } else { // Treating FEE Parameters
177                 AliDCSValue * lastVal = NULL;
178                 while((aValue = (AliDCSValue*) iterarray.Next())) lastVal = aValue; // Take only the last value
179                 fFEEParameters->Add(new TObjString(fAliasNames[iAlias].Data()),lastVal);
180         }      
181   }
182   
183   fIsProcessed=kTRUE;
184
185   return success;
186 }
187
188 //_____________________________________________________________________________
189 void AliVZERODataDCS::Init(){
190
191   // initialization of aliases and DCS data
192
193   TString sindex;
194   int iAlias = 0;
195   
196   for(int iSide = 0; iSide<2 ; iSide++){
197         for(int iRing = 0; iRing<4 ; iRing++){
198                 for(int iSector = 0; iSector<8 ; iSector++){
199                         if(iSide == 0) fAliasNames[iAlias] = "V00/HV/V0A/SECTOR";
200                         else fAliasNames[iAlias] = "V00/HV/V0C/SECTOR";
201                         sindex.Form("%d/RING%d",iSector,iRing);
202                         fAliasNames[iAlias] += sindex;
203                         
204                         fHv[iAlias] = new TH1F(fAliasNames[iAlias].Data(),fAliasNames[iAlias].Data(), 3000, kHvMin, kHvMax);
205                         fHv[iAlias]->GetXaxis()->SetTitle("Hv");
206                         iAlias++;
207                 }
208         }
209   }
210
211  // Time Resolution Parameters
212         
213         for(int iCIU = 0; iCIU<8 ; iCIU++){
214                 fAliasNames[iAlias++] = Form("V00/FEE/CIU%d/TimeResolution",iCIU);
215                 fAliasNames[iAlias++] = Form("V00/FEE/CIU%d/WidthResolution",iCIU);
216         }
217
218         // HPTDC parameters
219         for(int iCIU = 0; iCIU<8 ; iCIU++){
220           fAliasNames[iAlias++] = Form("V00/FEE/CIU%d/MatchWindow",iCIU);
221           fAliasNames[iAlias++] = Form("V00/FEE/CIU%d/SearchWindow",iCIU);
222           fAliasNames[iAlias++] = Form("V00/FEE/CIU%d/TriggerCountOffset",iCIU);
223           fAliasNames[iAlias++] = Form("V00/FEE/CIU%d/RollOver",iCIU);
224         }
225
226         for(int iCIU = 0; iCIU<8 ; iCIU++){
227           for(int iCh=1;iCh<=8;iCh++){
228             fAliasNames[iAlias++] = Form("V00/FEE/CIU%d/DelayHit%d",iCIU,iCh);
229           }
230         }
231
232         for(int iCIU = 0; iCIU<8 ; iCIU++){
233           for(int iCh=1;iCh<=8;iCh++){
234             fAliasNames[iAlias++] = Form("V00/FEE/CIU%d/DiscriThr%d",iCIU,iCh);
235           }
236         }
237
238   if(iAlias!=kNAliases) 
239               AliError(Form("Number of DCS Aliases defined not correct"));
240
241 }
242
243 //_____________________________________________________________________________
244 void AliVZERODataDCS::Introduce(UInt_t numAlias, const TObjArray* aliasArr)const
245 {
246
247   // method to introduce new aliases
248
249   int entries=aliasArr->GetEntries();
250   AliInfo(Form("************ Alias: %s **********",fAliasNames[numAlias].Data()));
251   AliInfo(Form("        %d DP values collected",entries));
252
253 }
254
255 //_____________________________________________________________________________
256 void AliVZERODataDCS::CreateGraph(int i, int dim, const Double_t *x, const Double_t *y)
257 {
258
259    // Create graphics
260    
261    TGraph *gr = new(fGraphs[fGraphs.GetEntriesFast()]) TGraph(dim, x, y);
262
263    gr->GetXaxis()->SetTimeDisplay(1);
264    gr->SetTitle(fAliasNames[i].Data());
265
266    AliInfo(Form("Array entries: %d",fGraphs.GetEntriesFast()));
267
268 }
269
270
271 //_____________________________________________________________________________
272 void AliVZERODataDCS::Draw(const Option_t* /*option*/)
273 {
274 // Draw all histos and graphs
275
276   if(!fIsProcessed) return;
277
278   if(fGraphs.GetEntries()==0)  return;
279   
280   TString canvasName;
281   TCanvas *cHV[8];
282   
283   for(int iSide = 0 ;iSide<2;iSide++){
284         for(int iRing=0;iRing<4;iRing++){
285                 if(iSide == 0)  canvasName = "V0A_Ring";
286                 else  canvasName = "V0C_Ring";
287                 canvasName += iRing;
288                 int iCanvas = iSide*4 + iRing;
289                 cHV[iCanvas] = new TCanvas(canvasName,canvasName);
290                 cHV[iCanvas]->Divide(3,3);
291                 for(int iSector=0;iSector<8;iSector++){
292                         cHV[iCanvas]->cd(iSector+1);
293                         int iChannel = iSide*32 + iRing*8 + iSector; 
294                         ((TGraph*) fGraphs.UncheckedAt(iChannel))->SetMarkerStyle(20);
295                         ((TGraph*) fGraphs.UncheckedAt(iChannel))->Draw("ALP");
296
297                 }
298                                 
299         }
300   }
301
302 }
303