CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
SummaryOutputProducer Class Reference

Classes

struct  Event
 
struct  GenericSummary
 
struct  Pair
 
struct  TriggerSummary
 

Public Member Functions

 SummaryOutputProducer (const JsonOutputProducer &_json, bool _storeROOT, bool _storeCSV)
 
void write ()
 

Public Attributes

bool storeCSV
 
bool storeROOT
 

Private Member Functions

void prepareSummaries (const int _run, const std::vector< JsonOutputProducer::JsonEvent > &_events)
 
bool writeCSV_module (std::string &file_name) const
 
bool writeCSV_trigger (std::string &file_name) const
 
bool writeHistograms (std::string &file_name) const
 

Private Attributes

const JsonOutputProducerjson
 
std::map< int, GenericSummarym_moduleSummary
 
std::map< int, TriggerSummarym_triggerSummary
 
int run
 

Detailed Description

Definition at line 808 of file hltDiff.cc.

Constructor & Destructor Documentation

◆ SummaryOutputProducer()

SummaryOutputProducer::SummaryOutputProducer ( const JsonOutputProducer _json,
bool  _storeROOT,
bool  _storeCSV 
)
inline

Definition at line 1168 of file hltDiff.cc.

1169  : json(_json), run(0), storeROOT(_storeROOT), storeCSV(_storeCSV) {}
const JsonOutputProducer & json
Definition: hltDiff.cc:810

Member Function Documentation

◆ prepareSummaries()

void SummaryOutputProducer::prepareSummaries ( const int  _run,
const std::vector< JsonOutputProducer::JsonEvent > &  _events 
)
inlineprivate

Definition at line 934 of file hltDiff.cc.

References Fail, mps_fire::i, and gpuClustering::moduleId.

934  {
935  this->run = _run;
936  // Initialising the summary objects for trigger/module
937  m_triggerSummary.clear();
938  m_moduleSummary.clear();
939  const size_t nTriggers(json.vars.trigger.size());
940  const size_t nModules(json.vars.label.size());
941  for (size_t i = 0; i < nTriggers; ++i)
942  m_triggerSummary.emplace(i, TriggerSummary(i, json));
943  for (size_t i = 0; i < nModules; ++i)
944  m_moduleSummary.emplace(i, GenericSummary(i, json, json.vars.label));
945 
946  // Add each affected trigger in each event to the trigger/module summary objects
947  for (const JsonOutputProducer::JsonEvent& event : _events) {
948  for (size_t iTrigger = 0; iTrigger < event.triggerStates.size(); ++iTrigger) {
949  const JsonOutputProducer::JsonTriggerEventState& state = event.triggerStates.at(iTrigger);
950  m_triggerSummary.at(state.tr).addEntry(event, iTrigger, json.vars.label);
951  const int moduleId = state.o.s == State::Fail ? state.o.l : state.n.l;
952  m_moduleSummary.at(moduleId).addEntry(event, iTrigger);
953  }
954  }
955  }
nlohmann::json json
std::map< int, GenericSummary > m_moduleSummary
Definition: hltDiff.cc:932
std::map< int, TriggerSummary > m_triggerSummary
Definition: hltDiff.cc:931
Definition: hltDiff.cc:244
uint16_t *__restrict__ uint16_t const *__restrict__ uint32_t const *__restrict__ uint32_t *__restrict__ uint32_t const *__restrict__ moduleId
Definition: event.py:1

◆ write()

void SummaryOutputProducer::write ( )
inline

Definition at line 1171 of file hltDiff.cc.

References gather_cfg::cout, corrVsCorr::filename, isotrackTrainRegressor::fName, hltMonBTagIPClient_cfi::storeROOT, and AlCaHLTBitMon_QueryRunRegistry::string.

