1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 #include <Riostream.h>
18 #include "AliLHCClockPhase.h"
19 #include "AliDCSValue.h"
22 ClassImp(AliLHCClockPhase)
24 //______________________________________________________________________________
25 AliLHCClockPhase::AliLHCClockPhase():
30 // default constructor
36 //______________________________________________________________________________
37 void AliLHCClockPhase::AddPhaseB1DP(UInt_t timestamp, Float_t phase)
39 // Add a phase beam1 measurement
40 // to the array of data-points
42 fPhaseB1.AddLast(new AliDCSValue(phase,timestamp));
45 //______________________________________________________________________________
46 void AliLHCClockPhase::AddPhaseB2DP(UInt_t timestamp, Float_t phase)
48 // Add a phase beam2 measurement
49 // to the array of data-points
51 fPhaseB2.AddLast(new AliDCSValue(phase,timestamp));
54 //______________________________________________________________________________
55 const AliDCSValue* AliLHCClockPhase::GetPhaseB1DP(Int_t index) const
57 // Get the value of the phase
58 // The argument is the DP index
59 AliDCSValue *value = (AliDCSValue*)fPhaseB1.At(index);
61 AliFatal(Form("Invalid index of the beam1 data point: %d (0 -> %d)",
62 index,fPhaseB1.GetEntries()));
68 //______________________________________________________________________________
69 const AliDCSValue* AliLHCClockPhase::GetPhaseB2DP(Int_t index) const
71 // Get the value of the phase
72 // The argument is the DP index
73 AliDCSValue *value = (AliDCSValue*)fPhaseB2.At(index);
75 AliFatal(Form("Invalid index of the beam2 data point: %d (0 -> %d)",
76 index,fPhaseB2.GetEntries()));
82 //______________________________________________________________________________
83 Float_t AliLHCClockPhase::GetMeanPhaseB1() const
85 // Get mean beam1 phase shift.
86 // The mean is calculated using all the data-points.
89 for(Int_t i = 0; i < fPhaseB1.GetEntries(); ++i) {
90 AliDCSValue *value = (AliDCSValue*)fPhaseB1.At(i);
92 phase += value->GetFloat();
97 AliError("No beam1 measurements found! Assuming 0 phase shift!");
104 //______________________________________________________________________________
105 Float_t AliLHCClockPhase::GetMeanPhaseB2() const
107 // Get mean beam2 phase shift.
108 // The mean is calculated using all the data-points.
111 for(Int_t i = 0; i < fPhaseB2.GetEntries(); ++i) {
112 AliDCSValue *value = (AliDCSValue*)fPhaseB2.At(i);
114 phase += value->GetFloat();
119 AliError("No beam2 measurements found! Assuming 0 phase shift!");
126 //______________________________________________________________________________
127 Float_t AliLHCClockPhase::GetMeanPhase() const
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;
136 //______________________________________________________________________________
137 Float_t AliLHCClockPhase::GetPhaseB1(UInt_t timestamp) const
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;
146 for(Int_t i = 0; i < fPhaseB1.GetEntries(); ++i) {
147 AliDCSValue *value = (AliDCSValue*)fPhaseB1.At(i);
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());
155 if (deltat == 0xffffffff) {
156 AliError(Form("Can't get the beam1 phase shift at time-stamp = %u",timestamp));
162 //______________________________________________________________________________
163 Float_t AliLHCClockPhase::GetPhaseB2(UInt_t timestamp) const
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;
172 for(Int_t i = 0; i < fPhaseB2.GetEntries(); ++i) {
173 AliDCSValue *value = (AliDCSValue*)fPhaseB2.At(i);
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());
181 if (deltat == 0xffffffff) {
182 AliError(Form("Can't get the beam2 phase shift at time-stamp = %u",timestamp));
188 //______________________________________________________________________________
189 Float_t AliLHCClockPhase::GetPhase(UInt_t timestamp) const
191 // Get mean phase shift using the event time-stamp as
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;
199 //______________________________________________________________________________
200 void AliLHCClockPhase::Print( const Option_t* ) const
202 // Print all the data-points for beam1 and beam2
203 // as well as the mean phases
204 cout << "AliLHCClockPhase object:" << endl;
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;
211 cout << "Beam1 mean phase=" << GetMeanPhaseB1() << " ns" << endl;
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;
218 cout << "Beam2 mean phase=" << GetMeanPhaseB2() << " ns" << endl;
220 cout << "Mean phase (beam1 & beam2) =" << GetMeanPhase() << " ns" << endl;