DESY Hbb Analysis Framework
Classes | Functions
utilLib.h File Reference
#include <sys/stat.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <cctype>
#include <algorithm>
#include "TFile.h"
#include "TTree.h"
#include "RooFit.h"
#include "RooWorkspace.h"
#include <boost/filesystem.hpp>

Go to the source code of this file.

Classes

struct  great_second< T1, T2 >
 
struct  less_second< T1, T2 >
 

Functions

void CheckOutputDir (const std::string &oDir)
 
void CheckZombie (const TFile &name)
 
void CheckZombieObjectInTFile (const TFile &file, const std::string &name)
 
bool file_exists (const std::string &name)
 
bool findStrings (const std::string &input, const std::string &needful)
 
template<typename T >
TGetFromTFile (TFile &file, const std::string &obj_name)
 
template<typename T >
TGetFromTFile (const std::string &file_name, const std::string &obj_name)
 
RooWorkspace * GetRooWorkspace (const std::string &path_to_file, const std::string &workspace_name="workspace")
 
int returnMassPoint (const std::string &name)
 
template<typename T >
std::string to_string_with_precision (const T a_value, const int n=6)
 

Function Documentation

void CheckOutputDir ( const std::string &  oDir)
void CheckZombie ( const TFile &  name)
void CheckZombieObjectInTFile ( const TFile &  file,
const std::string &  name 
)
bool file_exists ( const std::string &  name)
inline

Definition at line 63 of file utilLib.h.

Referenced by to_string_with_precision().

63  {
64  struct stat buffer;
65  return (stat (name.c_str(), &buffer) == 0);
66 }
bool findStrings ( const std::string &  input,
const std::string &  needful 
)
template<typename T >
T* GetFromTFile ( TFile &  file,
const std::string &  obj_name 
)

Definition at line 69 of file utilLib.h.

References T.

69  {
70  auto *obj = static_cast<T*>(file.Get(obj_name.c_str()));
71  if(!obj) throw std::invalid_argument("Invalid TObject name: " + obj_name);
72  return obj;
73 }
float T
Definition: PlotsCompare.cc:18
template<typename T >
T* GetFromTFile ( const std::string &  file_name,
const std::string &  obj_name 
)

Definition at line 74 of file utilLib.h.

References CheckZombie(), and f.

74  {
75  TFile f(file_name.c_str(),"READ");
76  CheckZombie(f);
77  auto *obj = GetFromTFile<T>(f,obj_name);
78  return obj;
79 }
TFile * f[10]
Definition: PlotsCompare.cc:24
void CheckZombie(const TFile &name)
RooWorkspace* GetRooWorkspace ( const std::string &  path_to_file,
const std::string &  workspace_name = "workspace" 
)
int returnMassPoint ( const std::string &  name)

Definition at line 129 of file mHatGenFilter.cc.

References DEFINE_FWK_MODULE().

Referenced by mHatGenFilter::filter(), and to_string_with_precision().

129  {
130  int Mpoint = 0;
131 
132  std::string MassPos = "_M-";
133  auto p1 = inputFilelist_.find(MassPos) + 3;
134  if(p1 == std::string::npos) {
135  std::cerr<<"FileNames were cahnged!!!!"<<std::endl;
136  exit(1);
137  }
138  auto p2 = inputFilelist_.find("_",p1);
139  std::string MpointString = inputFilelist_.substr(p1,size_t(p2-p1));
140  Mpoint = std::stoi(MpointString);
141  return Mpoint;
142 }
template<typename T >
std::string to_string_with_precision ( const T  a_value,
const int  n = 6 
)

Definition at line 40 of file utilLib.h.

References CheckOutputDir(), CheckZombie(), CheckZombieObjectInTFile(), file_exists(), findStrings(), GetRooWorkspace(), ConfFile_cfg::input, nano_94X_2017_rereco31Mar18-v1::name, and returnMassPoint().

41 {
42  std::ostringstream out;
43  out << std::setprecision(n) << a_value;
44  return out.str();
45 }