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/filesystem.hpp>
17 #include <boost/format.hpp>
18 
19 #include <string>
20 #include <sstream>
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  namespace bfs = boost::filesystem;
37 
38  bpt::ptree pt;
39 
40  int hostnameReturn;
41  char host[32];
42  hostnameReturn = gethostname(host, sizeof(host));
43  if (hostnameReturn == -1)
44  throw cms::Exception("fillJson") << "Internal error, cannot get host name";
45 
46  int pid = getpid();
47  std::ostringstream oss_pid;
48  oss_pid << pid;
49 
50  int nProcessed = fms ? (fms->getEventsProcessedForLumi(lumi)) : -1;
51 
52  // Stat the data file: if not there, throw
53  std::string dataFileName;
54  struct stat dataFileStat;
55  dataFileStat.st_size = 0;
56  if (nProcessed) {
57  if (stat(dataFilePathName.c_str(), &dataFileStat) != 0)
58  throw cms::Exception("fillJson") << "Internal error, cannot get data file: " << dataFilePathName;
59  // Extract only the data file name from the full path
60  dataFileName = bfs::path(dataFilePathName).filename().string();
61  }
62  // The availability test of the FastMonitoringService was done in the ctor.
63  bpt::ptree data;
64  bpt::ptree processedEvents, acceptedEvents, errorEvents, bitmask, fileList, fileSize, inputFiles, fileAdler32,
65  transferDestination, mergeType, hltErrorEvents;
66 
67  processedEvents.put("", nProcessed); // Processed events
68  acceptedEvents.put("", nProcessed); // Accepted events, same as processed for our purposes
69 
70  errorEvents.put("", 0); // Error events
71  bitmask.put("", 0); // Bitmask of abs of CMSSW return code
72  fileList.put("", dataFileName); // Data file the information refers to
73  fileSize.put("", dataFileStat.st_size); // Size in bytes of the data file
74  inputFiles.put("", ""); // We do not care about input files!
75  fileAdler32.put("", -1); // placeholder to match output json definition
76  transferDestination.put("", transferDestinationStr); // SM Transfer destination field
77  mergeType.put("", mergeTypeStr); // Merging type for merger and transfer services
78  hltErrorEvents.put("", 0); // Error events
79 
80  data.push_back(std::make_pair("", processedEvents));
81  data.push_back(std::make_pair("", acceptedEvents));
82  data.push_back(std::make_pair("", errorEvents));
83  data.push_back(std::make_pair("", bitmask));
84  data.push_back(std::make_pair("", fileList));
85  data.push_back(std::make_pair("", fileSize));
86  data.push_back(std::make_pair("", inputFiles));
87  data.push_back(std::make_pair("", fileAdler32));
88  data.push_back(std::make_pair("", transferDestination));
89  data.push_back(std::make_pair("", mergeType));
90  data.push_back(std::make_pair("", hltErrorEvents));
91 
92  pt.add_child("data", data);
93 
94  if (fms == nullptr) {
95  pt.put("definition", "/fakeDefinition.jsn");
96  } else {
97  // The availability test of the EvFDaqDirector Service was done in the ctor.
98  bfs::path outJsonDefName{
99  edm::Service<evf::EvFDaqDirector>()->baseRunDir()}; //we assume this file is written bu the EvF Output module
100  outJsonDefName /= (std::string("output_") + oss_pid.str() + std::string(".jsd"));
101  pt.put("definition", outJsonDefName.string());
102  }
103 
104  char sourceInfo[64]; //host and pid information
105  sprintf(sourceInfo, "%s_%d", host, pid);
106  pt.put("source", sourceInfo);
107 
108  return pt;
109 }
evf::FastMonitoringService::getEventsProcessedForLumi
unsigned int getEventsProcessedForLumi(unsigned int lumi, bool *abortFlag=nullptr)
Definition: FastMonitoringService.cc:708
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
fillJson.h
query.host
string host
Definition: query.py:115
evf::FastMonitoringService
Definition: FastMonitoringService.h:71
hgcalPlots.stat
stat
Definition: hgcalPlots.py:1119
Service.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
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
writedatasetfile.run
run
Definition: writedatasetfile.py:27
Exception
Definition: hltDiff.cc:246
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
lumi
Definition: LumiSectionData.h:20