CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BTagCalibration.cc
Go to the documentation of this file.
1 #include <fstream>
2 #include <sstream>
3 
6 
7 
9  tagger_(taggr)
10 {}
11 
13  const std::string &filename):
14  tagger_(taggr)
15 {
16  std::ifstream ifs(filename);
17  readCSV(ifs);
18  ifs.close();
19 }
20 
22 {
23  data_[token(entry.params)].push_back(entry);
24 }
25 
26 const std::vector<BTagEntry>& BTagCalibration::getEntries(
27  const BTagEntry::Parameters &par) const
28 {
29  std::string tok = token(par);
30  if (!data_.count(tok)) {
31  throw cms::Exception("BTagCalibration")
32  << "(OperatingPoint, measurementType, sysType) not available: "
33  << tok;
34  }
35  return data_.at(tok);
36 }
37 
39 {
40  std::stringstream buff(s);
41  readCSV(buff);
42 }
43 
44 void BTagCalibration::readCSV(std::istream &s)
45 {
47 
48  // firstline might be the header
49  getline(s,line);
50  if (line.find("OperatingPoint") == std::string::npos) {
51  addEntry(BTagEntry(line));
52  }
53 
54  while (getline(s,line)) {
55  line = BTagEntry::trimStr(line);
56  if (line.empty()) { // skip empty lines
57  continue;
58  }
59  addEntry(BTagEntry(line));
60  }
61 }
62 
63 void BTagCalibration::makeCSV(std::ostream &s) const
64 {
65  s << tagger_ << ";" << BTagEntry::makeCSVHeader();
66  for (std::map<std::string, std::vector<BTagEntry> >::const_iterator i
67  = data_.cbegin(); i != data_.cend(); ++i) {
68  const std::vector<BTagEntry> &vec = i->second;
69  for (std::vector<BTagEntry>::const_iterator j
70  = vec.cbegin(); j != vec.cend(); ++j) {
71  s << j->makeCSVLine();
72  }
73  }
74 }
75 
77 {
78  std::stringstream buff;
79  makeCSV(buff);
80  return buff.str();
81 }
82 
84 {
85  std::stringstream buff;
86  buff << par.operatingPoint << ", "
87  << par.measurementType << ", "
88  << par.sysType;
89  return buff.str();
90 }
std::string sysType
Definition: BTagEntry.h:41
int i
Definition: DBlmapReader.cc:9
static std::string trimStr(std::string str)
Definition: BTagEntry.cc:251
static std::string makeCSVHeader()
Definition: BTagEntry.cc:218
void readCSV(std::istream &s)
const std::vector< BTagEntry > & getEntries(const BTagEntry::Parameters &par) const
OperatingPoint operatingPoint
Definition: BTagEntry.h:39
int j
Definition: DBlmapReader.cc:9
std::string makeCSV() const
Parameters params
Definition: BTagEntry.h:79
void addEntry(const BTagEntry &entry)
tuple filename
Definition: lut2db_cfg.py:20
void readCSV(const std::string &s)
std::string tagger_
std::string measurementType
Definition: BTagEntry.h:40
static std::string token(const BTagEntry::Parameters &par)
std::map< std::string, std::vector< BTagEntry > > data_