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

Constructor & Destructor Documentation

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

Definition at line 749 of file hltDiff.cc.

749  :
750  writeJson(_writeJson),
751  out_filename_base(std::move(_file_name)) {
752  useSingleOutFile = out_filename_base.length() > 0;
753  }
std::string out_filename_base
Definition: hltDiff.cc:543
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 770 of file hltDiff.cc.

Referenced by HltDiff::compare().

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

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

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

Definition at line 495 of file hltDiff.cc.

References str, and AlCaHLTBitMon_QueryRunRegistry::string.

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

Definition at line 511 of file hltDiff.cc.

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

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

Definition at line 503 of file hltDiff.cc.

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

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

Definition at line 651 of file hltDiff.cc.

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

651  {
652  unsigned int id = std::find(vars.label.begin(), vars.label.end(), labelName) - vars.label.begin();
653  if (id < vars.label.size())
654  return id;
655  vars.label.push_back(labelName);
656  return vars.label.size()-1;
657  }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
std::vector< std::string > label
Definition: hltDiff.cc:621
static std::string JsonOutputProducer::list_string ( const std::vector< std::string > &  _values,
const std::string &  _delim = "" 
)
inlinestaticprivate

Definition at line 526 of file hltDiff.cc.

References str, and AlCaHLTBitMon_QueryRunRegistry::string.

526  {
527  std::string str = "[";
528  for (auto it = _values.begin(); it != _values.end(); ++it) {
529  str.append(_delim);
530  str.push_back('"');
531  str.append(*it);
532  str.push_back('"');
533  if (it != --_values.end()) str.push_back(',');
534  }
535  str.append(_delim);
536  str.push_back(']');
537 
538  return str;
539  }
#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 755 of file hltDiff.cc.

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

Referenced by HltDiff::compare().

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

Definition at line 518 of file hltDiff.cc.

References str, and AlCaHLTBitMon_QueryRunRegistry::string.

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

Definition at line 659 of file hltDiff.cc.

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

659  {
660  unsigned int id = std::find(vars.type.begin(), vars.type.end(), typeName) - vars.type.begin();
661  if (id < vars.type.size())
662  return id;
663  vars.type.push_back(typeName);
664  return vars.type.size()-1;
665  }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
std::vector< std::string > type
Definition: hltDiff.cc:622
void JsonOutputProducer::write ( )
inline

Definition at line 784 of file hltDiff.cc.

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

Referenced by HltDiff::compare().

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

Member Data Documentation

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

Definition at line 746 of file hltDiff.cc.

Referenced by SummaryOutputProducer::write().

std::string JsonOutputProducer::out_filename_base

Definition at line 543 of file hltDiff.cc.

size_t JsonOutputProducer::tab_spaces = 0
staticprivate

Definition at line 478 of file hltDiff.cc.

Referenced by write().

bool JsonOutputProducer::useSingleOutFile

Definition at line 544 of file hltDiff.cc.

JsonVars JsonOutputProducer::vars
bool JsonOutputProducer::writeJson

Definition at line 542 of file hltDiff.cc.