Commit af8bff8f authored by Andrea Petrucci's avatar Andrea Petrucci
Browse files

references #251: first version with new DIPBridge API with DipTime and notification on demand

parent 986f77f0
......@@ -91,6 +91,7 @@ namespace evb {
mutable std::mutex dcsMutex_;
std::string maskedDipTopics_;
const uint64_t numeratorNanosDIPTime_ = (1LL<<32)/1000000;
};
using MetaDataRetrieverDIPBridgePtr = std::shared_ptr<MetaDataRetrieverDIPBridge>;
......
......@@ -4,9 +4,9 @@
#include "config/PackageInfo.h"
#define WORKSUITE_EVB_VERSION_MAJOR 6
#define WORKSUITE_EVB_VERSION_MINOR 8
#define WORKSUITE_EVB_VERSION_PATCH 2
#define WORKSUITE_EVB_PREVIOUS_VERSIONS "6.5.0,6.5.1,6.5.2,6.6.0,6.6.1,6.7.0,6.7.1,6.8.0,6.8.1"
#define WORKSUITE_EVB_VERSION_MINOR 9
#define WORKSUITE_EVB_VERSION_PATCH 0
#define WORKSUITE_EVB_PREVIOUS_VERSIONS "6.5.0,6.5.1,6.5.2,6.6.0,6.6.1,6.7.0,6.7.1,6.8.0,6.8.1,6.8.2"
#define WORKSUITE_EVB_VERSION_CODE PACKAGE_VERSION_CODE(WORKSUITE_EVB_VERSION_MAJOR,WORKSUITE_EVB_VERSION_MINOR,WORKSUITE_EVB_VERSION_PATCH)
#ifndef WORKSUITE_EVB_PREVIOUS_VERSIONS
......
......@@ -6,11 +6,14 @@
#include "b2in/nub/Method.h"
#include "xcept/tools.h"
#include "xcept/Exception.h"
#include "toolbox/mem/AutoReference.h"
#include "xdata/Table.h"
#include "xdata/exdr/Serializer.h"
#include "xdata/exdr/FixedSizeInputStreamBuffer.h"
#include "xdata/Integer32.h"
#include "xdata/Integer64.h"
#include "xdata/Integer64.h"
#include "xdata/Float.h"
......@@ -72,8 +75,12 @@ evb::readoutunit::MetaDataRetrieverDIPBridge::~MetaDataRetrieverDIPBridge()
{
if ( maskedDipTopics_.find(topic.first) != std::string::npos )
topic.second = masked;
else if ( topic.second != okay )
this->getEventingBus(eventingBusName_).unsubscribe(topic.first.c_str());
else if ( topic.second != okay ) {
xdata::Properties plist;
plist.setProperty("urn:dip:action", "register");
plist.setProperty("urn:dip:topicname", topic.first.c_str());
this->getEventingBus(eventingBusName_).publish("urn:dip:metacontrol", 0, plist);
}
} catch(eventing::api::exception::Exception& e)
{
std::string msg("Failed to unsubscribe to eventing bus "+eventingBusName_);
......@@ -94,10 +101,13 @@ void evb::readoutunit::MetaDataRetrieverDIPBridge::subscribeToDip(const std::str
{
if ( maskedDipTopics.find(topic.first) != std::string::npos )
topic.second = masked;
else if ( topic.second != okay )
// TODO take the BUS from configuration
this->getEventingBus(eventingBusName_).subscribe(topic.first.c_str());
} catch(eventing::api::exception::Exception& e)
else if (topic.second != okay) {
xdata::Properties plist;
plist.setProperty("urn:dip:action", "unregister");
plist.setProperty("urn:dip:topicname", topic.first.c_str());
this->getEventingBus(eventingBusName_).publish("urn:dip:metacontrol", 0, plist);
}
} catch(eventing::api::exception::Exception& e)
{
std::string msg("Failed to subscribe to eventing bus "+eventingBusName_);
LOG4CPLUS_ERROR(logger_,msg+stdformat_exception_history(e));
......@@ -166,13 +176,16 @@ void evb::readoutunit::MetaDataRetrieverDIPBridge::handleMessage(toolbox::mem::R
ref->release();
}
try {
xdata::Serializable* p;
p = table.getValueAt(0, "DipTimestamp");
xdata::Integer64 timeStampNanos = dynamic_cast<xdata::Integer64*>(p)->value_;
uint64_t dipTime = static_cast<uint64_t>((timeStampNanos * numeratorNanosDIPTime_) >> 32);
if ( topicName == "dip/CMS/BRIL/Luminosity" )
{
std::lock_guard<std::mutex> guard(luminosityMutex_);
// TODO get the DIPTIME ???
//lastLuminosity_.timeStamp = dipData.extractDipTime().getAsMillis();
lastLuminosity_.timeStamp = dipTime;
//lastLuminosity_.lumiSection = dipData.extractInt("LumiSection");
p = table.getValueAt(0, "LumiSection");
......@@ -189,13 +202,20 @@ void evb::readoutunit::MetaDataRetrieverDIPBridge::handleMessage(toolbox::mem::R
//lastLuminosity_.avgPileUp = dipData.extractFloat("AvgPileUp");
p = table.getValueAt(0, "AvgPileUp");
lastLuminosity_.avgPileUp = dynamic_cast<xdata::Float*>(p)->value_;
LOG4CPLUS_INFO(logger_,
toolbox::toString(
"Got a dip/CMS/BRIL/Luminosity notification: diptime=%, lumiSection=%, LumiNibble=%, InstLumi=%f, AvgPileUp=%f",
dipTime, lastLuminosity_.lumiSection, lastLuminosity_.lumiNibble,lastLuminosity_.instLumi,lastLuminosity_.avgPileUp));
}
else if ( topicName == "dip/CMS/Tracker/BeamSpot" )
{
std::lock_guard<std::mutex> guard(beamSpotMutex_);
std::stringstream msg;
// TODO get the DIPTIME ???
//lastBeamSpot_.timeStamp = dipData.extractDipTime().getAsMillis();
lastBeamSpot_.timeStamp = dipTime;
msg << "Got a dip/CMS/Tracker/BeamSpot: diptime=" << dipTime;
//lastBeamSpot_.x = dipData.extractFloat("x");
p = table.getValueAt(0, "x");
......@@ -209,6 +229,8 @@ void evb::readoutunit::MetaDataRetrieverDIPBridge::handleMessage(toolbox::mem::R
p = table.getValueAt(0, "z");
lastBeamSpot_.z = dynamic_cast<xdata::Float*>(p)->value_;
msg << ", x=" << lastBeamSpot_.x << ", y=" << lastBeamSpot_.y <<", z=" << lastBeamSpot_.z;
//lastBeamSpot_.widthX = dipData.extractFloat("width_x");
p = table.getValueAt(0, "width_x");
lastBeamSpot_.widthX = dynamic_cast<xdata::Float*>(p)->value_;
......@@ -221,6 +243,7 @@ void evb::readoutunit::MetaDataRetrieverDIPBridge::handleMessage(toolbox::mem::R
p = table.getValueAt(0, "sigma_z");
lastBeamSpot_.sigmaZ = dynamic_cast<xdata::Float*>(p)->value_;
msg << ", width_x=" << lastBeamSpot_.widthX << ", width_y=" << lastBeamSpot_.widthY << ", sigma_z=" << lastBeamSpot_.sigmaZ;
//lastBeamSpot_.errX = dipData.extractFloat("err_x");
p = table.getValueAt(0, "err_x");
......@@ -234,6 +257,8 @@ void evb::readoutunit::MetaDataRetrieverDIPBridge::handleMessage(toolbox::mem::R
p = table.getValueAt(0, "err_z");
lastBeamSpot_.errZ = dynamic_cast<xdata::Float*>(p)->value_;
msg << ", err_x=" << lastBeamSpot_.errX << ", err_y=" << lastBeamSpot_.errY << ", err_z=" << lastBeamSpot_.errZ;
//lastBeamSpot_.errWidthX = dipData.extractFloat("err_width_x");
p = table.getValueAt(0, "err_width_x");
lastBeamSpot_.errWidthX = dynamic_cast<xdata::Float*>(p)->value_;
......@@ -246,6 +271,7 @@ void evb::readoutunit::MetaDataRetrieverDIPBridge::handleMessage(toolbox::mem::R
p = table.getValueAt(0, "err_sigma_z");
lastBeamSpot_.errSigmaZ = dynamic_cast<xdata::Float*>(p)->value_;
msg << ", err_width_x="<< lastBeamSpot_.errWidthX << ", err_width_y="<< lastBeamSpot_.errWidthY << ", err_sigma_z="<< lastBeamSpot_.errSigmaZ;
//lastBeamSpot_.dxdz = dipData.extractFloat("dxdz");
p = table.getValueAt(0, "dxdz");
......@@ -263,33 +289,45 @@ void evb::readoutunit::MetaDataRetrieverDIPBridge::handleMessage(toolbox::mem::R
p = table.getValueAt(0, "err_dydz");
lastBeamSpot_.errDydz = dynamic_cast<xdata::Float*>(p)->value_;
msg << ", dxdz=" << lastBeamSpot_.dxdz << ", dydz=" << lastBeamSpot_.dydz << ", err_dxdz="<< lastBeamSpot_.errDxdz << ", err_dydz="<< lastBeamSpot_.errDydz;
LOG4CPLUS_INFO(logger_,msg.str());
}
else if ( topicName == "dip/CMS/CTPPS/detectorFSM" )
{
std::lock_guard<std::mutex> guard(ctppsMutex_);
// TODO get the DIPTIME ???
//lastCTPPS_.timeStamp = dipData.extractDipTime().getAsMillis();
lastCTPPS_.timeStamp = dipTime;
lastCTPPS_.status = 0;
for (uint8_t i = 0; i < MetaData::CTPPS::rpCount; ++i)
{
// TODO get the DIPTIME ???
// TODO if it works
//uint64_t status = dipData.extractInt(MetaData::CTPPS::ctppsRP[i]);
//lastCTPPS_.status |= (status & 0x3) << (i*2);
p = table.getValueAt(0, MetaData::CTPPS::ctppsRP[i]);
uint64_t status = static_cast<uint64_t>(dynamic_cast<xdata::Integer32*>(p)->value_);
lastCTPPS_.status |= (status & 0x3) << (i*2);
}
LOG4CPLUS_INFO(logger_, toolbox::toString(
"Got a dip/CMS/CTPPS/detectorFSM notification: diptime=%, status=%",
dipTime, lastCTPPS_.status));
}
else if ( topicName == "dip/CMS/MCS/Current" )
{
std::lock_guard<std::mutex> guard(dcsMutex_);
// TODO get the DIPTIME ???
//const uint64_t dipTime = dipData.extractDipTime().getAsMillis();
//lastDCS_.timeStamp = std::max(lastDCS_.timeStamp,dipTime);
lastDCS_.timeStamp = std::max(lastDCS_.timeStamp,dipTime);
//lastDCS_.magnetCurrent = dipData.extractFloat();
// TODO check if the DIP default value is mapped as follow in the DIPbridge
p = table.getValueAt(0, "__DIP_DEFAULT__");
lastDCS_.magnetCurrent = dynamic_cast<xdata::Float*>(p)->value_;
LOG4CPLUS_INFO(logger_, toolbox::toString(
"Got a dip/CMS/MCS/Current notification: diptime=%, status=%f",
dipTime, lastDCS_.magnetCurrent));
}
else
{
......@@ -306,9 +344,17 @@ void evb::readoutunit::MetaDataRetrieverDIPBridge::handleMessage(toolbox::mem::R
else
lastDCS_.highVoltageReady &= ~(1 << pos);
// TODO get the DIPTIME ???
//const uint64_t dipTime = dipData.extractDipTime().getAsMillis();
lastDCS_.timeStamp = std::max(lastDCS_.timeStamp,dipTime);
LOG4CPLUS_INFO(logger_, toolbox::toString(
"Got a %s notification: diptime=%, status=%f",
topicName, dipTime, lastDCS_.highVoltageReady));
}
} catch (std::bad_cast& e)
{
LOG4CPLUS_ERROR(logger_,toolbox::toString("Failed to dynamic cast dip value and got this error: %s", e.what()));
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment