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"
24 ClassImp(AliLHCClockPhase)
26 //______________________________________________________________________________
27 AliLHCClockPhase::AliLHCClockPhase():
32 // default constructor
38 //______________________________________________________________________________
39 void AliLHCClockPhase::AddPhaseB1DP(UInt_t timestamp, Float_t phase)
41 // Add a phase beam1 measurement
42 // to the array of data-points
44 fPhaseB1.AddLast(new AliDCSValue(phase,timestamp));
47 //______________________________________________________________________________
48 void AliLHCClockPhase::AddPhaseB2DP(UInt_t timestamp, Float_t phase)
50 // Add a phase beam2 measurement
51 // to the array of data-points
53 fPhaseB2.AddLast(new AliDCSValue(phase,timestamp));
56 //______________________________________________________________________________
57 const AliDCSValue* AliLHCClockPhase::GetPhaseB1DP(Int_t index) const
59 // Get the value of the phase
60 // The argument is the DP index
61 AliDCSValue *value = (AliDCSValue*)fPhaseB1.At(index);
63 AliFatal(Form("Invalid index of the beam1 data point: %d (0 -> %d)",
64 index,fPhaseB1.GetEntries()));
70 //______________________________________________________________________________
71 const AliDCSValue* AliLHCClockPhase::GetPhaseB2DP(Int_t index) const
73 // Get the value of the phase
74 // The argument is the DP index
75 AliDCSValue *value = (AliDCSValue*)fPhaseB2.At(index);
77 AliFatal(Form("Invalid index of the beam2 data point: %d (0 -> %d)",
78 index,fPhaseB2.GetEntries()));
84 //______________________________________________________________________________
85 Float_t AliLHCClockPhase::GetMeanPhaseB1() const
87 // Get mean beam1 phase shift.
88 // The mean is calculated using all the data-points.
91 for(Int_t i = 0; i < fPhaseB1.GetEntries(); ++i) {
92 AliDCSValue *value = (AliDCSValue*)fPhaseB1.At(i);
94 phase += value->GetFloat();
99 AliError("No beam1 measurements found! Assuming 0 phase shift!");
106 //______________________________________________________________________________
107 Float_t AliLHCClockPhase::GetMeanPhaseB2() const
109 // Get mean beam2 phase shift.
110 // The mean is calculated using all the data-points.
113 for(Int_t i = 0; i < fPhaseB2.GetEntries(); ++i) {
114 AliDCSValue *value = (AliDCSValue*)fPhaseB2.At(i);
116 phase += value->GetFloat();
121 AliError("No beam2 measurements found! Assuming 0 phase shift!");
128 //______________________________________________________________________________
129 Float_t AliLHCClockPhase::GetMeanPhase() const
131 // Get mean phase shift.
132 // Beam1 and beam2 phases are calculated using
133 // all beam1 and beam2 data-points. The two phases are
134 // then averaged in order to get the mean value.
135 return (GetMeanPhaseB1() + GetMeanPhaseB2())/2;
138 //______________________________________________________________________________
139 Float_t AliLHCClockPhase::GetPhaseB1(UInt_t timestamp) const
141 // Get beam1 phase shift using the
142 // event time-stamp as an argument.
143 // This methods loops over data-points and
144 // returns the value of the closest (in time)
145 // measurement found.
146 Long64_t deltat = 0xffffffff;
148 for(Int_t i = 0; i < fPhaseB1.GetEntries(); ++i) {
149 AliDCSValue *value = (AliDCSValue*)fPhaseB1.At(i);
151 if (TMath::Abs((Long64_t)timestamp-(Long64_t)value->GetTimeStamp()) <= deltat) {
152 phase = value->GetFloat();
153 deltat = TMath::Abs((Long64_t)timestamp-(Long64_t)value->GetTimeStamp());
157 if (deltat == 0xffffffff) {
158 AliError(Form("Can't get the beam1 phase shift at time-stamp = %u",timestamp));
164 //______________________________________________________________________________
165 Float_t AliLHCClockPhase::GetPhaseB2(UInt_t timestamp) const
167 // Get beam2 phase shift using the
168 // event time-stamp as an argument.
169 // This methods loops over data-points and
170 // returns the value of the closest (in time)
171 // measurement found.
172 Long64_t deltat = 0xffffffff;
174 for(Int_t i = 0; i < fPhaseB2.GetEntries(); ++i) {
175 AliDCSValue *value = (AliDCSValue*)fPhaseB2.At(i);
177 if (TMath::Abs((Long64_t)timestamp-(Long64_t)value->GetTimeStamp()) <= deltat) {
178 phase = value->GetFloat();
179 deltat = TMath::Abs((Long64_t)timestamp-(Long64_t)value->GetTimeStamp());
183 if (deltat == 0xffffffff) {
184 AliError(Form("Can't get the beam2 phase shift at time-stamp = %u",timestamp));
190 //______________________________________________________________________________
191 Float_t AliLHCClockPhase::GetPhase(UInt_t timestamp) const
193 // Get mean phase shift using the event time-stamp as
195 // Beam1 and beam2 phases are calculated using
196 // the closest beam1 and beam2 data-points. The two phases are
197 // then averaged in order to get the mean value.
198 return (GetPhaseB1(timestamp) + GetPhaseB2(timestamp))/2;
201 //______________________________________________________________________________
202 void AliLHCClockPhase::Print( const Option_t* ) const
204 // Print all the data-points for beam1 and beam2
205 // as well as the mean phases
206 cout << "AliLHCClockPhase object:" << endl;
208 cout << "Beam1:" << endl;
209 for(Int_t i = 0; i < fPhaseB1.GetEntries(); ++i) {
210 AliDCSValue *value = (AliDCSValue*)fPhaseB1.At(i);
211 if (value) cout << "TS=" << value->GetTimeStamp() << " " << value->GetFloat() << endl;
213 cout << "Beam1 mean phase=" << GetMeanPhaseB1() << " ns" << endl;
215 cout << "Beam2:" << endl;
216 for(Int_t i = 0; i < fPhaseB2.GetEntries(); ++i) {
217 AliDCSValue *value = (AliDCSValue*)fPhaseB2.At(i);
218 if (value) cout << "TS=" << value->GetTimeStamp() << " " << value->GetFloat() << endl;
220 cout << "Beam2 mean phase=" << GetMeanPhaseB2() << " ns" << endl;
222 cout << "Mean phase (beam1 & beam2) =" << GetMeanPhase() << " ns" << endl;