CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CDFRunInfo.cc
Go to the documentation of this file.
1 #include <TMap.h>
2 #include <TObjString.h>
4 #include <stdlib.h>
5 
6 const char* CDFRunInfo::RootVariableName = "CDFRunInfo";
7 
9 }
10 
12  load(file);
13 }
14 
15 const char* CDFRunInfo::get(const char* key) const {
16  std::map<std::string,std::string>::const_iterator i=m_mapData.find(key);
17  if (i==m_mapData.end()) return NULL;
18  return i->second.c_str();
19 }
20 
21 int CDFRunInfo::getInt(const char* key) const {
22  const char* k=get(key);
23  if (k==NULL) return 0;
24  return atoi(k);
25 }
26 
27 double CDFRunInfo::getDouble(const char* key) const {
28  const char* k=get(key);
29  if (k==NULL) return 0;
30  return atof(k);
31 }
32 
33 int CDFRunInfo::getKeys(const char** buffer, int nbufs) {
34  int j=0;
35  for (std::map<std::string,std::string>::const_iterator i=m_mapData.begin(); i!=m_mapData.end() && j<nbufs; i++, j++) {
36  buffer[j]=i->first.c_str();
37  }
38  return j;
39 }
40 
41 bool CDFRunInfo::hasKey(const char* key) const {
42  std::map<std::string,std::string>::const_iterator i=m_mapData.find(key);
43  return (i!=m_mapData.end());
44 }
45 
46 void CDFRunInfo::setInfo(const char* key, const char* value) {
48 }
49 
50 bool CDFRunInfo::load(TFile* f) {
51  m_mapData.clear();
52  if (f==NULL) return false;
53  TMap* pMap=(TMap*)f->Get(RootVariableName);
54  if (pMap==NULL) return false;
55  TIterator* i=pMap->MakeIterator();
56  TObject* o;
57 
58  while ((o=i->Next())!=NULL) {
59  std::string a(o->GetName());
60  std::string b(pMap->GetValue(o)->GetName());
61  m_mapData.insert(std::pair<std::string,std::string>(a,b));
62  }
63  return true;
64 }
65 
66 void CDFRunInfo::store(TFile* f) {
67  f->cd();
68  TMap* myMap=new TMap();
69  for (std::map<std::string,std::string>::iterator i=m_mapData.begin(); i!=m_mapData.end(); i++) {
70  myMap->Add(new TObjString(i->first.c_str()), new TObjString(i->second.c_str()));
71  }
72  myMap->SetName(RootVariableName);
73  myMap->Write(RootVariableName,TObject::kSingleKey);
74 }
75 
76 void CDFRunInfo::print() const {
77  for (std::map<std::string,std::string>::const_iterator i=m_mapData.begin(); i!=m_mapData.end(); i++)
78  printf(" '%s' => '%s' \n",i->first.c_str(),i->second.c_str());
79 
80 }
int i
Definition: DBlmapReader.cc:9
#define NULL
Definition: scimark2.h:8
bool hasKey(const char *key) const
test for thr presence of given key
Definition: CDFRunInfo.cc:41
std::map< std::string, std::string > m_mapData
Definition: CDFRunInfo.h:42
void setInfo(const char *key, const char *value)
add some information to the run info
Definition: CDFRunInfo.cc:46
void store(TFile *toFile)
Definition: CDFRunInfo.cc:66
void print() const
print all information to the terminal
Definition: CDFRunInfo.cc:76
double getDouble(const char *key) const
Get a run info item by name and convert it to a double.
Definition: CDFRunInfo.cc:27
const char * get(const char *key) const
Get some run info by name.
Definition: CDFRunInfo.cc:15
int j
Definition: DBlmapReader.cc:9
double f[11][100]
static const char * RootVariableName
Definition: CDFRunInfo.h:41
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
int getKeys(const char **buffer, int nbufs)
fill the given array with key name pointers
Definition: CDFRunInfo.cc:33
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
int getInt(const char *key) const
Get a run info item by name and convert it to an integer.
Definition: CDFRunInfo.cc:21
bool load(TFile *fromFile)
Definition: CDFRunInfo.cc:50