GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RegistryItem.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2024, 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 
16 using std::string;
17 using std::endl;
18 
19 namespace genie {
20 
21 //____________________________________________________________________________
22 template ostream & operator <<
23  (ostream & stream, const RegistryItem<RgBool> & r);
24 template ostream & operator <<
25  (ostream & stream, const RegistryItem<RgInt> & r);
26 template ostream & operator <<
27  (ostream & stream, const RegistryItem<RgDbl> & r);
28 template ostream & operator <<
29  (ostream & stream, const RegistryItem<RgStr> & r);
30 template ostream & operator <<
31  (ostream & stream, const RegistryItem<RgAlg> & r);
32 template ostream & operator <<
33  (ostream & stream, const RegistryItem<RgH1F> & r);
34 template ostream & operator <<
35  (ostream & stream, const RegistryItem<RgH2F> & r);
36 template ostream & operator <<
37  (ostream & stream, const RegistryItem<RgTree> & r);
38 //____________________________________________________________________________
39 template <typename T>
40  ostream & operator << (ostream & stream, const RegistryItem<T> & rec)
41 {
42  rec.Print(stream);
43  return stream;
44 }
45 //____________________________________________________________________________
46 template<typename T>
47  RegistryItem<T>::RegistryItem(T item, bool locked, bool local)
48 {
49  fItem = item;
50  fIsLocked = locked;
51  fIsLocal = local;
52 }
53 //____________________________________________________________________________
54 template<typename T> RegistryItem<T>::RegistryItem(const RegistryItem * ri)
55 {
56  fItem = ri->fItem;
57  fIsLocked = ri->fIsLocked;
58  fIsLocal = ri->fIsLocal;
59 }
60 //____________________________________________________________________________
61 template<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 //____________________________________________________________________________
81 template<typename T> RegistryItemI * RegistryItem<T>::Clone(void) const
82 {
83  RegistryItemI * item = new RegistryItem<T>(fItem,fIsLocked);
84  return item;
85 }
86 //____________________________________________________________________________
88 {
89  return kRgBool;
90 }
91 //____________________________________________________________________________
92 template<> RgType_t RegistryItem<RgInt>::TypeInfo (void) const
93 {
94  return kRgInt;
95 }
96 //____________________________________________________________________________
97 template<> RgType_t RegistryItem<RgDbl>::TypeInfo (void) const
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 //____________________________________________________________________________
127 template<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 //____________________________________________________________________________
136 template<> void RegistryItem<RgAlg>::Print(ostream & stream) const
137 {
138  stream << ((fIsLocked) ? "[ locked]" : "[unlocked]")
139  << " "
140  << ((fIsLocal) ? "[l]" : "[g]")
141  << " : "
142  << (fItem);
143 }
144 //____________________________________________________________________________
145 template<> 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 //____________________________________________________________________________
157 template<> 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 //____________________________________________________________________________
169 template<> 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 //
188 template class RegistryItem<RgBool>;
189 template class RegistryItem<RgInt>;
190 template class RegistryItem<RgDbl>;
191 template class RegistryItem<RgStr>;
192 template class RegistryItem<RgAlg>;
193 template class RegistryItem<RgH1F>;
194 template class RegistryItem<RgH2F>;
195 template class RegistryItem<RgTree>;
196 
197 //____________________________________________________________________________
198 
199 } // genie namespace
Registry item pABC.
Definition: RegistryItemI.h:29
enum genie::ERgType RgType_t
void Print(ostream &stream) const
RgType_t TypeInfo(void) const
RegistryItemI * Clone(void) const
A templated concrete implementation of the RegistryItemI interface. Provides an arbitrary basic type ...
Definition: RegistryItem.h:32