File indexing completed on 2024-04-06 12:10:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <boost/property_tree/json_parser.hpp>
0015 #include <boost/property_tree/ptree.hpp>
0016 #include <boost/format.hpp>
0017
0018 #include <string>
0019 #include <sstream>
0020 #include <filesystem>
0021
0022
0023 #include "FWCore/ServiceRegistry/interface/Service.h"
0024 #include "DQMServices/Components/interface/fillJson.h"
0025 #include "EventFilter/Utilities/interface/FastMonitoringService.h"
0026 #include "EventFilter/Utilities/interface/EvFDaqDirector.h"
0027 #include "FWCore/Utilities/interface/Exception.h"
0028
0029 boost::property_tree::ptree dqmfilesaver::fillJson(int run,
0030 int lumi,
0031 const std::string& dataFilePathName,
0032 const std::string& transferDestinationStr,
0033 const std::string& mergeTypeStr,
0034 evf::FastMonitoringService* fms) {
0035 namespace bpt = boost::property_tree;
0036
0037 bpt::ptree pt;
0038
0039 int hostnameReturn;
0040 char host[32];
0041 hostnameReturn = gethostname(host, sizeof(host));
0042 if (hostnameReturn == -1)
0043 throw cms::Exception("fillJson") << "Internal error, cannot get host name";
0044
0045 int pid = getpid();
0046 std::ostringstream oss_pid;
0047 oss_pid << pid;
0048
0049 int nProcessed = fms ? (fms->getEventsProcessedForLumi(lumi)) : -1;
0050
0051
0052 std::string dataFileName;
0053 struct stat dataFileStat;
0054 dataFileStat.st_size = 0;
0055 if (nProcessed) {
0056 if (stat(dataFilePathName.c_str(), &dataFileStat) != 0)
0057 throw cms::Exception("fillJson") << "Internal error, cannot get data file: " << dataFilePathName;
0058
0059 dataFileName = std::filesystem::path(dataFilePathName).filename().string();
0060 }
0061
0062 bpt::ptree data;
0063 bpt::ptree processedEvents, acceptedEvents, errorEvents, bitmask, fileList, fileSize, inputFiles, fileAdler32,
0064 transferDestination, mergeType, hltErrorEvents;
0065
0066 processedEvents.put("", nProcessed);
0067 acceptedEvents.put("", nProcessed);
0068
0069 errorEvents.put("", 0);
0070 bitmask.put("", 0);
0071 fileList.put("", dataFileName);
0072 fileSize.put("", dataFileStat.st_size);
0073 inputFiles.put("", "");
0074 fileAdler32.put("", -1);
0075 transferDestination.put("", transferDestinationStr);
0076 mergeType.put("", mergeTypeStr);
0077 hltErrorEvents.put("", 0);
0078
0079 data.push_back(std::make_pair("", processedEvents));
0080 data.push_back(std::make_pair("", acceptedEvents));
0081 data.push_back(std::make_pair("", errorEvents));
0082 data.push_back(std::make_pair("", bitmask));
0083 data.push_back(std::make_pair("", fileList));
0084 data.push_back(std::make_pair("", fileSize));
0085 data.push_back(std::make_pair("", inputFiles));
0086 data.push_back(std::make_pair("", fileAdler32));
0087 data.push_back(std::make_pair("", transferDestination));
0088 data.push_back(std::make_pair("", mergeType));
0089 data.push_back(std::make_pair("", hltErrorEvents));
0090
0091 pt.add_child("data", data);
0092
0093 if (fms == nullptr) {
0094 pt.put("definition", "/fakeDefinition.jsn");
0095 } else {
0096
0097 std::filesystem::path outJsonDefName{
0098 edm::Service<evf::EvFDaqDirector>()->baseRunDir()};
0099 outJsonDefName /= (std::string("output_") + oss_pid.str() + std::string(".jsd"));
0100 pt.put("definition", outJsonDefName.string());
0101 }
0102
0103 char sourceInfo[64];
0104 sprintf(sourceInfo, "%s_%d", host, pid);
0105 pt.put("source", sourceInfo);
0106
0107 return pt;
0108 }