Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:59:07

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