/* * (C) Copyright 2009-2016 ECMWF. * * This software is licensed under the terms of the Apache Licence Version 2.0 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. * In applying this licence, ECMWF does not waive the privileges and immunities * granted to it by virtue of its status as an intergovernmental organisation * nor does it submit to any jurisdiction. */ #include "util/Logbook.h" #include #include #include #include #include "eckit/exception/Exceptions.h" #include "eckit/log/JSON.h" #include "eckit/parser/JSONParser.h" #include "util/Logger.h" #include "util/Mpi.h" namespace util { // ----------------------------------------------------------------------------- void Logbook::broadcast(Logbook& logbook, const size_t root) { std::string buffer; int buffer_size; if (mpi::comm().rank() == root) { std::stringstream s; eckit::JSON json(s); json.precision(std::numeric_limits::max_digits10); json << *this; buffer = s.str(); buffer_size = buffer.size(); } mpi::comm().broadcast(buffer_size, root); if (mpi::comm().rank() != root) { buffer.resize(buffer_size); } mpi::comm().broadcast(buffer.begin(), buffer.end(), root); if (not(&logbook == this && mpi::comm().rank() == root)) { std::stringstream s; s << buffer; eckit::JSONParser parser(s); logbook = Logbook(parser.parse()); } } // ----------------------------------------------------------------------------- void Logbook::broadcast(const size_t root) { this->broadcast(*this, root); } // ----------------------------------------------------------------------------- void Logbook::throw_exception(const std::string& name) const { std::stringstream msg; msg << "Logbook::throw_exception Could not find metadata \"" << name << "\""; throw eckit::OutOfRange(msg.str(), Here()); } // ----------------------------------------------------------------------------- } // namespace util