-
Notifications
You must be signed in to change notification settings - Fork 3
/
OREdelweissSLTWaveformDecoder.cc
122 lines (110 loc) · 4.73 KB
/
OREdelweissSLTWaveformDecoder.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
// OREdelweissSLTWaveformDecoder.cc
#include "OREdelweissSLTWaveformDecoder.hh"
#include "ORLogger.hh"
#include "ORUtils.hh"
//**************************************************************************************
OREdelweissSLTWaveformDecoder::OREdelweissSLTWaveformDecoder() { fDataRecord = NULL; fWaveformLength = -1; }
bool OREdelweissSLTWaveformDecoder::SetDataRecord(UInt_t* dataRecord)
{
fDataRecord = dataRecord;
UInt_t eventFlags=dataRecord[7];
UInt_t eventFlags4bit=eventFlags & 0xf;
if(eventFlags4bit==0x2) fWaveformLength = 2048;
else fWaveformLength = 10000;
//fWaveformLength = ( LengthOf(fDataRecord) / (kWaveformLength/2) ) * 10000;//this sets GetWaveformLen() -tb-//TODO: check it -tb-
ORLog(kDebug) << "SetDataRecord(): Setting the data record..." << std::endl;
// remarks for Till: LengthOf(...) is from ORVDataDecoder and is the length extracted from data record (in longs/int32s) -tb-
if(!IsValid() || LengthOf(fDataRecord) != kBufHeadLen + GetWaveformLen()/2) {
ORLog(kDebug) << "SetDataRecord(): data record is not valid" << std::endl;
ORLog(kDebug) << "LengthOf(data record) : " << LengthOf(fDataRecord)
<< " kBufHeadLen + GetWaveformLen()/2: " << kBufHeadLen + GetWaveformLen()/2 << std::endl;
fDataRecord = NULL;
fWaveformLength = -1;
return false;
}
ORLog(kDebug) << "SetDataRecord(): Exiting" << std::endl;
return true;
}
bool OREdelweissSLTWaveformDecoder::IsValid()
{
ORLog(kDebug) << "IsValid(): starting... " << std::endl;
if(IsShort(fDataRecord)) {
ORLog(kError) << "Data file is short" << std::endl;
return false;
}
return true;
}
void OREdelweissSLTWaveformDecoder::DumpBufferHeader()
{
if(fDataRecord)
{
ORLog(kDebug) << "Dumping Data Buffer Header (Raw Data): " << std::endl;
ORLog(kDebug) << "**************************************************" << std::endl;
for(size_t i=2;i<kBufHeadLen; i++)
{
ORLog(kDebug) << fDataRecord[i] << std::endl;
}
ORLog(kDebug) << "**************************************************" << std::endl;
}
}
size_t OREdelweissSLTWaveformDecoder::CopyWaveformData( UShort_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();
UInt_t* waveformData = GetWaveformDataPointer();
for(size_t i=0;i<len;i+=2)
{
//bin swapping handling changed 2008-11-18 (svn rev >=1354) ml, -tb-
waveform[i] = (waveformData[i/2] & 0xFFFF);
waveform[i+1] = ((waveformData[i/2] & 0xFFFF0000) >> 16) ;
}
return len;
}
size_t OREdelweissSLTWaveformDecoder::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();
UInt_t* waveformData = GetWaveformDataPointer();
for(size_t i=0;i<len;i+=2)
{
//bin swapping handling changed 2008-11-18 (svn rev >=1354) ml, -tb-
waveform[i] = (double) (waveformData[i/2] & 0xFFFF);
waveform[i+1] = (double) ((waveformData[i/2] & 0xFFFF0000) >> 16) ;
}
return len;
}
//debugging: *************************************************************************
void OREdelweissSLTWaveformDecoder::Dump(UInt_t* dataRecord) //debugging
{
ORLog(kDebug) << std::endl << std::endl << "OREdelweissSLTWaveformDecoder::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 Sec is " << GetSec() << std::endl
<< " The SubSec is " << GetSubSec() << std::endl
<< " The channel is " << GetChannel() << std::endl
<< " The channel map is " << GetChannelMap() << std::endl
<< " EventID: " << GetEventID() << std::endl
<< " Energy: " << GetEnergy() << std::endl
<< " EventFlags: " << GetEventFlags() << std::endl // -tb- 2010-02-16
<< " EventInfo: " << GetEventInfo() << std::endl // -tb- 2010-02-16
<< " The waveform data has " << GetWaveformLen()
<< " (32-bit) words" << std::endl;
}