File indexing completed on 2021-02-14 13:13:54
0001 #include <filesystem>
0002
0003 #include <fmt/printf.h>
0004 #include <boost/property_tree/json_parser.hpp>
0005 #include <boost/property_tree/ptree.hpp>
0006
0007 #include "DQMServices/Components/interface/fillJson.h"
0008 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0009 #include "JsonWritingTimeoutPoolOutputModule.h"
0010
0011 namespace dqmservices {
0012
0013 JsonWritingTimeoutPoolOutputModule::JsonWritingTimeoutPoolOutputModule(edm::ParameterSet const& ps)
0014 : edm::one::OutputModuleBase::OutputModuleBase(ps), edm::TimeoutPoolOutputModule(ps) {
0015 runNumber_ = ps.getUntrackedParameter<uint32_t>("runNumber");
0016 outputPath_ = ps.getUntrackedParameter<std::string>("outputPath");
0017 streamLabel_ = ps.getUntrackedParameter<std::string>("streamLabel");
0018
0019 sequence_ = 0;
0020 }
0021
0022 std::pair<std::string, std::string> JsonWritingTimeoutPoolOutputModule::physicalAndLogicalNameForNewFile() {
0023 sequence_++;
0024
0025 std::string base = fmt::sprintf("run%06d_ls%04d_%s", runNumber_, sequence_, streamLabel_);
0026
0027 std::filesystem::path p(outputPath_);
0028
0029 currentFileName_ = (p / base).string() + ".root";
0030 currentJsonName_ = (p / base).string() + ".jsn";
0031
0032 return std::make_pair(currentFileName_, currentFileName_);
0033 }
0034
0035 void JsonWritingTimeoutPoolOutputModule::doExtrasAfterCloseFile() {
0036 std::string json_tmp_ = currentJsonName_ + ".open";
0037 std::string transferDest = "";
0038 std::string mergeType = "ROOT";
0039 auto pt = dqmfilesaver::fillJson(runNumber_, sequence_, currentFileName_, transferDest, mergeType, nullptr);
0040 write_json(json_tmp_, pt);
0041 rename(json_tmp_.c_str(), currentJsonName_.c_str());
0042 }
0043
0044 void JsonWritingTimeoutPoolOutputModule::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0045 edm::ParameterSetDescription desc;
0046 TimeoutPoolOutputModule::fillDescription(desc);
0047
0048 desc.setComment(
0049 "Almost same as TimeoutPoolOutputModule, but the output files names "
0050 "follow the FFF naming convention. Additionally a json 'description' "
0051 "file is emitted for every .root file written.");
0052
0053 desc.addUntracked<uint32_t>("runNumber", 0)
0054 ->setComment(
0055 "The run number, only used for file prefix: "
0056 "'run000001_lumi0000_...'.");
0057
0058 desc.addUntracked<std::string>("outputPath", "./")
0059 ->setComment(
0060 "Output path for the root and json files, usually the run "
0061 "directory.");
0062
0063 desc.addUntracked<std::string>("streamLabel", "streamEvDOutput")->setComment("Stream label, used for file suffix.");
0064
0065 descriptions.add("jsonWriting", desc);
0066 }
0067
0068 }
0069
0070 #include "FWCore/Framework/interface/MakerMacros.h"
0071 using dqmservices::JsonWritingTimeoutPoolOutputModule;
0072 DEFINE_FWK_MODULE(JsonWritingTimeoutPoolOutputModule);