Skip to content

Commit b0e8ba3

Browse files
authored
Merge pull request #100 from coderdj/alternate_v2
Redax 2.0, attempt 2
2 parents ca9cb12 + e9f0c11 commit b0e8ba3

43 files changed

Lines changed: 2183 additions & 1914 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
*.swp
77
*~
88

9-
# executables
10-
main
11-
ccontrol
9+
# executable
10+
redax
1211

1312
# DAQ logs
1413
*.log

CControl_Handler.cc

Lines changed: 52 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
11
#include "CControl_Handler.hh"
22
#include "DAXHelpers.hh"
3-
#include "Options.hh"
4-
#include "MongoLog.hh"
53
#include "V2718.hh"
4+
#ifdef HASDDC10
65
#include "DDC10.hh"
6+
#endif
77
#include "V1495.hh"
8-
#include <vector>
98
#include <bsoncxx/builder/stream/document.hpp>
10-
#include <chrono>
11-
12-
CControl_Handler::CControl_Handler(MongoLog *log, std::string procname){
13-
fOptions = NULL;
14-
fLog = log;
15-
fProcname = procname;
16-
fCurrentRun = fBID = fBoardHandle-1;
17-
fV2718 = NULL;
18-
fV1495 = NULL;
19-
fDDC10 = NULL;
9+
10+
CControl_Handler::CControl_Handler(std::shared_ptr<MongoLog>& log, std::string procname) : DAQController(log, procname){
11+
fCurrentRun = fBID = fBoardHandle = -1;
12+
fV2718 = nullptr;
13+
fV1495 = nullptr;
14+
#ifdef HASDDC10
15+
fDDC10 = nullptr;
16+
#endif
2017
fStatus = DAXHelpers::Idle;
2118
}
2219

2320
CControl_Handler::~CControl_Handler(){
24-
DeviceStop();
21+
Stop();
2522
}
2623

2724
// Initialising various devices namely; V2718 crate controller, V1495, DDC10...
28-
int CControl_Handler::DeviceArm(int run, Options *opts){
25+
int CControl_Handler::Arm(std::shared_ptr<Options>& opts){
2926

3027
fStatus = DAXHelpers::Arming;
3128

3229
// Just in case clear out any remaining objects from previous runs
33-
DeviceStop();
30+
Stop();
3431

35-
fCurrentRun = run;
3632
fOptions = opts;
33+
try{
34+
fCurrentRun = opts->GetInt("run_identifier", -1);
35+
}catch(std::exception& e) {
36+
fLog->Entry(MongoLog::Warning, "No run number specified in config?? %s", e.what());
37+
return -1;
38+
}
3739

3840
// Pull options for V2718
3941
CrateOptions copts;
@@ -47,29 +49,28 @@ int CControl_Handler::DeviceArm(int run, Options *opts){
4749
// Getting the link and crate for V2718
4850
std::vector<BoardType> bv = fOptions->GetBoards("V2718");
4951
if(bv.size() != 1){
50-
fLog->Entry(MongoLog::Message, "Require one V2718 to be defined or we can't start the run");
52+
fLog->Entry(MongoLog::Message, "Require one V2718 to be defined");
5153
fStatus = DAXHelpers::Idle;
5254
return -1;
5355
}
5456
BoardType cc_def = bv[0];
55-
fV2718 = new V2718(fLog);
56-
if (fV2718->CrateInit(copts, cc_def.link, cc_def.crate)!=0){
57-
fLog->Entry(MongoLog::Error, "Failed to initialize V2718 crate controller");
57+
try{
58+
fV2718 = std::make_unique<V2718>(fLog, copts, cc_def.link, cc_def.crate);
59+
}catch(std::exception& e){
60+
fLog->Entry(MongoLog::Error, "Failed to initialize V2718 crate controller: %s", e.what());
5861
fStatus = DAXHelpers::Idle;
5962
return -1;
60-
}else{
61-
fBoardHandle = fV2718->GetHandle();
62-
fLog->Entry(MongoLog::Local, "V2718 Initialised");
6363
}
64+
fBoardHandle = fV2718->GetHandle();
65+
fLog->Entry(MongoLog::Local, "V2718 Initialized");
6466

67+
#ifdef HASDDC10
6568
// Getting options for DDC10 HEV module
66-
HEVOptions hopts;
67-
6869
std::vector<BoardType> dv = fOptions->GetBoards("DDC10");
69-
// Init DDC10 only when included in config - only for TPC
7070
if (dv.size() == 1){
71+
HEVOptions hopts;
7172
if(fOptions->GetHEVOpt(hopts) == 0){
72-
fDDC10 = new DDC10();
73+
fDDC10 = std::make_unique<DDC10>();
7374
if(fDDC10->Initialize(hopts) != 0){
7475
fLog->Entry(MongoLog::Error, "Failed to initialise DDC10 HEV");
7576
fStatus = DAXHelpers::Idle;
@@ -81,16 +82,14 @@ int CControl_Handler::DeviceArm(int run, Options *opts){
8182
fLog->Entry(MongoLog::Error, "Failed to pull DDC10 options from file");
8283
}
8384
} else {
84-
//fLog->Entry(MongoLog::Debug, "No HEV");
8585
}
86+
#endif // HASDDC10
8687

87-
88-
// Getting options for the V1495 board
8988
std::vector<BoardType> mv = fOptions->GetBoards("V1495");
9089
if (mv.size() == 1){
9190
BoardType mv_def = mv[0];
9291
fBID = mv_def.board;
93-
fV1495 = new V1495(fLog, fOptions, mv_def.board, fBoardHandle, mv_def.vme_address);
92+
fV1495 = std::make_unique<V1495>(fLog, fOptions, mv_def.board, fBoardHandle, mv_def.vme_address);
9493
// Writing registers to the V1495 board
9594
for(auto regi : fOptions->GetRegisters(fBID, true)){
9695
unsigned int reg = DAXHelpers::StringToHex(regi.reg);
@@ -102,73 +101,53 @@ int CControl_Handler::DeviceArm(int run, Options *opts){
102101
}
103102
}
104103
}else{
105-
//fLog->Entry(MongoLog::Debug, "No V1495");
106104
}
107-
//fLog->Entry(MongoLog::Local, "Arm sequence finished");
108105
fStatus = DAXHelpers::Armed;
109106
return 0;
110107

111-
} // end devicearm
112-
113-
114-
108+
}
115109

116-
// Send the start signal from crate controller
117-
int CControl_Handler::DeviceStart(){
110+
int CControl_Handler::Start(){
118111
if(fStatus != DAXHelpers::Armed){
119112
fLog->Entry(MongoLog::Warning, "V2718 attempt to start without arming. Maybe unclean shutdown");
120113
return 0;
121114
}
122-
if(fV2718 == NULL || fV2718->SendStartSignal()!=0){
115+
if(!fV2718 || fV2718->SendStartSignal()!=0){
123116
fLog->Entry(MongoLog::Error, "V2718 either failed to start");
124117
fStatus = DAXHelpers::Error;
125118
return -1;
126119
}
127120

128121
fStatus = DAXHelpers::Running;
129-
//fLog->Entry(MongoLog::Local, "Start sequence completed");
130122
return 0;
131123
}
132124

133125
// Stopping the previously started devices; V2718, V1495, DDC10...
134-
int CControl_Handler::DeviceStop(){
135-
//fLog->Entry(MongoLog::Local, "Beginning stop sequence");
136-
137-
// If V2718 here then send stop signal
138-
if(fV2718 != NULL){
126+
int CControl_Handler::Stop(){
127+
if(fV2718){
139128
if(fV2718->SendStopSignal() != 0){
140129
fLog->Entry(MongoLog::Warning, "Failed to stop V2718");
141130
}
142-
delete fV2718;
143-
fV2718 = NULL;
131+
fV2718.reset();
144132
}
133+
fV1495.reset();
134+
#ifdef HASDDC10
145135
// Don't need to stop the DDC10 but just clean up a bit
146-
if(fDDC10 != NULL){
147-
delete fDDC10;
148-
fDDC10 = NULL;
149-
}
150-
151-
if(fV1495 != NULL){
152-
delete fV1495;
153-
fV1495 = NULL;
154-
}
136+
fDDC10.reset();
137+
#endif
155138

156139
fStatus = DAXHelpers::Idle;
157140
return 0;
158141
}
159142

160-
161143
// Reporting back on the status of V2718, V1495, DDC10 etc...
162-
bsoncxx::document::value CControl_Handler::GetStatusDoc(std::string hostname){
163-
using namespace std::chrono;
164-
165-
// Updating the status doc
144+
void CControl_Handler::StatusUpdate(mongocxx::collection* collection){
166145
bsoncxx::builder::stream::document builder{};
167-
builder << "host" << hostname << "status" << fStatus <<
168-
"time" << bsoncxx::types::b_date(system_clock::now());
146+
builder << "host" << fHostname << "status" << fStatus <<
147+
"time" << bsoncxx::types::b_date(std::chrono::system_clock::now());
169148
auto in_array = builder << "active" << bsoncxx::builder::stream::open_array;
170149

171-
if(fV2718 != NULL){
150+
if(fV2718){
172151
auto crate_options = fV2718->GetCrateOptions();
173152
in_array << bsoncxx::builder::stream::open_document
174153
<< "run_number" << fCurrentRun
@@ -181,9 +160,11 @@ bsoncxx::document::value CControl_Handler::GetStatusDoc(std::string hostname){
181160
<< bsoncxx::builder::stream::close_document;
182161
}
183162
auto after_array = in_array << bsoncxx::builder::stream::close_array;
184-
return after_array << bsoncxx::builder::stream::finalize;
163+
collection->insert_one(after_array << bsoncxx::builder::stream::finalize);
164+
return;
165+
/*
185166
// DDC10 parameters might change for future updates of the XENONnT HEV
186-
if(fDDC10 != NULL){
167+
if(fDDC10){
187168
auto hev_options = fDDC10->GetHEVOptions();
188169
in_array << bsoncxx::builder::stream::open_document
189170
<< "type" << "DDC10"
@@ -207,7 +188,7 @@ bsoncxx::document::value CControl_Handler::GetStatusDoc(std::string hostname){
207188
<< bsoncxx::builder::stream::close_document;
208189
}
209190
// Write the settings for the Muon Veto V1495 board into status doc
210-
if(fV1495 != NULL){
191+
if(fV1495){
211192
auto registers = fOptions->GetRegisters(fBID);
212193
in_array << bsoncxx::builder::stream::open_document
213194
<< "type" << "V1495"
@@ -223,5 +204,5 @@ bsoncxx::document::value CControl_Handler::GetStatusDoc(std::string hostname){
223204
224205
after_array = in_array << bsoncxx::builder::stream::close_array;
225206
return after_array << bsoncxx::builder::stream::finalize;
226-
227-
}
207+
*/
208+
}

CControl_Handler.hh

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,35 @@
11
#ifndef _CCONTROL_HANDLER_HH_
22
#define _CCONTROL_HANDLER_HH_
33

4-
#include <string>
5-
#include <bsoncxx/document/value.hpp>
4+
#include "DAQController.hh"
65

7-
class MongoLog;
8-
class Options;
96
class V2718;
10-
class DDC10;
117
class V1495;
8+
#ifdef HASDDC10
9+
class DDC10;
10+
#endif
1211

13-
class CControl_Handler{
14-
12+
class CControl_Handler : public DAQController{
1513
public:
16-
CControl_Handler(MongoLog *log, std::string procname);
17-
~CControl_Handler();
14+
CControl_Handler(std::shared_ptr<MongoLog>&, std::string);
15+
virtual ~CControl_Handler();
1816

19-
bsoncxx::document::value GetStatusDoc(std::string hostname);
20-
int DeviceArm(int run, Options *opts);
21-
int DeviceStart();
22-
int DeviceStop();
17+
virtual void StatusUpdate(mongocxx::collection*);
18+
virtual int Arm(std::shared_ptr<Options>&);
19+
virtual int Start();
20+
virtual int Stop();
2321

2422
private:
2523

26-
V2718 *fV2718;
27-
DDC10 *fDDC10;
28-
V1495 *fV1495;
24+
std::unique_ptr<V2718> fV2718;
25+
std::unique_ptr<V1495> fV1495;
26+
#ifdef HASDDC10
27+
std::unique_ptr<DDC10> fDDC10;
28+
#endif
2929

30-
int fStatus;
3130
int fCurrentRun;
3231
int fBID;
3332
int fBoardHandle;
34-
std::string fProcname;
35-
Options *fOptions;
36-
MongoLog *fLog;
3733
};
3834

39-
#endif
35+
#endif // _CCONTROL_HANDLER_HH_ defined

0 commit comments

Comments
 (0)