CMS 3D CMS Logo

RunHistogramManager.cc
Go to the documentation of this file.
6 #include "TH1F.h"
7 #include "TH2F.h"
8 #include "TProfile.h"
9 #include "TProfile2D.h"
10 
12 
14 
15 /*
16 void BaseHistoParams::beginRun(const edm::Run& iRun, TFileDirectory& subrun) {
17 
18  beginRun(iRun.run(),subrun);
19 
20 }
21 */
22 
24  : _fillHistograms(fillHistograms),
25  _histograms(),
26  _conditionsInRunToken(iC.consumes<edm::ConditionsInRunBlock, edm::InRun>(edm::InputTag("conditionsInEdm"))) {}
27 
29  : _fillHistograms(fillHistograms),
30  _histograms(),
31  _conditionsInRunToken(iC.consumes<edm::ConditionsInRunBlock, edm::InRun>(edm::InputTag("conditionsInEdm"))) {}
32 
34  const char* name, const char* title, const unsigned int nbinx, const double xmin, const double xmax) {
35  TH1F** pointer = new TH1F*(nullptr);
36 
37  BaseHistoParams* hp = new HistoParams<TH1F>(pointer, "TH1F", name, title, nbinx, xmin, xmax);
38  _histograms.push_back(hp);
39 
40  LogDebug("TH1Fmade") << "Histogram " << name << " " << title << " pre-booked:" << _histograms.size();
41 
42  return pointer;
43 }
44 
46  for (std::vector<BaseHistoParams*>::const_iterator hp = _histograms.begin(); hp != _histograms.end(); ++hp) {
47  delete *hp;
48  }
49  LogDebug("Destructor") << "All BaseHistoParams destroyed ";
50 }
51 
53  const char* name, const char* title, const unsigned int nbinx, const double xmin, const double xmax) {
54  TProfile** pointer = new TProfile*(nullptr);
55 
56  BaseHistoParams* hp = new HistoParams<TProfile>(pointer, "TProfile", name, title, nbinx, xmin, xmax);
57  _histograms.push_back(hp);
58 
59  LogDebug("TProfilemade") << "Histogram " << name << " " << title << " pre-booked:" << _histograms.size();
60 
61  return pointer;
62 }
63 
65  const char* title,
66  const unsigned int nbinx,
67  const double xmin,
68  const double xmax,
69  const unsigned int nbiny,
70  const double ymin,
71  const double ymax) {
72  TH2F** pointer = new TH2F*(nullptr);
73 
74  BaseHistoParams* hp = new HistoParams<TH2F>(pointer, "TH2F", name, title, nbinx, xmin, xmax, nbiny, ymin, ymax);
75  _histograms.push_back(hp);
76 
77  LogDebug("TH2Fmade") << "Histogram " << name << " " << title << " pre-booked :" << _histograms.size();
78 
79  return pointer;
80 }
81 
82 TProfile2D** RunHistogramManager::makeTProfile2D(const char* name,
83  const char* title,
84  const unsigned int nbinx,
85  const double xmin,
86  const double xmax,
87  const unsigned int nbiny,
88  const double ymin,
89  const double ymax) {
90  TProfile2D** pointer = new TProfile2D*(nullptr);
91 
93  new HistoParams<TProfile2D>(pointer, "TProfile2D", name, title, nbinx, xmin, xmax, nbiny, ymin, ymax);
94  _histograms.push_back(hp);
95 
96  LogDebug("TProfile2Dmade") << "Histogram " << name << " " << title << " pre-booked :" << _histograms.size();
97 
98  return pointer;
99 }
100 
103  beginRun(iRun, tfserv->tFileDirectory());
104 }
105 
107  if (!_fillHistograms) {
108  beginRun(iRun.run(), subdir);
109  } else {
110  unsigned int fillnum = 0;
111 
113  iRun.getByToken(_conditionsInRunToken, cirb);
114 
115  if (!cirb.failedToGet() && cirb.isValid())
116  fillnum = cirb->lhcFillNumber;
117 
118  beginRun(fillnum, subdir);
119  }
120 }
121 
122 void RunHistogramManager::beginRun(const unsigned int irun) {
124  beginRun(irun, tfserv->tFileDirectory());
125 }
126 
127 void RunHistogramManager::beginRun(const unsigned int irun, TFileDirectory& subdir) {
128  // create/go to the run subdirectory
129 
130  char fillrun[30];
131 
132  if (!_fillHistograms) {
133  sprintf(fillrun, "%s", "run");
134  } else {
135  sprintf(fillrun, "%s", "fill");
136  }
137 
138  char dirname[300];
139  sprintf(dirname, "%s_%d", fillrun, irun);
140  TFileDirectory subrun = subdir.mkdir(dirname);
141 
142  // loop on the histograms and update the pointer references
143 
144  for (unsigned int ih = 0; ih < _histograms.size(); ++ih) {
145  _histograms[ih]->beginRun(irun, subrun, fillrun);
146  }
147 }
edm::EDGetTokenT< edm::ConditionsInRunBlock > _conditionsInRunToken
bool failedToGet() const
Definition: HandleBase.h:72
TFileDirectory & tFileDirectory()
Definition: TFileService.h:42
TH1F ** makeTH1F(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
RunNumber_t run() const
Definition: RunBase.h:40
RunHistogramManager(edm::ConsumesCollector &&iC, const bool fillHistograms=false)
TProfile ** makeTProfile(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
std::vector< BaseHistoParams * > _histograms
TProfile2D ** makeTProfile2D(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax, const unsigned int nbiny, const double ymin, const double ymax)
void beginRun(const edm::Run &iRun)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Run.h:315
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
TH2F ** makeTH2F(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax, const unsigned int nbiny, const double ymin, const double ymax)
Definition: Run.h:45
#define LogDebug(id)