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::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  }

Member Function Documentation

◆ eventState()

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

Definition at line 719 of file hltDiff.cc.

719  {
720  return JsonEventState(_s, _m, this->labelId(_l), this->typeId(_t));
721  }

References hgcalDigitizer_cfi::_m.

◆ indent()

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

Definition at line 426 of file hltDiff.cc.

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  }

References str, and AlCaHLTBitMon_QueryRunRegistry::string.

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

◆ key()

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

Definition at line 440 of file hltDiff.cc.

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

References str, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ key_int()

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.

456  {
457  std::string str = key(_key, _delim);
458  str.append(std::to_string(_int));
459 
460  return str;
461  }

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

◆ key_string()

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.

448  {
449  std::string str = key(_key, _delim);
450  str.push_back('"');
451  str.append(_string);
452  str.push_back('"');
453  return str;
454  }

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

◆ labelId()

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

Definition at line 600 of file hltDiff.cc.

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  }

References spr::find().

◆ list_string()

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.

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  }

References str, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ output_filename_base()

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

Definition at line 723 of file hltDiff.cc.

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

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

◆ pushEvent()

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

Definition at line 704 of file hltDiff.cc.

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  }

References callgrindSwitch_cfi::lastEvent.

◆ string()

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

Definition at line 463 of file hltDiff.cc.

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

References str, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ typeId()

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

Definition at line 608 of file hltDiff.cc.

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  }

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

◆ write()

void JsonOutputProducer::write ( )
inline

Definition at line 737 of file hltDiff.cc.

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  }

References ctppsRawToDigi_cff::configuration, gather_cfg::cout, corrVsCorr::filename, util.rrClient::indent, crabWrapper::key, MillePedeFileConverter_cfg::out, DeadROCCounter::out_file, writedatasetfile::run, and AlCaHLTBitMon_QueryRunRegistry::string.

Member Data Documentation

◆ configuration

JsonConfiguration JsonOutputProducer::configuration

◆ m_run_events

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

Definition at line 696 of file hltDiff.cc.

◆ out_filename_base

std::string JsonOutputProducer::out_filename_base

Definition at line 489 of file hltDiff.cc.

◆ tab_spaces

size_t JsonOutputProducer::tab_spaces = 0
staticprivate

Definition at line 423 of file hltDiff.cc.

◆ useSingleOutFile

bool JsonOutputProducer::useSingleOutFile

Definition at line 490 of file hltDiff.cc.

◆ vars

JsonVars JsonOutputProducer::vars

Definition at line 597 of file hltDiff.cc.

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

◆ writeJson

bool JsonOutputProducer::writeJson

Definition at line 488 of file hltDiff.cc.

JsonOutputProducer::tab_spaces
static size_t tab_spaces
Definition: hltDiff.cc:423
JsonOutputProducer::indent
static std::string indent(size_t _nTabs)
Definition: hltDiff.cc:426
JsonOutputProducer::m_run_events
std::map< int, std::vector< JsonEvent > > m_run_events
Definition: hltDiff.cc:696
gather_cfg.cout
cout
Definition: gather_cfg.py:144
JsonOutputProducer::labelId
unsigned int labelId(std::string labelName)
Definition: hltDiff.cc:600
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
JsonOutputProducer::JsonConfiguration::serialise
std::string serialise(size_t _indent=0) const
Definition: hltDiff.cc:546
hgcalDigitizer_cfi._m
_m
Definition: hgcalDigitizer_cfi.py:204
JsonOutputProducer::JsonConfiguration::o
JsonConfigurationBlock o
Definition: hltDiff.cc:541
vars
vars
Definition: DeepTauId.cc:158
JsonOutputProducer::key
static std::string key(const std::string &_key, const std::string &_delim="")
Definition: hltDiff.cc:440
str
#define str(s)
Definition: TestProcessor.cc:48
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
dqmiodumpindices.typeName
typeName
Definition: dqmiodumpindices.py:33
JsonOutputProducer::writeJson
bool writeJson
Definition: hltDiff.cc:488
callgrindSwitch_cfi.lastEvent
lastEvent
Definition: callgrindSwitch_cfi.py:5
JsonOutputProducer::JsonConfiguration::n
JsonConfigurationBlock n
Definition: hltDiff.cc:542
DeadROCCounter.out_file
out_file
Definition: DeadROCCounter.py:50
JsonOutputProducer::useSingleOutFile
bool useSingleOutFile
Definition: hltDiff.cc:490
JsonOutputProducer::JsonConfigurationBlock::process
std::string process
Definition: hltDiff.cc:495
JsonOutputProducer::output_filename_base
std::string output_filename_base(int _run) const
Definition: hltDiff.cc:723
eostools.move
def move(src, dest)
Definition: eostools.py:511
writedatasetfile.run
run
Definition: writedatasetfile.py:27
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
JsonOutputProducer::configuration
JsonConfiguration configuration
Definition: hltDiff.cc:596
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
JsonOutputProducer::typeId
unsigned int typeId(std::string typeName)
Definition: hltDiff.cc:608
JsonOutputProducer::out_filename_base
std::string out_filename_base
Definition: hltDiff.cc:489