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 }
CDFRunInfo::CDFRunInfo
CDFRunInfo()
Definition: CDFRunInfo.cc:8
mps_fire.i
i
Definition: mps_fire.py:428
CDFRunInfo::get
const char * get(const char *key) const
Get some run info by name.
Definition: CDFRunInfo.cc:12
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
CDFRunInfo::getDouble
double getDouble(const char *key) const
Get a run info item by name and convert it to a double.
Definition: CDFRunInfo.cc:26
CDFRunInfo::hasKey
bool hasKey(const char *key) const
test for thr presence of given key
Definition: CDFRunInfo.cc:42
CDFRunInfo::store
void store(TFile *toFile)
Definition: CDFRunInfo.cc:67
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:36
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
dqmdumpme.k
k
Definition: dqmdumpme.py:60
b
double b
Definition: hdecay.h:118
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CDFRunInfo::RootVariableName
static const char * RootVariableName
Definition: CDFRunInfo.h:42
a
double a
Definition: hdecay.h:119
CDFRunInfo::load
bool load(TFile *fromFile)
Definition: CDFRunInfo.cc:49
CDFRunInfo::m_mapData
std::map< std::string, std::string > m_mapData
Definition: CDFRunInfo.h:43
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
value
Definition: value.py:1
CDFRunInfo::getKeys
int getKeys(const char **buffer, int nbufs)
fill the given array with key name pointers
Definition: CDFRunInfo.cc:33
CDFRunInfo::getInt
int getInt(const char *key) const
Get a run info item by name and convert it to an integer.
Definition: CDFRunInfo.cc:19
relativeConstraints.value
value
Definition: relativeConstraints.py:53
CDFRunInfo.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
crabWrapper.key
key
Definition: crabWrapper.py:19
CDFRunInfo::print
void print() const
print all information to the terminal
Definition: CDFRunInfo.cc:77
CDFRunInfo::setInfo
void setInfo(const char *key, const char *value)
add some information to the run info
Definition: CDFRunInfo.cc:47