1171  {
1172  std::vector<std::string> filesCreated, filesNotCreated;
1173  // Processing every run from the JSON producer
1174  if (!json.m_run_events.empty()) {
1175  for (const auto& runEvents : json.m_run_events) {
1176  prepareSummaries(runEvents.first, runEvents.second);
1177  if (storeROOT) {
1179  auto& fNameVec = writeHistograms(fName) ? filesCreated : filesNotCreated;
1180  fNameVec.push_back(fName);
1181  }
1182  if (storeCSV) {
1183  std::string fNameTrigger;
1184  auto& fNameTriggerVec = writeCSV_trigger(fNameTrigger) ? filesCreated : filesNotCreated;
1185  fNameTriggerVec.push_back(fNameTrigger);
1186 
1187  std::string fNameModule;
1188  auto& fNameModuleVec = writeCSV_module(fNameModule) ? filesCreated : filesNotCreated;
1189  fNameModuleVec.push_back(fNameModule);
1190  }
1191  }
1192  } else {
1193  if (storeROOT) {
1195  auto& fNameVec = writeHistograms(fName) ? filesCreated : filesNotCreated;
1196  fNameVec.push_back(fName);
1197  }
1198  if (storeCSV) {
1199  std::string fNameTrigger;
1200  auto& fNameTriggerVec = writeCSV_trigger(fNameTrigger) ? filesCreated : filesNotCreated;
1201  fNameTriggerVec.push_back(fNameTrigger);
1202 
1203  std::string fNameModule;
1204  auto& fNameModuleVec = writeCSV_module(fNameModule) ? filesCreated : filesNotCreated;
1205  fNameModuleVec.push_back(fNameModule);
1206  }
1207  }
1208 
1209  if (!filesCreated.empty()) {
1210  std::cout << "Created the following summary files:" << std::endl;
1211  for (const std::string& filename : filesCreated)
1212  std::cout << " " << filename << std::endl;
1213  }
1214 
1215  if (!filesNotCreated.empty()) {
1216  std::cout << "Failed to create the following summary files (check output directory and its permissions):"
1217  << std::endl;
1218  for (const std::string& filename : filesNotCreated)
1219  std::cout << " " << filename << std::endl;
1220  }
1221  }
bool writeCSV_module(std::string &file_name) const
Definition: hltDiff.cc:1139
bool writeHistograms(std::string &file_name) const
Definition: hltDiff.cc:957
void prepareSummaries(const int _run, const std::vector< JsonOutputProducer::JsonEvent > &_events)
Definition: hltDiff.cc:934
nlohmann::json json
bool writeCSV_trigger(std::string &file_name) const
Definition: hltDiff.cc:1106

◆ writeCSV_module()

bool SummaryOutputProducer::writeCSV_module ( std::string &  file_name) const
inlineprivate

Definition at line 1139 of file hltDiff.cc.

References JsonOutputProducer::configuration, JsonOutputProducer::JsonConfiguration::events, isotrackNtuplerCondor::file_name, DeadROCCounter::out_file, and runTheMatrix::ret.

1139  {
1140  bool ret = false;
1141 
1142  file_name = json.output_filename_base(this->run) += "_module.csv";
1143  FILE* out_file = fopen(file_name.c_str(), "w");
1144 
1145  if (out_file) {
1146  fprintf(out_file, "Total,Gained,Lost,Changed,module\n");
1147  for (const auto& idSummary : m_moduleSummary) {
1148  const SummaryOutputProducer::GenericSummary& S = idSummary.second;
1149  fprintf(out_file,
1150  "%d,+%.f,-%.f,~%.f,%s\n",
1151  this->json.configuration.events,
1152  S.gained().v,
1153  S.lost().v,
1154  S.changed().v,
1155  S.name.c_str());
1156  }
1157  fclose(out_file);
1158  ret = true;
1159  }
1160 
1161  return ret;
1162  }
ret
prodAgent to be discontinued
nlohmann::json json
std::map< int, GenericSummary > m_moduleSummary
Definition: hltDiff.cc:932

◆ writeCSV_trigger()

bool SummaryOutputProducer::writeCSV_trigger ( std::string &  file_name) const
inlineprivate

