1 |
// $Id: EventHeader.cc,v 1.1 2008/06/17 14:45:22 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 >> value;
|
43 |
if ((name.IsNull()) || name.BeginsWith("#"))
|
44 |
continue;
|
45 |
in.getline(dummy,1024);
|
46 |
|
47 |
TFormula fval("formula",value);
|
48 |
MyParameter *par = new MyParameter(name,fval.Eval(0));
|
49 |
fTable.Add(par);
|
50 |
}
|
51 |
}
|
52 |
|
53 |
//--------------------------------------------------------------------------------------------------
|
54 |
Double_t SimpleTable::Get(const char *name) const
|
55 |
{
|
56 |
// Get value corresponding to name.
|
57 |
|
58 |
const MyParameter *p = dynamic_cast<const MyParameter*>(fTable.FindObject(name));
|
59 |
|
60 |
if(p)
|
61 |
Fatal("Get", "Could not get value for given name %s", name);
|
62 |
|
63 |
return p->GetVal();
|
64 |
}
|
65 |
|
66 |
//--------------------------------------------------------------------------------------------------
|
67 |
Double_t SimpleTable::Has(const char *name) const
|
68 |
{
|
69 |
// Return true if table contains given name.
|
70 |
|
71 |
TObject *o = fTable.FindObject(name);
|
72 |
return (o!=0);
|
73 |
}
|
74 |
|
75 |
//--------------------------------------------------------------------------------------------------
|
76 |
void SimpleTable::Print(Option_t *opt) const
|
77 |
{
|
78 |
// Print content of table.
|
79 |
|
80 |
TIter iter(fTable.MakeIterator());
|
81 |
const MyParameter *p = dynamic_cast<const MyParameter*>(iter.Next());
|
82 |
while (p) {
|
83 |
p->Print();
|
84 |
p = dynamic_cast<const MyParameter*>(iter.Next());
|
85 |
}
|
86 |
}
|