Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | List of all members
om::HistoTable Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-12-01/OnlineMonitoring/util/HistoTable.h"

Public Member Functions

void ReadFile (const char *file, Detector_t d)
 
const HistoDataLookUp (const char *nm) const
 
const HistoDataoperator[] (const char *nm) const
 

Static Public Member Functions

static HistoTableInstance (const char *f=0, Detector_t d=kALLDET)
 

Public Attributes

std::map< std::string, HistoDatafTable
 Histogram data by C++ name. More...
 

Private Member Functions

 HistoTable ()
 
char NewLineChar (const char *f)
 
void Unquote (std::string &s)
 

Detailed Description

Definition at line 14 of file HistoTable.h.

Constructor & Destructor Documentation

HistoTable::HistoTable ( )
private

Definition at line 17 of file HistoTable.cxx.

Referenced by Instance().

17 { }

Member Function Documentation

HistoTable & HistoTable::Instance ( const char *  f = 0,
Detector_t  d = kALLDET 
)
static
const HistoData * HistoTable::LookUp ( const char *  nm) const

Look up histogram data given name of histogram

Parameters
nm- "C++" name of histogram

Definition at line 293 of file HistoTable.cxx.

References om::cerr, e, allTimeWatchdog::endl, fTable, hd, MECModelEnuComparisons::i, and om::regex_match().

Referenced by om::HistoSet::CopyAndResetOne(), om::HistoSet::GetTH1F(), om::HistoSet::GetTH2F(), om::CaptionBox::GUIModelDataIssue(), om::ComparisonBox::GUIModelDataIssue(), operator[](), om::PlotViewer::Update(), om::PlotViewer::UpdateCompare(), and om::HistoSet::UTCReset().

294 {
295  //
296  // First, look for an exact match
297  //
298  std::map<std::string,HistoData>::const_iterator itr(fTable.find(nm));
299  if (itr!=fTable.end()) return (&itr->second);
300 
301  //
302  // If we didn't find an exact match, perhaps there is a wildcard
303  // expression that matches?
304  //
305  unsigned int nmatch = 0;
306  const HistoData* hd = 0;
307  std::map<std::string,HistoData>::const_iterator i(fTable.begin());
308  std::map<std::string,HistoData>::const_iterator e(fTable.end());
309  for (; i!=e; ++i) {
310  if (regex_match(nm, i->first)==0) {
311  hd = (&i->second);
312  ++nmatch;
313  }
314  }
315  //
316  // Success is finding one unique match
317  //
318  if (nmatch==1) return hd;
319 
320  //
321  // At this point, we have either zero matches or more than one
322  //
323  if (nmatch>1) {
324  std::cerr << "Match to histogram " << nm << " is not unique, nmatch="
325  << nmatch
326  << std::endl;
327  abort();
328  }
329  return hd;
330 }
static constexpr Double_t nm
Definition: Munits.h:133
OStream cerr
Definition: OStream.cxx:7
int regex_match(const std::string &s, const std::string &p)
Definition: RegexMatch.cxx:7
std::map< std::string, HistoData > fTable
Histogram data by C++ name.
Definition: HistoTable.h:34
Float_t e
Definition: plot.C:35
TH1F * hd
Definition: Xdiff_gwt.C:57
char HistoTable::NewLineChar ( const char *  f)
private

Definition at line 45 of file HistoTable.cxx.

References file, and string.

Referenced by ReadFile().

46 {
47  //
48  // Read a line assuming linux format ('\n' = new line)
49  //
50  std::string linux_line;
51  {
52  std::ifstream file(f);
53  if (file.good()) {
54  getline(file, linux_line, '\n');
55  }
56  }
57 
58  //
59  // Read a line assuming windows format ('\r' = new line)
60  //
61  std::string windows_line;
62  {
63  std::ifstream file(f);
64  if (file.good()) {
65  getline(file, windows_line, '\r');
66  }
67  }
68 
69  if (windows_line.length() < linux_line.length()) return '\r';
70  return '\n';
71 }
TFile * file
Definition: cellShifts.C:17
enum BeamMode string
const HistoData & HistoTable::operator[] ( const char *  nm) const

Definition at line 334 of file HistoTable.cxx.

References om::cerr, d, allTimeWatchdog::endl, and LookUp().

335 {
336  const HistoData* d = this->LookUp(nm);
337  if (d==0) {
338  std::cerr << __FILE__ << " " << __LINE__ << ": "
339  << "Unable to find " << nm << std::endl;
340  abort();
341  }
342  return *d;
343 }
const HistoData * LookUp(const char *nm) const
Definition: HistoTable.cxx:293
static constexpr Double_t nm
Definition: Munits.h:133
OStream cerr
Definition: OStream.cxx:7
Float_t d
Definition: plot.C:236
void HistoTable::ReadFile ( const char *  file,
Detector_t  d 
)

Load the histogram data from a .csv file

Parameters
file- name of file to read
d- which detector context to apply (far/near/NDOS?)