Definition at line 1106 of file hltDiff.cc.

References JsonOutputProducer::configuration, JsonOutputProducer::JsonConfiguration::events, isotrackNtuplerCondor::file_name, DeadROCCounter::out_file, and runTheMatrix::ret.

1106  {
1107  bool ret = false;
1108 
1109  file_name = json.output_filename_base(this->run) += "_trigger.csv";
1110  FILE* out_file = fopen(file_name.c_str(), "w");
1111 
1112  if (out_file) {
1113  fprintf(out_file,
1114  "Total,Accepted OLD,Accepted NEW,Gained,Lost,|G|/A_N + "
1115  "|L|/AO,sigma(AN)+sigma(AO),Changed,C/(T-AO),sigma(T-AO),trigger\n");
1116  for (const auto& idSummary : m_triggerSummary) {
1117  const SummaryOutputProducer::TriggerSummary& S = idSummary.second;
1118  fprintf(out_file,
1119  "%d,%d,%d,%+.f,%+.f,%.2f%%,%.2f%%,~%.f,~%.2f%%,%.2f%%,%s\n",
1120  this->json.configuration.events,
1121  S.accepted_o,
1122  S.accepted_n,
1123  S.gained().v,
1124  -1.0 * S.lost().v,
1125  (S.gained(1).v + S.lost(1).v) * 100.0,
1126  (S.gained(1).e + S.lost(1).e) * 100.0,
1127  S.changed().v,
1128  S.changed(1).v * 100.0,
1129  S.changed(1).e * 100.0,
1130  S.name.c_str());
1131  }
1132  fclose(out_file);
1133  ret = true;
1134  }
1135 
1136  return ret;
1137  }
ret
prodAgent to be discontinued
nlohmann::json json
std::map< int, TriggerSummary > m_triggerSummary
Definition: hltDiff.cc:931

◆ writeHistograms()

bool SummaryOutputProducer::writeHistograms ( std::string &  file_name) const
inlineprivate

Definition at line 957 of file hltDiff.cc.

References newFWLiteAna::bin, isotrackNtuplerCondor::file_name, timingPdfMaker::histo, WZElectronSkims53X_cff::max, mergeVDriftHistosByStation::name, or, DeadROCCounter::out_file, AlCaHLTBitMon_QueryRunRegistry::string, and edmLumisInFiles::summary.

