]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/STEER/AliLHCClockPhase.cxx
Setting of aliases to rawReader done only once. Base decision on cosmic or calib...
[u/mrichter/AliRoot.git] / STEER / 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 using std::endl;
23 using std::cout;
24 ClassImp(AliLHCClockPhase)
25
26 //______________________________________________________________________________
27 AliLHCClockPhase::AliLHCClockPhase():
28   TObject(),
29   fPhaseB1(),
30   fPhaseB2()
31 {
32   // default constructor
33   // ...
34   fPhaseB1.SetOwner();
35   fPhaseB2.SetOwner();
36 }
37
38 //______________________________________________________________________________
39 void AliLHCClockPhase::AddPhaseB1DP(UInt_t timestamp, Float_t phase)
40 {
41   // Add a phase beam1 measurement
42   // to the array of data-points
43
44   fPhaseB1.AddLast(new AliDCSValue(phase,timestamp));
45 }
46
47 //______________________________________________________________________________
48 void AliLHCClockPhase::AddPhaseB2DP(UInt_t timestamp, Float_t phase)
49 {
50   // Add a phase beam2 measurement
51   // to the array of data-points
52
53   fPhaseB2.AddLast(new AliDCSValue(phase,timestamp));
54 }
55
56 //______________________________________________________________________________
57 const AliDCSValue* AliLHCClockPhase::GetPhaseB1DP(Int_t index) const
58 {
59   // Get the value of the phase
60   // The argument is the DP index
61   AliDCSValue *value = (AliDCSValue*)fPhaseB1.At(index);
62   if (!value) {
63     AliFatal(Form("Invalid index of the beam1 data point: %d (0 -> %d)",
64                   index,fPhaseB1.GetEntries()));
65     return NULL;
66   }
67   return value;
68 }
69
70 //______________________________________________________________________________
71 const AliDCSValue* AliLHCClockPhase::GetPhaseB2DP(Int_t index) const
72 {
73   // Get the value of the phase
74   // The argument is the DP index
75   AliDCSValue *value = (AliDCSValue*)fPhaseB2.At(index);
76   if (!value) {
77     AliFatal(Form("Invalid index of the beam2 data point: %d (0 -> %d)",
78                   index,fPhaseB2.GetEntries()));
79     return NULL;
80   }
81   return value;
82 }
83
84 //______________________________________________________________________________
85 Float_t AliLHCClockPhase::GetMeanPhaseB1() const
86 {
87   // Get mean beam1 phase shift.
88   // The mean is calculated using all the data-points.
89   Int_t n = 0;
90   Float_t phase = 0;
91   for(Int_t i = 0; i < fPhaseB1.GetEntries(); ++i) {
92     AliDCSValue *value = (AliDCSValue*)fPhaseB1.At(i);
93     if (value) {
94       phase += value->GetFloat();
95       ++n;
96     }
97   }
98   if (n == 0) {
99     AliError("No beam1 measurements found! Assuming 0 phase shift!");
100     return 0;
101   }
102   phase /= n;
103   return phase;
104 }
105
106 //______________________________________________________________________________
107 Float_t AliLHCClockPhase::GetMeanPhaseB2() const
108 {
109   // Get mean beam2 phase shift.
110   // The mean is calculated using all the data-points.
111   Int_t n = 0;
112   Float_t phase = 0;
113   for(Int_t i = 0; i < fPhaseB2.GetEntries(); ++i) {
114     AliDCSValue *value = (AliDCSValue*)fPhaseB2.At(i);
115     if (value) {
116       phase += value->GetFloat();
117       ++n;
118     }
119   }
120   if (n == 0) {
121     AliError("No beam2 measurements found! Assuming 0 phase shift!");
122     return 0;
123   }
124   phase /= n;
125   return phase;
126 }
127
128 //______________________________________________________________________________
129 Float_t AliLHCClockPhase::GetMeanPhase() const
130 {
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;
136 }
137
138 //______________________________________________________________________________
139 Float_t AliLHCClockPhase::GetPhaseB1(UInt_t timestamp) const
140 {
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;
147   Float_t phase = 0;
148   for(Int_t i = 0; i < fPhaseB1.GetEntries(); ++i) {
149     AliDCSValue *value = (AliDCSValue*)fPhaseB1.At(i);
150     if (value) {
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());
154       }
155     }
156   }
157   if (deltat == 0xffffffff) {
158     AliError(Form("Can't get the beam1 phase shift at time-stamp = %u",timestamp));
159     return 0;
160   }
161   return phase;
162 }
163
164 //______________________________________________________________________________
165 Float_t AliLHCClockPhase::GetPhaseB2(UInt_t timestamp) const
166 {
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;
173   Float_t phase = 0;
174   for(Int_t i = 0; i < fPhaseB2.GetEntries(); ++i) {
175     AliDCSValue *value = (AliDCSValue*)fPhaseB2.At(i);
176     if (value) {
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());
180       }
181     }
182   }
183   if (deltat == 0xffffffff) {
184     AliError(Form("Can't get the beam2 phase shift at time-stamp = %u",timestamp));
185     return 0;
186   }
187   return phase;
188 }
189
190 //______________________________________________________________________________
191 Float_t AliLHCClockPhase::GetPhase(UInt_t timestamp) const
192 {
193   // Get mean phase shift using the event time-stamp as
194   // an argument.
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;
199 }
200
201 //______________________________________________________________________________
202 void AliLHCClockPhase::Print( const Option_t* ) const
203 {
204   // Print all the data-points for beam1 and beam2
205   // as well as the mean phases
206   cout << "AliLHCClockPhase object:" << endl;
207
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;
212   }
213   cout << "Beam1 mean phase=" << GetMeanPhaseB1() << " ns" << endl;
214
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;
219   }
220   cout << "Beam2 mean phase=" << GetMeanPhaseB2() << " ns" << endl;
221
222   cout << "Mean phase (beam1 & beam2) =" << GetMeanPhase() << " ns" << endl;
223 }