GENIEGenerator
Loading...
Searching...
No Matches
RegistryItem.cxx
Go to the documentation of this file.
1//____________________________________________________________________________
2/*
3 Copyright (c) 2003-2025, The GENIE Collaboration
4 For the full text of the license visit http://copyright.genie-mc.org
5
6 Costas Andreopoulos <c.andreopoulos \at cern.ch>
7 University of Liverpool
8*/
9//____________________________________________________________________________
10
11#include <string>
12#include <iostream>
13
15
16using std::string;
17using std::endl;
18
19namespace genie {
20
21//____________________________________________________________________________
22template ostream & operator <<
23 (ostream & stream, const RegistryItem<RgBool> & r);
24template ostream & operator <<
25 (ostream & stream, const RegistryItem<RgInt> & r);
26template ostream & operator <<
27 (ostream & stream, const RegistryItem<RgDbl> & r);
28template ostream & operator <<
29 (ostream & stream, const RegistryItem<RgStr> & r);
30template ostream & operator <<
31 (ostream & stream, const RegistryItem<RgAlg> & r);
32template ostream & operator <<
33 (ostream & stream, const RegistryItem<RgH1F> & r);
34template ostream & operator <<
35 (ostream & stream, const RegistryItem<RgH2F> & r);
36template ostream & operator <<
37 (ostream & stream, const RegistryItem<RgTree> & r);
38//____________________________________________________________________________
39template <typename T>
40 ostream & operator << (ostream & stream, const RegistryItem<T> & rec)
41{
42 rec.Print(stream);
43 return stream;
44}
45//____________________________________________________________________________
46template<typename T>
47 RegistryItem<T>::RegistryItem(T item, bool locked, bool local)
48{
49 fItem = item;
50 fIsLocked = locked;
51 fIsLocal = local;
52}
53//____________________________________________________________________________
54template<typename T> RegistryItem<T>::RegistryItem(const RegistryItem * ri)
55{
56 fItem = ri->fItem;
57 fIsLocked = ri->fIsLocked;
58 fIsLocal = ri->fIsLocal;
59}
60//____________________________________________________________________________
61template<typename T> RegistryItem<T>::~RegistryItem()
62{
63
64}
65//____________________________________________________________________________
67{
68 if (fItem) delete fItem;
69}
70//____________________________________________________________________________
72{
73 if (fItem) delete fItem;
74}
75//____________________________________________________________________________
77{
78 if (fItem) delete fItem;
79}
80//____________________________________________________________________________
81template<typename T> RegistryItemI * RegistryItem<T>::Clone(void) const
82{
84 return item;
85}
86//____________________________________________________________________________
88{
89 return kRgBool;
90}
91//____________________________________________________________________________
93{
94 return kRgInt;
95}
96//____________________________________________________________________________
98{
99 return kRgDbl;
100}
101//____________________________________________________________________________
103{
104 return kRgStr;
105}
106//____________________________________________________________________________
108{
109 return kRgAlg;
110}
111//____________________________________________________________________________
113{
114 return kRgH1F;
115}
116//____________________________________________________________________________
118{
119 return kRgH2F;
120}
121//____________________________________________________________________________
123{
124 return kRgTree;
125}
126//____________________________________________________________________________
127template<typename T> void RegistryItem<T>::Print(ostream & stream) const
128{
129 stream << ((fIsLocked) ? "[ locked]" : "[unlocked]")
130 << " "
131 << ((fIsLocal) ? "[l]" : "[g]")
132 << " : "
133 << (fItem);
134}
135//____________________________________________________________________________
136template<> void RegistryItem<RgAlg>::Print(ostream & stream) const
137{
138 stream << ((fIsLocked) ? "[ locked]" : "[unlocked]")
139 << " "
140 << ((fIsLocal) ? "[l]" : "[g]")
141 << " : "
142 << (fItem);
143}
144//____________________________________________________________________________
145template<> void RegistryItem<RgH1F>::Print(ostream & stream) const
146{
147 TH1F * histo = dynamic_cast<TH1F *>(fItem);
148 if(!histo) stream << "*** NULL RgH1F ***";
149
150 stream << ((fIsLocked) ? "[ locked]" : "[unlocked]")
151 << " "
152 << ((fIsLocal) ? "[l]" : "[g]")
153 << " : "
154 << (histo ? histo->GetName() : "NULL");
155}
156//____________________________________________________________________________
157template<> void RegistryItem<RgH2F>::Print(ostream & stream) const
158{
159 TH2F * histo = dynamic_cast<TH2F *>(fItem);
160 if(!histo) stream << "*** NULL RgH2F ***";
161
162 stream << ((fIsLocked) ? "[ locked]" : "[unlocked]")
163 << " "
164 << ((fIsLocal) ? "[l]" : "[g]")
165 << " : "
166 << (histo ? histo->GetName() : "NULL");
167}
168//____________________________________________________________________________
169template<> void RegistryItem<RgTree>::Print(ostream & stream) const
170{
171 TTree * tree = dynamic_cast<TTree *>(fItem);
172 if(!tree) stream << "*** NULL RgTree ***";
173
174 stream << ((fIsLocked) ? "[ locked]" : "[unlocked]")
175 << " "
176 << ((fIsLocal) ? "[l]" : "[g]")
177 << " : "
178 << (tree ? tree->GetName() : "NULL");
179}
180//____________________________________________________________________________
181
182// Declare all template specializations.
183// They need to be added at the end of the implementation file as described at
184// http://www.comeaucomputing.com/techtalk/templates/#whylinkerror
185// The need for them arises from the export C++ keyword not being properly
186// implemented at most C++ compilers. See http://gcc.gnu.org/bugs.html#known
187//
188template class RegistryItem<RgBool>;
189template class RegistryItem<RgInt>;
190template class RegistryItem<RgDbl>;
191template class RegistryItem<RgStr>;
192template class RegistryItem<RgAlg>;
193template class RegistryItem<RgH1F>;
194template class RegistryItem<RgH2F>;
195template class RegistryItem<RgTree>;
196
197//____________________________________________________________________________
198
199} // genie namespace
A templated concrete implementation of the RegistryItemI interface. Provides an arbitrary basic type ...
RgType_t TypeInfo(void) const
void Print(ostream &stream) const
RegistryItemI * Clone(void) const
THE MAIN GENIE PROJECT NAMESPACE
Definition AlgCmp.h:25
enum genie::ERgType RgType_t
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)