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
30 dqmfilesaver::fillJson(int run, int lumi, const std::string& dataFilePathName, const std::string& transferDestinationStr, const std::string& mergeTypeStr, evf::FastMonitoringService *fms)
31 {
32  namespace bpt = boost::property_tree;
33  namespace bfs = boost::filesystem;
34 
35  bpt::ptree pt;
36 
37  int hostnameReturn;
38  char host[32];
39  hostnameReturn = gethostname(host ,sizeof(host));
40  if (hostnameReturn == -1)
41  throw cms::Exception("fillJson")
42  << "Internal error, cannot get host name";
43 
44  int pid = getpid();
45  std::ostringstream oss_pid;
46  oss_pid << pid;
47 
48  int nProcessed = fms ? (fms->getEventsProcessedForLumi(lumi)) : -1;
49 
50  // Stat the data file: if not there, throw
51  std::string dataFileName;
52  struct stat dataFileStat;
53  dataFileStat.st_size=0;
54  if (nProcessed) {
55  if (stat(dataFilePathName.c_str(), &dataFileStat) != 0)
56  throw cms::Exception("fillJson")
57  << "Internal error, cannot get data file: "
58  << 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, 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  bfs::path outJsonDefName{edm::Service<evf::EvFDaqDirector>()->baseRunDir()}; //we assume this file is written bu the EvF Output module
98  outJsonDefName /= (std::string("output_") + oss_pid.str() + std::string(".jsd"));
99  pt.put("definition", outJsonDefName.string());
100  }
101 
102  char sourceInfo[64]; //host and pid information
103  sprintf(sourceInfo, "%s_%d", host, pid);
104  pt.put("source", sourceInfo);
105 
106  return pt;
107 }
host
Definition: query.py:115
unsigned int getEventsProcessedForLumi(unsigned int lumi, bool *abortFlag=0)
inputFiles
Definition: merge.py:6
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
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:30