Skip to content

Commit

Permalink
Merge pull request #100 from coderdj/alternate_v2
Browse files Browse the repository at this point in the history
Redax 2.0, attempt 2
  • Loading branch information
darrylmasson authored Oct 27, 2020
2 parents ca9cb12 + e9f0c11 commit b0e8ba3
Show file tree
Hide file tree
Showing 43 changed files with 2,183 additions and 1,914 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
*.swp
*~

# executables
main
ccontrol
# executable
redax

# DAQ logs
*.log
Expand Down
123 changes: 52 additions & 71 deletions CControl_Handler.cc
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
#include "CControl_Handler.hh"
#include "DAXHelpers.hh"
#include "Options.hh"
#include "MongoLog.hh"
#include "V2718.hh"
#ifdef HASDDC10
#include "DDC10.hh"
#endif
#include "V1495.hh"
#include <vector>
#include <bsoncxx/builder/stream/document.hpp>
#include <chrono>

CControl_Handler::CControl_Handler(MongoLog *log, std::string procname){
fOptions = NULL;
fLog = log;
fProcname = procname;
fCurrentRun = fBID = fBoardHandle-1;
fV2718 = NULL;
fV1495 = NULL;
fDDC10 = NULL;

CControl_Handler::CControl_Handler(std::shared_ptr<MongoLog>& log, std::string procname) : DAQController(log, procname){
fCurrentRun = fBID = fBoardHandle = -1;
fV2718 = nullptr;
fV1495 = nullptr;
#ifdef HASDDC10
fDDC10 = nullptr;
#endif
fStatus = DAXHelpers::Idle;
}

CControl_Handler::~CControl_Handler(){
DeviceStop();
Stop();
}

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

fStatus = DAXHelpers::Arming;

// Just in case clear out any remaining objects from previous runs
DeviceStop();
Stop();

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

// Pull options for V2718
CrateOptions copts;
Expand All @@ -47,29 +49,28 @@ int CControl_Handler::DeviceArm(int run, Options *opts){
// Getting the link and crate for V2718
std::vector<BoardType> bv = fOptions->GetBoards("V2718");
if(bv.size() != 1){
fLog->Entry(MongoLog::Message, "Require one V2718 to be defined or we can't start the run");
fLog->Entry(MongoLog::Message, "Require one V2718 to be defined");
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(MongoLog::Error, "Failed to initialize V2718 crate controller");
try{
fV2718 = std::make_unique<V2718>(fLog, copts, cc_def.link, cc_def.crate);
}catch(std::exception& e){
fLog->Entry(MongoLog::Error, "Failed to initialize V2718 crate controller: %s", e.what());
fStatus = DAXHelpers::Idle;
return -1;
}else{
fBoardHandle = fV2718->GetHandle();
fLog->Entry(MongoLog::Local, "V2718 Initialised");
}
fBoardHandle = fV2718->GetHandle();
fLog->Entry(MongoLog::Local, "V2718 Initialized");

#ifdef HASDDC10
// Getting options for DDC10 HEV module
HEVOptions hopts;

std::vector<BoardType> dv = fOptions->GetBoards("DDC10");
// Init DDC10 only when included in config - only for TPC
if (dv.size() == 1){
HEVOptions hopts;
if(fOptions->GetHEVOpt(hopts) == 0){
fDDC10 = new DDC10();
fDDC10 = std::make_unique<DDC10>();
if(fDDC10->Initialize(hopts) != 0){
fLog->Entry(MongoLog::Error, "Failed to initialise DDC10 HEV");
fStatus = DAXHelpers::Idle;
Expand All @@ -81,16 +82,14 @@ int CControl_Handler::DeviceArm(int run, Options *opts){
fLog->Entry(MongoLog::Error, "Failed to pull DDC10 options from file");
}
} else {
//fLog->Entry(MongoLog::Debug, "No HEV");
}
#endif // HASDDC10


// Getting options for the V1495 board
std::vector<BoardType> mv = fOptions->GetBoards("V1495");
if (mv.size() == 1){
BoardType mv_def = mv[0];
fBID = mv_def.board;
fV1495 = new V1495(fLog, fOptions, mv_def.board, fBoardHandle, mv_def.vme_address);
fV1495 = std::make_unique<V1495>(fLog, fOptions, mv_def.board, fBoardHandle, mv_def.vme_address);
// Writing registers to the V1495 board
for(auto regi : fOptions->GetRegisters(fBID, true)){
unsigned int reg = DAXHelpers::StringToHex(regi.reg);
Expand All @@ -102,73 +101,53 @@ int CControl_Handler::DeviceArm(int run, Options *opts){
}
}
}else{
//fLog->Entry(MongoLog::Debug, "No V1495");
}
//fLog->Entry(MongoLog::Local, "Arm sequence finished");
fStatus = DAXHelpers::Armed;
return 0;

} // end devicearm



}

// Send the start signal from crate controller
int CControl_Handler::DeviceStart(){
int CControl_Handler::Start(){
if(fStatus != DAXHelpers::Armed){
fLog->Entry(MongoLog::Warning, "V2718 attempt to start without arming. Maybe unclean shutdown");
return 0;
}
if(fV2718 == NULL || fV2718->SendStartSignal()!=0){
if(!fV2718 || fV2718->SendStartSignal()!=0){
fLog->Entry(MongoLog::Error, "V2718 either failed to start");
fStatus = DAXHelpers::Error;
return -1;
}

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

// Stopping the previously started devices; V2718, V1495, DDC10...
int CControl_Handler::DeviceStop(){
//fLog->Entry(MongoLog::Local, "Beginning stop sequence");

// If V2718 here then send stop signal
if(fV2718 != NULL){
int CControl_Handler::Stop(){
if(fV2718){
if(fV2718->SendStopSignal() != 0){
fLog->Entry(MongoLog::Warning, "Failed to stop V2718");
}
delete fV2718;
fV2718 = NULL;
fV2718.reset();
}
fV1495.reset();
#ifdef HASDDC10
// Don't need to stop the DDC10 but just clean up a bit
if(fDDC10 != NULL){
delete fDDC10;
fDDC10 = NULL;
}

if(fV1495 != NULL){
delete fV1495;
fV1495 = NULL;
}
fDDC10.reset();
#endif

fStatus = DAXHelpers::Idle;
return 0;
}


// Reporting back on the status of V2718, V1495, DDC10 etc...
bsoncxx::document::value CControl_Handler::GetStatusDoc(std::string hostname){
using namespace std::chrono;

// Updating the status doc
void CControl_Handler::StatusUpdate(mongocxx::collection* collection){
bsoncxx::builder::stream::document builder{};
builder << "host" << hostname << "status" << fStatus <<
"time" << bsoncxx::types::b_date(system_clock::now());
builder << "host" << fHostname << "status" << fStatus <<
"time" << bsoncxx::types::b_date(std::chrono::system_clock::now());
auto in_array = builder << "active" << bsoncxx::builder::stream::open_array;

if(fV2718 != NULL){
if(fV2718){
auto crate_options = fV2718->GetCrateOptions();
in_array << bsoncxx::builder::stream::open_document
<< "run_number" << fCurrentRun
Expand All @@ -181,9 +160,11 @@ bsoncxx::document::value CControl_Handler::GetStatusDoc(std::string hostname){
<< bsoncxx::builder::stream::close_document;
}
auto after_array = in_array << bsoncxx::builder::stream::close_array;
return after_array << bsoncxx::builder::stream::finalize;
collection->insert_one(after_array << bsoncxx::builder::stream::finalize);
return;
/*
// DDC10 parameters might change for future updates of the XENONnT HEV
if(fDDC10 != NULL){
if(fDDC10){
auto hev_options = fDDC10->GetHEVOptions();
in_array << bsoncxx::builder::stream::open_document
<< "type" << "DDC10"
Expand All @@ -207,7 +188,7 @@ bsoncxx::document::value CControl_Handler::GetStatusDoc(std::string hostname){
<< bsoncxx::builder::stream::close_document;
}
// Write the settings for the Muon Veto V1495 board into status doc
if(fV1495 != NULL){
if(fV1495){
auto registers = fOptions->GetRegisters(fBID);
in_array << bsoncxx::builder::stream::open_document
<< "type" << "V1495"
Expand All @@ -223,5 +204,5 @@ bsoncxx::document::value CControl_Handler::GetStatusDoc(std::string hostname){
after_array = in_array << bsoncxx::builder::stream::close_array;
return after_array << bsoncxx::builder::stream::finalize;

}
*/
}
38 changes: 17 additions & 21 deletions CControl_Handler.hh
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
#ifndef _CCONTROL_HANDLER_HH_
#define _CCONTROL_HANDLER_HH_

#include <string>
#include <bsoncxx/document/value.hpp>
#include "DAQController.hh"

class MongoLog;
class Options;
class V2718;
class DDC10;
class V1495;
#ifdef HASDDC10
class DDC10;
#endif

class CControl_Handler{

class CControl_Handler : public DAQController{
public:
CControl_Handler(MongoLog *log, std::string procname);
~CControl_Handler();
CControl_Handler(std::shared_ptr<MongoLog>&, std::string);
virtual ~CControl_Handler();

bsoncxx::document::value GetStatusDoc(std::string hostname);
int DeviceArm(int run, Options *opts);
int DeviceStart();
int DeviceStop();
virtual void StatusUpdate(mongocxx::collection*);
virtual int Arm(std::shared_ptr<Options>&);
virtual int Start();
virtual int Stop();

private:

V2718 *fV2718;
DDC10 *fDDC10;
V1495 *fV1495;
std::unique_ptr<V2718> fV2718;
std::unique_ptr<V1495> fV1495;
#ifdef HASDDC10
std::unique_ptr<DDC10> fDDC10;
#endif

int fStatus;
int fCurrentRun;
int fBID;
int fBoardHandle;
std::string fProcname;
Options *fOptions;
MongoLog *fLog;
};

#endif
#endif // _CCONTROL_HANDLER_HH_ defined
Loading

0 comments on commit b0e8ba3

Please sign in to comment.