CMS 3D CMS Logo

fillJson.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: DQMServices/Components
4 // Class : fillJson
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Christopher Jones
10 // Created: Thu, 08 Nov 2018 21:20:03 GMT
11 //
12 
13 // system include files
14 #include <boost/property_tree/json_parser.hpp>
15 #include <boost/property_tree/ptree.hpp>
16 #include <boost/format.hpp>
17 
18 #include <string>
19 #include <sstream>
20 #include <filesystem>
21 
22 // user include files
28 
29 boost::property_tree::ptree dqmfilesaver::fillJson(int run,
30  int lumi,
31  const std::string& dataFilePathName,
32  const std::string& transferDestinationStr,
33  const std::string& mergeTypeStr,
35  namespace bpt = boost::property_tree;
36 
37  bpt::ptree pt;
38 
39  int hostnameReturn;
40  char host[32];
41  hostnameReturn = gethostname(host, sizeof(host));
42  if (hostnameReturn == -1)
43  throw cms::Exception("fillJson") << "Internal error, cannot get host name";
44 
45  int pid = getpid();
46  std::ostringstream oss_pid;
47  oss_pid << pid;
48 
49  int nProcessed = fms ? (fms->getEventsProcessedForLumi(lumi)) : -1;
50 
51  // Stat the data file: if not there, throw
52  std::string dataFileName;
53  struct stat dataFileStat;
54  dataFileStat.st_size = 0;
55  if (nProcessed) {
56  if (stat(dataFilePathName.c_str(), &dataFileStat) != 0)
57  throw cms::Exception("fillJson") << "Internal error, cannot get data file: " << dataFilePathName;
58  // Extract only the data file name from the full path
59  dataFileName = std::filesystem::path(dataFilePathName).filename().string();
60  }
61  // The availability test of the FastMonitoringService was done in the ctor.
62  bpt::ptree data;
63  bpt::ptree processedEvents, acceptedEvents, errorEvents, bitmask, fileList, fileSize, inputFiles, fileAdler32,
64  transferDestination, mergeType, hltErrorEvents;
65 
66  processedEvents.put("", nProcessed); // Processed events
67  acceptedEvents.put("", nProcessed); // Accepted events, same as processed for our purposes
68 
69  errorEvents.put("", 0); // Error events
70  bitmask.put("", 0); // Bitmask of abs of CMSSW return code
71  fileList.put("", dataFileName); // Data file the information refers to
72  fileSize.put("", dataFileStat.st_size); // Size in bytes of the data file
73  inputFiles.put("", ""); // We do not care about input files!
74  fileAdler32.put("", -1); // placeholder to match output json definition
75  transferDestination.put("", transferDestinationStr); // SM Transfer destination field
76  mergeType.put("", mergeTypeStr); // Merging type for merger and transfer services
77  hltErrorEvents.put("", 0); // Error events
78 
79  data.push_back(std::make_pair("", processedEvents));
80  data.push_back(std::make_pair("", acceptedEvents));
81  data.push_back(std::make_pair("", errorEvents));
82  data.push_back(std::make_pair("", bitmask));
83  data.push_back(std::make_pair("", fileList));
84  data.push_back(std::make_pair("", fileSize));
85  data.push_back(std::make_pair("", inputFiles));
86  data.push_back(std::make_pair("", fileAdler32));
87  data.push_back(std::make_pair("", transferDestination));
88  data.push_back(std::make_pair("", mergeType));
89  data.push_back(std::make_pair("", hltErrorEvents));
90 
91  pt.add_child("data", data);
92 
93  if (fms == nullptr) {
94  pt.put("definition", "/fakeDefinition.jsn");
95  } else {
96  // The availability test of the EvFDaqDirector Service was done in the ctor.
97  std::filesystem::path outJsonDefName{
98  edm::Service<evf::EvFDaqDirector>()->baseRunDir()}; //we assume this file is written bu the EvF Output module
99  outJsonDefName /= (std::string("output_") + oss_pid.str() + std::string(".jsd"));
100  pt.put("definition", outJsonDefName.string());
101  }
102 
103  char sourceInfo[64]; //host and pid information
104  sprintf(sourceInfo, "%s_%d", host, pid);
105  pt.put("source", sourceInfo);
106 
107  return pt;
108 }
evf::FastMonitoringService::getEventsProcessedForLumi
unsigned int getEventsProcessedForLumi(unsigned int lumi, bool *abortFlag=nullptr)
Definition: FastMonitoringService.cc:726
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
fillJson.h
query.host
string host
Definition: query.py:115
evf::FastMonitoringService
Definition: FastMonitoringService.h:155
Service.h
dqmfilesaver::fillJson
boost::property_tree::ptree fillJson(int run, int lumi, const std::string &dataFilePathName, const std::string &transferDestinationStr, const std::string &mergeTypeStr, evf::FastMonitoringService *fms)
Definition: fillJson.cc:29
edm::Service
Definition: Service.h:30
EvFDaqDirector.h
FastMonitoringService.h
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
writedatasetfile.run
run
Definition: writedatasetfile.py:27
Exception
Definition: hltDiff.cc:245
Exception.h
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
submitPVValidationJobs.inputFiles
list inputFiles
Definition: submitPVValidationJobs.py:929
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
edm_modernize_messagelogger.stat
stat
Definition: edm_modernize_messagelogger.py:27
lumi
Definition: LumiSectionData.h:20