test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 469 of file hltDiff.cc.

Constructor & Destructor Documentation

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

Definition at line 743 of file hltDiff.cc.

743  :
744  writeJson(_writeJson),
745  out_filename_base(_file_name) {
746  useSingleOutFile = out_filename_base.length() > 0;
747  }
std::string out_filename_base
Definition: hltDiff.cc:537

Member Function Documentation

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

Definition at line 764 of file hltDiff.cc.

Referenced by HltDiff::compare().

764  {
765  return JsonEventState(_s, _m, this->labelId(_l), this->typeId(_t));
766  }
unsigned int typeId(std::string typeName)
Definition: hltDiff.cc:653
unsigned int labelId(std::string labelName)
Definition: hltDiff.cc:645
static std::string JsonOutputProducer::indent ( size_t  _nTabs)
inlinestaticprivate

Definition at line 475 of file hltDiff.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

475  {
476  std::string str = "\n";
477  while (_nTabs){
478  int nSpaces = tab_spaces;
479  while (nSpaces) {
480  str.push_back(' ');
481  nSpaces--;
482  }
483  _nTabs--;
484  }
485 
486  return str;
487  }
static size_t tab_spaces
Definition: hltDiff.cc:472
static std::string JsonOutputProducer::key ( const std::string &  _key,
const std::string &  _delim = "" 
)
inlinestaticprivate

Definition at line 489 of file hltDiff.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

489  {
490  std::string str = "\"\":";
491  str.insert(1, _key);
492  str.append(_delim);
493 
494  return str;
495  }
static std::string JsonOutputProducer::key_int ( const std::string &  _key,
int  _int,
const std::string &  _delim = "" 
)
inlinestaticprivate

Definition at line 505 of file hltDiff.cc.

References relval_steps::key, and AlCaHLTBitMon_QueryRunRegistry::string.

505  {
506  std::string str = key(_key, _delim);
507  str.append(std::to_string(_int));
508 
509  return str;
510  }
static std::string key(const std::string &_key, const std::string &_delim="")
Definition: hltDiff.cc:489
static std::string JsonOutputProducer::key_string ( const std::string &  _key,
const std::string &  _string,
const std::string &  _delim = "" 
)
inlinestaticprivate

Definition at line 497 of file hltDiff.cc.

References relval_steps::key, and AlCaHLTBitMon_QueryRunRegistry::string.

497  {
498  std::string str = key(_key, _delim);
499  str.push_back('"');
500  str.append(_string);
501  str.push_back('"');
502  return str;
503  }
static std::string key(const std::string &_key, const std::string &_delim="")
Definition: hltDiff.cc:489
unsigned int JsonOutputProducer::labelId ( std::string  labelName)
inlineprivate

Definition at line 645 of file hltDiff.cc.

References spr::find().

645  {
646  unsigned int id = std::find(vars.label.begin(), vars.label.end(), labelName) - vars.label.begin();
647  if (id < vars.label.size())
648  return id;
649  vars.label.push_back(labelName);
650  return vars.label.size()-1;
651  }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::vector< std::string > label
Definition: hltDiff.cc:615
static std::string JsonOutputProducer::list_string ( const std::vector< std::string > &  _values,
const std::string &  _delim = "" 
)
inlinestaticprivate

Definition at line 520 of file hltDiff.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

520  {
521  std::string str = "[";
522  for (std::vector<std::string>::const_iterator it = _values.begin(); it != _values.end(); ++it) {
523  str.append(_delim);
524  str.push_back('"');
525  str.append(*it);
526  str.push_back('"');
527  if (it != --_values.end()) str.push_back(',');
528  }
529  str.append(_delim);
530  str.push_back(']');
531 
532  return str;
533  }
std::string JsonOutputProducer::output_filename_base ( int  _run) const
inline

Definition at line 768 of file hltDiff.cc.

References cmsCodeRulesChecker::configuration, mergeVDriftHistosByStation::name, and AlCaHLTBitMon_QueryRunRegistry::string.

768  {
769  if (useSingleOutFile)
770  return out_filename_base;
771 
772  char name[1000];
773  sprintf(name, "DQM_V0001_R%.9d__OLD_%s__NEW_%s_DQM", _run, configuration.o.process.c_str(), configuration.n.process.c_str());
774 
775  return std::string(name);
776  }
JsonConfigurationBlock o
Definition: hltDiff.cc:586
std::string out_filename_base
Definition: hltDiff.cc:537
JsonConfigurationBlock n
Definition: hltDiff.cc:587
JsonConfiguration configuration
Definition: hltDiff.cc:641
JsonEvent& JsonOutputProducer::pushEvent ( int  _run,
int  _lumi,
int  _event 
)
inline

Definition at line 749 of file hltDiff.cc.

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

