Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooNameReg.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17/**
18\file RooNameReg.cxx
19\class RooNameReg
20\ingroup Roofitcore
21
22Registry for `const char*` names. For each unique
23name (which is not necessarily a unique pointer in the C++ standard),
24a unique pointer to a TNamed object is returned that can be used for
25fast searches and comparisons.
26**/
27
28#include "RooNameReg.h"
29
30#include <iostream>
31#include <memory>
32using std::make_unique;
33
34
36 TNamed("RooNameReg","RooFit Name Registry")
37{}
38
39////////////////////////////////////////////////////////////////////////////////
40/// Return reference to singleton instance
41
43{
44 static RooNameReg instance;
45 return instance;
46}
47
48
49////////////////////////////////////////////////////////////////////////////////
50/// Return a unique TNamed pointer for given C++ string
51
52const TNamed* RooNameReg::constPtr(const char* inStr)
53{
54 // Handle null pointer case explicitly
55 if (inStr==nullptr) return nullptr ;
56
57 // See if name is already registered ;
58 auto elm = _map.find(inStr) ;
59 if (elm != _map.end()) return elm->second.get();
60
61 // If not, register now
62 auto t = make_unique<TNamed>(inStr,inStr);
63 auto ret = t.get();
64 _map.emplace(std::string(inStr), std::move(t));
65
66 return ret;
67}
68
69
70////////////////////////////////////////////////////////////////////////////////
71/// Return a unique TNamed pointer for given C++ string
72
73const TNamed* RooNameReg::ptr(const char* stringPtr)
74{
75 if (stringPtr==nullptr) return nullptr ;
76 return instance().constPtr(stringPtr) ;
77}
78
79
80////////////////////////////////////////////////////////////////////////////////
81/// If the name is already known, return its TNamed pointer. Otherwise return 0 (don't register the name).
82
83const TNamed* RooNameReg::known(const char* inStr)
84{
85 // Handle null pointer case explicitly
86 if (inStr==nullptr) return nullptr ;
88 const auto elm = reg._map.find(inStr);
89 return elm != reg._map.end() ? elm->second.get() : nullptr;
90}
91
92
93////////////////////////////////////////////////////////////////////////////////
94/// The renaming counter has to be incremented every time a RooAbsArg is
95/// renamed. This is a protected function, and only the friend class RooAbsArg
96/// should call it when it gets renamed.
97
100}
101
102
103////////////////////////////////////////////////////////////////////////////////
104// Return a reference to a counter that keeps track how often a RooAbsArg was
105/// renamed in this RooFit process.
106
107const std::size_t& RooNameReg::renameCounter() {
108 return instance()._renameCounter;
109}
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void reg
Registry for const char* names.
Definition RooNameReg.h:26
std::unordered_map< std::string, std::unique_ptr< TNamed > > _map
Definition RooNameReg.h:56
static const TNamed * ptr(const char *stringPtr)
Return a unique TNamed pointer for given C++ string.
std::size_t _renameCounter
Definition RooNameReg.h:57
const TNamed * constPtr(const char *stringPtr)
Return a unique TNamed pointer for given C++ string.
static RooNameReg & instance()
Return reference to singleton instance.
static const TNamed * known(const char *stringPtr)
If the name is already known, return its TNamed pointer. Otherwise return 0 (don't register the name)...
static void incrementRenameCounter()
The renaming counter has to be incremented every time a RooAbsArg is renamed.
static const std::size_t & renameCounter()
renamed in this RooFit process.
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29