Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:08

0001 // -*- C++ -*-
0002 //
0003 // Package:     DQMServices/Components
0004 // Class  :     fillJson
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Christopher Jones
0010 //         Created:  Thu, 08 Nov 2018 21:20:03 GMT
0011 //
0012 
0013 // system include files
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 // user include files
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   // Stat the data file: if not there, throw
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     // Extract only the data file name from the full path
0059     dataFileName = std::filesystem::path(dataFilePathName).filename().string();
0060   }
0061   // The availability test of the FastMonitoringService was done in the ctor.
0062   bpt::ptree data;
0063   bpt::ptree processedEvents, acceptedEvents, errorEvents, bitmask, fileList, fileSize, inputFiles, fileAdler32,
0064       transferDestination, mergeType, hltErrorEvents;
0065 
0066   processedEvents.put("", nProcessed);  // Processed events
0067   acceptedEvents.put("", nProcessed);   // Accepted events, same as processed for our purposes
0068 
0069   errorEvents.put("", 0);                               // Error events
0070   bitmask.put("", 0);                                   // Bitmask of abs of CMSSW return code
0071   fileList.put("", dataFileName);                       // Data file the information refers to
0072   fileSize.put("", dataFileStat.st_size);               // Size in bytes of the data file
0073   inputFiles.put("", "");                               // We do not care about input files!
0074   fileAdler32.put("", -1);                              // placeholder to match output json definition
0075   transferDestination.put("", transferDestinationStr);  // SM Transfer destination field
0076   mergeType.put("", mergeTypeStr);                      // Merging type for merger and transfer services
0077   hltErrorEvents.put("", 0);                            // Error events
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     // The availability test of the EvFDaqDirector Service was done in the ctor.
0097     std::filesystem::path outJsonDefName{
0098         edm::Service<evf::EvFDaqDirector>()->baseRunDir()};  //we assume this file is written bu the EvF Output module
0099     outJsonDefName /= (std::string("output_") + oss_pid.str() + std::string(".jsd"));
0100     pt.put("definition", outJsonDefName.string());
0101   }
0102 
0103   char sourceInfo[64];  //host and pid information
0104   sprintf(sourceInfo, "%s_%d", host, pid);
0105   pt.put("source", sourceInfo);
0106 
0107   return pt;
0108 }