CMS 3D CMS Logo

CDFRunInfo.cc
Go to the documentation of this file.
1 #include <TMap.h>
2 #include <TObjString.h>
4 #include <cstdlib>
5 
6 const char* CDFRunInfo::RootVariableName = "CDFRunInfo";
7 
9 
11 
12 const char* CDFRunInfo::get(const char* key) const {
13  std::map<std::string, std::string>::const_iterator i = m_mapData.find(key);
14  if (i == m_mapData.end())
15  return nullptr;
16  return i->second.c_str();
17 }
18 
19 int CDFRunInfo::getInt(const char* key) const {
20  const char* k = get(key);
21  if (k == nullptr)
22  return 0;
23  return atoi(k);
24 }
25 
26 double CDFRunInfo::getDouble(const char* key) const {
27  const char* k = get(key);
28  if (k == nullptr)
29  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;
36  i++, j++) {
37  buffer[j] = i->first.c_str();
38  }
39  return j;
40 }
41 
42 bool CDFRunInfo::hasKey(const char* key) const {
43  std::map<std::string, std::string>::const_iterator i = m_mapData.find(key);
44  return (i != m_mapData.end());
45 }
46 
47 void CDFRunInfo::setInfo(const char* key, const char* value) { m_mapData[key] = value; }
48 
49 bool CDFRunInfo::load(TFile* f) {
50  m_mapData.clear();
51  if (f == nullptr)
52  return false;
53  TMap* pMap = (TMap*)f->Get(RootVariableName);
54  if (pMap == nullptr)
55  return false;
56  TIterator* i = pMap->MakeIterator();
57  TObject* o;
58 
59  while ((o = i->Next()) != nullptr) {
60  std::string a(o->GetName());
61  std::string b(pMap->GetValue(o)->GetName());
62  m_mapData.insert(std::pair<std::string, std::string>(a, b));
63  }
64  return true;
65 }
66 
67 void CDFRunInfo::store(TFile* f) {
68  f->cd();
69  TMap* myMap = new TMap();
70  for (std::map<std::string, std::string>::iterator i = m_mapData.begin(); i != m_mapData.end(); i++) {
71  myMap->Add(new TObjString(i->first.c_str()), new TObjString(i->second.c_str()));
72  }
73  myMap->SetName(RootVariableName);
74  myMap->Write(RootVariableName, TObject::kSingleKey);
75 }
76 
77 void CDFRunInfo::print() const {
78  for (std::map<std::string, std::string>::const_iterator i = m_mapData.begin(); i != m_mapData.end(); i++)
79  printf(" '%s' => '%s' \n", i->first.c_str(), i->second.c_str());
80 }
void print() const
print all information to the terminal
Definition: CDFRunInfo.cc:77
std::map< std::string, std::string > m_mapData
Definition: CDFRunInfo.h:43
double getDouble(const char *key) const
Get a run info item by name and convert it to a double.
Definition: CDFRunInfo.cc:26
void setInfo(const char *key, const char *value)
add some information to the run info
Definition: CDFRunInfo.cc:47
void store(TFile *toFile)
Definition: CDFRunInfo.cc:67
key
prepare the HTCondor submission files and eventually submit them
double f[11][100]
static const char * RootVariableName
Definition: CDFRunInfo.h:42
Definition: value.py:1
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
int getInt(const char *key) const
Get a run info item by name and convert it to an integer.
Definition: CDFRunInfo.cc:19
double a
Definition: hdecay.h:121
bool load(TFile *fromFile)
Definition: CDFRunInfo.cc:49
bool hasKey(const char *key) const
test for thr presence of given key
Definition: CDFRunInfo.cc:42
const char * get(const char *key) const
Get some run info by name.
Definition: CDFRunInfo.cc:12