Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ SHELL = /bin/bash -O extglob -c
CC = g++
CXX = g++
BUILD_COMMIT = "$(shell git log -n 1 --pretty=oneline | awk '{print $$1}')"
CFLAGS = -Wall -Wextra -pedantic -pedantic-errors -g -O2 -DLINUX -DREDAX_BUILD_COMMIT='$(BUILD_COMMIT)' -std=c++17 -pthread $(shell pkg-config --cflags libmongocxx)
CFLAGS += -Wall -Wextra -pedantic -pedantic-errors -g -O2 -DLINUX -DREDAX_BUILD_COMMIT='$(BUILD_COMMIT)' -std=c++17 -pthread $(shell pkg-config --cflags libmongocxx)
CPPFLAGS := $(CFLAGS)
IS_READER0 := false
ifeq "$(shell hostname)" "reader0"
IS_READER0 = true
endif
LDFLAGS = -lCAENVME -lstdc++fs -llz4 -lblosc $(shell pkg-config --libs libmongocxx) $(shell pkg-config --libs libbsoncxx)
LDFLAGS += -lCAENVME -lstdc++fs -llz4 -lblosc $(shell pkg-config --libs libmongocxx) $(shell pkg-config --libs mongoc2) $(shell pkg-config --libs libbsoncxx)
#LDFLAGS_CC = ${LDFLAGS} -lexpect -ltcl8.6

