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

Constructor & Destructor Documentation

◆ JsonOutputProducer()

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

Definition at line 698 of file hltDiff.cc.

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

Member Function Documentation

◆ eventState()

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

Definition at line 718 of file hltDiff.cc.

References hgcalDigitizer_cfi::_m.

718  {
719  return JsonEventState(_s, _m, this->labelId(_l), this->typeId(_t));
720  }
unsigned int typeId(std::string typeName)
Definition: hltDiff.cc:607
unsigned int labelId(std::string labelName)
Definition: hltDiff.cc:599

◆ indent()

static std::string JsonOutputProducer::indent ( size_t  _nTabs)
inlinestaticprivate

Definition at line 425 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().

425  {
426  std::string str = "\n";
427  while (_nTabs) {
428  int nSpaces = tab_spaces;
429  while (nSpaces) {
430  str.push_back(' ');
431  nSpaces--;
432  }
433  _nTabs--;
434  }
435 
436  return str;
437  }
static size_t tab_spaces
Definition: hltDiff.cc:422
#define str(s)

◆ key()

static std::string JsonOutputProducer::key ( const std::string &  _key,
const std::string &  _delim = "" 
)
inlinestaticprivate

Definition at line 439 of file hltDiff.cc.

References str, and AlCaHLTBitMon_QueryRunRegistry::string.

439  {
440  std::string str = "\"\":";
441  str.insert(1, _key);
442  str.append(_delim);
443 
444  return str;
445  }
#define str(s)

◆ key_int()

static std::string JsonOutputProducer::key_int ( const std::string &  _key,
int  _int,
const std::string &  _delim = "" 
)
inlinestaticprivate

Definition at line 455 of file hltDiff.cc.

References submitPVResolutionJobs::key, str, AlCaHLTBitMon_QueryRunRegistry::string, and to_string().

455  {
456  std::string str = key(_key, _delim);
457  str.append(std::to_string(_int));
458 
459  return str;
460  }
static std::string to_string(const XMLCh *ch)
#define str(s)
static std::string key(const std::string &_key, const std::string &_delim="")
Definition: hltDiff.cc:439

◆ key_string()

static std::string JsonOutputProducer::key_string ( const std::string &  _key,
const std::string &  _string,
const std::string &  _delim = "" 
)
inlinestaticprivate

Definition at line 447 of file hltDiff.cc.

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

447  {
448  std::string str = key(_key, _delim);
449  str.push_back('"');
450  str.append(_string);
451  str.push_back('"');
452  return str;
453  }
#define str(s)
static std::string key(const std::string &_key, const std::string &_delim="")
Definition: hltDiff.cc:439

◆ labelId()

unsigned int JsonOutputProducer::labelId ( std::string  labelName)
inlineprivate

Definition at line 599 of file hltDiff.cc.

References spr::find(), and customiseL1CustomReco::labelName.

599  {
600  unsigned int id = std::find(vars.label.begin(), vars.label.end(), labelName) - vars.label.begin();
601  if (id < vars.label.size())
602  return id;
603  vars.label.push_back(labelName);
604  return vars.label.size() - 1;
605  }
vars
Definition: DeepTauIdBase.h:60
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
labelName
Custom Jet reco ####.

◆ list_string()

static std::string JsonOutputProducer::list_string ( const std::vector< std::string > &  _values,
const std::string &  _delim = "" 
)
inlinestaticprivate

Definition at line 470 of file hltDiff.cc.

References ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, str, and AlCaHLTBitMon_QueryRunRegistry::string.

470  {
471  std::string str = "[";
472  for (auto it = _values.begin(); it != _values.end(); ++it) {
473  str.append(_delim);
474  str.push_back('"');
475  str.append(*it);
476  str.push_back('"');
477  if (it != --_values.end())
478  str.push_back(',');
479  }
480  str.append(_delim);
481  str.push_back(']');
482 
483  return str;
484  }
#define str(s)

◆ output_filename_base()

std::string JsonOutputProducer::output_filename_base ( int  _run) const
inline

Definition at line 722 of file hltDiff.cc.

References JetHT_cfg::configuration, Skims_PA_cff::name, and AlCaHLTBitMon_QueryRunRegistry::string.

722  {
723  if (useSingleOutFile)
724  return out_filename_base;
725 
726  char name[1000];
727  sprintf(name,
728  "DQM_V0001_R%.9d__OLD_%s__NEW_%s_DQM",
729  _run,
730  configuration.o.process.c_str(),
731  configuration.n.process.c_str());
732 
733  return std::string(name);
734  }
JsonConfigurationBlock o
Definition: hltDiff.cc:540
std::string out_filename_base
Definition: hltDiff.cc:488
JsonConfigurationBlock n
Definition: hltDiff.cc:541
JsonConfiguration configuration
Definition: hltDiff.cc:595

