Logo ROOT  
Reference Guide
TListOfFunctionTemplates.cxx
Go to the documentation of this file.
1 // @(#)root/cont
2 // Author: Bianca-Cristina Cristescu March 2014
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2013, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class TListOfFunctionTemplates
13 A collection of TFunction objects designed for fast access given a
14 DeclId_t and for keep track of TFunction that were described
15 unloaded function.
16 */
17 
19 #include "TClass.h"
20 #include "TExMap.h"
21 #include "TFunction.h"
22 #include "TFunctionTemplate.h"
23 #include "TMethod.h"
24 #include "TInterpreter.h"
25 #include "TVirtualMutex.h"
26 
28 
29 ////////////////////////////////////////////////////////////////////////////////
30 /// Constructor.
31 
33  fUnloaded(0),fLastLoadMarker(0)
34 {
35  fIds = new TExMap;
36  fUnloaded = new THashList;
37 }
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// Destructor.
41 
43 {
45  delete fIds;
46  fUnloaded->Delete();
47  delete fUnloaded;
48 }
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// Add pair<id, object> to the map of functions and their ids.
52 
54 {
55  TFunctionTemplate *f = dynamic_cast<TFunctionTemplate*>(obj);
56  if (f) {
57  fIds->Add((Long64_t)f->GetDeclId(),(Long64_t)f);
58  }
59 }
60 
61 ////////////////////////////////////////////////////////////////////////////////
62 /// Add object at the beginning of the list.
63 
65 {
67  MapObject(obj);
68 }
69 
70 ////////////////////////////////////////////////////////////////////////////////
71 /// Add object at the beginning of the list and also store option.
72 /// Storing an option is useful when one wants to change the behaviour
73 /// of an object a little without having to create a complete new
74 /// copy of the object. This feature is used, for example, by the Draw()
75 /// method. It allows the same object to be drawn in different ways.
76 
78 {
79  THashList::AddFirst(obj,opt);
80  MapObject(obj);
81 }
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 /// Add object at the end of the list.
85 
87 {
88  THashList::AddLast(obj);
89  MapObject(obj);
90 }
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// Add object at the end of the list and also store option.
94 /// Storing an option is useful when one wants to change the behaviour
95 /// of an object a little without having to create a complete new
96 /// copy of the object. This feature is used, for example, by the Draw()
97 /// method. It allows the same object to be drawn in different ways.
98 
100 {
101  THashList::AddLast(obj, opt);
102  MapObject(obj);
103 }
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// Insert object at location idx in the list.
107 
109 {
110  THashList::AddAt(obj, idx);
111  MapObject(obj);
112 }
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 /// Insert object after object after in the list.
116 
118 {
119  THashList::AddAfter(after, obj);
120  MapObject(obj);
121 }
122 
123 ////////////////////////////////////////////////////////////////////////////////
124 /// Insert object after object after in the list.
125 
127 {
128  THashList::AddAfter(after, obj);
129  MapObject(obj);
130 }
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// Insert object before object before in the list.
134 
136 {
137  THashList::AddBefore(before, obj);
138  MapObject(obj);
139 }
140 
141 ////////////////////////////////////////////////////////////////////////////////
142 /// Insert object before object before in the list.
143 
145 {
146  THashList::AddBefore(before, obj);
147  MapObject(obj);
148 }
149 
150 ////////////////////////////////////////////////////////////////////////////////
151 /// Remove all objects from the list. Does not delete the objects unless
152 /// the THashList is the owner (set via SetOwner()).
153 
155 {
156  fUnloaded->Clear(option);
157  fIds->Clear();
158  THashList::Clear(option);
159 }
160 
161 ////////////////////////////////////////////////////////////////////////////////
162 /// Delete all TFunction object files.
163 
165 {
166  fUnloaded->Delete(option);
167  fIds->Clear();
168  THashList::Delete(option);
169 }
170 
171 ////////////////////////////////////////////////////////////////////////////////
172 /// Specialize FindObject to do search for the
173 /// a function just by name or create it if its not already in the list
174 
176 {
178  if (!result) {
179 
181 
183  if (fClass) decl = gInterpreter->GetFunctionTemplate(fClass->GetClassInfo(),name);
184  else decl = gInterpreter->GetFunctionTemplate(0,name);
185  if (decl) result = const_cast<TListOfFunctionTemplates*>(this)->Get(decl);
186  }
187  return result;
188 }
189 
190 ////////////////////////////////////////////////////////////////////////////////
191 /// Return the set of overloads for this name, collecting all available ones.
192 /// Can construct and insert new TFunction-s.
193 
195 {
197 
198  TList* overloads = (TList*)fOverloads.FindObject(name);
199  TExMap overloadsSet;
200  Bool_t wasEmpty = true;
201  if (!overloads) {
202  overloads = new TList();
203  overloads->SetName(name);
204  fOverloads.Add(overloads);
205  } else {
206  TIter iOverload(overloads);
207  while (TFunctionTemplate* over = (TFunctionTemplate*)iOverload()) {
208  wasEmpty = false;
209  overloadsSet.Add((Long64_t)(ULong64_t)over->GetDeclId(),
210  (Long64_t)(ULong64_t)over);
211  }
212  }
213 
214  // Update if needed.
215  std::vector<DeclId_t> overloadDecls;
216  ClassInfo_t* ci = fClass ? fClass->GetClassInfo() : 0;
217  gInterpreter->GetFunctionOverloads(ci, name, overloadDecls);
218  for (std::vector<DeclId_t>::const_iterator iD = overloadDecls.begin(),
219  eD = overloadDecls.end(); iD != eD; ++iD) {
220  TFunctionTemplate* over = Get(*iD);
221  if (wasEmpty || !overloadsSet.GetValue((Long64_t)(ULong64_t)over->GetDeclId())) {
222  overloads->Add(over);
223  }
224  }
225 
226  return overloads;
227 }
228 
229 ////////////////////////////////////////////////////////////////////////////////
230 /// Return the set of overloads for this name, collecting all available ones.
231 /// Can construct and insert new TFunction-s.
232 
234 {
235  return const_cast<TListOfFunctionTemplates*>(this)->GetListForObjectNonConst(name);
236 }
237 
238 ////////////////////////////////////////////////////////////////////////////////
239 /// Return the set of overloads for function obj, collecting all available ones.
240 /// Can construct and insert new TFunction-s.
241 
243 {
244  if (!obj) return 0;
245  return const_cast<TListOfFunctionTemplates*>(this)
247 }
248 
249 ////////////////////////////////////////////////////////////////////////////////
250 /// Return (after creating it if necessary) the TMethod or TFunction
251 /// describing the function corresponding to the Decl 'id'.
252 
254 {
255  if (!id) return 0;
256 
258  if (!f) {
259  if (fClass) {
260  if (!gInterpreter->ClassInfo_Contains(fClass->GetClassInfo(),id)) return 0;
261  } else {
262  if (!gInterpreter->ClassInfo_Contains(0,id)) return 0;
263  }
264 
266 
267  FuncTempInfo_t *m = gInterpreter->FuncTempInfo_Factory(id);
268 
269  // Let's see if this is a reload ...
270  TString name;
271  gInterpreter->FuncTempInfo_Name(m, name);
273  if (update) {
275  update->Update(m);
276  f = update;
277  }
278  if (!f) {
279  if (fClass) f = new TFunctionTemplate(m, fClass);
280  else f = new TFunctionTemplate(m, 0);
281  }
282  // Calling 'just' THahList::Add would turn around and call
283  // TListOfFunctionTemplates::AddLast which should *also* do the fIds->Add.
285  fIds->Add((Long64_t)id,(Long64_t)f);
286  }
287  return f;
288 }
289 
290 ////////////////////////////////////////////////////////////////////////////////
291 /// Remove a pair<id, object> from the map of functions and their ids.
292 
294 {
295  TFunctionTemplate *f = dynamic_cast<TFunctionTemplate*>(obj);
296  if (f) {
297  fIds->Remove((Long64_t)f->GetDeclId());
298  }
299 }
300 
301 ////////////////////////////////////////////////////////////////////////////////
302 /// Remove object from this collection and recursively remove the object
303 /// from all other objects (and collections).
304 /// This function overrides TCollection::RecursiveRemove that calls
305 /// the Remove function. THashList::Remove cannot be called because
306 /// it uses the hash value of the hash table. This hash value
307 /// is not available anymore when RecursiveRemove is called from
308 /// the TObject destructor.
309 
311 {
312  if (!obj) return;
313 
316  UnmapObject(obj);
317 
318 }
319 
320 ////////////////////////////////////////////////////////////////////////////////
321 /// Remove object from the list.
322 
324 {
325  Bool_t found;
326 
327  found = THashList::Remove(obj);
328  if (!found) {
329  found = fUnloaded->Remove(obj);
330  }
331  UnmapObject(obj);
332  if (found) return obj;
333  else return 0;
334 }
335 
336 ////////////////////////////////////////////////////////////////////////////////
337 /// Remove object via its objlink from the list.
338 
340 {
341  if (!lnk) return 0;
342 
343  TObject *obj = lnk->GetObject();
344 
345  THashList::Remove(lnk);
346  fUnloaded->Remove(obj);
347 
348  UnmapObject(obj);
349  return obj;
350 }
351 
352 ////////////////////////////////////////////////////////////////////////////////
353 /// Load all the functions known to the interpreter for the scope 'fClass'
354 /// into this collection.
355 
357 {
358  if (fClass && fClass->GetClassInfo() == 0) return;
359 
361 
362  ULong64_t currentTransaction = gInterpreter->GetInterpreterStateMarker();
363  if (currentTransaction == fLastLoadMarker) {
364  return;
365  }
366  fLastLoadMarker = currentTransaction;
367 
368  gInterpreter->LoadFunctionTemplates(fClass);
369 }
370 
371 ////////////////////////////////////////////////////////////////////////////////
372 /// Mark 'all func' as being unloaded.
373 /// After the unload, the function can no longer be found directly,
374 /// until the decl can be found again in the interpreter (in which
375 /// the func object will be reused.
376 
378 {
379  TObjLink *lnk = FirstLink();
380  while (lnk) {
382 
383  fIds->Remove((Long64_t)func->GetDeclId());
384  fUnloaded->Add(func);
385 
386  lnk = lnk->Next();
387  }
388 
390 }
391 
392 ////////////////////////////////////////////////////////////////////////////////
393 /// Mark 'func' as being unloaded.
394 /// After the unload, the function can no longer be found directly,
395 /// until the decl can be found again in the interpreter (in which
396 /// the func object will be reused.
397 
399 {
400  if (THashList::Remove(func)) {
401  // We contains the object, let remove it from the other internal
402  // list and move it to the list of unloaded objects.
403 
404  fIds->Remove((Long64_t)func->GetDeclId());
405  fUnloaded->Add(func);
406  }
407 }
THashList::THashList
THashList(const THashList &)
m
auto * m
Definition: textangle.C:8
TListOfFunctionTemplates::Remove
TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TListOfFunctionTemplates.cxx:323
TListOfFunctionTemplates::AddFirst
void AddFirst(TObject *obj)
Add object at the beginning of the list.
Definition: TListOfFunctionTemplates.cxx:64
TListOfFunctionTemplates::fOverloads
THashTable fOverloads
Definition: TListOfFunctionTemplates.h:44
TListOfFunctionTemplates
Definition: TListOfFunctionTemplates.h:34
f
#define f(i)
Definition: RSha256.hxx:122
TListOfFunctionTemplates::GetListForObjectNonConst
TList * GetListForObjectNonConst(const char *name)
Return the set of overloads for this name, collecting all available ones.
Definition: TListOfFunctionTemplates.cxx:194
THashTable::Add
void Add(TObject *obj)
Add object to the hash table.
Definition: THashTable.cxx:92
THashList::AddAfter
void AddAfter(const TObject *after, TObject *obj)
Insert object after object after in the list.
Definition: THashList.cxx:143
TListOfFunctionTemplates::AddLast
void AddLast(TObject *obj)
Add object at the end of the list.
Definition: TListOfFunctionTemplates.cxx:86
TListOfFunctionTemplates::fClass
TClass * fClass
Definition: TListOfFunctionTemplates.h:40
TFunction.h
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TMethod.h
TListOfFunctionTemplates::AddAfter
void AddAfter(const TObject *after, TObject *obj)
Insert object after object after in the list.
Definition: TListOfFunctionTemplates.cxx:117
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
gInterpreter
#define gInterpreter
Definition: TInterpreter.h:558
TListOfFunctionTemplates::GetListForObject
virtual TList * GetListForObject(const char *name) const
Return the set of overloads for this name, collecting all available ones.
Definition: TListOfFunctionTemplates.cxx:233
TFunctionTemplate::GetDeclId
DeclId_t GetDeclId() const
Definition: TFunctionTemplate.cxx:137
TListOfFunctionTemplates::Get
TFunctionTemplate * Get(DeclId_t id)
Return (after creating it if necessary) the TMethod or TFunction describing the function correspondin...
Definition: TListOfFunctionTemplates.cxx:253
TInterpreter::DeclId_t
TDictionary::DeclId_t DeclId_t
Definition: TInterpreter.h:286
TClass.h
TExMap::GetValue
Long64_t GetValue(ULong64_t hash, Long64_t key)
Return the value belonging to specified key and hash value.
Definition: TExMap.cxx:173
TString
Definition: TString.h:136
TListOfFunctionTemplates::~TListOfFunctionTemplates
~TListOfFunctionTemplates()
Destructor.
Definition: TListOfFunctionTemplates.cxx:42
bool
TListOfFunctionTemplates::Delete
virtual void Delete(Option_t *option="")
Delete all TFunction object files.
Definition: TListOfFunctionTemplates.cxx:164
id
XFontStruct * id
Definition: TGX11.cxx:109
TObject::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:359
update
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)
Definition: RooAdaptiveGaussKronrodIntegrator1D.cxx:652
THashList::AddBefore
void AddBefore(const TObject *before, TObject *obj)
Insert object before object before in the list.
Definition: THashList.cxx:121
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TList::FirstLink
virtual TObjLink * FirstLink() const
Definition: TList.h:108
TListOfFunctionTemplates::MapObject
void MapObject(TObject *obj)
Add pair<id, object> to the map of functions and their ids.
Definition: TListOfFunctionTemplates.cxx:53
gInterpreterMutex
R__EXTERN TVirtualMutex * gInterpreterMutex
Definition: TInterpreter.h:43
TListOfFunctionTemplates::FindObject
virtual TObject * FindObject(const char *name) const
Specialize FindObject to do search for the a function just by name or create it if its not already in...
Definition: TListOfFunctionTemplates.cxx:175
TListOfFunctionTemplates::UnmapObject
void UnmapObject(TObject *obj)
Remove a pair<id, object> from the map of functions and their ids.
Definition: TListOfFunctionTemplates.cxx:293
TListOfFunctionTemplates::fIds
TExMap * fIds
Definition: TListOfFunctionTemplates.h:42
THashList::FindObject
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashList.cxx:262
THashTable::FindObject
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashTable.cxx:238
THashList::AddLast
void AddLast(TObject *obj)
Add object at the end of the list.
Definition: THashList.cxx:95
TList::TList
TList()
Definition: TList.h:78
R__LOCKGUARD
#define R__LOCKGUARD(mutex)
Definition: TVirtualMutex.h:104
TClass::GetClassInfo
ClassInfo_t * GetClassInfo() const
Definition: TClass.h:386
TListOfFunctionTemplates::RecursiveRemove
void RecursiveRemove(TObject *obj)
Remove object from this collection and recursively remove the object from all other objects (and coll...
Definition: TListOfFunctionTemplates.cxx:310
TListOfFunctionTemplates::Load
void Load()
Load all the functions known to the interpreter for the scope 'fClass' into this collection.
Definition: TListOfFunctionTemplates.cxx:356
TListOfFunctionTemplates::DeclId_t
TDictionary::DeclId_t DeclId_t
Definition: TListOfFunctionTemplates.h:39
TListOfFunctionTemplates::Clear
virtual void Clear(Option_t *option)
Remove all objects from the list.
Definition: TListOfFunctionTemplates.cxx:154
THashList::Remove
TObject * Remove(TObject *obj)
Remove object from the list.
Definition: THashList.cxx:378
TVirtualMutex.h
fClass
Cppyy::TCppType_t fClass
Definition: DeclareConverters.h:259
TListOfFunctionTemplates::AddBefore
void AddBefore(const TObject *before, TObject *obj)
Insert object before object before in the list.
Definition: TListOfFunctionTemplates.cxx:135
THashList::Delete
void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: THashList.cxx:207
TListOfFunctionTemplates::TListOfFunctionTemplates
TListOfFunctionTemplates(const TListOfFunctionTemplates &)
ULong64_t
unsigned long long ULong64_t
Definition: RtypesCore.h:74
TListOfFunctionTemplates::fLastLoadMarker
ULong64_t fLastLoadMarker
Definition: TListOfFunctionTemplates.h:45
TInterpreter.h
TClass
Definition: TClass.h:80
THashList::Clear
void Clear(Option_t *option="")
Remove all objects from the list.
Definition: THashList.cxx:189
TCollection::SetName
void SetName(const char *name)
Definition: TCollection.h:204
TListOfFunctionTemplates::fUnloaded
THashList * fUnloaded
Definition: TListOfFunctionTemplates.h:43
TList::Add
virtual void Add(TObject *obj)
Definition: TList.h:87
TObject
Definition: TObject.h:37
name
char name[80]
Definition: TGX11.cxx:110
TExMap::Remove
void Remove(ULong64_t hash, Long64_t key)
Remove entry with specified key from the TExMap.
Definition: TExMap.cxx:216
TListOfFunctionTemplates::AddAt
void AddAt(TObject *obj, Int_t idx)
Insert object at location idx in the list.
Definition: TListOfFunctionTemplates.cxx:108
THashList::AddAt
void AddAt(TObject *obj, Int_t idx)
Insert object at location idx in the list.
Definition: THashList.cxx:165
TIter
Definition: TCollection.h:233
TExMap
Definition: TExMap.h:33
TExMap::Add
void Add(ULong64_t hash, Long64_t key, Long64_t value)
Add an (key,value) pair to the table. The key should be unique.
Definition: TExMap.cxx:87
TFunctionTemplate.h
TListOfFunctionTemplates::Unload
void Unload()
Mark 'all func' as being unloaded.
Definition: TListOfFunctionTemplates.cxx:377
TListOfFunctionTemplates.h
TObject::Clear
virtual void Clear(Option_t *="")
Definition: TObject.h:100
THashList::AddFirst
void AddFirst(TObject *obj)
Add object at the beginning of the list.
Definition: THashList.cxx:69
TList
Definition: TList.h:44
TExMap.h
int
TFunctionTemplate
Definition: TFunctionTemplate.h:26
THashList::RecursiveRemove
void RecursiveRemove(TObject *obj)
Remove object from this collection and recursively remove the object from all other objects (and coll...
Definition: THashList.cxx:310