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 474 of file hltDiff.cc.

Constructor & Destructor Documentation

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

Definition at line 748 of file hltDiff.cc.

748  :
749  writeJson(_writeJson),
750  out_filename_base(_file_name) {
751  useSingleOutFile = out_filename_base.length() > 0;
752  }
std::string out_filename_base
Definition: hltDiff.cc:542

Member Function Documentation

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

Definition at line 769 of file hltDiff.cc.

Referenced by HltDiff::compare().

769  {
770  return JsonEventState(_s, _m, this->labelId(_l), this->typeId(_t));
771  }
unsigned int typeId(std::string typeName)
Definition: hltDiff.cc:658
unsigned int labelId(std::string labelName)
Definition: hltDiff.cc:650
static std::string JsonOutputProducer::indent ( size_t  _nTabs)
inlinestaticprivate

Definition at line 480 of file hltDiff.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

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

Definition at line 494 of file hltDiff.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

494  {
495  std::string str = "\"\":";
496  str.insert(1, _key);
497  str.append(_delim);
498 
499  return str;
500  }
static std::string JsonOutputProducer::key_int ( const std::string &  _key,
int  _int,
const std::string &  _delim = "" 
)
inlinestaticprivate

Definition at line 510 of file hltDiff.cc.

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

510  {
511  std::string str = key(_key, _delim);
512  str.append(std::to_string(_int));
513 
514  return str;
515  }
static std::string key(const std::string &_key, const std::string &_delim="")
Definition: hltDiff.cc:494
static std::string JsonOutputProducer::key_string ( const std::string &  _key,
const std::string &  _string,
const std::string &  _delim = "" 
)
inlinestaticprivate

Definition at line 502 of file hltDiff.cc.

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

502  {
503  std::string str = key(_key, _delim);
504  str.push_back('"');
505  str.append(_string);
506  str.push_back('"');
507  return str;
508  }
static std::string key(const std::string &_key, const std::string &_delim="")
Definition: hltDiff.cc:494
unsigned int JsonOutputProducer::labelId ( std::string  labelName)
inlineprivate

Definition at line 650 of file hltDiff.cc.

References spr::find().

650  {
651  unsigned int id = std::find(vars.label.begin(), vars.label.end(), labelName) - vars.label.begin();
652  if (id < vars.label.size())
653  return id;
654  vars.label.push_back(labelName);
655  return vars.label.size()-1;
656  }
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:620
static std::string JsonOutputProducer::list_string ( const std::vector< std::string > &  _values,
const std::string &  _delim = "" 
)
inlinestaticprivate

Definition at line 525 of file hltDiff.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

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

Definition at line 773 of file hltDiff.cc.

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

773  {
774  if (useSingleOutFile)
775  return out_filename_base;
776 
777  char name[1000];
778  sprintf(name, "DQM_V0001_R%.9d__OLD_%s__NEW_%s_DQM", _run, configuration.o.process.c_str(), configuration.n.process.c_str());
779 
780  return std::string(name);
781  }
JsonConfigurationBlock o
Definition: hltDiff.cc:591
std::string out_filename_base
Definition: hltDiff.cc:542
JsonConfigurationBlock n
Definition: hltDiff.cc:592
JsonConfiguration configuration
Definition: hltDiff.cc:646
JsonEvent& JsonOutputProducer::pushEvent ( int  _run,
int  _lumi,
int  _event 
)
inline

Definition at line 754 of file hltDiff.cc.

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

Referenced by HltDiff::compare().

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

Definition at line 517 of file hltDiff.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

517  {
518  std::string str = "\"\"";
519  str.insert(1, _string);
520  str.append(_delim);
521 
522  return str;
523  }
unsigned int JsonOutputProducer::typeId ( std::string  typeName)
inlineprivate

Definition at line 658 of file hltDiff.cc.

References spr::find().

