ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/Utils/src/SimpleTable.cc
Revision: 1.2
Committed: Fri Jan 23 08:46:48 2009 UTC (16 years, 3 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_008pre2, Mit_008pre1, Mit_006b, Mit_006a
Changes since 1.1: +7 -4 lines
Log Message:
Fixed first bugs.

File Contents

# Content
1 // $Id: SimpleTable.cc,v 1.1 2009/01/23 07:34:34 loizides Exp $
2
3 #include "MitAna/Utils/interface/SimpleTable.h"
4 #include <Riostream.h>
5 #include <TSystem.h>
6 #include <TFormula.h>
7
8 using namespace mithep;
9
10 ClassImp(mithep::SimpleTable)
11 ClassImp(mithep::SimpleTable::MyParameter)
12
13 //--------------------------------------------------------------------------------------------------
14 void SimpleTable::MyParameter::Print(Option_t */*option*/) const
15 {
16 // Print this parameter.
17
18 printf("%s -> %e\n", GetName(), GetVal());
19 }
20
21 //--------------------------------------------------------------------------------------------------
22 SimpleTable::SimpleTable(const char *input)
23 : fTable(TCollection::kInitHashTableCapacity, 1)
24 {
25 // Constructor.
26
27 fTable.SetOwner(kTRUE);
28
29 TString ifile(gSystem->ExpandPathName(input));
30
31 if (ifile.IsNull())
32 return;
33
34 ifstream in(ifile);
35 if (!in.good())
36 return;
37
38 Char_t dummy[1024];
39 TString name;
40 TString value;
41 while(!in.eof()) {
42 in >> name;
43 if ((name.IsNull()) || name.BeginsWith("#")) {
44 in.getline(dummy,1024);
45 continue;
46 }
47 in >> value;
48 in.getline(dummy,1024);
49
50 TFormula fval("formula",value);
51 MyParameter *par = new MyParameter(name,fval.Eval(0));
52 fTable.Add(par);
53 }
54 }
55
56 //--------------------------------------------------------------------------------------------------
57 Double_t SimpleTable::Get(const char *name) const
58 {
59 // Get value corresponding to name.
60
61 const MyParameter *p = dynamic_cast<const MyParameter*>(fTable.FindObject(name));
62
63 if(!p)
64 Fatal("Get", "Could not get value for given name %s", name);
65
66 return p->GetVal();
67 }
68
69 //--------------------------------------------------------------------------------------------------
70 Double_t SimpleTable::Has(const char *name) const
71 {
72 // Return true if table contains given name.
73
74 TObject *o = fTable.FindObject(name);
75 return (o!=0);
76 }
77
78 //--------------------------------------------------------------------------------------------------
79 void SimpleTable::Print(Option_t *opt) const
80 {
81 // Print content of table.
82
83 TIter iter(fTable.MakeIterator());
84 const MyParameter *p = dynamic_cast<const MyParameter*>(iter.Next());
85 while (p) {
86 p->Print();
87 p = dynamic_cast<const MyParameter*>(iter.Next());
88 }
89 }