source: branches/MarsGapdTimeJitter/mbase/MObjLookup.cc@ 18332

Last change on this file since 18332 was 9552, checked in by tbretz, 15 years ago
*** empty log message ***
File size: 2.5 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz 5/2008 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: CheObs Software Development, 2008
21!
22!
23\* ======================================================================== */
24
25
26//////////////////////////////////////////////////////////////////////////////
27//
28//
29//////////////////////////////////////////////////////////////////////////////
30#include "MObjLookup.h"
31
32#include <TNamed.h>
33#include <TObjString.h>
34
35ClassImp(MObjLookup);
36
37// --------------------------------------------------------------------------
38//
39// Delete all elements with kCenDelete set or all elements in case of
40// kIsOwener is set
41//
42MObjLookup::~MObjLookup()
43{
44 TExMapIter iter(&fMap);
45
46#if ROOT_VERSION_CODE < ROOT_VERSION(5,26,00)
47 Long_t key, value;
48#else
49 Long64_t key, value;
50#endif
51
52 while (iter.Next(key, value))
53 {
54 TObject *o = reinterpret_cast<TObject*>(value);
55 if (o->TestBit(kCanDelete) || TestBit(kIsOwner))
56 delete o;
57 }
58}
59
60// --------------------------------------------------------------------------
61//
62// Add a TObjString to the table
63//
64void MObjLookup::Add(Long_t key, const char *txt)
65{
66 TObject *o=new TObjString(txt);
67
68 o->SetBit(kCanDelete);
69
70 Add(key,o);
71}
72
73// --------------------------------------------------------------------------
74//
75// Add a TNames to the table
76//
77void MObjLookup::Add(Long_t key, const char *name, const char *title)
78{
79 TObject *o=new TNamed(name, title);
80
81 o->SetBit(kCanDelete);
82
83 Add(key,o);
84}
85
86// --------------------------------------------------------------------------
87//
88// Search for the object corresponding to key. If no object is found,
89// fDefault is returned instead.
90//
91TObject *MObjLookup::GetObj(Long_t key) const
92{
93 TObject *o = reinterpret_cast<TObject*>(const_cast<TExMap&>(fMap).GetValue(key));
94 return o ? o : fDefault;
95}
Note: See TracBrowser for help on using the repository browser.