SlowRate.cxx
1 
9 
10 #include "TMath.h"
11 #include "SlowRate.h"
12 #include "AnitaPacketUtil.h"
13 #include "AnitaEventCalibrator.h"
14 #include <iostream>
15 #include <fstream>
16 #include <cstring>
17 
18 ClassImp(SlowRate);
19 
21 {
22  //Default Constructor
23 }
24 
26  //Default Destructor
27 }
28 
29 SlowRate::SlowRate(Int_t trun, UInt_t trealTime, SlowRateFull_t *slowPtr)
30 {
31  simplePacketCheck(&(slowPtr->gHdr),PACKET_SLOW_FULL);
32 
33  run=trun;
34  realTime=trealTime;
35  payloadTime=slowPtr->unixTime;
36  eventNumber=slowPtr->rf.eventNumber;
37 
38  eventRate1Min=slowPtr->rf.eventRate1Min;
39  eventRate10Min=slowPtr->rf.eventRate10Min;
40 
41  latitude=slowPtr->hk.latitude;
42  longitude=slowPtr->hk.longitude;
43  altitude=slowPtr->hk.altitude;
44 
45  memcpy(rfPwrAvg,&(slowPtr->rf.rfPwrAvg[0][0]),sizeof(UChar_t)*ACTIVE_SURFS*RFCHAN_PER_SURF);
46  memcpy(avgScalerRates,&(slowPtr->rf.avgScalerRates[0][0]),sizeof(UChar_t)*TRIGGER_SURFS*SCALERS_PER_SURF);
47 
48  memcpy(temps,&(slowPtr->hk.temps[0]),sizeof(UChar_t)*4);
49  memcpy(powers,&(slowPtr->hk.powers[0]),sizeof(UChar_t)*4);
50 }
51 
52 Double_t SlowRate::getRFPowerInK(int surf, int chan)
53 {
54  if(surf<0 || surf>=ACTIVE_SURFS)
55  return -1;
56  if(chan<0 || chan>=RFCHAN_PER_SURF)
57  return -1;
58  Int_t adc=rfPwrAvg[surf][chan];
59  adc*=128;
60  Double_t kelvin=AnitaEventCalibrator::Instance()->convertRfPowToKelvin(surf,chan,adc);
61  if(TMath::IsNaN(kelvin)) return 290;
62  if(kelvin<0) return 290;
63  if(kelvin>1e6) return 290;
64  return kelvin;
65 }
66 
67 
68 // Double_t SlowRate::getMeasuredRFPowerInK(int surf, int chan)
69 // {
70 // if(surf<0 || surf>=ACTIVE_SURFS)
71 // return -1;
72 // if(chan<0 || chan>=RFCHAN_PER_SURF)
73 // return -1;
74 // Int_t adc=rfPwrAvg[surf][chan];
75 // adc*=4;
76 // Double_t kelvin=AnitaEventCalibrator::Instance()->convertRfPowToKelvinMeasured(surf,chan,adc);
77 // return kelvin;
78 // }
79 
80 Double_t SlowRate::getRawRFPower(int surf,int chan) {
81  return rfPwrAvg[surf][chan]*128;
82 }
83 
84 Int_t SlowRate::getAvgScaler(int surf, int ant)
85 {
86  if(surf<0 || surf>=ACTIVE_SURFS)
87  return -1;
88  if(ant<0 || ant>=SCALERS_PER_SURF)
89  return -1;
90  return Int_t(avgScalerRates[surf][ant])*4;
91 
92 }
93 
95 {
96  Float_t alt=altitude;
97  if(altitude<-5000) {
98  alt=65536+alt;
99  }
100  return alt;
101 }
102 
103 Float_t SlowRate::getPower(int powerInd)
104 {
105  float powerCal[4]={19.252,10.1377,20,20};
106  if(powerInd<0 || powerInd>3)
107  return 0;
108 
109  float adc=powers[powerInd];
110  float reading=((10*adc)/255.)-5;
111  float value=reading*powerCal[powerInd];
112  return value;
113 }
114 
115 Float_t SlowRate::getTemp(int tempInd)
116 {
117  if(tempInd<0 || tempInd>3)
118  return -273.15;
119  if(tempInd==0) return 4*temps[tempInd];
120  float adc=temps[tempInd];
121  float reading=((10*adc)/255.)-5;
122  float value=(reading*100)-273.15;
123  return value;
124 }
125 
126 const char *SlowRate::getPowerName(int powerInd)
127 {
128  const char *slowPowerNames[4]={"PV V","24 V","PV I","24 I"};
129  if(powerInd<0 || powerInd>3)
130  return NULL;
131  return slowPowerNames[powerInd];
132 
133 }
134 
135 const char *SlowRate::getTempName(int tempInd)
136 {
137  const char *slowTempNames[4]={"SBS","SURF","SHORT","Rad. Plate"};
138  if(tempInd<0 || tempInd>3)
139  return NULL;
140  return slowTempNames[tempInd];
141 }
Int_t run
Run number, assigned offline.
Definition: SlowRate.h:29
~SlowRate()
Destructor.
Definition: SlowRate.cxx:25
SlowRate()
Default constructor.
Definition: SlowRate.cxx:20
UChar_t eventRate1Min
Multiplied by 2.
Definition: SlowRate.h:40
Int_t getAvgScaler(int surf, int ant)
Returns the averaged scaler value.
Definition: SlowRate.cxx:84
SlowRate – The Slow Rate data.
Definition: SlowRate.h:21
UChar_t temps[4]
{SBS,SURF,TURF,RAD}
Definition: SlowRate.h:43
static AnitaEventCalibrator * Instance(int version=0)
Instance generator.
const char * getPowerName(int powerInd)
Returns the name of the power reading.
Definition: SlowRate.cxx:126
Float_t longitude
Payload longitude.
Definition: SlowRate.h:35
unsigned char powers[4]
{PV V, +24V, BAT I, 24 I}
Float_t latitude
Payload latitude.
Definition: SlowRate.h:34
Slow Rate Block – Telemetered.
UInt_t eventNumber
Latest event number.
Definition: SlowRate.h:37
UChar_t powers[4]
{PV V, +24V, PV I, 24 I}
Definition: SlowRate.h:44
UChar_t rfPwrAvg[12][8]
The average rf power (in ADCs) //128.
Definition: SlowRate.h:38
UInt_t payloadTime
Time in unixTime.
Definition: SlowRate.h:31
SlowRateFull_t – Yes.
UChar_t avgScalerRates[8][12]
Divided by 4.
Definition: SlowRate.h:39
Float_t getAltitude()
Returns the altitude correct for negative crazziness.
Definition: SlowRate.cxx:94
unsigned char eventRate1Min
Multiplied by 8.
Short_t altitude
Payload altitude.
Definition: SlowRate.h:36
UInt_t realTime
Time in unixTime.
Definition: SlowRate.h:30
unsigned char temps[4]
{SBS,SURF,TURF,RAD}
Float_t getPower(int powerInd)
Returns the actual power value.
Definition: SlowRate.cxx:103
UChar_t eventRate10Min
Multiplied by 2.
Definition: SlowRate.h:41
Double_t getRFPowerInK(int surf, int chan)
Returns the pseudo-calibrated RF power in K.
Definition: SlowRate.cxx:52
const char * getTempName(int tempInd)
Returns the name of temp sensor.
Definition: SlowRate.cxx:135
Float_t getTemp(int tempInd)
Returns the actual temp.
Definition: SlowRate.cxx:115
unsigned char eventRate10Min
Multiplied by 8.
unsigned char avgScalerRates[8][12]
int simplePacketCheck(GenericHeader_t *gHdr, PacketCode_t code)
simplePacketCheck – utility function