The Gaudi Framework  v38r3 (c3fc9673)
Gaudi::Histograming::Sink Namespace Reference

Namespaces

 details
 

Classes

class  Base
 
struct  Root
 
struct  Traits
 templated Traits dealing with Root Histogram filling for standard histograms More...
 
struct  Traits< false, RootHisto, N >
 Specialization of Traits dealing with non profile Root Histograms. More...
 
struct  Traits< true, RootHisto, N >
 Specialization of Traits dealing with profile Root Histograms. More...
 

Functions

template<typename Traits >
std::tuple< typename Traits::Histo, std::stringjsonToRootHistogram (std::string &dir, std::string &name, nlohmann::json const &j)
 generic function to convert json to a ROOT Histogram More...
 
template<typename Histo >
nlohmann::json rootHistogramTojson (Histo const &)
 generic function to convert a ROOT Histogram to json More...
 
template<typename Traits >
void saveRootHisto (TFile &file, std::string dir, std::string name, nlohmann::json const &j)
 generic method to save histograms to files, based on Traits More...
 
template<unsigned int N, bool isProfile, typename ROOTHisto >
void saveRootHisto (TFile &file, std::string dir, std::string name, nlohmann::json const &j)
 generic method to save regular histograms to files More...
 
template<Accumulators::atomicity Atomicity = Accumulators::atomicity::full, typename Arithmetic = double>
details::ProfileWrapper< TProfile > profileHisto1DToRoot (std::string name, Monitoring::Hub::Entity const &ent)
 Direct conversion of 1D histograms form Gaudi to ROOT format. More...
 
template<Accumulators::atomicity Atomicity = Accumulators::atomicity::full, typename Arithmetic = double>
details::ProfileWrapper< TProfile2D > profileHisto2DToRoot (std::string name, Monitoring::Hub::Entity const &ent)
 Direct conversion of 2D histograms form Gaudi to ROOT format. More...
 
template<Accumulators::atomicity Atomicity = Accumulators::atomicity::full, typename Arithmetic = double>
details::ProfileWrapper< TProfile3D > profileHisto3DToRoot (std::string name, Monitoring::Hub::Entity const &ent)
 Direct conversion of 3D histograms form Gaudi to ROOT format. More...
 
template<unsigned int N, Accumulators::atomicity Atomicity = Accumulators::atomicity::full, typename Arithmetic = double>
void saveProfileHisto (TFile &file, std::string dir, std::string name, Monitoring::Hub::Entity const &ent)
 

Function Documentation

◆ jsonToRootHistogram()

template<typename Traits >
std::tuple< typename Traits::Histo, std::string > Gaudi::Histograming::Sink::jsonToRootHistogram ( std::string dir,
std::string name,
nlohmann::json const &  j 
)

generic function to convert json to a ROOT Histogram

returns the Root histogram and the dir where to save it in the Root file This may be different from input dir in case name has slashes

Definition at line 392 of file Utils.h.

393  {
394  return details::jsonToRootHistogramInternal<Traits>( dir, name, j, std::make_index_sequence<Traits::Dimension>() );
395  }

◆ profileHisto1DToRoot()

template<Accumulators::atomicity Atomicity = Accumulators::atomicity::full, typename Arithmetic = double>
details::ProfileWrapper<TProfile> Gaudi::Histograming::Sink::profileHisto1DToRoot ( std::string  name,
Monitoring::Hub::Entity const &  ent 
)

Direct conversion of 1D histograms form Gaudi to ROOT format.

Definition at line 416 of file Utils.h.

416  {
417  // get original histogram from the Entity
418  auto const& gaudiHisto =
420  // convert to Root
421  auto const& gaudiAxis = gaudiHisto.axis()[0];
422  details::ProfileWrapper<TProfile> histo{ name.c_str(), gaudiHisto.title().c_str(), gaudiAxis.nBins,
423  gaudiAxis.minValue, gaudiAxis.maxValue };
424  histo.Sumw2();
425  unsigned long totNEntries{ 0 };
426  for ( unsigned int i = 0; i < gaudiHisto.totNBins(); i++ ) { totNEntries += gaudiHisto.nEntries( i ); }
427  if ( !gaudiAxis.labels.empty() ) {
428  auto& axis = *histo.GetXaxis();
429  for ( unsigned int i = 0; i < gaudiAxis.labels.size(); i++ ) {
430  axis.SetBinLabel( i + 1, gaudiAxis.labels[i].c_str() );
431  }
432  }
433  for ( unsigned int i = 0; i < gaudiHisto.totNBins(); i++ ) {
434  auto const& [tmp, sumw2] = gaudiHisto.binValue( i );
435  auto const& [nent, sumw] = tmp;
436  histo.SetBinContent( i, sumw );
437  histo.setBinNEntries( i, nent );
438  histo.setBinW2( i, sumw2 );
439  }
440  histo.SetEntries( totNEntries );
441  return histo;
442  }

