CMS 3D CMS Logo

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

Classes

struct  JsonConfiguration
 
struct  JsonConfigurationBlock
 
struct  JsonEvent
 
struct  JsonEventState
 
struct  JsonTriggerEventState
 
struct  JsonVars
 

Public Member Functions

JsonEventState eventState (State _s, int _m, const std::string &_l, const std::string &_t)
 
 JsonOutputProducer (bool _writeJson, std::string _file_name)
 
std::string output_filename_base (int _run) const
 
JsonEventpushEvent (int _run, int _lumi, int _event)
 
void write ()
 

Public Attributes

JsonConfiguration configuration
 
std::map< int, std::vector< JsonEvent > > m_run_events
 
std::string out_filename_base
 
bool useSingleOutFile
 
JsonVars vars
 
bool writeJson
 

Private Member Functions

unsigned int labelId (std::string labelName)
 
unsigned int typeId (std::string typeName)
 

Static Private Member Functions

static std::string indent (size_t _nTabs)
 
static std::string key (const std::string &_key, const std::string &_delim="")
 
static std::string key_int (const std::string &_key, int _int, const std::string &_delim="")
 
static std::string key_string (const std::string &_key, const std::string &_string, const std::string &_delim="")
 
static std::string list_string (const std::vector< std::string > &_values, const std::string &_delim="")
 
static std::string string (const std::string &_string, const std::string &_delim="")
 

Static Private Attributes

static size_t tab_spaces = 0
 

Detailed Description

Definition at line 421 of file hltDiff.cc.

Constructor & Destructor Documentation

JsonOutputProducer::JsonOutputProducer ( bool  _writeJson,
std::string  _file_name 
)
inline

Definition at line 699 of file hltDiff.cc.

700  : writeJson(_writeJson), out_filename_base(std::move(_file_name)) {
701  useSingleOutFile = out_filename_base.length() > 0;
702  }
std::string out_filename_base
Definition: hltDiff.cc:489
def move(src, dest)
Definition: eostools.py:511

Member Function Documentation

JsonEventState JsonOutputProducer::eventState ( State  _s,
int  _m,
const std::string &  _l,
const std::string &  _t 
)
inline

Definition at line 719 of file hltDiff.cc.

Referenced by HltDiff::compare().

719  {
720  return JsonEventState(_s, _m, this->labelId(_l), this->typeId(_t));
721  }
unsigned int typeId(std::string typeName)
Definition: hltDiff.cc:608
unsigned int labelId(std::string labelName)
Definition: hltDiff.cc:600
static std::string JsonOutputProducer::indent ( size_t  _nTabs)
inlinestaticprivate

Definition at line 426 of file hltDiff.cc.

References str, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by ntuplePrintersDiff.TrackingParticlePrinter::_parentageChain(), ntuplePrintersDiff.SeedPrinter::printHits(), ntuplePrintersDiff.TrackPrinter::printHits(), and ntuplePrintersDiff.TrackingParticlePrinter::printTrackingParticle().

426  {
427  std::string str = "\n";
428  while (_nTabs) {
429  int nSpaces = tab_spaces;
430  while (nSpaces) {
431  str.push_back(' ');
432  nSpaces--;
433  }
434  _nTabs--;
435  }
436 
437  return str;
438  }
static size_t tab_spaces
Definition: hltDiff.cc:423
#define str(s)
static std::string JsonOutputProducer::key ( const std::string &  _key,
const std::string &  _delim = "" 
)
inlinestaticprivate

Definition at line 440 of file hltDiff.cc.

References str, and AlCaHLTBitMon_QueryRunRegistry::string.

440  {
441  std::string str = "\"\":";
442  str.insert(1, _key);
443  str.append(_delim);
444 
445  return str;
446  }
#define str(s)
static std::string JsonOutputProducer::key_int ( const std::string &  _key,
int  _int,
const std::string &  _delim = "" 
)
inlinestaticprivate

Definition at line 456 of file hltDiff.cc.

References crabWrapper::key, str, and AlCaHLTBitMon_QueryRunRegistry::string.

