Skip to content

Commit 1b69e49

Browse files
committed
Tweaks
1 parent 56160d8 commit 1b69e49

File tree

7 files changed

+30
-21
lines changed

7 files changed

+30
-21
lines changed

DAQController.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void DAQController::ReadData(int link){
241241
if (local_buffer.size() > 0) {
242242
fDataRate += local_size;
243243
int selector = (fCounter++)%fNProcessingThreads;
244-
fFormatters[selector]->ReceiveDatapackets(local_buffer);
244+
fFormatters[selector]->ReceiveDatapackets(local_buffer, local_size);
245245
local_size = 0;
246246
}
247247
readcycler++;

StraxFormatter.cc

+22-19
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ StraxFormatter::StraxFormatter(std::shared_ptr<Options>& opts, std::shared_ptr<M
3131
fChunkLength = long(fOptions->GetDouble("strax_chunk_length", 5)*1e9); // default 5s
3232
fChunkOverlap = long(fOptions->GetDouble("strax_chunk_overlap", 0.5)*1e9); // default 0.5s
3333
fFragmentBytes = fOptions->GetInt("strax_fragment_payload_bytes", 110*2);
34+
FullFragmentSize = fFragmentBytes + fStraxHeaderSize;
3435
fCompressor = fOptions->GetString("compressor", "lz4");
3536
fFullChunkLength = fChunkLength+fChunkOverlap;
3637
fHostname = fOptions->Hostname();
@@ -39,6 +40,7 @@ StraxFormatter::StraxFormatter(std::shared_ptr<Options>& opts, std::shared_ptr<M
3940
if (run_num == -1) run_name = "run";
4041
else {
4142
run_name = std::to_string(run_num);
43+
// chunk names are 6 digits long
4244
if (run_name.size() < 6) run_name.insert(0, 6 - run_name.size(), int('0'));
4345
}
4446

@@ -97,24 +99,21 @@ void StraxFormatter::GetDataPerChan(std::map<int, int>& ret) {
9799

98100
void StraxFormatter::GenerateArtificialDeadtime(int64_t timestamp, const std::shared_ptr<V1724>& digi) {
99101
std::string fragment;
100-
fragment.reserve(fFragmentBytes + fStraxHeaderSize);
101-
timestamp *= digi->GetClockWidth();
102-
fragment.append((char*)&timestamp, sizeof(timestamp));
102+
fragment.reserve(fFullFragmentSize);
103+
timestamp *= digi->GetClockWidth(); // TODO nv
103104
int32_t length = fFragmentBytes>>1;
105+
int16_t sw = digi->SampleWidth(), channel = digi->GetADChannel(), zero = 0;
106+
fragment.append((char*)&timestamp, sizeof(timestamp));
104107
fragment.append((char*)&length, sizeof(length));
105-
int16_t sw = digi->SampleWidth();
106108
fragment.append((char*)&sw, sizeof(sw));
107-
int16_t channel = 790; // TODO add MV and NV support
108109
fragment.append((char*)&channel, sizeof(channel));
109110
fragment.append((char*)&length, sizeof(length));
110-
int16_t fragment_i = 0;
111-
fragment.append((char*)&fragment_i, sizeof(fragment_i));
112-
int16_t baseline = 0;
113-
fragment.append((char*)&baseline, sizeof(baseline));
114-
int16_t zero = 0;
111+
fragment.append((char*)&zero, sizeof(zero)); // fragment_i
112+
fragment.append((char*)&zero, sizeof(zero)); // baseline
115113
for (; length > 0; length--)
116-
fragment.append((char*)&zero, sizeof(zero));
114+
fragment.append((char*)&zero, sizeof(zero)); // wf
117115
AddFragmentToBuffer(std::move(fragment), 0, 0);
116+
return;
118117
}
119118

120119
void StraxFormatter::ProcessDatapacket(std::unique_ptr<data_packet> dp){
@@ -176,8 +175,9 @@ int StraxFormatter::ProcessEvent(std::u32string_view buff,
176175
buff.remove_prefix(event_header_words);
177176
int ret;
178177
int frags(0);
178+
unsigned n_chan = dp->digi->GetNumChannels();
179179

180-
for(unsigned ch=0; ch<max_channels; ch++){
180+
for(unsigned ch=0; ch<n_chan; ch++){
181181
if (channel_mask & (1<<ch)) {
182182
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ch_start);
183183
ret = ProcessChannel(buff, words, channel_mask, event_time, frags, ch, dp, dpc);
@@ -210,16 +210,19 @@ int StraxFormatter::ProcessChannel(std::u32string_view buff, int words_in_event,
210210

211211
int num_frags = std::ceil(1.*samples_in_pulse/samples_per_frag);
212212
frags += num_frags;
213+
int32_t samples_this_frag = 0;
214+
int64_t time_this_frag = 0;
215+
const uint16_t filler = 0;
213216
for (uint16_t frag_i = 0; frag_i < num_frags; frag_i++) {
214217
std::string fragment;
215-
fragment.reserve(fFragmentBytes + fStraxHeaderSize);
218+
fragment.reserve(fFullFragmentSize);
216219

217220
// How long is this fragment?
218-
int32_t samples_this_frag = samples_per_frag;
221+
samples_this_frag = samples_per_frag;
219222
if (frag_i == num_frags-1)
220223
samples_this_frag = samples_in_pulse - frag_i*samples_per_frag;
221224

222-
int64_t time_this_frag = timestamp + samples_per_frag*sw*frag_i;
225+
time_this_frag = timestamp + samples_per_frag*sw*frag_i;
223226
fragment.append((char*)&time_this_frag, sizeof(time_this_frag));
224227
fragment.append((char*)&samples_this_frag, sizeof(samples_this_frag));
225228
fragment.append((char*)&sw, sizeof(sw));
@@ -231,7 +234,6 @@ int StraxFormatter::ProcessChannel(std::u32string_view buff, int words_in_event,
231234
// Copy the raw buffer
232235
fragment.append((char*)wf.data(), samples_this_frag*sizeof(uint16_t));
233236
wf.remove_prefix(samples_this_frag*sizeof(uint16_t)/sizeof(char32_t));
234-
uint16_t zero_filler = 0;
235237
for (; samples_this_frag < samples_per_frag; samples_this_frag++)
236238
fragment.append((char*)&zero_filler, sizeof(zero_filler));
237239

@@ -264,7 +266,7 @@ void StraxFormatter::AddFragmentToBuffer(std::string fragment, uint32_t ts, int
264266
fThreadId, chunk_id - max_chunk - 1, channel);
265267
}
266268

267-
fOutputBufferSize += fFragmentBytes + fStraxHeaderSize;
269+
fOutputBufferSize += fFullFragmentSize;
268270

269271
if(!overlap){
270272
fChunks[chunk_id].emplace_back(std::move(fragment));
@@ -273,11 +275,12 @@ void StraxFormatter::AddFragmentToBuffer(std::string fragment, uint32_t ts, int
273275
}
274276
}
275277

276-
void StraxFormatter::ReceiveDatapackets(std::list<std::unique_ptr<data_packet>>& in) {
278+
void StraxFormatter::ReceiveDatapackets(std::list<std::unique_ptr<data_packet>>& in, int bytes) {
277279
{
278280
const std::lock_guard<std::mutex> lk(fBufferMutex);
279281
fBufferCounter[in.size()]++;
280282
fBuffer.splice(fBuffer.end(), in);
283+
fInputBufferSize += bytes;
281284
}
282285
fCV.notify_one();
283286
}
@@ -332,7 +335,7 @@ void StraxFormatter::WriteOutChunk(int chunk_i){
332335

333336
for (int i = 0; i < 2; i++) {
334337
if (buffers[i]->size() == 0) continue;
335-
uncompressed_size[i] = buffers[i]->size()*(fFragmentBytes + fStraxHeaderSize);
338+
uncompressed_size[i] = buffers[i]->size()*fFullFragmentSize;
336339
uncompressed.reserve(uncompressed_size[i]);
337340
for (auto it = buffers[i]->begin(); it != buffers[i]->end(); it++)
338341
uncompressed += *it; // std::accumulate would be nice but 3x slower without -O2

StraxFormatter.hh

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public:
5858
void Process();
5959
std::pair<int, int> GetBufferSize() {return {fInputBufferSize.load(), fOutputBufferSize.load()};}
6060
void GetDataPerChan(std::map<int, int>& ret);
61-
void ReceiveDatapackets(std::list<std::unique_ptr<data_packet>>&);
61+
void ReceiveDatapackets(std::list<std::unique_ptr<data_packet>>&, int);
6262

6363
private:
6464
void ProcessDatapacket(std::unique_ptr<data_packet> dp);
@@ -83,6 +83,7 @@ private:
8383
int64_t fChunkOverlap; // ns
8484
int fFragmentBytes;
8585
int fStraxHeaderSize; // bytes
86+
int fFullFragmentSize;
8687
int fBufferNumChunks;
8788
int fWarnIfChunkOlderThan;
8889
unsigned fChunkNameLength;

V1724.cc

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ V1724::V1724(std::shared_ptr<MongoLog>& log, std::shared_ptr<Options>& opts, int
3939
BLT_SIZE = opts->GetInt("blt_size", 512*1024);
4040
// there's a more elegant way to do this, but I'm not going to write it
4141
fClockPeriod = std::chrono::nanoseconds((1l<<31)*fClockCycle);
42+
fArtificialDeadtimeChannel = 790;
4243

4344
if (Init(link, crate, opts)) {
4445
throw std::runtime_error("Board init failed");

V1724.hh

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class V1724{
2727
int bid() {return fBID;}
2828
uint16_t SampleWidth() {return fSampleWidth;}
2929
int GetClockWidth() {return fClockCycle;}
30+
int16_t GetADChannel() {return fArtificialDeadtimeChannel;}
3031

3132
virtual int LoadDAC(std::vector<uint16_t>&);
3233
void ClampDACValues(std::vector<uint16_t>&, std::map<std::string, std::vector<double>>&);
@@ -90,6 +91,7 @@ protected:
9091

9192
float fBLTSafety, fBufferSafety;
9293
int fSampleWidth, fClockCycle;
94+
int16_t fArtificialDeadtimeChannel;
9395
};
9496

9597

V1724_MV.cc

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ V1724_MV::V1724_MV(std::shared_ptr<MongoLog>& log, std::shared_ptr<Options>& opt
66
V1724(log, opts, link, crate, bid, address) {
77
// MV boards seem to have reg 0x1n80 for channel n threshold
88
fChTrigRegister = 0x1080;
9+
fArtificialDeadtimeChannel = 791;
910
}
1011

1112
V1724_MV::~V1724_MV(){}

V1730.cc

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ V1730::V1730(std::shared_ptr<MongoLog>& log, std::shared_ptr<Options>& options,
77
fNChannels = 16;
88
fSampleWidth = 2;
99
fClockCycle = 2;
10+
fArtificialDeadtimeChannel = 792;
1011
}
1112

1213
V1730::~V1730(){}

0 commit comments

Comments
 (0)