]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliLHCClockPhase.cxx
New base class AliPIDResponse
[u/mrichter/AliRoot.git] / STEER / AliLHCClockPhase.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 #include <Riostream.h>
17
18 #include "AliLHCClockPhase.h"
19 #include "AliDCSValue.h"
20 #include "AliLog.h"
21
22 ClassImp(AliLHCClockPhase)
23
24 //______________________________________________________________________________
25 AliLHCClockPhase::AliLHCClockPhase():
26   TObject(),
27   fPhaseB1(),
28   fPhaseB2()
29 {
30   // default constructor
31   // ...
32   fPhaseB1.SetOwner();
33   fPhaseB2.SetOwner();
34 }
35
36 //______________________________________________________________________________
37 void AliLHCClockPhase::AddPhaseB1DP(UInt_t timestamp, Float_t phase)
38 {
39   // Add a phase beam1 measurement
40   // to the array of data-points
41
42   fPhaseB1.AddLast(new AliDCSValue(phase,timestamp));
43 }
44
45 //______________________________________________________________________________
46 void AliLHCClockPhase::AddPhaseB2DP(UInt_t timestamp, Float_t phase)
47 {
48   // Add a phase beam2 measurement
49   // to the array of data-points
50
51   fPhaseB2.AddLast(new AliDCSValue(phase,timestamp));
52 }
53
54 //______________________________________________________________________________
55 const AliDCSValue* AliLHCClockPhase::GetPhaseB1DP(Int_t index) const
56 {
57   // Get the value of the phase
58   // The argument is the DP index
59   AliDCSValue *value = (AliDCSValue*)fPhaseB1.At(index);
60   if (!value) {
61     AliFatal(Form("Invalid index of the beam1 data point: %d (0 -> %d)",
62                   index,fPhaseB1.GetEntries()));
63     return NULL;
64   }
65   return value;
66 }
67
68 //______________________________________________________________________________
69 const AliDCSValue* AliLHCClockPhase::GetPhaseB2DP(Int_t index) const
70 {
71   // Get the value of the phase
72   // The argument is the DP index
73   AliDCSValue *value = (AliDCSValue*)fPhaseB2.At(index);
74   if (!value) {
75     AliFatal(Form("Invalid index of the beam2 data point: %d (0 -> %d)",
76                   index,fPhaseB2.GetEntries()));
77     return NULL;
78   }
79   return value;
80 }
81
82 //______________________________________________________________________________
83 Float_t AliLHCClockPhase::GetMeanPhaseB1() const
84 {
85   // Get mean beam1 phase shift.
86   // The mean is calculated using all the data-points.
87   Int_t n = 0;
88   Float_t phase = 0;
89   for(Int_t i = 0; i < fPhaseB1.GetEntries(); ++i) {
90     AliDCSValue *value = (AliDCSValue*)fPhaseB1.At(i);
91     if (value) {
92       phase += value->GetFloat();
93       ++n;
94     }
95   }
96   if (n == 0) {
97     AliError("No beam1 measurements found! Assuming 0 phase shift!");
98     return 0;
99   }
100   phase /= n;
101   return phase;
102 }
103
104 //______________________________________________________________________________
105 Float_t AliLHCClockPhase::GetMeanPhaseB2() const
106 {
107   // Get mean beam2 phase shift.
108   // The mean is calculated using all the data-points.
109   Int_t n = 0;
110   Float_t phase = 0;
111   for(Int_t i = 0; i < fPhaseB2.GetEntries(); ++i) {
112     AliDCSValue *value = (AliDCSValue*)fPhaseB2.At(i);
113     if (value) {
114       phase += value->GetFloat();
115       ++n;
116     }
117   }
118   if (n == 0) {
119     AliError("No beam2 measurements found! Assuming 0 phase shift!");
120     return 0;
121   }
122   phase /= n;
123   return phase;
124 }
125
126 //______________________________________________________________________________
127 Float_t AliLHCClockPhase::GetMeanPhase() const
128 {
129   // Get mean phase shift.
130   // Beam1 and beam2 phases are calculated using
131   // all beam1 and beam2 data-points. The two phases are
132   // then averaged in order to get the mean value.
133   return (GetMeanPhaseB1() + GetMeanPhaseB2())/2;
134 }
135
136 //______________________________________________________________________________
137 Float_t AliLHCClockPhase::GetPhaseB1(UInt_t timestamp) const
138 {
139   // Get beam1 phase shift using the
140   // event time-stamp as an argument.
141   // This methods loops over data-points and
142   // returns the value of the closest (in time)
143   // measurement found.
144   Long64_t deltat = 0xffffffff;
145   Float_t phase = 0;
146   for(Int_t i = 0; i < fPhaseB1.GetEntries(); ++i) {
147     AliDCSValue *value = (AliDCSValue*)fPhaseB1.At(i);
148     if (value) {
149       if (TMath::Abs((Long64_t)timestamp-(Long64_t)value->GetTimeStamp()) <= deltat) {
150         phase = value->GetFloat();
151         deltat = TMath::Abs((Long64_t)timestamp-(Long64_t)value->GetTimeStamp());
152       }
153     }
154   }
155   if (deltat == 0xffffffff) {
156     AliError(Form("Can't get the beam1 phase shift at time-stamp = %u",timestamp));
157     return 0;
158   }
159   return phase;
160 }
161
162 //______________________________________________________________________________
163 Float_t AliLHCClockPhase::GetPhaseB2(UInt_t timestamp) const
164 {
165   // Get beam2 phase shift using the
166   // event time-stamp as an argument.
167   // This methods loops over data-points and
168   // returns the value of the closest (in time)
169   // measurement found.
170   Long64_t deltat = 0xffffffff;
171   Float_t phase = 0;
172   for(Int_t i = 0; i < fPhaseB2.GetEntries(); ++i) {
173     AliDCSValue *value = (AliDCSValue*)fPhaseB2.At(i);
174     if (value) {
175       if (TMath::Abs((Long64_t)timestamp-(Long64_t)value->GetTimeStamp()) <= deltat) {
176         phase = value->GetFloat();
177         deltat = TMath::Abs((Long64_t)timestamp-(Long64_t)value->GetTimeStamp());
178       }
179     }
180   }
181   if (deltat == 0xffffffff) {
182     AliError(Form("Can't get the beam2 phase shift at time-stamp = %u",timestamp));
183     return 0;
184   }
185   return phase;
186 }
187
188 //______________________________________________________________________________
189 Float_t AliLHCClockPhase::GetPhase(UInt_t timestamp) const
190 {
191   // Get mean phase shift using the event time-stamp as
192   // an argument.
193   // Beam1 and beam2 phases are calculated using
194   // the closest beam1 and beam2 data-points. The two phases are
195   // then averaged in order to get the mean value.
196   return (GetPhaseB1(timestamp) + GetPhaseB2(timestamp))/2;
197 }
198
199 //______________________________________________________________________________
200 void AliLHCClockPhase::Print( const Option_t* ) const
201 {
202   // Print all the data-points for beam1 and beam2
203   // as well as the mean phases
204   cout << "AliLHCClockPhase object:" << endl;
205
206   cout << "Beam1:" << endl;
207   for(Int_t i = 0; i < fPhaseB1.GetEntries(); ++i) {
208     AliDCSValue *value = (AliDCSValue*)fPhaseB1.At(i);
209     if (value) cout << "TS=" << value->GetTimeStamp() << "  " << value->GetFloat() << endl;
210   }
211   cout << "Beam1 mean phase=" << GetMeanPhaseB1() << " ns" << endl;
212
213   cout << "Beam2:" << endl;
214   for(Int_t i = 0; i < fPhaseB2.GetEntries(); ++i) {
215     AliDCSValue *value = (AliDCSValue*)fPhaseB2.At(i);
216     if (value) cout << "TS=" << value->GetTimeStamp() << "  " << value->GetFloat() << endl;
217   }
218   cout << "Beam2 mean phase=" << GetMeanPhaseB2() << " ns" << endl;
219
220   cout << "Mean phase (beam1 & beam2) =" << GetMeanPhase() << " ns" << endl;
221 }