456  {
457  std::string str = key(_key, _delim);
458  str.append(std::to_string(_int));
459 
460  return str;
461  }
#define str(s)
static std::string key(const std::string &_key, const std::string &_delim="")
Definition: hltDiff.cc:440
static std::string JsonOutputProducer::key_string ( const std::string &  _key,
const std::string &  _string,
const std::string &  _delim = "" 
)
inlinestaticprivate

Definition at line 448 of file hltDiff.cc.

References crabWrapper::key, str, and AlCaHLTBitMon_QueryRunRegistry::string.

448  {
449  std::string str = key(_key, _delim);
450  str.push_back('"');
451  str.append(_string);
452  str.push_back('"');
453  return str;
454  }
#define str(s)
static std::string key(const std::string &_key, const std::string &_delim="")
Definition: hltDiff.cc:440
unsigned int JsonOutputProducer::labelId ( std::string  labelName)
inlineprivate

Definition at line 600 of file hltDiff.cc.

References spr::find(), and JsonOutputProducer::JsonVars::label.

600  {
601  unsigned int id = std::find(vars.label.begin(), vars.label.end(), labelName) - vars.label.begin();
602  if (id < vars.label.size())
603  return id;
604  vars.label.push_back(labelName);
605  return vars.label.size() - 1;
606  }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
vars
Definition: DeepTauId.cc:158
static std::string JsonOutputProducer::list_string ( const std::vector< std::string > &  _values,
const std::string &  _delim = "" 
)
inlinestaticprivate

Definition at line 471 of file hltDiff.cc.

References str, and AlCaHLTBitMon_QueryRunRegistry::string.

471  {
472  std::string str = "[";
473  for (auto it = _values.begin(); it != _values.end(); ++it) {
474  str.append(_delim);
475  str.push_back('"');
476  str.append(*it);
477  str.push_back('"');
478  if (it != --_values.end())
479  str.push_back(',');
480  }
481  str.append(_delim);
482  str.push_back(']');
483 
484  return str;
485  }
#define str(s)
std::string JsonOutputProducer::output_filename_base ( int  _run) const
inline
JsonEvent& JsonOutputProducer::pushEvent ( int  _run,
int  _lumi,
int  _event 
)
inline

Definition at line 704 of file hltDiff.cc.

References JsonOutputProducer::JsonEvent::event, callgrindSwitch_cfi::lastEvent, JsonOutputProducer::JsonEvent::lumi, and JsonOutputProducer::JsonEvent::run.

Referenced by HltDiff::compare().

704  {
705  // ensuring that this RUN is present in the producer
706  if ((m_run_events.count(_run) == 0 && !useSingleOutFile) || m_run_events.empty())
707  m_run_events.emplace(_run, std::vector<JsonEvent>());
708  std::vector<JsonEvent>& v_events = useSingleOutFile ? m_run_events.begin()->second : m_run_events.at(_run);
709  // check whether the last event is the one
710  if (!v_events.empty()) {
711  JsonEvent& lastEvent = v_events.back();
712  if (lastEvent.run == _run && lastEvent.lumi == _lumi && lastEvent.event == _event)
713  return lastEvent;
714  }
715  v_events.push_back(JsonEvent(_run, _lumi, _event));
716  return v_events.back();
717  }
std::map< int, std::vector< JsonEvent > > m_run_events
Definition: hltDiff.cc:696
static std::string JsonOutputProducer::string ( const std::string &  _string,
const std::string &  _delim = "" 
)
inlinestaticprivate

Definition at line 463 of file hltDiff.cc.

References str, and AlCaHLTBitMon_QueryRunRegistry::string.

463  {
464  std::string str = "\"\"";
465  str.insert(1, _string);
466  str.append(_delim);
467 
468  return str;
469  }
#define str(s)
unsigned int JsonOutputProducer::typeId ( std::string  typeName)
inlineprivate

Definition at line 608 of file hltDiff.cc.

References spr::find(), JsonOutputProducer::JsonVars::type, and dqmiodumpindices::typeName.

608  {
609  unsigned int id = std::find(vars.type.begin(), vars.type.end(), typeName) - vars.type.begin();
610  if (id < vars.type.size())
611  return id;
612  vars.type.push_back(typeName);
613  return vars.type.size() - 1;
614  }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
vars
Definition: DeepTauId.cc:158
void JsonOutputProducer::write ( )
inline

