-
Notifications
You must be signed in to change notification settings - Fork 3
/
ORAcqirisDC440Decoder.cc
185 lines (157 loc) · 5.91 KB
/
ORAcqirisDC440Decoder.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// ORAcqirisDC440Decoder.cc
#include "ORAcqirisDC440Decoder.hh"
#include "ORLogger.hh"
#include "ORUtils.hh"
#include "ORDictionary.hh"
#include <sstream>
//**************************************************************************************
ORAcqirisDC440Decoder::ORAcqirisDC440Decoder() { fDataRecord = NULL; }
void ORAcqirisDC440Decoder::Swap(UInt_t* dataRecord)
{
// Given that there is a 16-bit buffer, we have to swap things if there has
// been a switch of endian-ness. This means the data looks like 2143 and it
// needs to look like 1234, so we just need to swap the 16-bit words.
// The first long word has already been swapped. There is a header of length
// kBufHeadLen that needs to be swapped as longs.
ORLog(kDebug) << "Calling Swap()" << std::endl;
UInt_t lengthOfBuffer = LengthOf(dataRecord);
if(lengthOfBuffer < 2) return;
for(size_t i=1;i<kBufHeadLen; i++) {
ORUtils::Swap(dataRecord[i]);
}
UShort_t* theShortDataRecord = (UShort_t*) (dataRecord + kBufHeadLen);
for(size_t i=0;i<2*(lengthOfBuffer-1);i++) {
ORUtils::Swap(theShortDataRecord[i]);
}
}
bool ORAcqirisDC440Decoder::SetDataRecord(UInt_t* dataRecord)
{
fDataRecord = dataRecord;
ORLog(kDebug) << "SetDataRecord(): Setting the data record..." << std::endl;
return true;
}
double ORAcqirisDC440Decoder::GetSamplingFrequency()
{
return 1./GetSampleInterval();
}
size_t ORAcqirisDC440Decoder::CopyWaveformData(Short_t* waveform, size_t len)
//copies the waveform data to the array pointed to by
//waveform, which is of length len
{
size_t wflen = GetWaveformLen();
if (wflen == 0) return 0;
if ((len < wflen) || (len == 0)) {
ORLog(kWarning) << "CopyWaveformData(): destination array length is " << len
<< "; waveform data length is " << GetWaveformLen() << std::endl;
}
else {
len = GetWaveformLen();
}
UShort_t* waveformData = GetWaveformDataPointer();
memcpy(waveform, waveformData, sizeof(UShort_t)*len);
return len;
}
size_t ORAcqirisDC440Decoder::CopyWaveformDataDouble(double* waveform, size_t len)
//copies the waveform data to the array pointed to by
//waveform, which is of length len
{
size_t wflen = GetWaveformLen();
if (wflen == 0) return 0;
if ((len < wflen) || (len == 0)) {
ORLog(kWarning) << "CopyWaveformData(): destination array length is " << len
<< "; waveform data length is " << GetWaveformLen() << std::endl;
}
else {
len = GetWaveformLen();
}
UShort_t* waveformData = GetWaveformDataPointer();
for(size_t i=0;i<len;i++)
{
waveform[i] = (Double_t) waveformData[i];
}
return len;
}
/* Functions returning card/channel settings. */
double ORAcqirisDC440Decoder::GetDelayTime()
{
return GetRealValueFromKey("delayTime", CrateOf(), CardOf());
}
double ORAcqirisDC440Decoder::GetFullScale()
{
return GetRealValueFromKey("fullScale", CrateOf(), CardOf());
}
UInt_t ORAcqirisDC440Decoder::GetNumberOfSamples()
{
return GetIntValueFromKey("numberSamples", CrateOf(), CardOf());
}
double ORAcqirisDC440Decoder::GetSampleInterval()
{
/* sampleInterval is in microseconds, but we want it in nano seconds. */
return 1e3*GetRealValueFromKey("sampleInterval", CrateOf(), CardOf());
}
ORAcqirisDC440Decoder::EAcqirisDC440TriggerCoupling ORAcqirisDC440Decoder::GetTriggerCoupling()
{
return (EAcqirisDC440TriggerCoupling) GetIntValueFromKey("triggerCoupling", CrateOf(), CardOf());
}
double ORAcqirisDC440Decoder::GetTriggerLevel()
{
return GetRealValueFromKeyArray("triggerLevels",
CrateOf(), CardOf(), GetChannelNum());
}
ORAcqirisDC440Decoder::EAcqirisDC440TriggerSlope ORAcqirisDC440Decoder::GetTriggerSlope()
{
return (EAcqirisDC440TriggerSlope) GetIntValueFromKey("triggerSlope", CrateOf(), CardOf());
}
ORAcqirisDC440Decoder::EAcqirisDC440TriggerSource ORAcqirisDC440Decoder::GetTriggerSource()
{
return (EAcqirisDC440TriggerSource) GetIntValueFromKey("triggerSource", CrateOf(), CardOf());
}
ORAcqirisDC440Decoder::EAcqirisDC440VerticalCoupling ORAcqirisDC440Decoder::GetVerticalCoupling()
{
return (EAcqirisDC440VerticalCoupling) GetIntValueFromKey("verticalCoupling", CrateOf(), CardOf());
}
double ORAcqirisDC440Decoder::GetVerticalOffset()
{
return GetRealValueFromKey("verticalOffset", CrateOf(), CardOf());
}
//Error checking: **********************************************************************
bool ORAcqirisDC440Decoder::IsValid()
{
ORLog(kDebug) << "IsValid(): starting... " << std::endl;
if(IsShort(fDataRecord)) {
ORLog(kError) << "Data file is short" << std::endl;
return false;
}
return true;
}
void ORAcqirisDC440Decoder::DumpBufferHeader()
{
if(fDataRecord)
{
ORLog(kDebug) << "Dumping Data Buffer Header (Raw Data): " << std::endl;
ORLog(kDebug) << "**************************************************" << std::endl;
for(size_t i=1;i<kBufHeadLen; i++)
{
ORLog(kDebug) << fDataRecord[i] << std::endl;
}
ORLog(kDebug) << "**************************************************" << std::endl;
}
}
//debugging: *************************************************************************
void ORAcqirisDC440Decoder::Dump(UInt_t* dataRecord) //debugging
{
ORLog(kDebug) << std::endl << std::endl << "ORAcqirisDC440Decoder::Dump():" << std::endl ;
if(!SetDataRecord(dataRecord)) return;
ORLog(kDebug) << " Header functions: " << std::endl
<< " Crate = " << CrateOf() << "; card = " << CardOf() << std::endl
<< " The buffer is " << kBufHeadLen << " (32-bit) words long" << std::endl
<< " The channel is " << GetChannelNum() << std::endl
<< " Timestamp: " << GetTimeStamp() << std::endl
<< " Index offset: " << GetIndexOffset() << std::endl
<< " The waveform data has " << GetWaveformLen() << " (16-bit) words" << std::endl;
}
UInt_t ORAcqirisDC440Decoder::GetEventWaveformPoint( size_t /*event*/,
size_t waveformPoint )
{
return (UInt_t)GetWaveformDataPointer()[waveformPoint];
}