◆ profileHisto2DToRoot()

template<Accumulators::atomicity Atomicity = Accumulators::atomicity::full, typename Arithmetic = double>
details::ProfileWrapper<TProfile2D> Gaudi::Histograming::Sink::profileHisto2DToRoot ( std::string  name,
Monitoring::Hub::Entity const &  ent 
)

Direct conversion of 2D histograms form Gaudi to ROOT format.

Definition at line 446 of file Utils.h.

446  {
447  // get original histogram from the Entity
448  auto const& gaudiHisto =
450  // convert to Root
451  auto const& gaudiXAxis = gaudiHisto.axis()[0];
452  auto const& gaudiYAxis = gaudiHisto.axis()[1];
453  details::ProfileWrapper<TProfile2D> histo{ name.c_str(), gaudiHisto.title().c_str(), gaudiXAxis.nBins,
454  gaudiXAxis.minValue, gaudiXAxis.maxValue, gaudiYAxis.nBins,
455  gaudiYAxis.minValue, gaudiYAxis.maxValue };
456  histo.Sumw2();
457  if ( !gaudiXAxis.labels.empty() ) {
458  auto& axis = *histo.GetXaxis();
459  for ( unsigned int i = 0; i < gaudiXAxis.labels.size(); i++ ) {
460  axis.SetBinLabel( i + 1, gaudiXAxis.labels[i].c_str() );
461  }
462  }
463  if ( !gaudiYAxis.labels.empty() ) {
464  auto& axis = *histo.GetYaxis();
465  for ( unsigned int i = 0; i < gaudiYAxis.labels.size(); i++ ) {
466  axis.SetBinLabel( i + 1, gaudiYAxis.labels[i].c_str() );
467  }
468  }
469  for ( unsigned int i = 0; i < gaudiHisto.totNBins(); i++ ) {
470  auto const& [tmp, sumw2] = gaudiHisto.binValue( i );
471  auto const& [nent, sumw] = tmp;
472  histo.SetBinContent( i, sumw );
473  histo.setBinNEntries( i, nent );
474  histo.setBinW2( i, sumw2 );
475  }
476  unsigned long totNEntries{ 0 };
477  for ( unsigned int i = 0; i < gaudiHisto.totNBins(); i++ ) { totNEntries += gaudiHisto.nEntries( i ); }
478  histo.SetEntries( totNEntries );
479  return histo;
480  }

◆ profileHisto3DToRoot()

template<Accumulators::atomicity Atomicity = Accumulators::atomicity::full, typename Arithmetic = double>
details::ProfileWrapper<TProfile3D> Gaudi::Histograming::Sink::profileHisto3DToRoot ( std::string  name,
Monitoring::Hub::Entity const &  ent 
)

Direct conversion of 3D histograms form Gaudi to ROOT format.

Definition at line 484 of file Utils.h.

484  {
485  // get original histogram from the Entity
486  auto const& gaudiHisto =
488  // convert to Root
489  auto const& gaudiXAxis = gaudiHisto.axis()[0];
490  auto const& gaudiYAxis = gaudiHisto.axis()[1];
491  auto const& gaudiZAxis = gaudiHisto.axis()[2];
492  details::ProfileWrapper<TProfile3D> histo{ name.c_str(), gaudiHisto.title().c_str(), gaudiXAxis.nBins,
493  gaudiXAxis.minValue, gaudiXAxis.maxValue, gaudiYAxis.nBins,
494  gaudiYAxis.minValue, gaudiYAxis.maxValue, gaudiZAxis.nBins,
495  gaudiZAxis.minValue, gaudiZAxis.maxValue };
496  histo.Sumw2();
497  if ( !gaudiXAxis.labels.empty() ) {
498  auto& axis = *histo.GetXaxis();
499  for ( unsigned int i = 0; i < gaudiXAxis.labels.size(); i++ ) {
500  axis.SetBinLabel( i + 1, gaudiXAxis.labels[i].c_str() );
501  }
502  }
503  if ( !gaudiYAxis.labels.empty() ) {
504  auto& axis = *histo.GetYaxis();
505  for ( unsigned int i = 0; i < gaudiYAxis.labels.size(); i++ ) {
506  axis.SetBinLabel( i + 1, gaudiYAxis.labels[i].c_str() );
507  }
508  }
509  if ( !gaudiZAxis.labels.empty() ) {
510  auto& axis = *histo.GetZaxis();
511  for ( unsigned int i = 0; i < gaudiZAxis.labels.size(); i++ ) {
512  axis.SetBinLabel( i + 1, gaudiZAxis.labels[i].c_str() );
513  }
514  }
515  for ( unsigned int i = 0; i < gaudiHisto.totNBins(); i++ ) {
516  auto const& [tmp, sumw2] = gaudiHisto.binValue( i );
517  auto const& [nent, sumw] = tmp;
518  histo.SetBinContent( i, sumw );
519  histo.setBinNEntries( i, nent );
520  histo.setBinW2( i, sumw2 );
521  }
522  unsigned long totNEntries{ 0 };
523  for ( unsigned int i = 0; i < gaudiHisto.totNBins(); i++ ) { totNEntries += gaudiHisto.nEntries( i ); }
524  histo.SetEntries( totNEntries );
525  return histo;
526  }

