KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVVarGlob.cpp
1#include "KVVarGlob.h"
2#include "KVClassFactory.h"
3#include "TObjString.h"
4
7/*
8
9*/
11
12//_________________________________________________________________
13
14
15
16void KVVarGlob::init(void)
17{
18 nameList.Clear();
19 // one-body variable by default
20 fType = kOneBody;
21 fValueType = 'D';
22 fMaxNumBranches = -1;
23 fIsInitialized = kFALSE;
24 fNormalization = 1.0;
25 fOptions.SetName("Options");
26 fParameters.SetName("Parameters");
27}
28
29
30
44
45void KVVarGlob::MakeClass(const Char_t* classname, const Char_t* classdesc, int type)
46{
47 // Creates skeleton '.h' and '.cpp' files for a new global variable class which
48 // inherits from this class. Give a name for the new class and a short description
49 // which will be used to document the class.
50 //
51 // By default the new class will be of type 1-body. A fill(const KVNucleus*) method
52 // will be generated which the user should complete.
53 //
54 // For a 2-body variable, call MakeClass with type = KVVarGlob::kTwoBody.
55 // A skeleton fill2(const KVNucleus*,const KVNucleus*) method will be generated.
56 //
57 // For a N-body variable, call MakeClass with type = KVVarGlob::kNBody.
58 // A skeleton fillN(KVEvent*) method will be generated.
59
60 KVClassFactory cf(classname, classdesc, "KVVarGlob", kTRUE);
61
62 KVString body;
63
64 // add 'init' method
68
69 // add 'fill', 'fill2', or 'FillN' method
71
72 // body of 'fill', 'fill2', or 'FillN' method
74
75 // add body of method
77
78 cf.GenerateCode();
79}
80
81
82
86
88{
89 // PRIVATE method used by MakeClass.
90 // body of 'fill', 'fill2', or 'FillN' method
91 switch (type) {
92 case kTwoBody:
93 body = "Calculation of contribution to 2-body global variable of pair (n1,n2) of nuclei.\n";
94 body += "NOTE: this method will be called once for each distinct pair of nuclei in the event\n";
95 body += "including pairs of identical nuclei (n1 = n2).\n";
96 body += "If you want to calculate a global variable using only each non-identical pair,\n";
97 body += "then make sure in your implementation that you check n1!=n2\n";
98 break;
99 case kNBody:
100 body = "Calculation of contribution to N-body global variable of particles in event e.\n";
101 break;
102 default:
103 body = "Calculation of contribution to 1-body global variable of nucleus n\n";
104 }
105}
106
107
108
110
112{
113 switch (type) {
114 case kTwoBody:
115 body = " fType = KVVarGlob::kTwoBody; // this is a 2-body variable\n";
116 break;
117 case kNBody:
118 body = " fType = KVVarGlob::kNBody; // this is a N-body variable\n";
119 break;
120 default:
121 body = " fType = KVVarGlob::kOneBody; // this is a 1-body variable\n";
122 }
123 cf.AddMethodBody("init", body);
124}
125
126
127
129
131{
132 body += "\n";
133 body += "You should also (if your variable calculates several different quantities)\n";
134 body += "set up a correspondance between named values and index number\n";
135 body += "using method SetNameIndex(const Char_t*,Int_t)\n";
136 body += "in order for GetValue(const Char_t*) to work correctly.\n";
137 body += "The index numbers should be the same as in your getvalue_int(Int_t) method.\n";
138 body += "\n";
139 cf.AddMethodComment("init", body);
140}
141
142
143
147
149{
150 // PRIVATE method used by MakeClass.
151 // add 'init' method
152 cf.AddMethod("init", "void", "private");
153 body = "Private initialisation method called by all constructors.\n";
154 body += "All member initialisations should be done here.\n";
155 cf.AddMethodComment("init", body);
156}
157
158
159
163
165{
166 // PRIVATE method used by MakeClass.
167 // add 'Fill', 'Fill2', or 'FillN' method
168 switch (type) {
169 case kTwoBody:
170 cf.AddMethod("fill2", "void", "protected");
171 cf.AddMethodArgument("fill2", "const KVNucleus*", "n1");
172 cf.AddMethodArgument("fill2", "const KVNucleus*", "n2");
173 break;
174 case kNBody:
175 cf.AddMethod("FillN", "void");
176 cf.AddMethodArgument("FillN", "const KVEvent*", "e");
177 cf.AddHeaderIncludeFile("KVEvent.h");
178 break;
179 default:
180 cf.AddMethod("fill", "void", "protected");
181 cf.AddMethodArgument("fill", "const KVNucleus*", "n");
182 }
183}
184
185
186
190
192{
193 // PRIVATE method used by MakeClass.
194 // add body of fill method
195 switch (type) {
196 case kTwoBody:
197 cf.AddMethodComment("fill2", body);
198 break;
199 case kNBody:
200 cf.AddMethodComment("FillN", body);
201 break;
202 default:
203 cf.AddMethodComment("fill", body);
204 }
205}
206
207
208
222
223void KVVarGlob::SetNameIndex(const Char_t* name, Int_t index)
224{
225 // For a multi-valued global variable, sets up the correspondance between value name and index.
226 //
227 // These can then be used to retrieve values with GetValue("name") or GetValue(index).
228 //
229 // When automatic branch creation in a TTree is used (see KVGVList::MakeBranches()), the names given
230 // to this method will be used to name the branches as:
231 // - [varName].[value0_name]
232 // - [varName].[value1_name]
233 // - ... etc.
234 //
235 // GetNumberOfValues() returns the number of values associated with the variable,
236 // corresponding to the number of name-index associations are created by calling this method.
237
238 if (!(nameList.HasParameter(name))) {
240 }
241 else {
242 Warning("SetNameIndex(const Char_t *name,Int_t index)",
243 "No link between \"%s\" and the index %d: the name already exists.",
244 name, index);
245 }
246}
247
248
249
253
255{
256 // \return the index corresponding to name
257 // \sa SetNameIndex()
258
259 Int_t index = 0;
262 }
263 else {
264 Warning("GetNameIndex(const Char_t *name)",
265 "The parameter \"%s\" does not exist fot the Class %s.\n 0 returned.",
266 name, ClassName());
267
268 }
269 return index;
270}
271
272
273
274
276
278{
279 printf("GLOBVAR: %s class=%s [", GetName(), ClassName());
280 switch (fType) {
281 case kOneBody:
282 printf("One-body variable]\n");
283 break;
284 case kTwoBody:
285 printf("Two-body variable]\n");
286 break;
287 case kNBody:
288 printf("N-body variable]\n");
289 break;
290 default:
291 printf("Variable type unknown!]\n");
292 }
293 if (GetNumberOfValues() > 1)
294 printf("- Multi-valued variable:\n");
295 else
296 printf("- Single-valued variable:\n");
297 printf("- Kinematics calculated in ");
298 if (fFrame != "") printf("%s", fFrame.Data());
299 else printf("default");
300 printf(" frame\n");
301 if (fOptions.GetNpar()) {
302 printf("- List of options:\n");
303 fOptions.Print();
304 }
305 if (fParameters.GetNpar()) {
306 printf("- List of parameters:\n");
308 }
309 if (fSelection.IsSet()) {
310 printf("- Particle selection criteria:\n");
312 }
313 printf("- Number of branches in TTree: %d\n", GetNumberOfBranches());
314 if (GetNumberOfValues() > 1) {
315 printf("- Available values:\n");
316 printf(" IND. NAME VALUE\n");
317 for (int i = 0; i < GetNumberOfValues(); ++i) {
319 printf(" %d %s %f\n", np->GetInt(), np->GetName(), GetValue(np->GetName()));
320 }
321 }
322 printf("\n");
323}
324
325
326
332
334{
335 // If called, any particle which is accepted by the selection conditions will be added
336 // to a group with the name of this variable.
337 //
338 // \param[in] groupname [optional] specify different name of group
339
341 if (groupname.IsNull()) SetOption("GROUP_NAME", GetName());
342 else SetOption("GROUP_NAME", groupname);
343}
344
345
346
int Int_t
char Char_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
const char Option_t
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
virtual void Clear(Option_t *opt="")
Clear object properties : name, type/title, number, label.
Definition KVBase.cpp:380
Factory class for generating skeleton files for new classes.
void AddMethodComment(const Char_t *method_name, const KVString &comment)
Set the comments for method 'method_name' added to the class using AddMethod.
void GenerateCode()
Generate header and implementation file for currently-defined class.
void AddHeaderIncludeFile(const Char_t *filename)
void AddMethodBody(const Char_t *method_name, const KVString &body)
void AddMethodArgument(const Char_t *method_name, const Char_t *argument_type, const Char_t *argument_name="", const Char_t *default_value="")
KVClassMethod * AddMethod(const Char_t *name, const Char_t *return_type, const Char_t *access="public", Bool_t isVirtual=kFALSE, Bool_t isConst=kFALSE)
virtual void Print(Option_t *opt="") const
KVNamedParameter * GetParameter(Int_t idx) const
return the parameter object with index idx
Int_t GetIntValue(const Char_t *name) const
void SetValue(const Char_t *name, value_type value)
Int_t GetNpar() const
return the number of stored parameters
Bool_t HasParameter(const Char_t *name) const
A generic named parameter storing values of different types.
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition KVString.h:73
void Print(Option_t *opt="") const
Base class for all global variable implementations.
Definition KVVarGlob.h:233
void SetOption(const Char_t *option, const Char_t *value)
Definition KVVarGlob.h:521
static void AddInitMethod(KVClassFactory &cf, KVString &body)
void Print(Option_t *="") const
Bool_t fDefineGroupFromSelection
Definition KVVarGlob.h:262
virtual Int_t GetNumberOfValues() const
Definition KVVarGlob.h:638
Double_t GetValue(void) const
Definition KVVarGlob.h:443
KVString fFrame
(optional) name of reference frame used for kinematics
Definition KVVarGlob.h:248
KVNameValueList fOptions
list of options
Definition KVVarGlob.h:249
void SetNameIndex(const Char_t *name, Int_t index)
Int_t GetNameIndex(const Char_t *name) const
static void MakeClass(const Char_t *classname, const Char_t *classdesc, int type=kOneBody)
Definition KVVarGlob.cpp:45
static void AddFillMethodBody(KVClassFactory &cf, KVString &body, int type)
static void ImplementInitMethod(KVClassFactory &cf, KVString &body, int type)
static void AddFillMethod(KVClassFactory &cf, int type)
static void FillMethodBody(KVString &body, int type)
Definition KVVarGlob.cpp:87
KVNameValueList nameList
correspondence between variable name and index
Definition KVVarGlob.h:246
Int_t GetNumberOfBranches() const
Definition KVVarGlob.h:644
KVParticleCondition fSelection
(optional) condition used to select particles
Definition KVVarGlob.h:251
KVNameValueList fParameters
list of parameters
Definition KVVarGlob.h:250
static void AddExtraInitMethodComment(KVClassFactory &cf, KVString &body)
Int_t fType
type of variable global; = kOneBody, kTwoBody or kNBody
Definition KVVarGlob.h:243
void SetDefineGroup(const KVString &groupname="")
const char * GetName() const override
virtual const char * ClassName() const
virtual void Warning(const char *method, const char *msgfmt,...) const
const char * Data() const
Bool_t IsNull() const
ClassImp(TPyArg)