Definition at line 737 of file hltDiff.cc.

References gather_cfg::cout, corrVsCorr::filename, util.rrClient::indent, crabWrapper::key, MillePedeFileConverter_cfg::out, DeadROCCounter::out_file, writedatasetfile::run, JsonOutputProducer::JsonConfiguration::serialise(), JsonOutputProducer::JsonVars::serialise(), AlCaHLTBitMon_QueryRunRegistry::string, and tab_spaces.

Referenced by HltDiff::compare().

737  {
738  if (!writeJson)
739  return;
740  std::set<std::string> filesCreated;
741  std::ofstream out_file;
742  if (!m_run_events.empty()) {
743  // Creating a separate file for each run
744  for (const auto& runEvents : m_run_events) {
745  const int run = runEvents.first;
746  const std::vector<JsonEvent>& v_events = runEvents.second;
747  // Writing the output to a JSON file
748  std::string output_name = output_filename_base(run) += ".json";
749  out_file.open(output_name, std::ofstream::out);
750  out_file << '{'; // line open
751  out_file << configuration.serialise(1) << ',';
752  out_file << vars.serialise(1) << ',';
753  // writing block for each event
754  out_file << indent(1) << key("events") << '['; // line open
755  for (auto it = v_events.begin(); it != v_events.end(); ++it) {
756  out_file << (*it).serialise(2);
757  if (it != --v_events.end())
758  out_file << ',';
759  }
760  out_file << indent(1) << ']'; // line close
761  out_file << indent(0) << "}"; // line close
762  out_file.close();
763  // Adding file name to the list of created files
764  filesCreated.insert(output_name);
765  }
766  } else {
767  // Creating a single file containing with only configuration part
768  std::string output_name = output_filename_base(0) += ".json";
769  out_file.open(output_name, std::ofstream::out);
770  out_file << '{'; // line open
771  out_file << configuration.serialise(1) << ',';
772  out_file << vars.serialise(1) << ',';
773  // writing block for each event
774  out_file << indent(1) << key("events") << '['; // line open
775  // for (std::vector<JsonEvent>::const_iterator it = v_events.begin(); it != v_events.end(); ++it) {
776  // out_file << (*it).serialise(2);
777  // if (it != --v_events.end()) out_file << ',';
778  // }
779  out_file << indent(1) << ']'; // line close
780  out_file << indent(0) << "}"; // line close
781  out_file.close();
782  // Adding file name to the list of created files
783  filesCreated.insert(output_name);
784  }
785 
786  if (!filesCreated.empty()) {
787  std::cout << "Created the following JSON files:" << std::endl;
788  for (const std::string& filename : filesCreated)
789  std::cout << " " << filename << std::endl;
790  }
791  }
static std::string indent(size_t _nTabs)
Definition: hltDiff.cc:426
std::map< int, std::vector< JsonEvent > > m_run_events
Definition: hltDiff.cc:696
std::string output_filename_base(int _run) const
Definition: hltDiff.cc:723
std::string serialise(size_t _indent=0) const
Definition: hltDiff.cc:546
vars
Definition: DeepTauId.cc:158
JsonConfiguration configuration
Definition: hltDiff.cc:596
static std::string key(const std::string &_key, const std::string &_delim="")
Definition: hltDiff.cc:440

Member Data Documentation

JsonConfiguration JsonOutputProducer::configuration
std::map<int, std::vector<JsonEvent> > JsonOutputProducer::m_run_events

Definition at line 696 of file hltDiff.cc.

Referenced by SummaryOutputProducer::write().

std::string JsonOutputProducer::out_filename_base

Definition at line 489 of file hltDiff.cc.

size_t JsonOutputProducer::tab_spaces = 0
staticprivate

Definition at line 423 of file hltDiff.cc.

Referenced by write().

bool JsonOutputProducer::useSingleOutFile

Definition at line 490 of file hltDiff.cc.

JsonVars JsonOutputProducer::vars
bool JsonOutputProducer::writeJson

Definition at line 488 of file hltDiff.cc.