Logo ROOT  
Reference Guide
RNTupleMetrics.cxx
Go to the documentation of this file.
1 /// \file RNTupleMetrics.cxx
2 /// \ingroup NTuple ROOT7
3 /// \author Jakob Blomer <jblomer@cern.ch>
4 /// \date 2019-08-27
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6 /// is welcome!
7 
8 /*************************************************************************
9  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
10  * All rights reserved. *
11  * *
12  * For the licensing terms see $ROOTSYS/LICENSE. *
13  * For the list of contributors see $ROOTSYS/README/CREDITS. *
14  *************************************************************************/
15 
16 #include <ROOT/RNTupleMetrics.hxx>
17 
18 #include <ostream>
19 
20 #include <iostream>
21 
23 {
24 }
25 
27 {
28  return fName + kFieldSeperator + fUnit + kFieldSeperator + fDescription + kFieldSeperator + GetValueAsString();
29 }
30 
32 {
33  for (const auto &c : fCounters) {
34  if (c->GetName() == name)
35  return true;
36  }
37  return false;
38 }
39 
42 {
43  std::string prefix = fName + ".";
44  if (name.compare(0, prefix.length(), std::string_view(prefix)) != 0)
45  return nullptr;
46 
47  auto innerName = name.substr(prefix.length());
48  for (const auto &c : fCounters) {
49  if (c->GetName() == innerName)
50  return c.get();
51  }
52 
53  for (auto m : fObservedMetrics) {
54  auto counter = m->GetCounter(innerName);
55  if (counter != nullptr)
56  return counter;
57  }
58 
59  return nullptr;
60 }
61 
62 void ROOT::Experimental::Detail::RNTupleMetrics::Print(std::ostream &output, const std::string &prefix) const
63 {
64  if (!fIsEnabled) {
65  output << fName << " metrics disabled!" << std::endl;
66  return;
67  }
68 
69  for (const auto &c : fCounters) {
70  output << prefix << fName << kNamespaceSeperator << c->ToString() << std::endl;
71  }
72  for (const auto c : fObservedMetrics) {
73  c->Print(output, prefix + fName + ".");
74  }
75 }
76 
78 {
79  for (auto &c: fCounters)
80  c->Enable();
81  fIsEnabled = true;
82  for (auto m: fObservedMetrics)
83  m->Enable();
84 }
85 
87 {
88  fObservedMetrics.push_back(&observee);
89 }
c
#define c(i)
Definition: RSha256.hxx:119
m
auto * m
Definition: textangle.C:8
RNTupleMetrics.hxx
ROOT::Experimental::Detail::RNTupleMetrics
A collection of Counter objects with a name, a unit, and a description.
Definition: RNTupleMetrics.hxx:261
ROOT::Experimental::Detail::RNTuplePerfCounter::ToString
std::string ToString() const
Definition: RNTupleMetrics.cxx:26
output
static void output(int code)
Definition: gifencode.c:226
string_view
basic_string_view< char > string_view
Definition: libcpp_string_view.h:785
ROOT::Experimental::Detail::RNTupleMetrics::Enable
void Enable()
Definition: RNTupleMetrics.cxx:77
ROOT::Experimental::Detail::RNTuplePerfCounter::~RNTuplePerfCounter
virtual ~RNTuplePerfCounter()
Definition: RNTupleMetrics.cxx:22
ROOT::Experimental::Detail::RNTupleMetrics::Print
void Print(std::ostream &output, const std::string &prefix="") const
Definition: RNTupleMetrics.cxx:62
ROOT::Experimental::Detail::RNTuplePerfCounter
A performance counter with a name and a unit, which can be activated on demand.
Definition: RNTupleMetrics.hxx:65
name
char name[80]
Definition: TGX11.cxx:110
ROOT::Experimental::Detail::RNTupleMetrics::Contains
bool Contains(const std::string &name) const
Definition: RNTupleMetrics.cxx:31
ROOT::Experimental::Detail::RNTupleMetrics::GetCounter
const RNTuplePerfCounter * GetCounter(std::string_view name) const
Searches this object and all the observed sub metrics. Returns nullptr if name is not found.
Definition: RNTupleMetrics.cxx:41
ROOT::Experimental::Detail::RNTupleMetrics::ObserveMetrics
void ObserveMetrics(RNTupleMetrics &observee)
Definition: RNTupleMetrics.cxx:86