Definition at line 75 of file HistoTable.cxx.

References plot_validation_datamc::c, make_true_q0q3_plots::caption, make_static_page::cat, gen_flatrecord::category, om::cerr, om::cout, runNovaSAM::detector, allTimeWatchdog::endl, om::HistoData::fCaption, om::HistoData::fCategory, om::HistoData::fDetector, file, om::HistoData::fLookBack, om::HistoData::fName, om::HistoData::fNx, om::HistoData::fNy, om::HistoData::fOption, om::HistoData::fReset, fTable, om::HistoData::fTitle, om::HistoData::fType, om::HistoData::fX1, om::HistoData::fX2, om::HistoData::fY1, om::HistoData::fY2, make_syst_table_plots::h, MECModelEnuComparisons::i, om::HistoData::IsValid(), om::TickerSubscriber::k10min, om::TickerSubscriber::k1min, om::TickerSubscriber::k24hr, om::TickerSubscriber::k30min, om::TickerSubscriber::k30sec, om::TickerSubscriber::k5min, om::kALLDET, om::kFARDET, om::TickerSubscriber::kHour, om::kNDOS, om::kNEARDET, om::TickerSubscriber::kRun, om::TickerSubscriber::kSubrun, om::kTESTBEAM, om::kTH1F, om::kTH2F, om::kUnknownDet, om::kUnknownType, om::TickerSubscriber::kUTC, NewLineChar(), msf_helper::o, MECModelEnuComparisons::opt, string, plotROC::title, Unquote(), x1, submit_syst::x2, y1, and submit_syst::y2.

Referenced by Instance().

