Skip to content

Commit

Permalink
Merge pull request #30857 from fwyzard/migrate_boost_format_to_fmt_DQM
Browse files Browse the repository at this point in the history
Migrate DQM from boost::format to {fmt}
  • Loading branch information
cmsbuild committed Aug 5, 2020
2 parents ac2d172 + 286e3f3 commit 8cdb296
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 93 deletions.
6 changes: 3 additions & 3 deletions DQM/HLTEvF/plugins/TriggerBxMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <iterator>
#include <string>

// boost headers
#include <boost/format.hpp>
// {fmt} headers
#include <fmt/printf.h>

// CMSSW headers
#include "FWCore/Framework/interface/Frameworkfwd.h"
Expand Down Expand Up @@ -232,7 +232,7 @@ void TriggerBxMonitor::bookHistograms(DQMStore::IBooker& booker,
auto const& l1tMenu = edm::get<L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd>(setup);
for (auto const& keyval : l1tMenu.getAlgorithmMap()) {
unsigned int bit = keyval.second.getIndex();
std::string const& name = (boost::format("%s (bit %d)") % keyval.first % bit).str();
std::string const& name = fmt::sprintf("%s (bit %d)", keyval.first, bit);
if (m_make_1d_plots) {
histograms.l1t_bx.at(bit) = booker.book1D(name, name, s_bx_range + 1, -0.5, s_bx_range + 0.5);
}
Expand Down
9 changes: 5 additions & 4 deletions DQM/HLTEvF/plugins/TriggerRatesMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#include <string>
#include <cstring>

#include <fmt/printf.h>

// boost headers
#include <boost/regex.hpp>
#include <boost/format.hpp>

// Root headers
#include <TH1F.h>
Expand Down Expand Up @@ -230,7 +231,7 @@ void TriggerRatesMonitor::bookHistograms(DQMStore::IBooker &booker,
booker.setCurrentFolder(m_dqm_path + "/TCDS");
for (unsigned int i = 0; i < sizeof(s_tcds_trigger_types) / sizeof(const char *); ++i)
if (s_tcds_trigger_types[i]) {
std::string const &title = (boost::format("%s events vs. lumisection") % s_tcds_trigger_types[i]).str();
std::string const &title = fmt::sprintf("%s events vs. lumisection", s_tcds_trigger_types[i]);
histograms.tcds_counts[i] =
booker.book1D(s_tcds_trigger_types[i], title, m_lumisections_range + 1, -0.5, m_lumisections_range + 0.5);
}
Expand All @@ -241,9 +242,9 @@ void TriggerRatesMonitor::bookHistograms(DQMStore::IBooker &booker,
for (auto const &keyval : l1tMenu.getAlgorithmMap()) {
unsigned int bit = keyval.second.getIndex();
bool masked = false; // FIXME read L1 masks once they will be avaiable in the EventSetup
std::string const &name = (boost::format("%s (bit %d)") % keyval.first % bit).str();
std::string const &name = fmt::sprintf("%s (bit %d)", keyval.first, bit);
std::string const &title =
(boost::format("%s (bit %d)%s vs. lumisection") % keyval.first % bit % (masked ? " (masked)" : "")).str();
fmt::sprintf("%s (bit %d)%s vs. lumisection", keyval.first, bit, (masked ? " (masked)" : ""));
histograms.l1t_counts.at(bit) =
booker.book1D(name, title, m_lumisections_range + 1, -0.5, m_lumisections_range + 0.5);
}
Expand Down
42 changes: 21 additions & 21 deletions DQMServices/FileIO/plugins/DQMFileSaverPB.cc
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
#include "DQMServices/Core/interface/DQMStore.h"
#include "FWCore/Framework/interface/LuminosityBlock.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ServiceRegistry/interface/Service.h"

#include "DQMFileSaverPB.h"

#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <utility>
#include "TString.h"
#include "TSystem.h"
#include "TBufferFile.h"

#include <openssl/md5.h>
#include <vector>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <boost/property_tree/json_parser.hpp>
#include <filesystem>
#include <boost/format.hpp>
#include <openssl/md5.h>
#include <fmt/printf.h>

#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/gzip_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>

#include <TString.h>
#include <TSystem.h>
#include <TBufferFile.h>

#include "DQMServices/Core/interface/DQMStore.h"
#include "DQMServices/Core/src/ROOTFilePB.pb.h"
#include "FWCore/Framework/interface/LuminosityBlock.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ServiceRegistry/interface/Service.h"

#include "DQMFileSaverPB.h"

using namespace dqm;

Expand Down Expand Up @@ -67,8 +67,8 @@ void DQMFileSaverPB::saveLumi(const FileParameters& fp) const {

// create the files names
if (fakeFilterUnitMode_) {
std::string runDir = str(boost::format("%s/run%06d") % fp.path_ % fp.run_);
std::string baseName = str(boost::format("%s/run%06d_ls%04d_%s") % runDir % fp.run_ % fp.lumi_ % streamLabel_);
std::string runDir = fmt::sprintf("%s/run%06d", fp.path_, fp.run_);
std::string baseName = fmt::sprintf("%s/run%06d_ls%04d_%s", runDir, fp.run_, fp.lumi_, streamLabel_);

std::filesystem::create_directories(runDir);

Expand Down
27 changes: 14 additions & 13 deletions DQMServices/StreamerIO/plugins/DQMFileIterator.cc
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#include "DQMFileIterator.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/TimeOfDay.h"

#include <boost/regex.hpp>
#include <boost/format.hpp>
#include <boost/range.hpp>
#include <filesystem>
#include <boost/algorithm/string/predicate.hpp>

#include <iterator>
#include <memory>
#include <string>
#include <iterator>

#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/range.hpp>
#include <boost/regex.hpp>
#include <fmt/printf.h>

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/TimeOfDay.h"
#include "DQMFileIterator.h"

namespace dqmservices {

Expand Down Expand Up @@ -95,7 +96,7 @@ namespace dqmservices {
boost::split(tokens, runInputDir_, boost::is_any_of(":"));

for (auto token : tokens) {
runPath_.push_back(boost::str(boost::format("%s/run%06d") % token % runNumber_));
runPath_.push_back(fmt::sprintf("%s/run%06d", token, runNumber_));
}

eor_.loaded = false;
Expand Down Expand Up @@ -175,7 +176,7 @@ namespace dqmservices {
return;

ptree doc;
doc.put(str(boost::format("extra.lumi_seen.lumi%06d") % lumi.file_ls), lumi.state);
doc.put(fmt::sprintf("extra.lumi_seen.lumi%06d", lumi.file_ls), lumi.state);
mon_->outputUpdate(doc);
}

Expand Down
11 changes: 6 additions & 5 deletions DQMServices/StreamerIO/plugins/DQMMonitoringService.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "DQMMonitoringService.h"
#include <ctime>
#include <iostream>

#include <fmt/printf.h>

#include <boost/algorithm/string.hpp>
#include <boost/format.hpp>
#include <boost/algorithm/string/predicate.hpp>

#include <ctime>
#include <iostream>
#include "DQMMonitoringService.h"

/*
* This service is very similar to the FastMonitoringService in the HLT,
Expand Down Expand Up @@ -74,7 +75,7 @@ namespace dqmservices {
plumi.put("rate", rate);

std::time_t hkey = std::time(nullptr);
doc.add_child(str(boost::format("extra.lumi_stats.%d") % hkey), plumi);
doc.add_child(fmt::sprintf("extra.lumi_stats.%d", hkey), plumi);
}

outputUpdate(doc);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "JsonWritingTimeoutPoolOutputModule.h"

#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "DQMServices/Components/interface/fillJson.h"

#include <boost/format.hpp>
#include <filesystem>

#include <fmt/printf.h>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>

#include "DQMServices/Components/interface/fillJson.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "JsonWritingTimeoutPoolOutputModule.h"

namespace dqmservices {

JsonWritingTimeoutPoolOutputModule::JsonWritingTimeoutPoolOutputModule(edm::ParameterSet const& ps)
Expand All @@ -22,7 +22,7 @@ namespace dqmservices {
std::pair<std::string, std::string> JsonWritingTimeoutPoolOutputModule::physicalAndLogicalNameForNewFile() {
sequence_++;

std::string base = str(boost::format("run%06d_ls%04d_%s") % runNumber_ % sequence_ % streamLabel_);
std::string base = fmt::sprintf("run%06d_ls%04d_%s", runNumber_, sequence_, streamLabel_);

std::filesystem::path p(outputPath_);

Expand Down
36 changes: 17 additions & 19 deletions DQMServices/StreamerIO/plugins/RamdiskMonitor.cc
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include <filesystem>
#include <map>
#include <vector>
#include <sys/stat.h>

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include <fmt/printf.h>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem.hpp>
#include <boost/range.hpp>
#include <boost/regex.hpp>

#include "DQMServices/Core/interface/DQMOneEDAnalyzer.h"
#include "DQMServices/Core/interface/DQMStore.h"

#include "DQMServices/StreamerIO/plugins/DQMFileIterator.h"

#include <vector>
#include <map>
#include <sys/stat.h>

#include <boost/regex.hpp>
#include <boost/format.hpp>
#include <boost/range.hpp>
#include <filesystem>
#include <boost/algorithm/string/predicate.hpp>
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"

namespace dqm {
namespace rdm {
Expand Down Expand Up @@ -65,7 +63,7 @@ namespace dqm {
: runNumber_{ps.getUntrackedParameter<unsigned int>("runNumber")},
runInputDir_{ps.getUntrackedParameter<std::string>("runInputDir")},
streamLabels_{ps.getUntrackedParameter<std::vector<std::string>>("streamLabels")},
runPath_{str(boost::format("%s/run%06d") % runInputDir_ % runNumber_)}
runPath_{fmt::sprintf("%s/run%06d", runInputDir_, runNumber_)}

{}

Expand Down Expand Up @@ -110,7 +108,7 @@ namespace dqm {
if (global_start_ != 0)
return global_start_;

std::string run_global = str(boost::format("%s/.run%06d.global") % runInputDir_ % runNumber_);
std::string run_global = fmt::sprintf("%s/.run%06d.global", runInputDir_, runNumber_);
struct stat st;
if (::stat(run_global.c_str(), &st) != 0) {
edm::LogWarning("RamdiskMonitor") << "Stat failed: " << run_global;
Expand Down
22 changes: 10 additions & 12 deletions DQMServices/StreamerIO/test/DQMStreamerOutputRepackerTest.cc
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
#include "FWCore/Framework/interface/LuminosityBlockForOutput.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "IOPool/Streamer/interface/StreamerOutputModuleBase.h"
#include <iomanip>
#include <filesystem>
#include <memory>
#include <sstream>

#include <zlib.h>
#include <fmt/printf.h>
#include <boost/algorithm/string.hpp>
#include <filesystem>
#include <boost/format.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>

#include <iomanip>
#include <memory>
#include <sstream>

#include "EventFilter/Utilities/interface/FastMonitor.h"
#include "EventFilter/Utilities/interface/FastMonitoringService.h"
#include "EventFilter/Utilities/interface/FileIO.h"
#include "EventFilter/Utilities/interface/JSONSerializer.h"
#include "EventFilter/Utilities/interface/JsonMonitorable.h"
#include "FWCore/Framework/interface/LuminosityBlockForOutput.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/Utilities/interface/Adler32Calculator.h"

#include "IOPool/Streamer/interface/EventMessage.h"
#include "IOPool/Streamer/interface/EventMsgBuilder.h"
#include "IOPool/Streamer/interface/InitMessage.h"
#include "IOPool/Streamer/interface/InitMsgBuilder.h"
#include "IOPool/Streamer/interface/MsgTools.h"
#include "IOPool/Streamer/interface/StreamerOutputFile.h"
#include "IOPool/Streamer/interface/StreamerOutputModuleBase.h"

namespace dqmservices {

Expand Down Expand Up @@ -83,10 +81,10 @@ namespace dqmservices {

eventsProcessedFile_ = 0;

currentFileBase_ = str(boost::format("run%06d_ls%04d_stream%s_local") % run % lumi % streamLabel_);
currentFileBase_ = fmt::sprintf("run%06d_ls%04d_stream%s_local", run, lumi, streamLabel_);

std::filesystem::path p = outputPath_;
p /= str(boost::format("run%06d") % run);
p /= fmt::sprintf("run%06d", run);

std::filesystem::create_directories(p);

Expand Down
18 changes: 9 additions & 9 deletions DQMServices/StreamerIO/test/DQMStreamerWriteJsonAnalyzer.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include <filesystem>

#include <boost/algorithm/string.hpp>
#include <filesystem>
#include <boost/format.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <fmt/printf.h>

#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"

namespace dqmservices {
class DQMStreamerWriteJsonAnalyzer : public edm::one::EDAnalyzer<> {
Expand Down Expand Up @@ -38,7 +39,7 @@ namespace dqmservices {
nEventsSeenSinceWrite_{0},
fileIndex_{0} {
std::filesystem::path path = iPSet.getUntrackedParameter<std::string>("pathToWriteJson");
writePath_ /= str(boost::format("run%06d") % runNumber_);
writePath_ /= fmt::sprintf("run%06d", runNumber_);

std::filesystem::create_directories(writePath_);
}
Expand Down Expand Up @@ -68,8 +69,7 @@ namespace dqmservices {
}

void DQMStreamerWriteJsonAnalyzer::writeJson() const {
auto currentFileBase =
str(boost::format("run%06d_ls%04d_%s_local.jsn") % runNumber_ % (fileIndex_ + 2) % streamName_);
auto currentFileBase = fmt::sprintf("run%06d_ls%04d_%s_local.jsn", runNumber_, fileIndex_ + 2, streamName_);
auto currentJsonPath = (writePath_ / currentFileBase).string();

using namespace boost::property_tree;
Expand All @@ -95,7 +95,7 @@ namespace dqmservices {
}

void DQMStreamerWriteJsonAnalyzer::writeEndJob() const {
auto currentFileBase = str(boost::format("run%06d_ls%04d_EoR.jsn") % runNumber_ % 0);
auto currentFileBase = fmt::sprintf("run%06d_ls%04d_EoR.jsn", runNumber_, 0);
auto currentJsonPath = (writePath_ / currentFileBase).string();

using namespace boost::property_tree;
Expand Down

0 comments on commit 8cdb296

Please sign in to comment.