Referenced by HltDiff::compare().

749  {
750  // ensuring that this RUN is present in the producer
751  if ( (m_run_events.count(_run) == 0 && !useSingleOutFile) || m_run_events.size() == 0 )
752  m_run_events.emplace(_run, std::vector<JsonEvent>());
753  std::vector<JsonEvent>& v_events = useSingleOutFile ? m_run_events.begin()->second : m_run_events.at(_run);
754  // check whether the last event is the one
755  if (v_events.size() > 0) {
756  JsonEvent& lastEvent = v_events.back();
757  if (lastEvent.run == _run && lastEvent.lumi == _lumi && lastEvent.event == _event)
758  return lastEvent;
759  }
760  v_events.push_back(JsonEvent(_run, _lumi, _event));
761  return v_events.back();
762  }
std::map< int, std::vector< JsonEvent > > m_run_events
Definition: hltDiff.cc:740
static std::string JsonOutputProducer::string ( const std::string &  _string,
const std::string &  _delim = "" 
)
inlinestaticprivate

Definition at line 512 of file hltDiff.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

512  {
513  std::string str = "\"\"";
514  str.insert(1, _string);
515  str.append(_delim);
516 
517  return str;
518  }
unsigned int JsonOutputProducer::typeId ( std::string  typeName)
inlineprivate

Definition at line 653 of file hltDiff.cc.

References spr::find().

653  {
654  unsigned int id = std::find(vars.type.begin(), vars.type.end(), typeName) - vars.type.begin();
655  if (id < vars.type.size())
656  return id;
657  vars.type.push_back(typeName);
658  return vars.type.size()-1;
659  }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::vector< std::string > type
Definition: hltDiff.cc:616
void JsonOutputProducer::write ( )
inline

Definition at line 778 of file hltDiff.cc.

References cmsCodeRulesChecker::configuration, lut2db_cfg::filename, dataformats::indent(), relval_steps::key, GenerateHcalLaserBadRunList::out, DTTTrigCorrFirst::run, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by HltDiff::compare().

778  {
779  std::set<std::string> filesCreated;
780  for (const auto& runEvents : m_run_events) {
781  const int run = runEvents.first;
782  const std::vector<JsonEvent>& v_events = runEvents.second;
783  // Writing the output to a JSON file
784  std::ofstream out_file;
785  std::string output_name = output_filename_base(run)+=".json";
786  out_file.open(output_name, std::ofstream::out);
787  out_file << '{'; // line open
788  out_file << configuration.serialise(1) << ',';
789  out_file << vars.serialise(1) << ',';
790  // writing block for each event
791  out_file << indent(1) << key("events") << '['; // line open
792  for (std::vector<JsonEvent>::const_iterator it = v_events.begin(); it != v_events.end(); ++it) {
793  out_file << (*it).serialise(2);
794  if (it != --v_events.end()) out_file << ',';
795  }
796  out_file << indent(1) << ']'; // line close
797  out_file << indent(0) << "}"; // line close
798  out_file.close();
799  // Adding file name to the list of created files
800  filesCreated.insert(output_name);
801  }
802 
803  printf("Created the following JSON files:\n");
804  for (const std::string& filename : filesCreated)
805  printf(" %s\n", filename.c_str());
806  }
static std::string indent(size_t _nTabs)
Definition: hltDiff.cc:475
std::map< int, std::vector< JsonEvent > > m_run_events
Definition: hltDiff.cc:740
std::string output_filename_base(int _run) const
Definition: hltDiff.cc:768
std::string serialise(size_t _indent=0) const
Definition: hltDiff.cc:618
std::string serialise(size_t _indent=0) const
Definition: hltDiff.cc:591
tuple filename
Definition: lut2db_cfg.py:20
JsonConfiguration configuration
Definition: hltDiff.cc:641
static std::string key(const std::string &_key, const std::string &_delim="")
Definition: hltDiff.cc:489

Member Data Documentation

JsonConfiguration JsonOutputProducer::configuration

Definition at line 641 of file hltDiff.cc.

Referenced by HltDiff::compare(), and showPage.BuildViewer::showResults().

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

Definition at line 740 of file hltDiff.cc.

std::string JsonOutputProducer::out_filename_base

Definition at line 537 of file hltDiff.cc.

size_t JsonOutputProducer::tab_spaces = 0
staticprivate

Definition at line 472 of file hltDiff.cc.

bool JsonOutputProducer::useSingleOutFile

Definition at line 538 of file hltDiff.cc.

JsonVars JsonOutputProducer::vars

Definition at line 642 of file hltDiff.cc.

Referenced by HltDiff::compare(), tree.Tree::fill(), and tree.Tree::var().

bool JsonOutputProducer::writeJson

Definition at line 536 of file hltDiff.cc.