76 {
77  fTable.clear();
78 
79  //
80  // See if we can detect if this file is windows or linux formatted
81  //
82  char newline = this->NewLineChar(f);
83 
88  std::string nx;
91  std::string ny;
94  std::string option;
96  std::string reset;
97  std::string lookback;
99 
100  int i;
101  int lineno = 0;
102  std::ifstream file(f);
103  bool haveheader = false;
104  while (file.good()) {
105  getline(file, name, ',');
106  getline(file, title, ',');
107  getline(file, category, ',');
108  getline(file, type, ',');
109  getline(file, nx, ',');
110  getline(file, x1, ',');
111  getline(file, x2, ',');
112  getline(file, ny, ',');
113  getline(file, y1, ',');
114  getline(file, y2, ',');
115  getline(file, option, ',');
116  getline(file, detector, ',');
117  getline(file, reset, ',');
118  getline(file, lookback, ',');
119  getline(file, caption, newline);
120  ++lineno;
121 
122  //
123  // Some editors put all text into quotes in .csv files. Undo that
124  // if its happened
125  //
126  this->Unquote(name);
127  this->Unquote(title);
128  this->Unquote(category);
129  this->Unquote(type);
130  this->Unquote(nx);
131  this->Unquote(x1);
132  this->Unquote(x2);
133  this->Unquote(ny);
134  this->Unquote(y1);
135  this->Unquote(y2);
136  this->Unquote(option);
137  this->Unquote(detector);
138  this->Unquote(reset);
139  this->Unquote(lookback);
140  this->Unquote(caption);
141 
142  // line for debugging .csv file
143  //std::cout << "\n" << lineno << "\t" << name << "\t" << title << "\t" << category << std::endl;
144 
145  //
146  // Check if this line is the column labels across the top
147  //
148  if (name == "Name" &&
149  title == "Title" &&
150  category == "Category" &&
151  type == "Type" &&
152  nx == "nx" &&
153  x1 == "x1" &&
154  x2 == "x2" &&
155  ny == "ny" &&
156  y1 == "y1" &&
157  y2 == "y2" &&
158  option == "Option" &&
159  detector == "Detector" &&
160  reset == "Reset" &&
161  lookback == "Look back" &&
162  caption == "Caption") {
163  if (haveheader==false) {
164  haveheader = true;
165  continue;
166  }
167  }
168 
169  //
170  // Contruct the data object
171  //
172  HistoData h;
173  h.fName = name;
174  h.fTitle = title;
175  h.fCaption = caption;
176 
177  h.fNx = atoi(nx.c_str());
178  h.fX1 = atof(x1.c_str());
179  h.fX2 = atof(x2.c_str());
180 
181  h.fNy = atoi(ny.c_str());
182  h.fY1 = atof(y1.c_str());
183  h.fY2 = atof(y2.c_str());
184 
186  const char* detstr[] = {"all", "test", "far", "near", "NDOS",0};
188  for (i=0; detstr[i]!=0; ++i) {
189  if (detector==detstr[i]) { h.fDetector = detind[i]; break; }
190  }
191 
192  h.fType = kUnknownType;
193  const char* typestr[] = {"TH1F","TH2F",0};
194  Histo_t typeind[] = {kTH1F, kTH2F};
195  for (i=0; typestr[i]!=0; ++i) {
196  if (type==typestr[i]) { h.fType = typeind[i]; break; }
197  }
198 
199  const char* rstr[] = {
200  "run",
201  "subrun",
202  "30sec",
203  "1min",
204  "5min",
205  "10min",
206  "30min",
207  "hour",
208  "24hr",
209  "utc",
210  0
211  };
212  unsigned int rind[] = {
223  };
224  for (i=0; rstr[i]!=0; ++i) {
225  if (reset==rstr[i]) { h.fReset = rind[i]; break; }
226  }
227  h.fLookBack = atoi(lookback.c_str());
228 
229  //
230  // If the histogram name is a wildcard, we want to create a
231  // sub-category to hold all the possible matches.
232  //
233  bool iswildcard = (name.find('*')!=name.npos);
234  std::string suffix;
235  if (iswildcard) {
236  suffix = "/";
237  suffix += name;
238  }
239 
240  //
241  // Parse out the category field
242  //
243  std::stringstream cat(category);
244  std::string c;
245  while (cat.good()) {
246  getline(cat, c, ':');
247  c += suffix;
248  h.fCategory.push_back(c);
249  }
250 
251  std::stringstream opt(option);
252  std::string o;
253  while (opt.good()) {
254  getline(opt, o, ':');
255  h.fOption.push_back(o);
256  }
257 
258  //
259  // Check that the entry makes sense before inserting into table
260  //
261  if (!h.IsValid()) {
262  std::cerr << __FILE__ << ":" << __LINE__ <<
263  " Bad entry at line " << lineno << " in file " << f << std::endl;
264  abort();
265  }
266 
267  //
268  // Insert it into the table if the detector context matches and we
269  // do not already have an entry for this histogram
270  //
271  if (h.fDetector==kALLDET || h.fDetector==det) {
272  if (fTable.find(name)==fTable.end()) {
273  fTable[name] = h;
274  }
275  else {
276  std::cerr << "Duplicate entries for histogram "
277  << name << std::endl;
278  abort();
279  }
280  }
281  }
282  if (haveheader==false) {
283  std::cout << __FILE__ << ":" << __LINE__
284  << " Bad csv file read " << f
285  << ". Header has incorrect format."
286  << std::endl;
287  abort();
288  }
289 }
double fX1
Low edge of x range.
Definition: HistoData.h:50
unsigned int fLookBack
How many copies to save in history.
Definition: HistoData.h:43
const XML_Char * name
Definition: expat.h:151
std::vector< std::string > fCategory
Categories this hist. belongs to.
Definition: HistoData.h:41
char NewLineChar(const char *f)
Definition: HistoTable.cxx:45
Float_t y1[n_points_granero]
Definition: compare.C:5
Float_t x1[n_points_granero]
Definition: compare.C:5
OStream cerr
Definition: OStream.cxx:7
bool IsValid() const
Definition: HistoData.cxx:4
std::string fCaption
What does this histogram show?
Definition: HistoData.h:56
std::string fTitle
Titles for histogram.
Definition: HistoData.h:48
int fNx
Number of bins in x.
Definition: HistoData.h:49
std::vector< std::string > fOption
Booking/drawing options.
Definition: HistoData.h:55
double fY2
High edge of y range.
Definition: HistoData.h:54
std::string fName
C++ name of this histogram.
Definition: HistoData.h:47
double fX2
High edge of x range.
Definition: HistoData.h:51
OStream cout
Definition: OStream.cxx:6
Histo_t fType
What kind of histogram is this?
Definition: HistoData.h:46
TFile * file
Definition: cellShifts.C:17
std::map< std::string, HistoData > fTable
Histogram data by C++ name.
Definition: HistoTable.h:34
double fNy
Number of bins in y.
Definition: HistoData.h:52
Detector_t fDetector
Detector these settings apply to.
Definition: HistoData.h:44
unsigned int fReset
Reset schedule (see TickerSubscriber.h)
Definition: HistoData.h:42
double fY1
Low edge of y range.
Definition: HistoData.h:53
enum om::_det_types Detector_t
void Unquote(std::string &s)
Definition: HistoTable.cxx:31
enum om::_histo_types Histo_t
enum BeamMode string
void HistoTable::Unquote ( std::string s)
private

Definition at line 31 of file HistoTable.cxx.

References ss, and string.

Referenced by ReadFile().

32 {
33  //
34  // Check if leading and trailing characters are "'s
35  //
36  if ( (*s.begin())=='"' && (*s.rbegin()=='"') ) {
38  ss = s.substr(1,s.length()-2);
39  s = ss;
40  }
41 }
Float_t ss
Definition: plot.C:24
const XML_Char * s
Definition: expat.h:262
enum BeamMode string

Member Data Documentation

std::map<std::string,HistoData> om::HistoTable::fTable

Histogram data by C++ name.

Definition at line 34 of file HistoTable.h.

Referenced by LookUp(), om::HistogramBrowser::MakeCategories(), and ReadFile().


The documentation for this class was generated from the following files: