Commit 7e5cad62 authored by Andrea Petrucci's avatar Andrea Petrucci
Browse files

references #251: first working version with DIPbridge

parent d91b0ab7
......@@ -128,8 +128,8 @@ namespace evb {
dummyFedSizeMax(0), // no limitation
dipNodes("cmsdimns1.cern.ch,cmsdimns2.cern.ch"),
maskedDipTopics(""),
dipEventingBus("slimbus"),
dipBridgeRegisterTimeout(15),
dipEventingBus("slimbus"),
dipBridgeRegisterTimeout(11),
fragmentPoolSize(200000000),
createSoftFed1022(false),
checkBxId(true),
......
......@@ -43,11 +43,8 @@ namespace evb {
bool fillData(unsigned char*);
// DIP listener callbacks
// DIPBridgs listener callback
void handleMessage(toolbox::mem::Reference * ref, xdata::Properties & plist);
//void disconnected(DipSubscription*, char*);
//void connected(DipSubscription*);
//void handleException(DipSubscription*, DipException&);
void subscribeToDip(const std::string& maskedDipTopics);
void timerToRegisterToDipBridge();
......@@ -101,7 +98,6 @@ namespace evb {
mutable std::mutex dcsMutex_;
std::string maskedDipTopics_;
//const uint64_t numeratorNanosDIPTime_ = (1LL<<32)/1000000;
};
using MetaDataRetrieverDIPBridgePtr = std::shared_ptr<MetaDataRetrieverDIPBridge>;
......
......@@ -5,8 +5,8 @@
#define WORKSUITE_EVB_VERSION_MAJOR 6
#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_PATCH 1
#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,6.9.0"
#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
......
......@@ -31,7 +31,6 @@ evb::EVM::EVM(xdaq::ApplicationStub* app) :
void evb::EVM::timeExpired (toolbox::task::TimerEvent& e) {
std::cout<< "Called evb::EVM::timeExpired "<< e.type()<<std::endl;
xdata::String maskedDipTopics = this->configuration_->maskedDipTopics;
evb::readoutunit::MetaDataRetrieverDIPBridgePtr dipRetriver = this->input_.get()->getMetaDataRetrieverDIPBridgePtr();
dipRetriver->registerToDipBridge(maskedDipTopics);
......
#include <iomanip>
#include <sstream>
#include <bitset>
#include "evb/readoutunit/MetaDataRetrieverDIPBridge.h"
#include "log4cplus/loggingmacros.h"
......@@ -119,8 +120,7 @@ evb::readoutunit::MetaDataRetrieverDIPBridge::~MetaDataRetrieverDIPBridge()
plist.setProperty("urn:dip:action", "unregister");
plist.setProperty("urn:dip:topicname", topic.first.c_str());
this->getEventingBus(eventingBusName_).publish("urn:dip:metacontrol", 0, plist);
LOG4CPLUS_WARN(logger_,toolbox::toString("urn:dip:action=unregister, urn:dip:topicname=%s",topic.first.c_str()));
std::cout<< "urn:dip:action=unregister topicname='"<< topic.first.c_str() <<std::endl;
LOG4CPLUS_INFO(logger_,toolbox::toString("urn:dip:action=unregister, urn:dip:topicname=%s",topic.first.c_str()));
}
} catch(eventing::api::exception::Exception& e)
{
......@@ -132,14 +132,6 @@ evb::readoutunit::MetaDataRetrieverDIPBridge::~MetaDataRetrieverDIPBridge()
}
void evb::readoutunit::MetaDataRetrieverDIPBridge::timerToRegisterToDipBridge() {
/*
toolbox::task::Timer * timer = toolbox::task::getTimerFactory()->createTimer("PeriodicDiagnostic");
toolbox::TimeInterval interval(8,0); // period of 8 secs
toolbox::TimeVal start;
start = toolbox::TimeVal::gettimeofday();
timer->scheduleAtFixedRate( start, timerListener_, interval, 0, "" );
std::cout<< "Started timerToRegisterToDipBridge TimeInterval="<< interval <<std::endl;
*/
std::string appUUID= this->getOwnerApplication()->getApplicationDescriptor()->getUUID().toString();
std::string timerName_= "timer_" + appUUID + toolbox::toString(".%d", rand());
......@@ -152,8 +144,6 @@ void evb::readoutunit::MetaDataRetrieverDIPBridge::timerToRegisterToDipBridge()
// schedule start of monitoring
toolbox::TimeVal startTime(startTimeSecs_);
timer_->schedule(timerListener_, startTime, 0, "");
std::cout<< "Started timerToRegisterToDipBridge TimeInterval="<< startTime <<std::endl;
}
......@@ -170,12 +160,11 @@ void evb::readoutunit::MetaDataRetrieverDIPBridge::registerToDipBridge(
plist.setProperty("urn:dip:topicname", topic.first.c_str());
this->getEventingBus(eventingBusName_).publish(
"urn:dip:metacontrol", 0, plist);
LOG4CPLUS_WARN(logger_,
LOG4CPLUS_INFO(logger_,
toolbox::toString(
"urn:dip:action=register, urn:dip:topicname=%s",
topic.first.c_str()));
std::cout<< "urn:dip:action=register topicname='"<< topic.first.c_str() <<std::endl;
usleep(200);
usleep(100);
}
} catch (eventing::api::exception::Exception &e) {
std::string msg(
......@@ -197,11 +186,9 @@ void evb::readoutunit::MetaDataRetrieverDIPBridge::subscribeToDip(
else if (topic.second != okay) {
this->getEventingBus(eventingBusName_).subscribe(
topic.first.c_str());
LOG4CPLUS_WARN(logger_,
LOG4CPLUS_INFO(logger_,
toolbox::toString("subsribe, topicname=%s",
topic.first.c_str()));
std::cout << "Subscribe topicname='" << topic.first.c_str()
<< std::endl;
}
} catch (eventing::api::exception::Exception &e) {
std::string msg(
......@@ -214,46 +201,8 @@ void evb::readoutunit::MetaDataRetrieverDIPBridge::subscribeToDip(
}
// Call the timer to register to DIPBridge
this->timerToRegisterToDipBridge();
std::cout<< "Called timerToRegisterToDipBridge"<<std::endl;
}
/*
void evb::readoutunit::MetaDataRetrieverDIPBridge::connected(DipSubscription* subscription)
{
std::ostringstream msg;
msg << "Connected to " << subscription->getTopicName();
LOG4CPLUS_INFO(logger_, msg.str());
const DipTopics::iterator pos = std::find_if(dipTopics_.begin(), dipTopics_.end(), isTopic( subscription->getTopicName() ));
if ( pos != dipTopics_.end() )
pos->second = okay;
}
void evb::readoutunit::MetaDataRetrieverDIPBridge::disconnected(DipSubscription* subscription, char* message)
{
std::ostringstream msg;
msg << "Disconnected from " << subscription->getTopicName() << ": " << message;
LOG4CPLUS_ERROR(logger_, msg.str());
const DipTopics::iterator pos = std::find_if(dipTopics_.begin(), dipTopics_.end(), isTopic( subscription->getTopicName() ));
if ( pos != dipTopics_.end() )
pos->second = unavailable;
}
void evb::readoutunit::MetaDataRetrieverDIPBridge::handleException(DipSubscription* subscription, DipException& exception)
{
std::ostringstream msg;
msg << "Exception for " << subscription->getTopicName() << ": " << exception.what();
LOG4CPLUS_ERROR(logger_, msg.str());
const DipTopics::iterator pos = std::find_if(dipTopics_.begin(), dipTopics_.end(), isTopic( subscription->getTopicName() ));
if ( pos != dipTopics_.end() )
pos->second = unavailable;
}
*/
void evb::readoutunit::MetaDataRetrieverDIPBridge::handleMessage(toolbox::mem::Reference * ref, xdata::Properties & plist)
{
toolbox::mem::AutoReference refguard(ref); //guarantee ref is released when refguard is out of scope
......@@ -261,10 +210,8 @@ void evb::readoutunit::MetaDataRetrieverDIPBridge::handleMessage(toolbox::mem::R
if ( action == "notify" && ref!=0 )
{
const std::string topicName = plist.getProperty("urn:b2in-eventing:topic");
LOG4CPLUS_WARN(logger_,"received topic "+topicName);
//parse table message
xdata::Table table;
std::cout<< "received topic='"<< topicName << "' Message buffer size "<<ref->getDataSize()<<std::endl;
xdata::exdr::FixedSizeInputStreamBuffer inBuffer(static_cast<char*>(ref->getDataLocation()),ref->getDataSize());
xdata::exdr::Serializer serializer;
try
......@@ -281,8 +228,7 @@ void evb::readoutunit::MetaDataRetrieverDIPBridge::handleMessage(toolbox::mem::R
xdata::Serializable* p;
p = table.getValueAt(0, "DipTimestamp");
xdata::Integer64 timeStampNanos = dynamic_cast<xdata::Integer64*>(p)->value_;
std::cout << "time in nanoseconds=" <<timeStampNanos<<std::endl;
uint64_t dipTime = static_cast<uint64_t>(timeStampNanos / 1000000UL);
uint64_t dipTime = static_cast<uint64_t>(timeStampNanos);
std::map<std::string,int> ::iterator it;
it = dipTopicsMap_.find(topicName);
......@@ -290,6 +236,7 @@ void evb::readoutunit::MetaDataRetrieverDIPBridge::handleMessage(toolbox::mem::R
if(it != dipTopicsMap_.end()) {
dipTopics_[it->second].second = okay;
}
std::stringstream msg;
if ( topicName == "dip/CMS/BRIL/Luminosity" )
{
std::lock_guard<std::mutex> guard(luminosityMutex_);
......@@ -311,20 +258,21 @@ 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_WARN(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));
msg << "Got a 'dip/CMS/BRIL/Luminosity' notification: diptime=" << dipTime <<
" lumiSection=" << lastLuminosity_.lumiSection << " LumiNibble=" <<
lastLuminosity_.lumiNibble << " InstLumi=" << lastLuminosity_.instLumi <<
" AvgPileUp=" << lastLuminosity_.avgPileUp;
LOG4CPLUS_INFO(logger_,msg.str());
}
else if ( topicName == "dip/CMS/Tracker/BeamSpot" )
{
std::lock_guard<std::mutex> guard(beamSpotMutex_);
std::stringstream msg;
//lastBeamSpot_.timeStamp = dipData.extractDipTime().getAsMillis();
lastBeamSpot_.timeStamp = dipTime;
msg << "Got a dip/CMS/Tracker/BeamSpot: diptime=" << dipTime;
msg << "Got a 'dip/CMS/Tracker/BeamSpot': diptime=" << dipTime;
//lastBeamSpot_.x = dipData.extractFloat("x");
p = table.getValueAt(0, "x");
......@@ -399,67 +347,56 @@ void evb::readoutunit::MetaDataRetrieverDIPBridge::handleMessage(toolbox::mem::R
lastBeamSpot_.errDydz = dynamic_cast<xdata::Float*>(p)->value_;
msg << ", dxdz=" << lastBeamSpot_.dxdz << ", dydz=" << lastBeamSpot_.dydz << ", err_dxdz="<< lastBeamSpot_.errDxdz << ", err_dydz="<< lastBeamSpot_.errDydz;
std::cout<< msg.str()<<std::endl;
LOG4CPLUS_WARN(logger_,msg.str());
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 if it works
//uint64_t status = dipData.extractInt(MetaData::CTPPS::ctppsRP[i]);
// TODO check if it works
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_WARN(logger_, toolbox::toString(
"Got a dip/CMS/CTPPS/detectorFSM notification: diptime=%, status=%",
dipTime, lastCTPPS_.status));
msg << "Got a 'dip/CMS/CTPPS/detectorFSM' notification: diptime=" << dipTime <<
" status=" << lastCTPPS_.status;
LOG4CPLUS_INFO(logger_, msg.str());
}
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_.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_WARN(logger_, toolbox::toString(
"Got a dip/CMS/MCS/Current notification: diptime=%, status=%f",
dipTime, lastDCS_.magnetCurrent));
msg << "Got a 'dip/CMS/MCS/Current' notification: diptime=" << dipTime <<
" magnetCurrent=" << lastDCS_.magnetCurrent;
LOG4CPLUS_INFO(logger_, msg.str());
}
else
{
const uint16_t pos = std::find_if(dipTopics_.begin(), dipTopics_.end(), isTopic(topicName)) - dipTopics_.begin();
std::lock_guard<std::mutex> guard(dcsMutex_);
//const std::string state = dipData.extractString();
// TODO check if the DIP default value is mapped as follow in the DIPbridge
p = table.getValueAt(0, "__DIP_DEFAULT__");
const std::string state = dynamic_cast<xdata::String*>(p)->value_;
if ( state.find("READY") != std::string::npos || state.find("ON") != std::string::npos )
lastDCS_.highVoltageReady |= (1 << pos);
else
lastDCS_.highVoltageReady &= ~(1 << pos);
//const uint64_t dipTime = dipData.extractDipTime().getAsMillis();
std::bitset<32> bitValue(lastDCS_.highVoltageReady);
lastDCS_.timeStamp = std::max(lastDCS_.timeStamp,dipTime);
std::cout<< "diptime='"<< dipTime << "' state='"<<state<<"'"<<std::endl;
LOG4CPLUS_WARN(logger_, toolbox::toString(
"Got a %s notification: diptime=%, status=%f",
topicName, dipTime, lastDCS_.highVoltageReady));
msg << "Got a '" << topicName << "' notification: diptime=" << dipTime << " state=" <<
state << " status=" << bitValue;
LOG4CPLUS_INFO(logger_, msg.str());
}
} catch (std::bad_cast& e)
......
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