957  {
958  // Storing histograms to a ROOT file
959  file_name = json.output_filename_base(this->run) += ".root";
960  auto out_file = new TFile(file_name.c_str(), "RECREATE");
961  if (not out_file or out_file->IsZombie()) {
962  out_file->Close();
963  return false;
964  }
965 
966  std::map<std::string, TH1*> m_histo;
967  // Counting the numbers of bins for different types of histograms
968  // *_c - changed; *_gl - gained or lost
969  int nTriggers(0), nTriggers_c(0), nTriggers_gl(0), nModules_c(0), nModules_gl(0);
970 
971  for (const auto& idSummary : m_triggerSummary) {
972  if (idSummary.second.accepted_o > 0)
973  ++nTriggers;
974  if (idSummary.second.keepForGL())
975  ++nTriggers_gl;
976  if (idSummary.second.keepForC())
977  ++nTriggers_c;
978  }
979  for (const auto& idSummary : m_moduleSummary) {
980  if (idSummary.second.keepForGL())
981  ++nModules_gl;
982  if (idSummary.second.keepForC())
983  ++nModules_c;
984  }
985  // Manually increasing N bins to have histograms with meaningful axis ranges
986  nTriggers = std::max(1, nTriggers);
987  nTriggers_gl = std::max(1, nTriggers_gl);
988  nTriggers_c = std::max(1, nTriggers_c);
989  nModules_c = std::max(1, nModules_c);
990  nModules_gl = std::max(1, nModules_gl);
991 
992  // Initialising overview histograms
993  std::string name = "trigger_accepted";
994  m_histo.emplace(name, new TH1F(name.c_str(), ";;Events accepted^{OLD}", nTriggers, 0, nTriggers));
995  name = "trigger_gained";
996  m_histo.emplace(name, new TH1F(name.c_str(), ";;Events gained", nTriggers_gl, 0, nTriggers_gl));
997  name = "trigger_lost";
998  m_histo.emplace(name, new TH1F(name.c_str(), ";;Events lost", nTriggers_gl, 0, nTriggers_gl));
999  name = "trigger_changed";
1000  m_histo.emplace(name, new TH1F(name.c_str(), ";;Events changed", nTriggers_c, 0, nTriggers_c));
1001  name = "trigger_gained_frac";
1002  m_histo.emplace(name, new TH1F(name.c_str(), ";;#frac{gained}{accepted}", nTriggers_gl, 0, nTriggers_gl));
1003  name = "trigger_lost_frac";
1004  m_histo.emplace(name, new TH1F(name.c_str(), ";;#frac{lost}{accepted}", nTriggers_gl, 0, nTriggers_gl));
1005  name = "trigger_changed_frac";
1006  m_histo.emplace(name, new TH1F(name.c_str(), ";;#frac{changed}{all - accepted}", nTriggers_c, 0, nTriggers_c));
1007  name = "module_changed";
1008  m_histo.emplace(name, new TH1F(name.c_str(), ";;Events changed", nModules_c, 0, nModules_c));
1009  name = "module_gained";
1010  m_histo.emplace(name, new TH1F(name.c_str(), ";;Events gained", nModules_gl, 0, nModules_gl));
1011  name = "module_lost";
1012  m_histo.emplace(name, new TH1F(name.c_str(), ";;Events lost", nModules_gl, 0, nModules_gl));
1013 
1014  // Filling the per-trigger bins in the summary histograms
1015  size_t bin(0), bin_c(0), bin_gl(0);
1016  for (const auto& idSummary : m_triggerSummary) {
1017  const TriggerSummary& summary = idSummary.second;
1018  if (summary.accepted_o > 0) {
1019  ++bin;
1020  // Setting bin contents
1021  m_histo.at("trigger_accepted")->SetBinContent(bin, summary.accepted_o);
1022  // Setting bin labels
1023  m_histo.at("trigger_accepted")->GetXaxis()->SetBinLabel(bin, summary.name.c_str());
1024  }
1025  if (summary.keepForGL()) {
1026  ++bin_gl;
1027  // Setting bin contents
1028  m_histo.at("trigger_gained")->SetBinContent(bin_gl, summary.gained().v);
1029  m_histo.at("trigger_lost")->SetBinContent(bin_gl, -summary.lost().v);
1030  m_histo.at("trigger_gained_frac")->SetBinContent(bin_gl, summary.gained(1).v);
1031  m_histo.at("trigger_lost_frac")->SetBinContent(bin_gl, -summary.lost(1).v);
1032  // Setting bin errors
1033  m_histo.at("trigger_gained_frac")->SetBinError(bin_gl, summary.gained(1).e);
1034  m_histo.at("trigger_lost_frac")->SetBinError(bin_gl, -summary.lost(1).e);
1035  // Setting bin labels
1036  m_histo.at("trigger_gained")->GetXaxis()->SetBinLabel(bin_gl, summary.name.c_str());
1037  m_histo.at("trigger_lost")->GetXaxis()->SetBinLabel(bin_gl, summary.name.c_str());
1038  m_histo.at("trigger_gained_frac")->GetXaxis()->SetBinLabel(bin_gl, summary.name.c_str());
1039  m_histo.at("trigger_lost_frac")->GetXaxis()->SetBinLabel(bin_gl, summary.name.c_str());
1040  }
1041  if (summary.keepForC()) {
1042  ++bin_c;
1043  // Setting bin contents
1044  m_histo.at("trigger_changed")->SetBinContent(bin_c, summary.changed().v);
1045  m_histo.at("trigger_changed_frac")->SetBinContent(bin_c, summary.changed(1).v);
1046  // Setting bin errors
1047  m_histo.at("trigger_changed_frac")->SetBinError(bin_c, summary.changed(1).e);
1048  // Setting bin labels
1049  m_histo.at("trigger_changed")->GetXaxis()->SetBinLabel(bin_c, summary.name.c_str());
1050  m_histo.at("trigger_changed_frac")->GetXaxis()->SetBinLabel(bin_c, summary.name.c_str());
1051  }
1052  }
1053 
1054  // Filling the per-module bins in the summary histograms
1055  bin = 0;
1056  bin_c = 0;
1057  bin_gl = 0;
1058  for (const auto& idSummary : m_moduleSummary) {
1059  ++bin;
1060  const GenericSummary& summary = idSummary.second;
1061  if (summary.keepForGL()) {
1062  ++bin_gl;
1063  // Setting bin contents
1064  m_histo.at("module_gained")->SetBinContent(bin_gl, summary.gained().v);
1065  m_histo.at("module_lost")->SetBinContent(bin_gl, -summary.lost().v);
1066  // Setting bin labels
1067  m_histo.at("module_gained")->GetXaxis()->SetBinLabel(bin_gl, summary.name.c_str());
1068  m_histo.at("module_lost")->GetXaxis()->SetBinLabel(bin_gl, summary.name.c_str());
1069  }
1070  if (summary.keepForC()) {
1071  ++bin_c;
1072  // Setting bin contents
1073  m_histo.at("module_changed")->SetBinContent(bin_c, summary.changed().v);
1074  // Setting bin labels
1075  m_histo.at("module_changed")->GetXaxis()->SetBinLabel(bin_c, summary.name.c_str());
1076  }
1077  }
1078 
1079  // Styling the histograms
1080  for (const auto& nameHisto : m_histo) {
1081  const std::string name = nameHisto.first;
1082  TH1* histo = nameHisto.second;
1083  if (name.find("gained") != std::string::npos || name.find("changed") != std::string::npos) {
1084  if (name.find("frac") != std::string::npos)
1085  histo->GetYaxis()->SetRangeUser(0.0, 1.0);
1086  }
1087  if (name.find("lost") != std::string::npos) {
1088  if (name.find("frac") != std::string::npos)
1089  histo->GetYaxis()->SetRangeUser(-1.0, 0.0);
1090  }
1091  }
1092 
1093  // Storing the histograms in a proper folder according to the DQM convention
1094  char savePath[1000];
1095  sprintf(savePath, "DQMData/Run %d/HLT/Run summary/EventByEvent/", this->run);
1096  out_file->mkdir(savePath);
1097  gDirectory->cd(savePath);
1098  gDirectory->Write();
1099  for (const auto& nameHisto : m_histo)
1100  nameHisto.second->Write(nameHisto.first.c_str());
1101  out_file->Close();
1102 
1103  return true;
1104  }
nlohmann::json json
std::map< int, GenericSummary > m_moduleSummary
Definition: hltDiff.cc:932
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
std::map< int, TriggerSummary > m_triggerSummary
Definition: hltDiff.cc:931

Member Data Documentation

◆ json

const JsonOutputProducer& SummaryOutputProducer::json
private

Definition at line 810 of file hltDiff.cc.

Referenced by postprocessor.PostProcessor::run().

◆ m_moduleSummary

std::map<int, GenericSummary> SummaryOutputProducer::m_moduleSummary
private

Definition at line 932 of file hltDiff.cc.

◆ m_triggerSummary

std::map<int, TriggerSummary> SummaryOutputProducer::m_triggerSummary
private

Definition at line 931 of file hltDiff.cc.

◆ run

int SummaryOutputProducer::run
private

◆ storeCSV

bool SummaryOutputProducer::storeCSV

Definition at line 1166 of file hltDiff.cc.

◆ storeROOT

bool SummaryOutputProducer::storeROOT

Definition at line 1165 of file hltDiff.cc.