@@ -112,39 +112,52 @@ int main(int argc, char** argv){
112112 // Can only arm if we're in the idle, arming, or armed state
113113 if (controller->status () == 0 || controller->status () == 1 || controller->status () == 2 ){
114114 controller->End ();
115+
116+ // Try to pull options from database and store in an 'optional' object
115117 string options = " " ;
118+ bsoncxx::stdx::optional<bsoncxx::document::value> trydoc;
116119 try {
117120 string option_name = doc[" mode" ].get_utf8 ().value .to_string ();
118121 logger->Entry (" Loading options " + option_name, MongoLog::Debug);
119122
120- bsoncxx::stdx::optional<bsoncxx::document::value> trydoc =
121- options_collection.find_one (bsoncxx::builder::stream::document{}<<
122- " name" << option_name.c_str () <<
123- bsoncxx::builder::stream::finalize);
123+ trydoc = options_collection.find_one (bsoncxx::builder::stream::document{}<<
124+ " name" << option_name.c_str () <<
125+ bsoncxx::builder::stream::finalize);
124126 logger->Entry (" Received arm command from user " +
125127 doc[" user" ].get_utf8 ().value .to_string () +
126128 " for mode " + option_name, MongoLog::Message);
127- if (trydoc){
128- options = bsoncxx::to_json (*trydoc);
129- if (controller->InitializeElectronics (options)!=0 ){
130- logger->Entry (" Failed to initialized electronics" , MongoLog::Error);
131- }
132- else {
133- logger->Entry (" Initialized electronics" , MongoLog::Debug);
134- }
135-
136- if (readoutThread!=NULL ){
137- logger->Entry (" Cannot start DAQ while readout thread from previous run active. Please perform a reset" , MongoLog::Message);
138- }
139- else
140- readoutThread = new std::thread (DAQController::ReadThreadWrapper,
141- (static_cast <void *>(controller)));
142- }
143129 }
144- catch ( const std::exception &e){
130+ catch (const std::exception &e){
145131 logger->Entry (" Want to arm boards but no valid mode provided" , MongoLog::Warning);
146- options = " " ;
132+ options = " " ;
133+ }
134+
135+ // Get an override doc from the 'options_override' field if it exists
136+ std::string override_json = " " ;
137+ try {
138+ bsoncxx::document::view oopts = doc[" options_override" ].get_document ().view ();
139+ override_json = bsoncxx::to_json (oopts);
140+ }
141+ catch (const std::exception &e){
142+ logger->Entry (" No override options provided, continue without." , MongoLog::Debug);
147143 }
144+
145+ if (trydoc){
146+ options = bsoncxx::to_json (*trydoc);
147+ if (controller->InitializeElectronics (options, override_json)!=0 ){
148+ logger->Entry (" Failed to initialized electronics" , MongoLog::Error);
149+ }
150+ else {
151+ logger->Entry (" Initialized electronics" , MongoLog::Debug);
152+ }
153+
154+ if (readoutThread!=NULL ){
155+ logger->Entry (" Cannot start DAQ while readout thread from previous run active. Please perform a reset" , MongoLog::Message);
156+ }
157+ else
158+ readoutThread = new std::thread (DAQController::ReadThreadWrapper,
159+ (static_cast <void *>(controller)));
160+ }
148161 }
149162 else
150163 logger->Entry (" Cannot arm DAQ while not 'Idle'" , MongoLog::Warning);
0 commit comments