5
5
#include " V1730.hh"
6
6
#include " DAXHelpers.hh"
7
7
#include " Options.hh"
8
- #include " StraxInserter .hh"
8
+ #include " StraxFormatter .hh"
9
9
#include " MongoLog.hh"
10
10
#include < unistd.h>
11
11
#include < algorithm>
22
22
// 3-running
23
23
// 4-error
24
24
25
- DAQController::DAQController (MongoLog * log, std::string hostname){
25
+ DAQController::DAQController (std::shared_ptr< MongoLog>& log, std::string hostname){
26
26
fLog =log ;
27
- fOptions = NULL ;
27
+ fOptions = nullptr ;
28
28
fStatus = DAXHelpers::Idle;
29
29
fReadLoop = false ;
30
30
fNProcessingThreads =8 ;
31
- fBufferLength = 0 ;
32
31
fDataRate =0 .;
33
32
fHostname = hostname;
34
33
}
35
34
36
35
DAQController::~DAQController (){
37
36
if (fProcessingThreads .size ()!=0 )
38
- CloseProcessingThreads ();
37
+ CloseThreads ();
39
38
}
40
39
41
40
std::string DAQController::run_mode (){
@@ -77,6 +76,7 @@ int DAQController::InitializeElectronics(std::shared_ptr<Options>& options){
77
76
}catch (const std::exception & e) {
78
77
fLog ->Entry (MongoLog::Warning, " Failed to initialize digitizer %i: %s" , d.board ,
79
78
e.what ());
79
+ fDigitizers .clear ();
80
80
return -1 ;
81
81
}
82
82
}
@@ -91,7 +91,6 @@ int DAQController::InitializeElectronics(std::shared_ptr<Options>& options){
91
91
if (fOptions ->GetString (" baseline_dac_mode" ) == " cached" )
92
92
fOptions ->GetDAC (dac_values, BIDs);
93
93
std::vector<std::thread*> init_threads;
94
- fMaxEventsPerThread = fOptions ->GetInt (" max_events_per_thread" , 1024 );
95
94
std::map<int ,int > rets;
96
95
// Parallel digitizer programming to speed baselining
97
96
for ( auto & link : fDigitizers ) {
@@ -121,9 +120,10 @@ int DAQController::InitializeElectronics(std::shared_ptr<Options>& options){
121
120
digi->AcquisitionStop ();
122
121
}
123
122
}
123
+ fCounter = 0 ;
124
124
if (OpenThreads ()) {
125
125
fLog ->Entry (MongoLog::Warning, " Error opening threads" );
126
- fStatus = DAQXHelpers ::Idle;
126
+ fStatus = DAXHelpers ::Idle;
127
127
return -1 ;
128
128
}
129
129
sleep (1 );
@@ -200,7 +200,7 @@ void DAQController::End(){
200
200
digi->End ();
201
201
digi.reset ();
202
202
}
203
- link .clear ();
203
+ link .second . clear ();
204
204
}
205
205
fDigitizers .clear ();
206
206
fStatus = DAXHelpers::Idle;
@@ -257,7 +257,7 @@ void DAQController::ReadData(int link){
257
257
if (local_buffer.size () > 0 ) {
258
258
fDataRate += local_size;
259
259
int selector = (fCounter ++)%fNProcessingThreads ;
260
- fProcessingThreads [selector]->ReceiveDatapackets (local_buffer);
260
+ fFormatters [selector]->ReceiveDatapackets (local_buffer);
261
261
local_size = 0 ;
262
262
}
263
263
readcycler++;
@@ -269,30 +269,27 @@ void DAQController::ReadData(int link){
269
269
270
270
std::map<int , int > DAQController::GetDataPerChan (){
271
271
// 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 )
276
276
p->GetDataPerChan (retmap);
277
277
return retmap;
278
278
}
279
279
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;
291
289
}
292
290
293
291
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 );
296
293
fProcessingThreads .reserve (fNProcessingThreads );
297
294
for (int i=0 ; i<fNProcessingThreads ; i++){
298
295
try {
@@ -312,7 +309,7 @@ int DAQController::OpenThreads(){
312
309
313
310
void DAQController::CloseThreads (){
314
311
std::map<int ,int > board_fails;
315
- const std::lock_guard<std::mutex> lg (fPTmutex );
312
+ const std::lock_guard<std::mutex> lg (fMutex );
316
313
for (auto & sf : fFormatters ) sf->Close (board_fails);
317
314
// give threads time to finish
318
315
std::this_thread::sleep_for (std::chrono::milliseconds (10 ));
@@ -350,9 +347,9 @@ void DAQController::InitLink(std::vector<std::shared_ptr<V1724>>& digis,
350
347
int bid = digi->bid (), success (0 );
351
348
if (BL_MODE == " fit" ) {
352
349
} else if (BL_MODE == " cached" ) {
353
- fMapMutex .lock ();
350
+ fMutex .lock ();
354
351
auto board_dac_cal = cal_values.count (bid) ? cal_values[bid] : cal_values[-1 ];
355
- fMapMutex .unlock ();
352
+ fMutex .unlock ();
356
353
dac_values[bid] = std::vector<uint16_t >(digi->GetNumChannels ());
357
354
fLog ->Entry (MongoLog::Local, " Board %i using cached baselines" , bid);
358
355
for (unsigned ch = 0 ; ch < digi->GetNumChannels (); ch++)
@@ -515,7 +512,7 @@ int DAQController::FitBaselines(std::vector<std::shared_ptr<V1724>> &digis,
515
512
516
513
// readout
517
514
for (auto d : digis) {
518
- bytes_read [d->bid ()] = d->Read (buffers[d->bid ()]);
515
+ words_read [d->bid ()] = d->Read (buffers[d->bid ()]);
519
516
}
520
517
521
518
// decode
@@ -551,7 +548,7 @@ int DAQController::FitBaselines(std::vector<std::shared_ptr<V1724>> &digis,
551
548
it += 4 ;
552
549
continue ;
553
550
}
554
- if (mask == 0 ) { // should be impossible?
551
+ if (channel_mask == 0 ) { // should be impossible?
555
552
it += 4 ;
556
553
continue ;
557
554
}
@@ -615,11 +612,11 @@ int DAQController::FitBaselines(std::vector<std::shared_ptr<V1724>> &digis,
615
612
// ****************************
616
613
for (auto d : digis) {
617
614
bid = d->bid ();
618
- fMapMutex .lock ();
615
+ fMutex .lock ();
619
616
cal_values[bid] = std::map<std::string, vector<double >>(
620
617
{{" slope" , vector<double >(d->GetNumChannels ())},
621
618
{" yint" , vector<double >(d->GetNumChannels ())}});
622
- fMapMutex .unlock ();
619
+ fMutex .unlock ();
623
620
for (unsigned ch = 0 ; ch < d->GetNumChannels (); ch++) {
624
621
B = C = D = E = F = 0 ;
625
622
for (unsigned i = 0 ; i < DAC_cal_points.size (); i++) {
0 commit comments