658  {
659  unsigned int id = std::find(vars.type.begin(), vars.type.end(), typeName) - vars.type.begin();
660  if (id < vars.type.size())
661  return id;
662  vars.type.push_back(typeName);
663  return vars.type.size()-1;
664  }
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:621
void JsonOutputProducer::write ( )
inline

Definition at line 783 of file hltDiff.cc.

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

Referenced by HltDiff::compare().

783  {
784  if (!writeJson) return;
785  std::set<std::string> filesCreated;
786  std::ofstream out_file;
787  if (m_run_events.size() > 0) {
788  // Creating a separate file for each run
789  for (const auto& runEvents : m_run_events) {
790  const int run = runEvents.first;
791  const std::vector<JsonEvent>& v_events = runEvents.second;
792  // Writing the output to a JSON file
793  std::string output_name = output_filename_base(run)+=".json";
794  out_file.open(output_name, std::ofstream::out);
795  out_file << '{'; // line open
796  out_file << configuration.serialise(1) << ',';
797  out_file << vars.serialise(1) << ',';
798  // writing block for each event
799  out_file << indent(1) << key("events") << '['; // line open
800  for (std::vector<JsonEvent>::const_iterator it = v_events.begin(); it != v_events.end(); ++it) {
801  out_file << (*it).serialise(2);
802  if (it != --v_events.end()) out_file << ',';
803  }
804  out_file << indent(1) << ']'; // line close
805  out_file << indent(0) << "}"; // line close
806  out_file.close();
807  // Adding file name to the list of created files
808  filesCreated.insert(output_name);
809  }
810  } else {
811  // Creating a single file containing with only configuration part
812  std::string output_name = output_filename_base(0)+=".json";
813  out_file.open(output_name, std::ofstream::out);
814  out_file << '{'; // line open
815  out_file << configuration.serialise(1) << ',';
816  out_file << vars.serialise(1) << ',';
817  // writing block for each event
818  out_file << indent(1) << key("events") << '['; // line open
819  // for (std::vector<JsonEvent>::const_iterator it = v_events.begin(); it != v_events.end(); ++it) {
820  // out_file << (*it).serialise(2);
821  // if (it != --v_events.end()) out_file << ',';
822  // }
823  out_file << indent(1) << ']'; // line close
824  out_file << indent(0) << "}"; // line close
825  out_file.close();
826  // Adding file name to the list of created files
827  filesCreated.insert(output_name);
828  }
829 
830  if (filesCreated.size() > 0) {
831  std::cout << "Created the following JSON files:" << std::endl;
832  for (const std::string& filename : filesCreated)
833  std::cout << " " << filename << std::endl;
834  }
835  }
static std::string indent(size_t _nTabs)
Definition: hltDiff.cc:480
std::map< int, std::vector< JsonEvent > > m_run_events
Definition: hltDiff.cc:745
std::string output_filename_base(int _run) const
Definition: hltDiff.cc:773
std::string serialise(size_t _indent=0) const
Definition: hltDiff.cc:623
std::string serialise(size_t _indent=0) const
Definition: hltDiff.cc:596
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:145
JsonConfiguration configuration
Definition: hltDiff.cc:646
static std::string key(const std::string &_key, const std::string &_delim="")
Definition: hltDiff.cc:494

Member Data Documentation

JsonConfiguration JsonOutputProducer::configuration

Definition at line 646 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 745 of file hltDiff.cc.

std::string JsonOutputProducer::out_filename_base

Definition at line 542 of file hltDiff.cc.

size_t JsonOutputProducer::tab_spaces = 0
staticprivate

Definition at line 477 of file hltDiff.cc.

bool JsonOutputProducer::useSingleOutFile

Definition at line 543 of file hltDiff.cc.

JsonVars JsonOutputProducer::vars

Definition at line 647 of file hltDiff.cc.

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

bool JsonOutputProducer::writeJson

Definition at line 541 of file hltDiff.cc.