◆ rootHistogramTojson()

template<typename Histo >
nlohmann::json Gaudi::Histograming::Sink::rootHistogramTojson ( Histo const &  )

generic function to convert a ROOT Histogram to json

essentially used for backward compatibility of old HistogramService with MonitoringHub

◆ saveProfileHisto()

template<unsigned int N, Accumulators::atomicity Atomicity = Accumulators::atomicity::full, typename Arithmetic = double>
void Gaudi::Histograming::Sink::saveProfileHisto ( TFile &  file,
std::string  dir,
std::string  name,
Monitoring::Hub::Entity const &  ent 
)

Definition at line 530 of file Utils.h.

530  {
531  // fix name and dir if needed
533  // Change to the proper directory in the ROOT file
534  auto previousDir = details::changeDir( file, dir );
535  // write to file
536  if constexpr ( N == 1 ) {
537  profileHisto1DToRoot<Atomicity, Arithmetic>( name, ent ).Write();
538  } else if constexpr ( N == 2 ) {
539  profileHisto2DToRoot<Atomicity, Arithmetic>( name, ent ).Write();
540  } else if constexpr ( N == 3 ) {
541  profileHisto3DToRoot<Atomicity, Arithmetic>( name, ent ).Write();
542  }
543  // switch back to the previous directory
544  previousDir->cd();
545  }

◆ saveRootHisto() [1/2]

template<typename Traits >
void Gaudi::Histograming::Sink::saveRootHisto ( TFile &  file,
std::string  dir,
std::string  name,
nlohmann::json const &  j 
)

generic method to save histograms to files, based on Traits

Definition at line 398 of file Utils.h.

398  {
399  // get the Root histogram
400  auto [histo, newDir] = jsonToRootHistogram<Traits>( dir, name, j );
401  // Change to the proper directory in the ROOT file
402  auto previousDir = details::changeDir( file, newDir );
403  // write to file
404  histo.Write();
405  // switch back to the previous directory
406  previousDir->cd();
407  }

◆ saveRootHisto() [2/2]

template<unsigned int N, bool isProfile, typename ROOTHisto >
void Gaudi::Histograming::Sink::saveRootHisto ( TFile &  file,
std::string  dir,
std::string  name,
nlohmann::json const &  j 
)

generic method to save regular histograms to files

Can be used in most cases as the handler function to register into Sink::Base contains all the boiler plate code and redirects specific code to the adapted Traits template

Definition at line 410 of file Utils.h.

410  {
411  saveRootHisto<Traits<isProfile, ROOTHisto, N>>( file, std::move( dir ), std::move( name ), j );
412  }
IOTest.N
N
Definition: IOTest.py:112
std::move
T move(T... args)
Gaudi::Histograming::Sink::details::fixNameAndDir
void fixNameAndDir(std::string &name, std::string &dir)
handles cases where name includes '/' character(s) and move needed part of it to dir.
Definition: Utils.h:114
Gaudi::Histograming::Sink::details::changeDir
TDirectory * changeDir(TFile &file, std::string dir)
changes to the ROOT directory given in the current ROOT file and returns the current directory before...
Definition: Utils.h:264
ProduceConsume.j
j
Definition: ProduceConsume.py:101
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
Gaudi::Accumulators::HistogramingCounterBaseInternal
A base counter dealing with Histograms.
Definition: Histogram.h:464