SOURCES_SLAVE = CControl_Handler.cc DAQController.cc f1724.cc main.cc MongoLog.cc \
Expand Down
2 changes: 1 addition & 1 deletion MongoLog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ int MongoLog::Entry(int priority, const std::string& message, ...){

fs::path MongoLog_nT::OutputDirectory(struct tm* date) {
char temp[6];
std::sprintf(temp, "%02d.%02d", date->tm_mon+1, date->tm_mday);
std::sprintf(temp, "%02d.%02d", 0x3f & (date->tm_mon+1), 0x3f & date->tm_mday);
return fOutputDir / std::to_string(date->tm_year+1900) / std::string(temp);
}

Expand Down
26 changes: 14 additions & 12 deletions Options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int Options::Load(std::string name, mongocxx::collection* opts_collection, std::
bson_value = new bsoncxx::document::value(doc);
bson_options = bson_value->view();
try{
fDetector = bson_options["detectors"][fHostname].get_utf8().value.to_string();
fDetector = bson_options["detectors"][fHostname].get_string().value;
}catch(const std::exception& e){
fLog->Entry(MongoLog::Warning, "No detector specified for this host");
return -1;
Expand Down Expand Up @@ -147,7 +147,7 @@ int Options::GetNestedInt(std::string path, int default_value){

std::string Options::GetString(std::string path, std::string default_value){
try{
return bson_options[path].get_utf8().value.to_string();
return std::string(bson_options[path].get_string().value);
}
catch (const std::exception &e){
//LOG
Expand All @@ -169,7 +169,7 @@ std::string Options::GetNestedString(std::string path, std::string default_value
auto val = bson_options[fields[0]];
for(unsigned int i=1; i<fields.size(); i++)
val = val[fields[i]];
return val.get_utf8().value.to_string();
return std::string(val.get_string().value);
}catch(const std::exception &e){
fLog->Entry(MongoLog::Local, "Using default value for %s",path.c_str());
return default_value;
Expand All @@ -192,22 +192,24 @@ std::vector<BoardType> Options::GetBoards(std::string type){
types.push_back(type);

for(bsoncxx::array::element ele : subarr){
std::string btype = ele["type"].get_utf8().value.to_string();
std::string btype(ele["type"].get_string().value);
if(!std::count(types.begin(), types.end(), btype))
continue;
try{
if(ele["host"].get_utf8().value.to_string() != fHostname)
if(ele["host"].get_string().value != fHostname)
continue;
}
catch(const std::exception &e){
// If there is no host field then no biggie. Assume we have just 1 host.
};
BoardType bt;
if (ele["skip"] && ele["skip"].get_bool().value == true)
continue;
bt.link = ele["link"].get_int32();
bt.crate = ele["crate"].get_int32();
bt.board = ele["board"].get_int32();
bt.type = ele["type"].get_utf8().value.to_string();
bt.vme_address = DAXHelpers::StringToHex(ele["vme_address"].get_utf8().value.to_string());
bt.type = ele["type"].get_string().value;
bt.vme_address = DAXHelpers::StringToHex(std::string(ele["vme_address"].get_string().value));
ret.push_back(bt);
}

Expand All @@ -225,7 +227,7 @@ std::vector<RegisterType> Options::GetRegisters(int board, bool strict){
sdet = "";
}catch(const std::exception& e){
try{
sdet = ele["board"].get_utf8().value.to_string();
sdet = ele["board"].get_string().value;
ibid = -1;
}catch(const std::exception& ee){
throw std::runtime_error("Invalid register: board is neither int nor string");
Expand All @@ -234,8 +236,8 @@ std::vector<RegisterType> Options::GetRegisters(int board, bool strict){
if ((ibid != board) && strict) continue;
if ((ibid == board) || (sdet == fDetector) || (sdet == "all")) {
RegisterType rt;
rt.reg = ele["reg"].get_utf8().value.to_string();
rt.val = ele["val"].get_utf8().value.to_string();
rt.reg = ele["reg"].get_string().value;
rt.val = ele["val"].get_string().value;

ret.push_back(rt);
}
Expand Down Expand Up @@ -330,8 +332,8 @@ int Options::GetHEVOpt(HEVOptions &ret){
ret.component_status = bson_options["DDC10"]["component_status"].get_int32().value;
ret.width_cut = bson_options["DDC10"]["width_cut"].get_int32().value;
ret.delay = bson_options["DDC10"]["delay"].get_int32().value;
ret.address = bson_options["DDC10"]["address"].get_utf8().value.to_string();
ret.required = bson_options["DDC10"]["required"].get_utf8().value.to_string();
ret.address = bson_options["DDC10"]["address"].get_string().value;
ret.required = bson_options["DDC10"]["required"].get_string().value;
}catch(std::exception &E){
fLog->Entry(MongoLog::Local, "Exception getting DDC10 opts: %s",E.what());
return -1;
Expand Down
3 changes: 2 additions & 1 deletion StraxFormatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ long compress_lz4(std::shared_ptr<std::string>& in, std::shared_ptr<std::string>
// the LZ4F_preferences_t object to the new format.
// Can tune here as needed, these are defaults from the LZ4 examples
LZ4F_preferences_t kPrefs = {
{ LZ4F_max256KB, LZ4F_blockLinked, LZ4F_noContentChecksum, LZ4F_frame, 0, { 0, 0 } },
{ LZ4F_max256KB, LZ4F_blockLinked, LZ4F_noContentChecksum, LZ4F_frame, 0, 0, LZ4F_noBlockChecksum },
0, /* compression level; 0 == default */
0, /* autoflush */
0, /* favorDecSpeed */
{ 0, 0, 0 }, /* reserved, must be set to 0 */
};
long max_compressed_size = LZ4F_compressFrameBound(size_in, &kPrefs);
Expand Down
223 changes: 198 additions & 25 deletions V1495_tpc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,221 @@
#include "MongoLog.hh"

V1495_TPC::V1495_TPC(std::shared_ptr<MongoLog>& log, std::shared_ptr<Options>& opts, int bid, int handle, unsigned int address) :
V1495(log, opts, bid, handle, address), fControlReg(0x101E),
fVetoOffMSBReg(0x1012), fVetoOffLSBReg(0x1010),
fVetoOnMSBReg(0x100E), fVetoOnLSBReg(0x100C) {
fFractionalModeActive = 0;
fVetoOn_clk = fVetoOff_clk = 0;
V1495(log, opts, bid, handle, address),
fModeReg(0x100C),
fFracLtOnAReg(0x100E), fFracLtOnBReg(0x1010),
fFracLtOffAReg(0x1012), fFracLtOffBReg(0x1014),
fAntiVetoDelayAReg(0x1016), fAntiVetoDelayBReg(0x1018),
fAntiVetoDurationAReg(0x101A), fAntiVetoDurationBReg(0x101C) {
fFracLTVetoOn_clk = fFracLTVetoOff_clk = 0;
fAntiVetoDelay_clk = fAntiVetoDuration_clk = 0;
fMode = 0x0;
}

V1495_TPC::~V1495_TPC() {}

int V1495_TPC::Arm(std::map<std::string, int>& opts) {
int clocks_per_us = 40;
if ((fFractionalModeActive = opts["fractional_mode_active"]) == 1) {
fVetoOn_clk = opts["veto_on_us"] * clocks_per_us;
fVetoOff_clk = opts["veto_off_us"] * clocks_per_us;
if (fVetoOn_clk * fVetoOff_clk == 0) {
unsigned int is_busy_he_used = 1;
unsigned int is_hev_on = opts["is_hev_on"];
unsigned int is_hev_start_stop_on = 1;
unsigned int is_frac_lt_mode_on = opts["is_frac_lt_mode_on"];
unsigned int is_led_start_stop_active = opts["is_led_start_stop_active"];
unsigned int is_anti_veto_active = opts["is_anti_veto_active"];
unsigned int is_anti_veto_start_stop_active = 0;
unsigned int use_legacy_port_hev = opts["_use_legacy_port_hev"];
unsigned int use_regular_port_trg = opts["_use_regular_port_trg"];
unsigned int use_legacy_port_trg = opts["_use_legacy_port_trg"];
unsigned int use_NG_input = opts["_use_NG_input"];

// High Energy Busy always used for Busy Veto
if (is_busy_he_used == 0){ // this is currently forced to be zero, but in case we want to still use this someday.
fLog->Entry(MongoLog::Message, "V1495: Busy from high energy ADCs are set to be ignored, "
"however this is probably not a good idea. You have been warned! :)");
}

// Anti Veto Time conversion, duration > 0
if (is_anti_veto_active == 1) {
fAntiVetoDelay_clk = opts["anti_veto_delay_us"] * clocks_per_us;
fAntiVetoDuration_clk = opts["anti_veto_duration_us"] * clocks_per_us;
if (fAntiVetoDuration_clk == 0) {
fLog->Entry(MongoLog::Message, "V1495: Neutron Generator anti-veto duration is zero. Turning anti-veto off.");
is_anti_veto_active = 0;
} else {
fLog->Entry(MongoLog::Local, "V1495 Neutron Generator anti-veto mode active: delay %ius, duration %ius",
opts["anti_veto_delay_us"], opts["anti_veto_duration_us"]);
}
}

// Fractional Lifetime Veto On & Off durations conversion, both > 0
if (is_frac_lt_mode_on == 1) {
fFracLTVetoOn_clk = opts["fractional_lifetime_veto_on_us"] * clocks_per_us;
fFracLTVetoOff_clk = opts["fractional_lifetime_veto_off_us"] * clocks_per_us;
if (fFracLTVetoOn_clk * fFracLTVetoOff_clk == 0) {
fLog->Entry(MongoLog::Message, "V1495: at least one value is zero, check the config: %i/%i",
opts["veto_on_us"], opts["veto_off_us"]);
fFractionalModeActive = 0;
opts["fractional_lifetime_veto_on_us"], opts["fractional_lifetime_veto_off_us"]);
is_frac_lt_mode_on = 0;
} else {
fLog->Entry(MongoLog::Local, "V1495 fractional mode active: %i/%i",
opts["veto_on_us"], opts["veto_off_us"]);
fLog->Entry(MongoLog::Local, "V1495 fractional mode active: on %i, off %i",
opts["fractional_lifetime_veto_on_us"], opts["fractional_lifetime_veto_off_us"]);
}
} else {
fLog->Entry(MongoLog::Local, "V1495 fractional mode inactive");
}

// Only for testing, that of Anti-Veto start/stop is reconstructed corretcly in straxen from NG start/stop
// Anti-Veto start/stop on, if HEV is not used (they are on the same output; Anti-Veto can be reconstructed otherwise)
if ((is_anti_veto_active == 1) && (is_hev_on == 0)) {
fLog->Entry(MongoLog::Message, "V1495: Anti-Veto on and HEV off: putting Anti-Veto start/stops on HEV start/stop output");
is_anti_veto_start_stop_active = 1;
is_hev_start_stop_on = 0;
}

// Fractional Lifetime mode: no HEV at the same time. Turn off HEV start/stops (they are on the same output)
if (is_frac_lt_mode_on == 1){
if (is_hev_on == 1) {
fLog->Entry(MongoLog::Message, "V1495: HEV and Fractional Lifetime set to on. Assuming that was a mistake. Switching off FracLT.");
is_frac_lt_mode_on = 0;
} else {
fLog->Entry(MongoLog::Message, "V1495: Fractional Lifetime set to on. Switching off HEV start/stop to avoid confusion.");
is_hev_start_stop_on = 0;
}
}

fMode = (is_busy_he_used << 0) |
(is_hev_on << 2) |
(is_hev_start_stop_on << 3) |
(is_frac_lt_mode_on << 4) |
(is_led_start_stop_active << 5) |
(is_anti_veto_active << 6) |
(is_anti_veto_start_stop_active << 7) |
(use_legacy_port_hev << 8) |
(use_regular_port_trg << 9) |
(use_legacy_port_trg << 10) |
(use_NG_input << 11);

fLog->Entry(MongoLog::Local, "V1495: Mode register will be: 0x%X", fMode);
fLog->Entry(MongoLog::Message, "V1495: Final Mode: "
"hebusy %i, hev %i, hevss %i, "
"fraclt %i, LEDss_on %i, antiv %i, antivss %i, "
"hev_leg %i, reg_trg %i, leg_trg %i, NG_inp %i",
is_busy_he_used, is_hev_on, is_hev_start_stop_on,
is_frac_lt_mode_on, is_led_start_stop_active, is_anti_veto_active, is_anti_veto_start_stop_active,
use_legacy_port_hev, use_regular_port_trg, use_legacy_port_trg, use_NG_input);
return 0;
}



int V1495_TPC::ArmSoft(std::map<std::string, int>& opts) {
int clocks_per_us = 40;
unsigned int is_busy_he_used = 1;
unsigned int is_hev_on = opts["is_hev_on"];
unsigned int is_hev_start_stop_on = 1;
unsigned int is_frac_lt_mode_on = opts["is_frac_lt_mode_on"];
unsigned int is_led_start_stop_active = opts["is_led_start_stop_active"];
unsigned int is_anti_veto_active = opts["is_anti_veto_active"];
unsigned int is_anti_veto_start_stop_active = 0;
unsigned int use_legacy_port_hev = opts["_use_legacy_port_hev"];
unsigned int use_regular_port_trg = opts["_use_regular_port_trg"];
unsigned int use_legacy_port_trg = opts["_use_legacy_port_trg"];
unsigned int use_NG_input = opts["_use_NG_input"];

// Only for testing, that of Anti-Veto start/stop is reconstructed corretcly in straxen from NG start/stop
// Anti-Veto start/stop on, if HEV is not used (they are on the same output; Anti-Veto can be reconstructed otherwise)
if ((is_anti_veto_active == 1) && (is_hev_on == 0)) {
fLog->Entry(MongoLog::Message, "V1495: Anti-Veto on and HEV off: putting Anti-Veto start/stops on HEV start/stop output");
is_anti_veto_start_stop_active = 1;
is_hev_start_stop_on = 0;
}

// Fractional Lifetime mode: no HEV at the same time. Turn off HEV start/stops (they are on the same output)
if (is_frac_lt_mode_on == 1){
if (is_hev_on == 1) {
fLog->Entry(MongoLog::Message, "V1495: HEV and Fractional Lifetime set to on. Please activate only 1 of them at a time.");
return 1;
} else {
fLog->Entry(MongoLog::Message, "V1495: Fractional Lifetime set to on. Switching off HEV start/stop to avoid confusion.");
is_hev_start_stop_on = 0;
}
}

// Check numerical options, if we run in modes that require those
// Anti Veto Time conversion, duration > 0
if (is_anti_veto_active == 1) {
fAntiVetoDelay_clk = opts["anti_veto_delay_us"] * clocks_per_us;
fAntiVetoDuration_clk = opts["anti_veto_duration_us"] * clocks_per_us;
if (fAntiVetoDuration_clk == 0) {
fLog->Entry(MongoLog::Message, "V1495: Neutron Generator anti-veto duration is zero. Turning anti-veto off.");
is_anti_veto_active = 0;
return 1;
} else {
fLog->Entry(MongoLog::Local, "V1495 Neutron Generator anti-veto mode active: delay %ius, duration %ius",
opts["anti_veto_delay_us"], opts["anti_veto_duration_us"]);
}
}

// Fractional Lifetime Veto On & Off durations conversion, both > 0
if (is_frac_lt_mode_on == 1) {
fFracLTVetoOn_clk = opts["fractional_lifetime_veto_on_us"] * clocks_per_us;
fFracLTVetoOff_clk = opts["fractional_lifetime_veto_off_us"] * clocks_per_us;
if (fFracLTVetoOn_clk * fFracLTVetoOff_clk == 0) {
fLog->Entry(MongoLog::Message, "V1495: at least one value is zero, check the config: %i/%i",
opts["fractional_lifetime_veto_on_us"], opts["fractional_lifetime_veto_off_us"]);
return 1;
} else {
fLog->Entry(MongoLog::Local, "V1495 fractional mode active: on %i, off %i",
opts["fractional_lifetime_veto_on_us"], opts["fractional_lifetime_veto_off_us"]);
}
}

fMode = (is_busy_he_used << 0) |
(is_hev_on << 2) |
(is_hev_start_stop_on << 3) |
(is_frac_lt_mode_on << 4) |
(is_led_start_stop_active << 5) |
(is_anti_veto_active << 6) |
(is_anti_veto_start_stop_active << 7) |
(use_legacy_port_hev << 8) |
(use_regular_port_trg << 9) |
(use_legacy_port_trg << 10) |
(use_NG_input << 11);

fLog->Entry(MongoLog::Local, "V1495: Mode register will be: 0x%X", fMode);
fLog->Entry(MongoLog::Message, "V1495: Final Mode: "
"hebusy %i, hev %i, hevss %i, "
"fraclt %i, LEDss_on %i, antiv %i, antivss %i, "
"hev_leg %i, reg_trg %i, leg_trg %i, NG_inp %i",
is_busy_he_used, is_hev_on, is_hev_start_stop_on,
is_frac_lt_mode_on, is_led_start_stop_active, is_anti_veto_active, is_anti_veto_start_stop_active,
use_legacy_port_hev, use_regular_port_trg, use_legacy_port_trg, use_NG_input);
return 0;
}


int V1495_TPC::BeforeSINStart() {
int ret = 0;
if (fFractionalModeActive) {
ret += WriteReg(fControlReg, 0x1);
ret += WriteReg(fVetoOffMSBReg, (fVetoOff_clk & 0xFFFF0000) >> 16);
ret += WriteReg(fVetoOffLSBReg, fVetoOff_clk & 0xFFFF);
ret += WriteReg(fVetoOnMSBReg, (fVetoOn_clk & 0xFFFF0000) >> 16);
ret += WriteReg(fVetoOnLSBReg, fVetoOn_clk & 0xFFFF);
} else {
ret = WriteReg(fControlReg, 0x0);
}
ret += WriteReg(fModeReg, fMode);
ret += WriteReg(fFracLtOnBReg, (fFracLTVetoOn_clk & 0xFFFF0000) >> 16);
ret += WriteReg(fFracLtOnAReg, fFracLTVetoOn_clk & 0xFFFF);
ret += WriteReg(fFracLtOffBReg, (fFracLTVetoOff_clk & 0xFFFF0000) >> 16);
ret += WriteReg(fFracLtOffAReg, fFracLTVetoOff_clk & 0xFFFF);
ret += WriteReg(fAntiVetoDelayBReg, (fAntiVetoDelay_clk & 0xFFFF0000) >> 16);
ret += WriteReg(fAntiVetoDelayAReg, fAntiVetoDelay_clk & 0xFFFF);
ret += WriteReg(fAntiVetoDurationBReg, (fAntiVetoDuration_clk & 0xFFFF0000) >> 16);
ret += WriteReg(fAntiVetoDurationAReg, fAntiVetoDuration_clk & 0xFFFF);
return ret;
}

int V1495_TPC::BeforeSINStop() {
return WriteReg(fControlReg, 0x0);
int ret = 0;
ret += WriteReg(fModeReg, 0xD);
ret += WriteReg(fFracLtOnBReg, 0x0000);
ret += WriteReg(fFracLtOnAReg, 0x0000);
ret += WriteReg(fFracLtOffBReg, 0x0000);
ret += WriteReg(fFracLtOffAReg, 0x0000);
ret += WriteReg(fAntiVetoDelayBReg, 0x0000);
ret += WriteReg(fAntiVetoDelayAReg, 0x0000);
ret += WriteReg(fAntiVetoDurationBReg, 0x0000);
ret += WriteReg(fAntiVetoDurationAReg, 0x0000);
return ret;
}

Loading