Commit ab244bed authored by Martin Vala's avatar Martin Vala

Merge branch '63-port-mapping' into 'master'

Resolve "Port mapping"

Closes #63

See merge request !42
parents 682138a0 9dc2d38c
Pipeline #1508 passed with stage
in 16 minutes and 2 seconds
#include "NDimMapping.hh"
#include <bitset>
#include <math.h>
#include <string>
namespace Salsa
{
NDimMapping::NDimMapping(int nBin, int lBorder, int rBorder)
: Object()
, mNBin(nBin)
, mLBorder(lBorder)
, mRBorder(rBorder)
{
/// Constructor
const int p = ceil(log2(mNBin));
int size = pow(2, p);
for (auto i = 1; i <= size; i++)
{
std::bitset<64> b(i - 1);
std::string bits = b.to_string<char, std::char_traits<char>, std::allocator<char>>();
bits.erase(0, 64 - p);
mBinMap.insert(std::make_pair(std::make_pair(i, bits), i));
}
}
NDimMapping::~NDimMapping()
{
/// Destructor
}
void NDimMapping::print() const
{
SPD_INFO("nBin [{}] pow [{}]", mNBin, ceil(log2(mNBin)));
for (auto it = mBinMap.begin(); it != mBinMap.end(); ++it)
SPD_INFO("[{}] [{}]", it->first.first, it->first.second);
}
} // namespace Salsa
#pragma once
#include <Object.hh>
#include <map>
namespace Salsa
{
///
/// \class NDimMapping
///
/// \brief NDimMapping algorithm class
/// \author Yuri Butenko <gohas94@gmail.com>
///
class NDimMapping : public Object
{
public:
NDimMapping(int nBin = 8, int lBorder = -4, int rBorder = 3);
virtual ~NDimMapping();
/// Printing
void print() const;
private:
int mNBin; ///< number of bin's
int mLBorder; ///< left border
int mRBorder; ///< right border
std::map<std::pair<int, std::string>, int> mBinMap; ///< bin mapping
};
} // namespace Salsa
......@@ -29,7 +29,7 @@ add_executable(salsa-redirector salsa-redirector.cc)
target_link_libraries (salsa-redirector ${LIBZMQ_LIBRARIES} ${CZMQ_LIBRARIES} ${ZYRE_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} SalsaProto SalsaBase SalsaZmq)
add_executable(salsa-test-hc salsa-test-hc.cc)
target_link_libraries (salsa-test-hc ${LIBZMQ_LIBRARIES} ${CZMQ_LIBRARIES} ${ZYRE_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} SalsaProto SalsaBase SalsaZmq)
target_link_libraries (salsa-test-hc SalsaBase)
#set(TARGETS i)
#install(TARGETS ${TARGETS} RUNTIME DESTINATION bin COMPONENT RUNTIME)
add_executable(salsa-test-mapping salsa-test-mapping.cc)
target_link_libraries (salsa-test-mapping SalsaBase)
#include <NDimMapping.hh>
#include <spdlog/sinks/stdout_sinks.h>
int main()
{
std::shared_ptr<spdlog::logger> logger = spdlog::stdout_logger_mt("console");
Salsa::NDimMapping ndm;
ndm.print();
// Doesn't this get done automatically? (That's kind of purpose of
// shared_ptr...)
spdlog::drop_all();
return 0;
}
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