/******************************************************************************** * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence version 3 (LGPL) version 3, * * copied verbatim in the file "LICENSE" * ********************************************************************************/ /* * File: runSamplerRoot.cxx * Author: winckler */ // FairRoot - FairMQ #include "FairMQLogger.h" #include "FairMQProgOptions.h" #include "FairMQDevice.h" typedef std::unordered_map> FairMQMap; class MyDevice : public FairMQDevice { public: MyDevice() : rate(0.5) {} virtual ~MyDevice() {} void SetRate(double r){rate=r;} void Print(){LOG(INFO)<<"[MyDevice] rate = "<()->default_value(0.5), "Data rate"); // parse command lines, parse json file and init FairMQMap config.ParseAll(argc, argv); // get FairMQMap auto map1 = config.GetFairMQMap(); // form keys from map1 and print the value stored in variable map PrintMQParam(map1,config); // update value in variable map, and propagate the update to the FairMQMap config.UpdateValue("data.0.address","tcp://localhost:1234"); // get the updated FairMQMap auto map2 = config.GetFairMQMap(); // modify one channel value map2.at("data").at(0).UpdateSndBufSize(500); // update the FairMQMap and propagate the change in variable map config.UpdateChannelMap(map2); // print values stored in variable map PrintMQParam(map2,config); MyDevice device; device.CatchSignals(); device.SetConfig(config); std::string blah = config.GetStringValue("data-rate"); double blah2 = config.ConvertTo(blah); LOG(INFO)<<"blah2 "<("data.0.address",[&device](const std::string& key, const std::string& value) { LOG(INFO) << "[Lambda] Update parameter (0) " << key << " = " << value; device.fChannels.at("data").at(0).UpdateAddress(value); }); std::string key1("data.0.address"); std::string value1("tcp://localhost:4321"); config.UpdateValue(key1,value1); LOG(INFO)<<"device.fChannels.GetAddress = "<("data.0.method",[&device](const std::string& key, const std::string& value) { //value="abcd"; LOG(INFO) << "[Lambda] Update parameter " << key << " = " << value; device.fChannels.at("data").at(0).UpdateMethod(value); }); LOG(INFO)<<"---- Connect 3"; config.Subscribe("data.0.rcvBufSize",[&device](const std::string& key, int value) { LOG(INFO) << "[Lambda] Update parameter " << key << " = " << value; device.fChannels.at("data").at(0).UpdateRcvBufSize(value); }); LOG(INFO)<<"---- Connect 4"; config.Subscribe("data-rate",[&device](const std::string& key, double value) { LOG(INFO) << "[Lambda] Update parameter " << key << " = " << value; device.SetRate(value); }); std::string key2("data.0.rcvBufSize"); int value2(100); std::string key3("data.0.method"); std::string value3("bind"); LOG(INFO)<<"-------------------- start update"; //config.EmitUpdate(key,value); config.UpdateValue(key1,value1); LOG(INFO)<<"device.fChannels.GetAddress = "<("myNewKey",[](MyDevice& d, double val) { d.SetRate(val); d.Print(); }); double value4=0.123; config.Emit("myNewKey",device,value4); LOG(INFO)<<"-------------------- start custom 2 with function"; config.Connect("function example",&MyCallBack); value4=6.66; config.Emit("function example",device,value4); } catch (std::exception& e) { LOG(ERROR) << "Unhandled Exception reached the top of main: " << e.what() << ", application will now exit"; return 1; } return 0; }