/* * File: FairMQParser.cxx * Author: winckler * * Created on May 14, 2015, 5:01 PM */ #include "FairMQParser.h" #include "FairMQLogger.h" #include // WARNING : pragma commands to hide boost (1.54.0) warning // TODO : remove these pragma commands when boost will fix this issue in future release #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wshadow" #include #pragma clang diagnostic pop namespace FairMQParser { no_id_exception NoIdErr; // TODO : add key-value map parameter for replacing/updating values from keys // function that convert property tree (given the xml or json structure) to FairMQMap FairMQMap boost_ptree_to_MQMap(const boost::property_tree::ptree& pt, const std::string& device_id, const std::string& root_node, const std::string& format_flag) { // Create fair mq map FairMQMap MQChannelMap; // variables to create key for the mq map. Note: maybe device name and id useless here std::string kdevice_id; std::string kchannel; if(device_id.empty()) throw NoIdErr; // do a first loop just to print the device-id in xml/json input for(const auto& p : pt.get_child(root_node)) { if (p.first != "device") continue; //get id attribute to choose the device if(format_flag=="xml") { kdevice_id=p.second.get(".id"); MQLOG(DEBUG)<<"Found device id '"<< kdevice_id <<"' in XML input"; } if(format_flag=="json") { kdevice_id=p.second.get("id"); MQLOG(DEBUG)<<"Found device id '"<< kdevice_id <<"' in JSON input"; } } // Extract value from boost::property_tree // For each device in fairMQOptions for(const auto& p : pt.get_child(root_node)) { if (p.first != "device") continue; //get id attribute to choose the device if(format_flag=="xml") kdevice_id=p.second.get(".id"); if(format_flag=="json") kdevice_id=p.second.get("id"); // if not correct device id, do not fill MQMap if(device_id != kdevice_id) continue; // print if DEBUG log level set std::stringstream ss_device; ss_device << "[node = " << p.first << "] id = " << kdevice_id; MQLOG(DEBUG)<(".name"); if(format_flag=="json") kchannel=q.second.get("name"); // print if DEBUG log level set std::stringstream ss_chan; ss_chan << "\t [node = " << q.first << "] name = " << kchannel; MQLOG(DEBUG)< channel_list; int count_socket=0; // for each socket in channel for(const auto& r : q.second.get_child("")) { if (r.first != "socket") continue; count_socket++; FairMQChannel channel; // print if DEBUG log level set std::stringstream ss_sock; ss_sock << "\t \t [node = " << r.first << "] socket index = " << count_socket; MQLOG(DEBUG)<("type",channel.fType); channel.fMethod = r.second.get("method",channel.fMethod); channel.fAddress = r.second.get("address",channel.fAddress); channel.fSndBufSize = r.second.get("sndBufSize",channel.fSndBufSize);//int channel.fRcvBufSize = r.second.get("rcvBufSize",channel.fRcvBufSize);//int channel.fRateLogging = r.second.get("rateLogging",channel.fRateLogging);//int channel_list.push_back(channel); }// end socket loop //fill mq map option MQChannelMap.insert(std::make_pair(kchannel,std::move(channel_list))); } } if(MQChannelMap.size()>0) { MQLOG(DEBUG)<<"---- Channel-keys found are :"; for(const auto& p : MQChannelMap) MQLOG(DEBUG)<> match; std::pair device_match; ProcessTree(xml.begin (), xml.end (), std::back_inserter(match), [] (const std::string& key) { return key == "device"; }); // for each device for (const auto& pair: match) { if(pair.second.get(".name") == devicename) { device_match=pair; } else { //match.erase(std::remove(match.begin(), match.end(), pair), match.end()); continue; } //std::cout << "pair.first " << pair.first << std::endl;//device //std::cout << "\t node = " << pair.first // << "\t name = " << pair.second.get(".name") // << "\t id = " << pair.second.get(".id"); //std::cout<