◆ pushEvent()

JsonEvent& JsonOutputProducer::pushEvent ( int  _run,
int  _lumi,
int  _event 
)
inline

Definition at line 703 of file hltDiff.cc.

References callgrindSwitch_cfi::lastEvent.

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

◆ string()

static std::string JsonOutputProducer::string ( const std::string &  _string,
const std::string &  _delim = "" 
)
inlinestaticprivate

Definition at line 462 of file hltDiff.cc.

References str, and AlCaHLTBitMon_QueryRunRegistry::string.

462  {
463  std::string str = "\"\"";
464  str.insert(1, _string);
465  str.append(_delim);
466 
467  return str;
468  }
#define str(s)

◆ typeId()

unsigned int JsonOutputProducer::typeId ( std::string  typeName)
inlineprivate

Definition at line 607 of file hltDiff.cc.

References spr::find(), and dqmiodumpindices::typeName.

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

◆ write()

void JsonOutputProducer::write ( )
inline

Definition at line 736 of file hltDiff.cc.

References JetHT_cfg::configuration, gather_cfg::cout, corrVsCorr::filename, validateAlignments::indent, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, submitPVResolutionJobs::key, MillePedeFileConverter_cfg::out, DeadROCCounter::out_file, writedatasetfile::run, and AlCaHLTBitMon_QueryRunRegistry::string.

736  {
737  if (!writeJson)
738  return;
739  std::set<std::string> filesCreated, filesNotCreated;
740  std::ofstream out_file;
741  if (!m_run_events.empty()) {
742  // Creating a separate file for each run
743  for (const auto& runEvents : m_run_events) {
744  const int run = runEvents.first;
745  const std::vector<JsonEvent>& v_events = runEvents.second;
746  // Writing the output to a JSON file
747  std::string output_name = output_filename_base(run) += ".json";
748  out_file.open(output_name, std::ofstream::out);
749  if (out_file.good()) {
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  } else
766  filesNotCreated.insert(output_name);
767  }
768  } else {
769  // Creating a single file containing with only configuration part
770  std::string output_name = output_filename_base(0) += ".json";
771  out_file.open(output_name, std::ofstream::out);
772  if (out_file.good()) {
773  out_file << '{'; // line open
774  out_file << configuration.serialise(1) << ',';
775  out_file << vars.serialise(1) << ',';
776  // writing block for each event
777  out_file << indent(1) << key("events") << '['; // line open
778  // for (std::vector<JsonEvent>::const_iterator it = v_events.begin(); it != v_events.end(); ++it) {
779  // out_file << (*it).serialise(2);
780  // if (it != --v_events.end()) out_file << ',';
781  // }
782  out_file << indent(1) << ']'; // line close
783  out_file << indent(0) << "}"; // line close
784  out_file.close();
785  // Adding file name to the list of created files
786  filesCreated.insert(output_name);
787  } else
788  filesNotCreated.insert(output_name);
789  }
790 
791  if (!filesCreated.empty()) {
792  std::cout << "Created the following JSON files:" << std::endl;
793  for (const std::string& filename : filesCreated)
794  std::cout << " " << filename << std::endl;
795  }
796 
797  if (!filesNotCreated.empty()) {
798  std::cout << "Failed to create the following JSON files (check output directory and its permissions):"
799  << std::endl;
800  for (const std::string& filename : filesNotCreated)
801  std::cout << " " << filename << std::endl;
802  }
803  }
static std::string indent(size_t _nTabs)
Definition: hltDiff.cc:425
std::map< int, std::vector< JsonEvent > > m_run_events
Definition: hltDiff.cc:695
std::string output_filename_base(int _run) const
Definition: hltDiff.cc:722
vars
Definition: DeepTauIdBase.h:60
std::string serialise(size_t _indent=0) const
Definition: hltDiff.cc:545
JsonConfiguration configuration
Definition: hltDiff.cc:595
static std::string key(const std::string &_key, const std::string &_delim="")
Definition: hltDiff.cc:439

Member Data Documentation

◆ configuration

JsonConfiguration JsonOutputProducer::configuration

◆ m_run_events

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

Definition at line 695 of file hltDiff.cc.

◆ out_filename_base

std::string JsonOutputProducer::out_filename_base

Definition at line 488 of file hltDiff.cc.

◆ tab_spaces

size_t JsonOutputProducer::tab_spaces = 0
staticprivate

Definition at line 422 of file hltDiff.cc.

◆ useSingleOutFile

bool JsonOutputProducer::useSingleOutFile

Definition at line 489 of file hltDiff.cc.

◆ vars

JsonVars JsonOutputProducer::vars

Definition at line 596 of file hltDiff.cc.

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

◆ writeJson

bool JsonOutputProducer::writeJson

Definition at line 487 of file hltDiff.cc.