forked from coderdj/redax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CControl_Handler.cc
133 lines (106 loc) · 3.57 KB
/
CControl_Handler.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
123
124
125
126
127
128
129
#include "CControl_Handler.hh"
#include "DAXHelpers.hh"
#include "V2718.hh"
CControl_Handler::CControl_Handler(MongoLog *log, std::string procname){
fOptions = NULL;
fLog = log;
fProcname = procname;
fCurrentRun = -1;
fV2718 = NULL;
fV1495 = NULL;
fDDC10 = NULL;
fStatus = DAXHelpers::Idle;
}
CControl_Handler::~CControl_Handler(){
DeviceStop();
}
// Initialising various devices namely; V2718 crate controller, V1495, DDC10...
int CControl_Handler::DeviceArm(int run, Options *opts){
fStatus = DAXHelpers::Arming;
// Just in case clear out any remaining objects from previous runs
DeviceStop();
fCurrentRun = run;
fOptions = opts;
// Pull options for modules
CrateOptions copts;
if(fOptions->GetCrateOpt(copts, "V2718") != 0){
fLog->Entry("Failed to pull crate options from file. Required fields: s_in, pulser_freq, muon_veto, neutron_veto, led_trigger", MongoLog::Error);
fStatus = DAXHelpers::Idle;
return -1;
}
// Getting the link and crate for V2718
std::vector<BoardType> bv = fOptions->GetBoards("V2718", fProcname);
if(bv.size() != 1){
fLog->Entry("Require one V2718 to be defined or we can't start the run", MongoLog::Error);
fStatus = DAXHelpers::Idle;
return -1;
}
BoardType cc_def = bv[0];
fV2718 = new V2718(fLog);
if (fV2718->CrateInit(copts, cc_def.link, cc_def.crate)!=0){
fLog->Entry("Failed to initialize V2718 crate controller", MongoLog::Error);
fStatus = DAXHelpers::Idle;
return -1;
}
fStatus = DAXHelpers::Armed;
return 0;
}
// Send the start signal from crate controller
int CControl_Handler::DeviceStart(){
if(fStatus != DAXHelpers::Armed){
fLog->Entry("V2718 attempt to start without arming. Maybe unclean shutdown", MongoLog::Warning);
return 0;
}
if(fV2718 == NULL || fV2718->SendStartSignal()!=0){
fLog->Entry("V2718 either failed to start", MongoLog::Error);
fStatus = DAXHelpers::Error;
return -1;
}
std::cout << "V2718 Started" << std::endl;
fStatus = DAXHelpers::Running;
return 0;
}
// Stopping the previously started devices; V2718, V1495, DDC10...
int CControl_Handler::DeviceStop(){
// If V2718 here then send stop signal
if(fV2718 != NULL){
if(fV2718->SendStopSignal() != 0){
fLog->Entry("Failed to stop V2718", MongoLog::Warning);
}
delete fV2718;
fV2718 = NULL;
}
/*
if(fV1495 != NULL){
delete fV1495;
fV1495 = NULL;
}
if(fDDC10 != NULL){
delete fDDC10;
fDDC10 = NULL;
}
*/
fStatus = DAXHelpers::Idle;
return 0;
}
// Reporting back on the status of V2718, V1495, DDC10 etc...
bsoncxx::document::value CControl_Handler::GetStatusDoc(std::string hostname){
// Updating the status doc
bsoncxx::builder::stream::document builder{};
builder << "host" << hostname << "type" << "ccontrol" << "status" << fStatus;
auto in_array = builder << "active" << bsoncxx::builder::stream::open_array;
if(fV2718 != NULL){
in_array << bsoncxx::builder::stream::open_document
<< "run_number" << fCurrentRun
<< "type" << "V2718"
<< "s_in" << fV2718->GetCrateOptions().s_in
<< "neutron_veto" << fV2718->GetCrateOptions().neutron_veto
<< "muon_veto" << fV2718->GetCrateOptions().muon_veto
<< "led_trigger" << fV2718->GetCrateOptions().led_trigger
<< "pulser_freq" << fV2718->GetCrateOptions().pulser_freq
<< bsoncxx::builder::stream::close_document;
}
// Here you would add the DDC10 and V1495
auto after_array = in_array << bsoncxx::builder::stream::close_array;
return after_array << bsoncxx::builder::stream::finalize;
}