Revision: | 1.3 |
Committed: | Mon Mar 23 14:42:12 2009 UTC (16 years, 1 month ago) by loizides |
Content type: | text/plain |
Branch: | MAIN |
CVS Tags: | Mit_032, Mit_031, Mit_025c_branch2, Mit_025c_branch1, Mit_030, Mit_029c, Mit_029b, Mit_030_pre1, Mit_029a, Mit_029, Mit_029_pre1, Mit_028a, Mit_025c_branch0, Mit_028, Mit_027a, Mit_027, Mit_026, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1, Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e, Mit_014d, Mit_014c, Mit_014b, Mit_014a, Mit_014, Mit_014pre3, Mit_014pre2, Mit_014pre1, Mit_013d, Mit_013c, Mit_013b, Mit_013a, Mit_013, Mit_013pre1, Mit_012i, Mit_012h, Mit_012g, Mit_012f, Mit_012e, Mit_012d, Mit_012c, Mit_012b, Mit_012a, Mit_012, Mit_011a, Mit_011, Mit_010a, Mit_010, Mit_009c, Mit_009b, Mit_009a, Mit_009, Mit_008, HEAD |
Branch point for: | Mit_025c_branch |
Changes since 1.2: | +5 -1 lines |
Log Message: | Fix null value. |
# | Content |
---|---|
1 | // $Id: SimpleTable.cc,v 1.2 2009/01/23 08:46:48 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 | if (value.IsNull()) { |
51 | Error("SimpleTable", "Value corresponding to name %s is null.", name.Data()); |
52 | continue; |
53 | } |
54 | TFormula fval("formula",value); |
55 | MyParameter *par = new MyParameter(name,fval.Eval(0)); |
56 | fTable.Add(par); |
57 | } |
58 | } |
59 | |
60 | //-------------------------------------------------------------------------------------------------- |
61 | Double_t SimpleTable::Get(const char *name) const |
62 | { |
63 | // Get value corresponding to name. |
64 | |
65 | const MyParameter *p = dynamic_cast<const MyParameter*>(fTable.FindObject(name)); |
66 | |
67 | if(!p) |
68 | Fatal("Get", "Could not get value for given name %s", name); |
69 | |
70 | return p->GetVal(); |
71 | } |
72 | |
73 | //-------------------------------------------------------------------------------------------------- |
74 | Double_t SimpleTable::Has(const char *name) const |
75 | { |
76 | // Return true if table contains given name. |
77 | |
78 | TObject *o = fTable.FindObject(name); |
79 | return (o!=0); |
80 | } |
81 | |
82 | //-------------------------------------------------------------------------------------------------- |
83 | void SimpleTable::Print(Option_t *opt) const |
84 | { |
85 | // Print content of table. |
86 | |
87 | TIter iter(fTable.MakeIterator()); |
88 | const MyParameter *p = dynamic_cast<const MyParameter*>(iter.Next()); |
89 | while (p) { |
90 | p->Print(); |
91 | p = dynamic_cast<const MyParameter*>(iter.Next()); |
92 | } |
93 | } |