Skip to content

Commit f4d9848

Browse files
author
Darryl Masson
committed
Compiles
1 parent a83d432 commit f4d9848

14 files changed

+94
-134
lines changed

Diff for: DAQController.cc

+30-33
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "V1730.hh"
66
#include "DAXHelpers.hh"
77
#include "Options.hh"
8-
#include "StraxInserter.hh"
8+
#include "StraxFormatter.hh"
99
#include "MongoLog.hh"
1010
#include <unistd.h>
1111
#include <algorithm>
@@ -22,20 +22,19 @@
2222
// 3-running
2323
// 4-error
2424

25-
DAQController::DAQController(MongoLog *log, std::string hostname){
25+
DAQController::DAQController(std::shared_ptr<MongoLog>& log, std::string hostname){
2626
fLog=log;
27-
fOptions = NULL;
27+
fOptions = nullptr;
2828
fStatus = DAXHelpers::Idle;
2929
fReadLoop = false;
3030
fNProcessingThreads=8;
31-
fBufferLength = 0;
3231
fDataRate=0.;
3332
fHostname = hostname;
3433
}
3534

3635
DAQController::~DAQController(){
3736
if(fProcessingThreads.size()!=0)
38-
CloseProcessingThreads();
37+
CloseThreads();
3938
}
4039

4140
std::string DAQController::run_mode(){
@@ -77,6 +76,7 @@ int DAQController::InitializeElectronics(std::shared_ptr<Options>& options){
7776
}catch(const std::exception& e) {
7877
fLog->Entry(MongoLog::Warning, "Failed to initialize digitizer %i: %s", d.board,
7978
e.what());
79+
fDigitizers.clear();
8080
return -1;
8181
}
8282
}
@@ -91,7 +91,6 @@ int DAQController::InitializeElectronics(std::shared_ptr<Options>& options){
9191
if (fOptions->GetString("baseline_dac_mode") == "cached")
9292
fOptions->GetDAC(dac_values, BIDs);
9393
std::vector<std::thread*> init_threads;
94-
fMaxEventsPerThread = fOptions->GetInt("max_events_per_thread", 1024);
9594
std::map<int,int> rets;
9695
// Parallel digitizer programming to speed baselining
9796
for( auto& link : fDigitizers ) {
@@ -121,9 +120,10 @@ int DAQController::InitializeElectronics(std::shared_ptr<Options>& options){
121120
digi->AcquisitionStop();
122121
}
123122
}
123+
fCounter = 0;
124124
if (OpenThreads()) {
125125
fLog->Entry(MongoLog::Warning, "Error opening threads");
126-
fStatus = DAQXHelpers::Idle;
126+
fStatus = DAXHelpers::Idle;
127127
return -1;
128128
}
129129
sleep(1);
@@ -200,7 +200,7 @@ void DAQController::End(){
200200
digi->End();
201201
digi.reset();
202202
}
203-
link.clear();
203+
link.second.clear();
204204
}
205205
fDigitizers.clear();
206206
fStatus = DAXHelpers::Idle;
@@ -257,7 +257,7 @@ void DAQController::ReadData(int link){
257257
if (local_buffer.size() > 0) {
258258
fDataRate += local_size;
259259
int selector = (fCounter++)%fNProcessingThreads;
260-
fProcessingThreads[selector]->ReceiveDatapackets(local_buffer);
260+
fFormatters[selector]->ReceiveDatapackets(local_buffer);
261261
local_size = 0;
262262
}
263263
readcycler++;
@@ -269,30 +269,27 @@ void DAQController::ReadData(int link){
269269

270270
std::map<int, int> DAQController::GetDataPerChan(){
271271
// Return a map of data transferred per channel since last update
272-
// Clears the private maps in the StraxInserters
273-
const std::lock_guard<std::mutex> lg(fPTmutex);
274-
std::map <int, int> retmap;
275-
for (auto& p : fProcessors)
272+
// Clears the private maps in the StraxFormatters
273+
const std::lock_guard<std::mutex> lg(fMutex);
274+
std::map<int, int> retmap;
275+
for (auto& p : fFormatters)
276276
p->GetDataPerChan(retmap);
277277
return retmap;
278278
}
279279

280-
long DAQController::GetStraxBufferSize() {
281-
const std::lock_guard<std::mutex> lg(fPTmutex);
282-
return std::accumulate(fProcessingThreads.begin(), fProcessingThreads.end(), 0,
283-
[=](long tot, processingThread pt) {return tot + pt.inserter->GetBufferSize();});
284-
}
285-
286-
int DAQController::GetBufferLength() {
287-
const std::lock_guard<std::mutex> lg(fPTmutex);
288-
return fBufferLength.load() + std::accumulate(fProcessingThreads.begin(),
289-
fProcessingThreads.end(), 0,
290-
[](int tot, auto pt){return tot + pt.inserter->GetBufferLength();});
280+
std::pair<long, long> DAQController::GetBufferSize() {
281+
const std::lock_guard<std::mutex> lg(fMutex);
282+
std::pair<long, long> ret{0l,0l};
283+
for (const auto& p : fFormatters) {
284+
auto x = p->GetBufferSize();
285+
ret.first += x.first;
286+
ret.second += x.second;
287+
}
288+
return ret;
291289
}
292290

293291
int DAQController::OpenThreads(){
294-
int ret = 0;
295-
const std::lock_guard<std::mutex> lg(fPTmutex);
292+
const std::lock_guard<std::mutex> lg(fMutex);
296293
fProcessingThreads.reserve(fNProcessingThreads);
297294
for(int i=0; i<fNProcessingThreads; i++){
298295
try {
@@ -312,7 +309,7 @@ int DAQController::OpenThreads(){
312309

313310
void DAQController::CloseThreads(){
314311
std::map<int,int> board_fails;
315-
const std::lock_guard<std::mutex> lg(fPTmutex);
312+
const std::lock_guard<std::mutex> lg(fMutex);
316313
for (auto& sf : fFormatters) sf->Close(board_fails);
317314
// give threads time to finish
318315
std::this_thread::sleep_for(std::chrono::milliseconds(10));
@@ -350,9 +347,9 @@ void DAQController::InitLink(std::vector<std::shared_ptr<V1724>>& digis,
350347
int bid = digi->bid(), success(0);
351348
if (BL_MODE == "fit") {
352349
} else if(BL_MODE == "cached") {
353-
fMapMutex.lock();
350+
fMutex.lock();
354351
auto board_dac_cal = cal_values.count(bid) ? cal_values[bid] : cal_values[-1];
355-
fMapMutex.unlock();
352+
fMutex.unlock();
356353
dac_values[bid] = std::vector<uint16_t>(digi->GetNumChannels());
357354
fLog->Entry(MongoLog::Local, "Board %i using cached baselines", bid);
358355
for (unsigned ch = 0; ch < digi->GetNumChannels(); ch++)
@@ -515,7 +512,7 @@ int DAQController::FitBaselines(std::vector<std::shared_ptr<V1724>> &digis,
515512

516513
// readout
517514
for (auto d : digis) {
518-
bytes_read[d->bid()] = d->Read(buffers[d->bid()]);
515+
words_read[d->bid()] = d->Read(buffers[d->bid()]);
519516
}
520517

521518
// decode
@@ -551,7 +548,7 @@ int DAQController::FitBaselines(std::vector<std::shared_ptr<V1724>> &digis,
551548
it += 4;
552549
continue;
553550
}
554-
if (mask == 0) { // should be impossible?
551+
if (channel_mask == 0) { // should be impossible?
555552
it += 4;
556553
continue;
557554
}
@@ -615,11 +612,11 @@ int DAQController::FitBaselines(std::vector<std::shared_ptr<V1724>> &digis,
615612
// ****************************
616613
for (auto d : digis) {
617614
bid = d->bid();
618-
fMapMutex.lock();
615+
fMutex.lock();
619616
cal_values[bid] = std::map<std::string, vector<double>>(
620617
{{"slope", vector<double>(d->GetNumChannels())},
621618
{"yint", vector<double>(d->GetNumChannels())}});
622-
fMapMutex.unlock();
619+
fMutex.unlock();
623620
for (unsigned ch = 0; ch < d->GetNumChannels(); ch++) {
624621
B = C = D = E = F = 0;
625622
for (unsigned i = 0; i < DAC_cal_points.size(); i++) {

Diff for: DAQController.hh

+8-14
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <mutex>
1111
#include <list>
1212

13-
class StraxInserter;
13+
class StraxFormatter;
1414
class MongoLog;
1515
class Options;
1616
class V1724;
@@ -37,24 +37,21 @@ public:
3737

3838
int GetDataSize(){int ds = fDataRate; fDataRate=0; return ds;}
3939
std::map<int, int> GetDataPerChan();
40-
void CheckError(int bid) {fCheckFails[bid] = true;}
41-
long GetStraxBufferSize();
42-
int GetBufferSize() {return fBufferSize.load();}
43-
44-
void GetDataFormat(std::map<int, std::map<std::string, int>>&);
40+
std::pair<long, long> GetBufferSize();
4541

4642
private:
4743
void ReadData(int link);
48-
int OpenProcessingThreads();
49-
void CloseProcessingThreads();
44+
int OpenThreads();
45+
void CloseThreads();
5046
void InitLink(std::vector<std::shared_ptr<V1724>>&, std::map<int, std::map<std::string, std::vector<double>>>&, int&);
5147
int FitBaselines(std::vector<std::shared_ptr<V1724>>&, std::map<int, std::vector<uint16_t>>&, int,
5248
std::map<int, std::map<std::string, std::vector<double>>>&);
5349

54-
std::vector<std::unique_ptr<StraxInserter>> fFormatters;
50+
std::vector<std::unique_ptr<StraxFormatter>> fFormatters;
5551
std::vector<std::thread> fProcessingThreads;
52+
std::vector<std::thread> fReadoutThreads;
5653
std::map<int, std::vector<std::shared_ptr<V1724>>> fDigitizers;
57-
std::mutex fMapMutex;
54+
std::mutex fMutex;
5855

5956
std::atomic_bool fReadLoop;
6057
std::map<int, std::atomic_bool> fRunning;
@@ -63,13 +60,10 @@ private:
6360
std::string fHostname;
6461
std::shared_ptr<MongoLog> fLog;
6562
std::shared_ptr<Options> fOptions;
66-
std::shared_ptr<ThreadPool> fTP;
6763

6864
// For reporting to frontend
69-
std::atomic_int fBufferSize;
70-
std::atomic_int fBufferLength;
7165
std::atomic_int fDataRate;
72-
std::map<int, std::atomic_bool> fCheckFails;
66+
std::atomic_long fCounter;
7367
};
7468

7569
#endif

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LDFLAGS = -lCAENVME -lstdc++fs -llz4 -lblosc $(shell pkg-config --libs libmongoc
77
LDFLAGS_CC = ${LDFLAGS} -lexpect -ltcl8.6
88

99
SOURCES_SLAVE = DAQController.cc main.cc Options.cc MongoLog.cc \
10-
StraxInserter.cc V1724.cc V1724_MV.cc V1730.cc
10+
StraxFormatter.cc V1724.cc V1724_MV.cc V1730.cc
1111
OBJECTS_SLAVE = $(SOURCES_SLAVE:%.cc=%.o)
1212
DEPS_SLAVE = $(OBJECTS_SLAVE:%.o=%.d)
1313
EXEC_SLAVE = main

Diff for: Options.hh

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private:
8888
mongocxx::client fClient;
8989
bsoncxx::document::view bson_options;
9090
bsoncxx::document::value *bson_value;
91-
MongoLog *fLog;
91+
std::shared_ptr<MongoLog> fLog;
9292
mongocxx::collection fDAC_collection;
9393
std::string fDBname;
9494
std::string fHostname;

0 commit comments

Comments
 (0)