Commit 335db58b authored by Remi Mommsen's avatar Remi Mommsen
Browse files

references #159: create new package for shared include files from BRIL

parent be59cc42
BUILD_HOME:=$(shell pwd)/../..
BUILD_SUPPORT=build
PROJECT_NAME=worksuite
include $(XDAQ_ROOT)/$(BUILD_SUPPORT)/mfAutoconf.rules
include $(XDAQ_ROOT)/$(BUILD_SUPPORT)/mfDefs.$(XDAQ_OS)
Project=$(PROJECT_NAME)
Package=interface/bril
PackageName=interfacebril
Sources=version.cc
IncludeDirs=$(CONFIG_INCLUDE_PREFIX)
# interface requires no compilation
include $(XDAQ_ROOT)/$(BUILD_SUPPORT)/Makefile.rules
include $(XDAQ_ROOT)/$(BUILD_SUPPORT)/mfRPM.rules
#ifndef _interface_bril_CommonDataFormat_h_
#define _interface_bril_CommonDataFormat_h_
#include <string>
#include "interface/bril/CompoundDataStreamer.h"
#define STRINGIZE_NX(z) #z
#define STRINGIZE(z) STRINGIZE_NX(z)
#define PPCAT_NX(A,B) A ## B
#define PPCAT(A,B) PPCAT_NX(A,B)
#define PPCAT_DOT(A,B) PPCAT(PPCAT(A,.),B)
namespace interface{ namespace bril{
//static const std::string DATA_VERSION = STRINGIZE( PPCAT_DOT(INTERFACEBRIL_VERSION_MAJOR,INTERFACEBRIL_VERSION_MINOR) );
//required common property for bril data "DATA_VERSION" to compare with interface::bril::DATA_VERSION
static const std::string DATA_VERSION = "1.1";
const unsigned int MAX_NUM_LOOKUPITEMS = 26;
const int MAX_NBX = 3564;
const unsigned int INVALID_ITEMID = 0xff;
const std::string INVALID_ITEMNAME = "";
//
// Enum factory , Produces Enums in namespace and with lookup table
//
struct LookupItem{unsigned int id; std::string name;};
#define ENUM_VALUE(Xname,Xassign) Xname Xassign,
#define LOOKUP_PAIR(Xname,Xassign) {Xname,STRINGIZE(Xname)},
#define DEFINE_LOOKUPTABLE(Xnsname,ENUM_DEF) namespace Xnsname{ \
enum{ENUM_DEF(ENUM_VALUE)}; \
static const LookupItem lookuptable[MAX_NUM_LOOKUPITEMS]={ENUM_DEF(LOOKUP_PAIR) {INVALID_ITEMID,INVALID_ITEMNAME} };}
/**
* Global Enums
**/
// Data Source
#define DataSource_ENUM(XX) XX(TCDS,=1) XX(DIP,=2) XX(PLT,=3) XX(BCM1F,=4) XX(BHM,=5) XX(BCML,=6) XX(LUMI,=7) XX(HF,=8) XX(BPTX,=9) XX(BCM1FUTCA,=10) XX(RADMON,=11) XX(DT,=12) XX(BCM1FSCVD,=13) XX(BCM1FPCVD,=14) XX(BCM1FSI,=15) XX(HFOC,=16) XX(HFET,=17) XX(BCM1FUTCASCVD,=18) XX(BCM1FUTCAPCVD,=19) XX(BCM1FUTCASI,=20) XX(PLTSLINK,=21)
DEFINE_LOOKUPTABLE(DataSource,DataSource_ENUM)
// Frequency Type
#define FrequencyType_ENUM(XX) XX(NB1,=1) XX(NB4,=4) XX(NB64,=64) XX(RUN,=99)
DEFINE_LOOKUPTABLE(FrequencyType,FrequencyType_ENUM)
// Storage Type
#define StorageType_ENUM(XX) XX(UINT8,=1) XX(INT8,) XX(UINT16,) XX(INT16,) XX(UINT32,) XX(INT32,) XX(UINT64,) XX(INT64,) XX(FLOAT,) XX(DOUBLE,) XX(COMPOUND,)
DEFINE_LOOKUPTABLE(StorageType,StorageType_ENUM)
/**
* Data structure
**/
//
// Common message header. This header definition can be used for casting a buffer into header only
// The header contains 4 categories of information: time,publish frequency,provenance,payloadsize
//
class DatumHead{
public:
unsigned int fillnum;
unsigned int runnum;
unsigned int lsnum;
unsigned int nbnum;
unsigned int timestampsec;
unsigned int timestampmsec;
unsigned int totsize;
unsigned char publishnnb;
unsigned char datasourceid;
unsigned char algoid;
unsigned char channelid;
unsigned char payloadtype;
unsigned char payloadanchor[1];
public:
static std::string headdict(){ return std::string("fillnum:uint32:1 runnum:uint32:1 lsnum:uint32:1 nbnum:uint32:1 timestampsec:uint32:1 timestampmsec:uint32:1 totsize:uint32:1 publishnnb:uint8:1 datasourceid:uint8:1 algoid:uint8:1 channelid:uint8:1 payloadtype:uint8:1"); }
DatumHead():fillnum(0),runnum(0),lsnum(0),nbnum(0),timestampsec(0),timestampmsec(0),totsize(0),publishnnb(0),datasourceid(0),algoid(0),channelid(0),payloadtype(0){}
DatumHead(const DatumHead& o){
fillnum = o.fillnum; runnum = o.runnum; lsnum = o.lsnum; nbnum = o.nbnum, timestampsec = o.timestampsec; timestampmsec = o.timestampmsec; totsize = o.totsize; publishnnb = o.publishnnb; datasourceid = o.datasourceid; algoid = o.algoid; channelid = o.channelid; payloadtype = o.payloadtype;
}
DatumHead& operator =(const DatumHead&o){
if(this == &o) return *this;
fillnum = o.fillnum; runnum = o.runnum; lsnum = o.lsnum; nbnum = o.nbnum, timestampsec = o.timestampsec; timestampmsec = o.timestampmsec; totsize = o.totsize; publishnnb = o.publishnnb; datasourceid = o.datasourceid; algoid = o.algoid; channelid = o.channelid; payloadtype = o.payloadtype;
return *this;
}
inline unsigned int totalsize() const{return totsize; }
inline unsigned int payloadsize() const{ return (totsize>sizeof(DatumHead)) ? (totsize-sizeof(DatumHead)):0;}
inline unsigned int nitems() const{
unsigned int id=getStorageTypeID();
if(id==bril::StorageType::UINT16 || id==bril::StorageType::INT16) return (unsigned int)payloadsize()/2;
if(id==bril::StorageType::UINT32 || id==bril::StorageType::INT32 || id==bril::StorageType::FLOAT) return (unsigned int)payloadsize()/4;
if(id==bril::StorageType::UINT64 || id==bril::StorageType::INT64 || id==bril::StorageType::DOUBLE) return (unsigned int)payloadsize()/8;
if(id==bril::StorageType::COMPOUND) return 1;
return 0;
}
inline DatumHead& head(){return const_cast<DatumHead&>(static_cast<DatumHead&>(*this));}
inline void setTime(unsigned int ifill, unsigned int irun, unsigned int ils, unsigned int inb, unsigned int itssec, unsigned int itsmsec){
fillnum=ifill;runnum=irun;lsnum=ils;nbnum=inb;timestampsec=itssec;timestampmsec=itsmsec;
}
inline void setResource(unsigned int isourceid, unsigned int ialgo, unsigned int ichannel, unsigned int ipayloadtype){
datasourceid = (unsigned char)isourceid;
algoid = (unsigned char)ialgo;
channelid = (unsigned char)ichannel;
payloadtype = (unsigned char)ipayloadtype;
}
inline void setTotalsize(unsigned int itsize){totsize=itsize;}
inline void setFrequency(unsigned int ipubfreq){publishnnb=(unsigned char)ipubfreq;}
inline unsigned int getDataSourceID()const{return (unsigned int)datasourceid;}
inline unsigned int getStorageTypeID()const{return (unsigned int)payloadtype;}
inline unsigned int getAlgoID()const{return (unsigned int)algoid;}
inline unsigned int getChannelID()const{return (unsigned int)channelid;}
};//DatumHead
template <typename T>
struct Datum : public DatumHead{
static std::string topicname();
static std::string payloaddict();
static size_t n();
static size_t maxsize();
static std::string description();
static std::string unit();
static const LookupItem* algo_lookuptable();
inline T* payloadptr(){T* __attribute__((__may_alias__)) r=reinterpret_cast<T*>(payloadanchor);return r;}
inline T& payload(){return *payloadptr();}
};//Datum
#define DECLARE_DATUM(Xname) typedef interface::bril::Datum<Xname> Xname##T
#define DEF_TOPICNAME(x) template<> inline std::string interface::bril::Datum<x>::topicname(){ return STRINGIZE(x); }
#define DEF_PAYLOADDICT(x,pd) template<> inline std::string interface::bril::Datum<x>::payloaddict(){ return pd; }
#define DEF_N(x,z) template<> inline size_t interface::bril::Datum<x>::n(){ return z; }
#define DEF_SIMPLE_MAXSIZE(x,y,z) template<> inline size_t Datum<x>::maxsize(){ return sizeof(y)*(z)+sizeof(DatumHead); }
#define DEF_COMPOUND_MAXSIZE(x,y) template<> inline size_t Datum<x>::maxsize(){ interface::bril::CompoundDataStreamer c(y); return c.datasize()+sizeof(DatumHead); }
#define DEF_ALGOS(x,a) template<> inline const interface::bril::LookupItem* interface::bril::Datum<x>::algo_lookuptable(){return a;}
#define DEF_DESCRIPTION(x,d) template<> inline std::string interface::bril::Datum<x>::description(){ return d; }
#define DEF_UNIT(x,u) template<> inline std::string interface::bril::Datum<x>::unit(){ return u; }
#define DEFINE_COMPOUND_TOPIC(Xname,Xpdict,Xdesc,Xunit) struct Xname{}; \
DECLARE_DATUM(Xname); \
DEF_TOPICNAME(Xname); \
DEF_PAYLOADDICT(Xname,Xpdict); \
DEF_N(Xname,1); \
DEF_COMPOUND_MAXSIZE(Xname,Xpdict); \
DEF_ALGOS(Xname,NULL); \
DEF_DESCRIPTION(Xname,Xdesc); \
DEF_UNIT(Xname,Xunit);
#define DEFINE_SIMPLE_TOPIC(Xname,Xtype,Xlen,Xalgos,Xdesc,Xunit) struct Xname{ \
Xtype value[Xlen]; \
typedef Xtype value_type; \
inline value_type& operator[](size_t idx){return value[idx];} \
inline const value_type& operator[](size_t idx)const{return value[idx];} \
}; \
DECLARE_DATUM(Xname); \
DEF_TOPICNAME(Xname); \
DEF_PAYLOADDICT(Xname,""); \
DEF_N(Xname,Xlen); \
DEF_SIMPLE_MAXSIZE(Xname,Xtype,Xlen); \
DEF_ALGOS(Xname,Xalgos); \
DEF_DESCRIPTION(Xname,Xdesc); \
DEF_UNIT(Xname,Xunit);
#define DEFINE_SIGNAL_TOPIC(Xname,Xdesc) struct Xname{ typedef void* value_type;};\
DECLARE_DATUM(Xname); \
DEF_TOPICNAME(Xname); \
DEF_PAYLOADDICT(Xname,""); \
DEF_N(Xname,0); \
DEF_SIMPLE_MAXSIZE(Xname,Xname,0); \
DEF_ALGOS(Xname,NULL); \
DEF_DESCRIPTION(Xname,Xdesc); \
DEF_UNIT(Xname,"");
static inline unsigned int IdByName(const LookupItem* lookuptable, const std::string& name){
if(!lookuptable) return 0;
unsigned int index = 0;
while( (lookuptable[index].name != INVALID_ITEMNAME) && (index < MAX_NUM_LOOKUPITEMS)){
if(lookuptable[index].name==name) return lookuptable[index].id;
index++;
}
return 0;
}
static inline std::string NameById(const LookupItem* lookuptable, unsigned int id){
if(!lookuptable) return "";
unsigned int index = 0;
while((index < MAX_NUM_LOOKUPITEMS) && (lookuptable[index].id != INVALID_ITEMID)){
if(lookuptable[index].id==id) return lookuptable[index].name;
index++;
}
return "";
}
}//ns interface
}//ns bril
#endif
#ifndef _interface_bril_CompoundDataStreamer_h
#define _interface_bril_CompoundDataStreamer_h
#include <string.h>
#include <string>
#include <vector>
#include <stdexcept>
#include <cstdlib>
#include <iostream>
#include "interface/bril/Utils.h"
namespace interface{ namespace bril{
class CompoundDataStreamer{
public:
struct Column{
std::string name;
std::string type;
int size;
int nitems;
};
explicit CompoundDataStreamer(const std::string& rowdict):m_rowsize(0){
std::vector<std::string> fieldstrs;
fieldstrs = Utils::splitstring(rowdict,' ');
for( std::vector<std::string>::iterator it=fieldstrs.begin(); it!=fieldstrs.end(); ++it ){
std::string fieldstr = *it;
std::vector<std::string> columndef = Utils::splitstring(fieldstr.c_str(),':');
if(columndef.size()!=3){
throw std::range_error("size of column definition out of range");
}
Column col;
col.name = columndef[0];
col.type = columndef[1];
col.nitems = atoi(columndef[2].c_str());
if(col.type=="uint32"||col.type=="int32"||col.type=="float"){
col.size = col.nitems*4;
}else if(col.type=="uint64"||col.type=="int64"||col.type=="double"){
col.size = col.nitems*8;
}else if(col.type=="uint8"||col.type=="int8"||col.type=="bool"){
col.size = col.nitems;
}else if(col.type=="uint16"||col.type=="int16"){
col.size = col.nitems*2;
}else if(col.type.substr(0,3)=="str"){
std::string strmaxlen = col.type.substr(3,col.type.size()-3);
int maxlen = atoi( strmaxlen.c_str() );
col.size = col.nitems*(maxlen);
}else{
throw std::runtime_error("unrecognized column type "+col.type);
}
m_rowsize += col.size;
m_columns.push_back(col);
}
}
inline size_t datasize() const{ return m_rowsize;}
inline size_t get_offset(int column_index) const{ size_t offset = 0; for(int i=0;i<column_index;++i) offset += m_columns[i].size;
return offset;}
inline size_t get_fieldsize(int column_index)const{ return m_columns[column_index].size; }
inline size_t ncolumns()const{ return m_columns.size(); }
inline const Column& column(int column_index) const{ return m_columns[column_index]; }
bool insert_field( unsigned char* bufref, const std::string& column_name, const void* fielddata){
int column_index = -1;
for(int i=0;i<(int)m_columns.size();++i){
if(m_columns[i].name == column_name){
column_index = i; break;
}
}
if(column_index<0) return false;
return insert_field(bufref, column_index, fielddata);
}
bool insert_field( unsigned char* bufref, int column_index, const void* fielddata){
if((size_t)column_index<m_columns.size()){
if(m_columns[column_index].type.substr(0,3)=="str"){
memset( bufref+get_offset(column_index), 0 , get_fieldsize(column_index) );
memcpy( bufref+get_offset(column_index), fielddata, strlen((char*)fielddata) );
}else{
memcpy( bufref+get_offset(column_index), fielddata, get_fieldsize(column_index) );
}
return true;
}
return false;
}
bool extract_field( void* fielddata, int column_index, unsigned char* bufref){
if((size_t)column_index<m_columns.size()){
memcpy( fielddata, bufref+get_offset(column_index), get_fieldsize(column_index) );
return true;
}
return false;
}
bool extract_field( void* fielddata, const std::string& column_name, unsigned char* bufref){
int column_index = -1;
for(int i=0;i<(int)m_columns.size();++i){
if(m_columns[i].name == column_name){
column_index = i; break;
}
}
if(column_index<0) return false;
return extract_field(fielddata,column_index,bufref);
}
private:
size_t m_rowsize;
std::vector<Column> m_columns;
};
}}
#endif
#ifndef _interface_bril_LUMITopics_hh_
#define _interface_bril_LUMITopics_hh_
#include "interface/bril/CommonDataFormat.h"
namespace interface{ namespace bril{
DEFINE_COMPOUND_TOPIC(bestlumi,"provider:str8:1 calibtag:str32:1 delivered:float:1 recorded:float:1 avgpu:float:1 bxdelivered:float:3564","best instantaneous luminosity","Hz/ub");
DEFINE_COMPOUND_TOPIC(atlaslumi,"delivered:float:1 bxdelivered:float:3564","atlas instantaneous luminosity","Hz/ub");
DEFINE_COMPOUND_TOPIC(dtlumi,"calibtag:str32:1 avgraw:float:1 avg:float:1","instantaneous luminosity", "Hz/ub");
}}//ns interface/bril
#endif
#ifndef _interface_bril_version_h_
#define _interface_bril_version_h_
#include "interface/bril/CommonDataFormat.h"
#include "config/PackageInfo.h"
// !!! Edit this line to reflect the latest package version !!!
// version definition moved to DataFormat.h to synchronize rpm and dataversion numbers
#define BRIL_INTERFACEBRIL_VERSION_MAJOR 3
#define BRIL_INTERFACEBRIL_VERSION_MINOR 0
#define BRIL_INTERFACEBRIL_VERSION_PATCH 0
// If any previous versions available E.g. #define INTERFACEBRIL_PREVIOUS_VERSIONS "3.8.0,3.8.1"
#undef BRIL_INTERFACEBRIL_PREVIOUS_VERSIONS
//
// Template macros
//
#define BRIL_INTERFACEBRIL_VERSION_CODE PACKAGE_VERSION_CODE(BRIL_INTERFACEBRIL_VERSION_MAJOR,BRIL_INTERFACEBRIL_VERSION_MINOR,BRIL_INTERFACEBRIL_VERSION_PATCH)
#ifndef BRIL_INTERFACEBRIL_PREVIOUS_VERSIONS
#define BRIL_INTERFACEBRIL_FULL_VERSION_LIST PACKAGE_VERSION_STRING(BRIL_INTERFACEBRIL_VERSION_MAJOR,BRIL_INTERFACEBRIL_VERSION_MINOR,BRIL_INTERFACEBRIL_VERSION_PATCH)
#else
#define BRIL_INTERFACEBRIL_FULL_VERSION_LIST BRIL_INTERFACEBRIL_PREVIOUS_VERSIONS "," PACKAGE_VERSION_STRING(BRIL_INTERFACEBRIL_VERSION_MAJOR,BRIL_INTERFACEBRIL_VERSION_MINOR,BRIL_INTERFACEBRIL_VERSION_PATCH)
#endif
namespace interfacebril
{
const std::string project = "bril";
const std::string package = "interfacebril";
const std::string versions = BRIL_INTERFACEBRIL_FULL_VERSION_LIST;
const std::string summary = "Header files shared with bril eventing publisher/subscriber and other common data headers";
const std::string description = "Header files are required for bril eventing publisher/subscriber";
const std::string authors = "Zhen Xie";
const std::string link = "https://twiki.cern.ch/twiki/bin/viewauth/CMS/LumiCalc";
config::PackageInfo getPackageInfo();
void checkPackageDependencies();
std::set<std::string, std::less<std::string> > getPackageDependencies();
}
#endif
#include "interface/bril/version.h"
#include "config/version.h"
GETPACKAGEINFO(interfacebril)
void interfacebril::checkPackageDependencies() {
CHECKDEPENDENCY(config);
}
std::set<std::string, std::less<std::string> > interfacebril::getPackageDependencies(){
std::set<std::string, std::less<std::string> > dependencies;
ADDDEPENDENCY(dependencies,config);
return dependencies;
}
Supports Markdown
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