QwAnalysis
QwHistogramHelper Class Reference

#include <QwHistogramHelper.h>

Data Structures

class  HistParams
 Histogram parameter class. More...
 

Public Member Functions

 QwHistogramHelper ()
 
virtual ~QwHistogramHelper ()
 
void ProcessOptions (QwOptions &options)
 Process the configuration options. More...
 
void LoadHistParamsFromFile (const std::string &filename)
 
void LoadTreeParamsFromFile (const std::string &filename)
 
void PrintHistParams () const
 
TH1F * Construct1DHist (const TString &inputfile, const TString &name_title)
 
TH2F * Construct2DHist (const TString &inputfile, const TString &name_title)
 
TH1F * Construct1DHist (const TString &name_title)
 
TH2F * Construct2DHist (const TString &name_title)
 
TProfile * Construct1DProf (const TString &name_title)
 
TProfile2D * Construct2DProf (const TString &name_title)
 
TH1F * Construct1DHist (const std::string &inputfile, const TString &name_title)
 
TH2F * Construct2DHist (const std::string &inputfile, const TString &name_title)
 
TProfile * Construct1DProf (const std::string &inputfile, const TString &name_title)
 
TProfile2D * Construct2DProf (const std::string &inputfile, const TString &name_title)
 
Bool_t MatchDeviceParamsFromList (const std::string &devicename)
 
Bool_t MatchVQWKElementFromList (const std::string &subsystemname, const std::string &moduletype, const std::string &devicename)
 

Static Public Member Functions

static void DefineOptions (QwOptions &options)
 Define the configuration options. More...
 

Protected Member Functions

TH1F * Construct1DHist (const HistParams &params)
 
TH2F * Construct2DHist (const HistParams &params)
 
TProfile * Construct1DProf (const HistParams &params)
 
TProfile2D * Construct2DProf (const HistParams &params)
 
const HistParams GetHistParamsFromLine (QwParameterFile &mapstr)
 
const HistParams GetHistParamsFromFile (const std::string &filename, const TString &histname)
 
const HistParams GetHistParamsFromList (const TString &histname)
 
Bool_t DoesMatch (const TString &s, const TRegexp &wildcard)
 

Protected Attributes

Bool_t fDEBUG
 
Bool_t fTrimDisable
 
Bool_t fTrimHistoEnable
 
Bool_t fTreeTrimFileLoaded
 
std::string fInputFile
 
std::vector< HistParamsfHistParams
 
std::vector< std::pair
< TString, TRegexp > > 
fTreeParams
 
std::vector< TString > fSubsystemList
 
std::vector< std::vector
< TString > > 
fModuleList
 
std::vector< std::vector
< std::vector< TString > > > 
fVQWKTrimmedList
 

Static Protected Attributes

static const Double_t fInvalidNumber = -1.0e7
 
static const TString fInvalidName = "EmptyEmpty"
 

Detailed Description

This class exists to encapsulate several helper functions to aid in describing histograms. There will be a global copy defined within the analysis framework.

Definition at line 21 of file QwHistogramHelper.h.

Constructor & Destructor Documentation

QwHistogramHelper::QwHistogramHelper ( )
inline

Definition at line 23 of file QwHistogramHelper.h.

References fHistParams.

23 : fDEBUG(kFALSE) { fHistParams.clear(); };
std::vector< HistParams > fHistParams
virtual QwHistogramHelper::~QwHistogramHelper ( )
inlinevirtual

Definition at line 24 of file QwHistogramHelper.h.

24 { };

Member Function Documentation

TH1F* QwHistogramHelper::Construct1DHist ( const TString &  inputfile,
const TString &  name_title 
)
inline
TH1F * QwHistogramHelper::Construct1DHist ( const TString &  name_title)

Definition at line 441 of file QwHistogramHelper.cc.

References Construct1DHist(), and GetHistParamsFromList().

442 {
443  HistParams tmpstruct = GetHistParamsFromList(name_title);
444  return Construct1DHist(tmpstruct);
445 }
const HistParams GetHistParamsFromList(const TString &histname)
TH1F * Construct1DHist(const TString &inputfile, const TString &name_title)

+ Here is the call graph for this function:

TH1F * QwHistogramHelper::Construct1DHist ( const std::string &  inputfile,
const TString &  name_title 
)

Definition at line 473 of file QwHistogramHelper.cc.

References Construct1DHist(), and GetHistParamsFromFile().

474 {
475  HistParams tmpstruct = GetHistParamsFromFile(inputfile, name_title);
476  return Construct1DHist(tmpstruct);
477 }
const HistParams GetHistParamsFromFile(const std::string &filename, const TString &histname)
TH1F * Construct1DHist(const TString &inputfile, const TString &name_title)

+ Here is the call graph for this function:

TH1F * QwHistogramHelper::Construct1DHist ( const HistParams params)
protected

Definition at line 497 of file QwHistogramHelper.cc.

References fInvalidName, fTrimHistoEnable, QwHistogramHelper::HistParams::name_title, QwHistogramHelper::HistParams::x_max, QwHistogramHelper::HistParams::x_min, QwHistogramHelper::HistParams::x_nbins, QwHistogramHelper::HistParams::xtitle, and QwHistogramHelper::HistParams::ytitle.

498 {
499  TH1F* h1 = 0;
500  if (fTrimHistoEnable && params.name_title == fInvalidName) {
501  return h1;
502  }
503 
504  h1 = new TH1F(params.name_title,
505  params.name_title,
506  params.x_nbins,
507  Double_t(params.x_min),Double_t(params.x_max));
508  h1->SetXTitle(params.xtitle);
509  h1->SetYTitle(params.ytitle);
510  // if(params.min!=fInvalidNumber) h1->SetMinimum(params.min);
511  // if(params.max!=fInvalidNumber) h1->SetMinimum(params.max);
512  return h1;
513 }
static const TString fInvalidName
TProfile * QwHistogramHelper::Construct1DProf ( const TString &  name_title)

Definition at line 457 of file QwHistogramHelper.cc.

References GetHistParamsFromList().

Referenced by Construct1DProf(), and QwBeamMod::ConstructHistograms().

458 {
459  HistParams tmpstruct = GetHistParamsFromList(name_title);
460  return Construct1DProf(tmpstruct);
461 }
const HistParams GetHistParamsFromList(const TString &histname)
TProfile * Construct1DProf(const TString &name_title)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

TProfile * QwHistogramHelper::Construct1DProf ( const std::string &  inputfile,
const TString &  name_title 
)

Definition at line 489 of file QwHistogramHelper.cc.

References Construct1DProf(), and GetHistParamsFromFile().

490 {
491  HistParams tmpstruct = GetHistParamsFromFile(inputfile, name_title);
492  return Construct1DProf(tmpstruct);
493 }
const HistParams GetHistParamsFromFile(const std::string &filename, const TString &histname)
TProfile * Construct1DProf(const TString &name_title)

+ Here is the call graph for this function:

TProfile * QwHistogramHelper::Construct1DProf ( const HistParams params)
protected

Definition at line 539 of file QwHistogramHelper.cc.

References fInvalidName, fTrimHistoEnable, QwHistogramHelper::HistParams::name_title, QwHistogramHelper::HistParams::x_max, QwHistogramHelper::HistParams::x_min, QwHistogramHelper::HistParams::x_nbins, QwHistogramHelper::HistParams::xtitle, QwHistogramHelper::HistParams::y_max, QwHistogramHelper::HistParams::y_min, and QwHistogramHelper::HistParams::ytitle.

540 {
541  TProfile* h1 = 0;
542  if (fTrimHistoEnable && params.name_title == fInvalidName) {
543  return h1;
544  }
545 
546  h1 = new TProfile(params.name_title,
547  params.name_title,
548  params.x_nbins,
549  Double_t(params.x_min),Double_t(params.x_max),
550  Double_t(params.y_min),Double_t(params.y_max));
551  h1->SetMinimum(params.y_min);
552  h1->SetMaximum(params.y_max);
553  h1->SetXTitle(params.xtitle);
554  h1->SetYTitle(params.ytitle);
555  return h1;
556 }
static const TString fInvalidName
TH2F* QwHistogramHelper::Construct2DHist ( const TString &  inputfile,
const TString &  name_title 
)
inline

Definition at line 41 of file QwHistogramHelper.h.

Referenced by Construct2DHist().

41  {
42  std::string tmpfile = inputfile.Data();
43  return Construct2DHist(tmpfile, name_title);
44  };
TH2F * Construct2DHist(const TString &inputfile, const TString &name_title)

+ Here is the caller graph for this function:

TH2F * QwHistogramHelper::Construct2DHist ( const TString &  name_title)

Definition at line 433 of file QwHistogramHelper.cc.

References Construct2DHist(), and GetHistParamsFromList().

434 {
435  HistParams tmpstruct = GetHistParamsFromList(name_title);
436  return Construct2DHist(tmpstruct);
437 }
const HistParams GetHistParamsFromList(const TString &histname)
TH2F * Construct2DHist(const TString &inputfile, const TString &name_title)

+ Here is the call graph for this function:

TH2F * QwHistogramHelper::Construct2DHist ( const std::string &  inputfile,
const TString &  name_title 
)

Definition at line 465 of file QwHistogramHelper.cc.

References Construct2DHist(), and GetHistParamsFromFile().

466 {
467  HistParams tmpstruct = GetHistParamsFromFile(inputfile, name_title);
468  return Construct2DHist(tmpstruct);
469 }
TH2F * Construct2DHist(const TString &inputfile, const TString &name_title)
const HistParams GetHistParamsFromFile(const std::string &filename, const TString &histname)

+ Here is the call graph for this function:

TH2F * QwHistogramHelper::Construct2DHist ( const HistParams params)
protected

Definition at line 517 of file QwHistogramHelper.cc.

References fInvalidName, fTrimHistoEnable, QwHistogramHelper::HistParams::name_title, QwHistogramHelper::HistParams::x_max, QwHistogramHelper::HistParams::x_min, QwHistogramHelper::HistParams::x_nbins, QwHistogramHelper::HistParams::xtitle, QwHistogramHelper::HistParams::y_max, QwHistogramHelper::HistParams::y_min, QwHistogramHelper::HistParams::y_nbins, and QwHistogramHelper::HistParams::ytitle.

518 {
519  TH2F* h2 = 0;
520  if (fTrimHistoEnable && params.name_title == fInvalidName) {
521  return h2;
522  }
523 
524  h2 = new TH2F(params.name_title,
525  params.name_title,
526  params.x_nbins,
527  Double_t(params.x_min),Double_t(params.x_max),
528  params.y_nbins,
529  Double_t(params.y_min),Double_t(params.y_max));
530  h2->SetXTitle(params.xtitle);
531  h2->SetYTitle(params.ytitle);
532  // if (params.min != fInvalidNumber) h2->SetMinimum(params.min);
533  // if (params.max != fInvalidNumber) h2->SetMinimum(params.max);
534  return h2;
535 }
static const TString fInvalidName
TProfile2D * QwHistogramHelper::Construct2DProf ( const TString &  name_title)

Definition at line 449 of file QwHistogramHelper.cc.

References GetHistParamsFromList().

Referenced by Construct2DProf().

450 {
451  HistParams tmpstruct = GetHistParamsFromList(name_title);
452  return Construct2DProf(tmpstruct);
453 }
const HistParams GetHistParamsFromList(const TString &histname)
TProfile2D * Construct2DProf(const TString &name_title)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

TProfile2D * QwHistogramHelper::Construct2DProf ( const std::string &  inputfile,
const TString &  name_title 
)

Definition at line 481 of file QwHistogramHelper.cc.

References Construct2DProf(), and GetHistParamsFromFile().

482 {
483  HistParams tmpstruct = GetHistParamsFromFile(inputfile, name_title);
484  return Construct2DProf(tmpstruct);
485 }
TProfile2D * Construct2DProf(const TString &name_title)
const HistParams GetHistParamsFromFile(const std::string &filename, const TString &histname)

+ Here is the call graph for this function:

TProfile2D * QwHistogramHelper::Construct2DProf ( const HistParams params)
protected

Definition at line 560 of file QwHistogramHelper.cc.

References fInvalidName, fTrimHistoEnable, QwHistogramHelper::HistParams::name_title, QwHistogramHelper::HistParams::x_max, QwHistogramHelper::HistParams::x_min, QwHistogramHelper::HistParams::x_nbins, QwHistogramHelper::HistParams::xtitle, QwHistogramHelper::HistParams::y_max, QwHistogramHelper::HistParams::y_min, QwHistogramHelper::HistParams::y_nbins, QwHistogramHelper::HistParams::ytitle, QwHistogramHelper::HistParams::z_max, and QwHistogramHelper::HistParams::z_min.

561 {
562  TProfile2D* h2 = 0;
563  if (fTrimHistoEnable && params.name_title == fInvalidName) {
564  return h2;
565  }
566 
567  h2 = new TProfile2D(params.name_title,
568  params.name_title,
569  params.x_nbins,
570  Double_t(params.x_min),Double_t(params.x_max),
571  params.y_nbins,
572  Double_t(params.y_min),Double_t(params.y_max),
573  Double_t(params.z_min),Double_t(params.z_max));
574  h2->SetMinimum(params.z_min);
575  h2->SetMaximum(params.z_max);
576  h2->SetXTitle(params.xtitle);
577  h2->SetYTitle(params.ytitle);
578  return h2;
579 }
static const TString fInvalidName
void QwHistogramHelper::DefineOptions ( QwOptions options)
static

Define the configuration options.

Definition at line 24 of file QwHistogramHelper.cc.

References QwOptions::AddOptions(), and default_bool_value.

Referenced by QwOptions::DefineOptions().

25 {
26  // Define the histogram and tree options
27  options.AddOptions()
28  ("enable-tree-trim", po::value<bool>()->default_bool_value(false),
29  "enable trimmed trees");
30 
31  options.AddOptions()
32  ("enable-histo-trim", po::value<bool>()->default_bool_value(false),
33  "enable trimmed histograms");
34 
35  options.AddOptions()(
36  "tree-trim-file",
37  po::value<string>()->default_value("tree_trim.in"),
38  "trimmed tree file name"
39  );
40 
41  // What about QwTracking ?
42  // Monday, October 18 23:19:09 EDT 2010, jhlee
43  options.AddOptions()(
44  "histo-trim-file",
45  po::value<string>()->default_value("parity_hist.in"),
46  "trimmed histo file name"
47  );
48 
49 }
#define default_bool_value(b)
Definition: QwOptions.h:51
po::options_description_easy_init AddOptions(const std::string &blockname="Specialized options")
Add an option to a named block or create new block.
Definition: QwOptions.h:164

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Bool_t QwHistogramHelper::DoesMatch ( const TString &  s,
const TRegexp &  wildcard 
)
protected

Definition at line 416 of file QwHistogramHelper.cc.

Referenced by GetHistParamsFromFile(), GetHistParamsFromList(), MatchDeviceParamsFromList(), and MatchVQWKElementFromList().

417 {
418  // A very quick and dirty string matching routine using root
419  // TString and TRegExp functions. Require the string and wildcard string
420  // to have the SAME length to match (much risky if we don't require this),
421  // so the only wildcard you want to use here is ".".
422 
423  static Ssiz_t len = 0;
424  if (wildcard.Index(s,&len) == 0 && len == s.Length()) {
425  // found a match!
426  return kTRUE;
427  } else
428  return kFALSE;
429 }

+ Here is the caller graph for this function:

const QwHistogramHelper::HistParams QwHistogramHelper::GetHistParamsFromFile ( const std::string &  filename,
const TString &  histname 
)
protected

Definition at line 369 of file QwHistogramHelper.cc.

References DoesMatch(), QwLog::endl(), fDEBUG, fInvalidName, fTrimHistoEnable, GetHistParamsFromLine(), QwHistogramHelper::HistParams::name_title, QwError, QwMessage, and QwParameterFile::TrimComment().

Referenced by Construct1DHist(), Construct1DProf(), Construct2DHist(), and Construct2DProf().

372 {
373  // The idea is to look up the input file and get the needed histogram parameters
374  // For each histogram we are going to scan the input file once, which
375  // is not very efficient. But we only construct histograms once per run ...
376 
377  HistParams tmpstruct;
378  tmpstruct.name_title = fInvalidName;
379 
380  // Open the file
381  QwParameterFile mapstr(filename.c_str());
382  while (mapstr.ReadNextLine()) {
383  mapstr.TrimComment(); // Remove everything after a comment character
384  mapstr.TrimWhitespace(); // Get rid of leading and trailing spaces
385  if (mapstr.LineIsEmpty()) continue;
386 
387  TString tmpname = mapstr.GetTypedNextToken<TString>();
388  TString tmptype = mapstr.GetTypedNextToken<TString>();
389  if (tmptype != "TH1F" && tmptype != "TH2F") {
390  QwError << "QwHistogramHelper::GetHistParamsFromFile: Unrecognized histogram type: "
391  << tmptype << " (tmpname==" << tmpname <<")"<< QwLog::endl;
392  continue;
393  }
394 
395  if (DoesMatch(histname,tmpname)) {
396  // Found a match
397  mapstr.RewindToLineStart();
398  tmpstruct = GetHistParamsFromLine(mapstr);
399  tmpstruct.name_title = histname;
400  }
401  }
402 
403  if (fDEBUG) {
404  QwMessage << tmpstruct << QwLog::endl;
405  }
406  if (tmpstruct.name_title == fInvalidName && !fTrimHistoEnable) {
407  QwError << "GetHistParamsFromFile: We haven't found a match of the histogram name: "
408  << histname << QwLog::endl;
409  QwError << " Please check the input file "
410  << filename << QwLog::endl;
411  exit(1);
412  }
413  return tmpstruct;
414 }
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
const HistParams GetHistParamsFromLine(QwParameterFile &mapstr)
void TrimComment(const char commentchar)
static const TString fInvalidName
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
Bool_t DoesMatch(const TString &s, const TRegexp &wildcard)
#define QwError
Predefined log drain for errors.
Definition: QwLog.h:40

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const QwHistogramHelper::HistParams QwHistogramHelper::GetHistParamsFromLine ( QwParameterFile mapstr)
protected

Decodes the histogram parameters from the current line of a QwParameter file. If the line cannot be decoded, the name is returned as fInvalidName.

Definition at line 75 of file QwHistogramHelper.cc.

References QwLog::endl(), QwHistogramHelper::HistParams::expression, fInvalidName, fInvalidNumber, QwParameterFile::GetTypedNextToken(), QwHistogramHelper::HistParams::max, QwHistogramHelper::HistParams::min, QwHistogramHelper::HistParams::name_title, QwError, QwHistogramHelper::HistParams::type, QwHistogramHelper::HistParams::x_max, QwHistogramHelper::HistParams::x_min, QwHistogramHelper::HistParams::x_nbins, QwHistogramHelper::HistParams::xtitle, QwHistogramHelper::HistParams::y_max, QwHistogramHelper::HistParams::y_min, QwHistogramHelper::HistParams::y_nbins, and QwHistogramHelper::HistParams::ytitle.

Referenced by GetHistParamsFromFile(), and LoadHistParamsFromFile().

76 {
77  /// Decodes the histogram parameters from the current line of
78  /// a QwParameter file.
79  /// If the line cannot be decoded, the name is returned as
80  /// fInvalidName.
81  HistParams tmpstruct;
82  tmpstruct.name_title = fInvalidName;
83 
84  std::string tmpname = mapstr.GetTypedNextToken<std::string>();
85  std::string tmptype = mapstr.GetTypedNextToken<std::string>();
86  if (tmptype != "TH1F" && tmptype != "TH2F"
87  && tmptype != "TProfile" && tmptype != "TProfile2D"){
88  QwError << "QwHistogramHelper::GetHistParamsFromFile: Unrecognized histogram type: "
89  << tmptype << " (tmpname==" << tmpname <<")"<< QwLog::endl;
90  } else {
91  tmpstruct.expression = tmpname;
92  tmpstruct.name_title = tmpname;
93  tmpstruct.type = tmptype;
94  tmpstruct.x_nbins = mapstr.GetTypedNextToken<Int_t>();
95  tmpstruct.x_min = mapstr.GetTypedNextToken<Float_t>();
96  tmpstruct.x_max = mapstr.GetTypedNextToken<Float_t>();
97  if (tmptype == "TH2F") {
98  tmpstruct.y_nbins = mapstr.GetTypedNextToken<Int_t>();
99  tmpstruct.y_min = mapstr.GetTypedNextToken<Float_t>();
100  tmpstruct.y_max = mapstr.GetTypedNextToken<Float_t>();
101  } else if (tmptype == "TProfile") {
102  tmpstruct.y_nbins = 0;
103  tmpstruct.y_min = mapstr.GetTypedNextToken<Float_t>();
104  tmpstruct.y_max = mapstr.GetTypedNextToken<Float_t>();
105  } else {
106  tmpstruct.y_nbins = 0;
107  tmpstruct.y_min = 0.0;
108  tmpstruct.y_max = 0.0;
109  }
110  tmpstruct.xtitle = mapstr.GetTypedNextToken<TString>();
111  tmpstruct.ytitle = mapstr.GetTypedNextToken<TString>();
112 
113  std::string tmpmin = mapstr.GetTypedNextToken<std::string>();
114  if (tmpmin.find_first_not_of("-+1234567890.eE") == std::string::npos) {
115  // tmpmin is a number
116  tmpstruct.min = atof(tmpmin.c_str());
117  } else {
118  tmpstruct.min = fInvalidNumber;
119  }
120  std::string tmpmax = mapstr.GetTypedNextToken<std::string>();
121  if (tmpmax.find_first_not_of("-+1234567890.eE") == std::string::npos) {
122  // tmpmax is a number
123  tmpstruct.max = atof(tmpmax.c_str());
124  } else {
125  tmpstruct.max = fInvalidNumber;
126  }
127  }
128  return tmpstruct;
129 }
static const Double_t fInvalidNumber
static const TString fInvalidName
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
T GetTypedNextToken()
Get next token into specific type.
#define QwError
Predefined log drain for errors.
Definition: QwLog.h:40

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const QwHistogramHelper::HistParams QwHistogramHelper::GetHistParamsFromList ( const TString &  histname)
protected

Definition at line 247 of file QwHistogramHelper.cc.

References DoesMatch(), QwLog::endl(), fDEBUG, fHistParams, fInputFile, fInvalidName, fTrimHistoEnable, QwHistogramHelper::HistParams::max, QwHistogramHelper::HistParams::min, QwHistogramHelper::HistParams::name_title, QwHistogramHelper::HistParams::nbins, QwMessage, QwWarning, QwHistogramHelper::HistParams::x_max, QwHistogramHelper::HistParams::x_min, QwHistogramHelper::HistParams::x_nbins, QwHistogramHelper::HistParams::y_max, QwHistogramHelper::HistParams::y_min, and QwHistogramHelper::HistParams::y_nbins.

Referenced by Construct1DHist(), Construct1DProf(), Construct2DHist(), and Construct2DProf().

248 {
249  HistParams tmpstruct, matchstruct;
250  tmpstruct.name_title = fInvalidName;
251 
252  std::vector<int> matches;
253  for (size_t i = 0; i < fHistParams.size(); i++) {
254  if (DoesMatch(histname,fHistParams.at(i).expression)) {
255  matchstruct = fHistParams.at(i);
256  if (tmpstruct.name_title == fInvalidName) {
257  tmpstruct = matchstruct;
258  tmpstruct.name_title = histname;
259  matches.push_back(i);
260  break; // enabled (to get warnings for multiple definitions, disable)
261  } else if (tmpstruct.nbins == matchstruct.nbins
262  && tmpstruct.min == matchstruct.min
263  && tmpstruct.max == matchstruct.max
264  && tmpstruct.x_nbins == matchstruct.x_nbins
265  && tmpstruct.x_min == matchstruct.x_min
266  && tmpstruct.x_max == matchstruct.x_max
267  && tmpstruct.y_nbins == matchstruct.y_nbins
268  && tmpstruct.y_min == matchstruct.y_min
269  && tmpstruct.y_max == matchstruct.y_max) {
270  //matches.push_back(i); // disabled (to enable, also remove break above)
271  }
272  }
273  }
274 
275  // Warn when multiple identical matches were found
276  if (matches.size() > 1) {
277  QwWarning << "Multiple identical matches for histogram " << histname << ":" << QwLog::endl;
278  for (size_t i = 0; i < matches.size(); i++) {
279  QwWarning << " " << fHistParams.at(matches.at(i)).name_title << QwLog::endl;
280  }
281  }
282 
283  fDEBUG = 0;
284  if (fDEBUG) {
285  QwMessage << "Finding histogram defination from: " << histname << QwLog::endl;
286  QwMessage << tmpstruct << QwLog::endl;
287  }
288  if (tmpstruct.name_title == fInvalidName && !fTrimHistoEnable) {
289  std::cerr << "GetHistParamsFromList: We haven't found a match of the histogram name: "
290  << histname << std::endl;
291  std::cerr << " Please check the input file "
292  << fInputFile << std::endl;
293  exit(1);
294  }
295  return tmpstruct;
296 }
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
static const TString fInvalidName
std::vector< HistParams > fHistParams
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
Bool_t DoesMatch(const TString &s, const TRegexp &wildcard)
#define QwWarning
Predefined log drain for warnings.
Definition: QwLog.h:45

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void QwHistogramHelper::LoadHistParamsFromFile ( const std::string &  filename)

Definition at line 133 of file QwHistogramHelper.cc.

References QwLog::endl(), fDEBUG, fHistParams, fInputFile, fInvalidName, fTrimHistoEnable, GetHistParamsFromLine(), QwParameterFile::LineIsEmpty(), QwHistogramHelper::HistParams::name_title, QwMessage, QwParameterFile::ReadNextLine(), QwParameterFile::TrimComment(), and QwParameterFile::TrimWhitespace().

Referenced by main(), and ProcessOptions().

134 {
135  fInputFile = filename;
136 
137  fDEBUG = 0;
138  //fDEBUG = 1;
139 
140  if (fDEBUG) std::cout<< "file name "<<fInputFile<<std::endl;
141  //Important to empty the fHistParams to reload the real time histo difinition file
142  if (fTrimHistoEnable)
143  fHistParams.clear();
144 
145  // Open the file
146  QwParameterFile mapstr(filename);
147  while (mapstr.ReadNextLine()){
148  mapstr.TrimComment(); // Remove everything after a comment character.
149  mapstr.TrimWhitespace(); // Get rid of leading and trailing spaces.
150  if (mapstr.LineIsEmpty()) continue;
151 
152  HistParams tmpstruct = GetHistParamsFromLine(mapstr);
153  if (tmpstruct.name_title != fInvalidName){
154  fHistParams.push_back(tmpstruct);
155  if (fDEBUG) {
156  QwMessage << fHistParams.back() << QwLog::endl;
157  }
158  }
159  }
160 
161  // Sort the histogram parameter definitions
162  sort(fHistParams.begin(), fHistParams.end());
163 }
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
const HistParams GetHistParamsFromLine(QwParameterFile &mapstr)
static const TString fInvalidName
std::vector< HistParams > fHistParams
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void QwHistogramHelper::LoadTreeParamsFromFile ( const std::string &  filename)

Definition at line 175 of file QwHistogramHelper.cc.

References QwLog::endl(), fDEBUG, fModuleList, fSubsystemList, fTreeParams, fTreeTrimFileLoaded, fTrimDisable, fVQWKTrimmedList, QwParameterFile::GetLine(), QwParameterFile::LineIsEmpty(), QwMessage, QwParameterFile::ReadNextLine(), QwParameterFile::ReadNextModule(), QwParameterFile::ReadNextSection(), QwParameterFile::TrimComment(), and QwParameterFile::TrimWhitespace().

Referenced by ProcessOptions().

176 {
177  TString devicename;
178  TString moduletype;
179  TString subsystemname;
180  QwParameterFile *section;
181  QwParameterFile *module;
182  std::vector<TString> TrimmedList;//stores the list of elements for each module
183  std::vector<std::vector<TString> > ModulebyTrimmedList;//stores the list of elements for each module
184  std::vector<TString> ModuleList;//stores the list of modules for each subsystem
185  fDEBUG = 0;
186  //fDEBUG = 1;
187  if (fTrimDisable)
188  return;
189  QwMessage << "Tree trim definition file for Offline Engine"<< QwLog::endl;
190  QwParameterFile mapstr(filename.c_str()); //Open the file
191 
192  fTreeTrimFileLoaded=!mapstr.IsEOF();
193  fSubsystemList.clear();
194  fModuleList.clear();
195  fVQWKTrimmedList.clear();
196 
197  while ( (section=mapstr.ReadNextSection(subsystemname)) ){
198  if (subsystemname=="DEVICELIST")//done with VQWK element trimming
199  break;
200  fSubsystemList.push_back(subsystemname);
201  QwMessage <<"Subsystem found "<<subsystemname<<QwLog::endl;
202 
203  ModuleList.clear();
204  ModulebyTrimmedList.clear();
205  while ( (module=section->ReadNextModule(moduletype)) ){
206 
207  ModuleList.push_back(moduletype);
208  QwMessage <<"Module found "<<moduletype<<QwLog::endl;
209  TrimmedList.clear();
210  while (module->ReadNextLine()){
211  module->TrimComment('#'); // Remove everything after a '#' character.
212  module->TrimWhitespace(); // Get rid of leading and trailing spaces.
213  if (module->LineIsEmpty()) continue;
214  devicename=(module->GetLine()).c_str();
215  TrimmedList.push_back(devicename);
216  if (fDEBUG) {
217  QwMessage <<"data element "<<devicename<<QwLog::endl;
218  }
219  }
220  ModulebyTrimmedList.push_back(TrimmedList);
221 
222 
223  }
224  fModuleList.push_back(ModuleList);
225  fVQWKTrimmedList.push_back(ModulebyTrimmedList);
226 
227 
228  }
229  //Start decoding the device list in the section [DEVICELIST]
230  fTreeParams.clear();
231  while (section->ReadNextLine()){
232  section->TrimComment('#'); // Remove everything after a '#' character.
233  section->TrimWhitespace(); // Get rid of leading and trailing spaces.
234  if (section->LineIsEmpty()) continue;
235  devicename=(section->GetLine()).c_str();
236  fTreeParams.push_back(std::pair<TString,TRegexp>(devicename,devicename));
237  if (fDEBUG)
238  QwMessage <<"device name "<<devicename<<QwLog::endl;
239 
240  }
241 
242  //exit(1);
243 
244 }
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
void TrimComment(const char commentchar)
std::vector< std::pair< TString, TRegexp > > fTreeParams
QwParameterFile * ReadNextSection(std::string &secname, const bool keep_header=false)
std::vector< TString > fSubsystemList
QwParameterFile * ReadNextModule(std::string &secname, bool keep_header=false)
std::string GetLine()
Bool_t ReadNextLine()
std::vector< std::vector< std::vector< TString > > > fVQWKTrimmedList
std::vector< std::vector< TString > > fModuleList
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Bool_t QwHistogramHelper::MatchDeviceParamsFromList ( const std::string &  devicename)

Definition at line 299 of file QwHistogramHelper.cc.

References DoesMatch(), QwLog::endl(), fDEBUG, fTreeParams, fTreeTrimFileLoaded, fTrimDisable, QwMessage, and QwWarning.

Referenced by QwScanner::ConstructBranchAndVector(), VQwScaler_Channel::ConstructBranchAndVector(), and QwVQWK_Channel::ConstructBranchAndVector().

300 {
301  Int_t matched;
302  matched=0;
303  if (!fTreeTrimFileLoaded || fTrimDisable){//if file is not loaded or trim tree is disable by cmd flag
304 
305  return kTRUE;//return true for all devices
306  }
307  for (size_t i = 0; i < fTreeParams.size(); i++) {
308  if (DoesMatch(devicename,fTreeParams.at(i).second)) {
309  if (fDEBUG)
310  QwMessage << " Branch name found " << fTreeParams.at(i).first << QwLog::endl;
311  matched++;
312  }
313  }
314 
315  // Warn when multiple identical matches were found
316  if (matched > 1) {
317  QwWarning << "Multiple identical matches for branch name " << devicename << ":" << QwLog::endl;
318  }
319  if (matched)
320  return kTRUE;
321  else
322  return kFALSE;
323 }
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
std::vector< std::pair< TString, TRegexp > > fTreeParams
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
Bool_t DoesMatch(const TString &s, const TRegexp &wildcard)
#define QwWarning
Predefined log drain for warnings.
Definition: QwLog.h:45

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Bool_t QwHistogramHelper::MatchVQWKElementFromList ( const std::string &  subsystemname,
const std::string &  moduletype,
const std::string &  devicename 
)

Definition at line 325 of file QwHistogramHelper.cc.

References DoesMatch(), QwLog::endl(), fDEBUG, fModuleList, fSubsystemList, fTreeTrimFileLoaded, fTrimDisable, fVQWKTrimmedList, QwMessage, and QwWarning.

Referenced by QwVQWK_Channel::ConstructBranchAndVector().

329 {
330  Int_t matched = 0;
331  if (!fTreeTrimFileLoaded || fTrimDisable){//if file is not loaded or trim tree is disable by cmd flag
332 
333  return kTRUE;//return true for all devices
334  }
335 
336  for (size_t j = 0; j < fSubsystemList.size(); j++) {
337  // QwMessage << " Subsystem name "<< subsystemname<< " From List "<<fSubsystemList.at(j) << QwLog::endl;
338  if (DoesMatch(subsystemname,fSubsystemList.at(j))){
339  for (size_t i = 0; i < fModuleList.at(j).size(); i++) {
340  if (DoesMatch(moduletype,fModuleList.at(j).at(i))) {
341  for (size_t k = 0; k < fVQWKTrimmedList.at(j).at(i).size(); k++) {
342  if (DoesMatch(elementname,fVQWKTrimmedList.at(j).at(i).at(k))){
343  if (fDEBUG)
344  QwMessage << "Subsystem " << fSubsystemList.at(j)
345  << " Module Type " << fModuleList.at(j).at(i)
346  << " Element " << fVQWKTrimmedList.at(j).at(i).at(k)
347  << QwLog::endl;
348  matched++;
349  }
350  }
351  break;
352  }
353  }
354  }
355  }
356 
357 
358  // Warn when multiple identical matches were found
359  if (matched > 1) {
360  QwWarning << "Multiple identical matches for element name " <<elementname << ":" << QwLog::endl;
361  }
362  if (matched)
363  return kTRUE;
364  else
365  return kFALSE;
366 }
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
std::vector< TString > fSubsystemList
std::vector< std::vector< std::vector< TString > > > fVQWKTrimmedList
std::vector< std::vector< TString > > fModuleList
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
Bool_t DoesMatch(const TString &s, const TRegexp &wildcard)
#define QwWarning
Predefined log drain for warnings.
Definition: QwLog.h:45

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void QwHistogramHelper::PrintHistParams ( ) const

Definition at line 166 of file QwHistogramHelper.cc.

References QwLog::endl(), fHistParams, and QwMessage.

167 {
168  for (std::vector<HistParams>::const_iterator h = fHistParams.begin();
169  h != fHistParams.end(); ++h) {
170  QwMessage << *h << QwLog::endl;
171  }
172 }
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
std::vector< HistParams > fHistParams
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299

+ Here is the call graph for this function:

void QwHistogramHelper::ProcessOptions ( QwOptions options)

Process the configuration options.

Definition at line 51 of file QwHistogramHelper.cc.

References QwLog::endl(), fTrimDisable, fTrimHistoEnable, QwOptions::GetValue(), QwOptions::HasValue(), LoadHistParamsFromFile(), LoadTreeParamsFromFile(), and QwMessage.

Referenced by main().

52 {
53  //enable the tree trim when --enable-tree-trim in offline mode or --enable-mapfile for real time mode
54  fTrimDisable =!( options.GetValue<bool>("enable-tree-trim") || options.GetValue<bool>("enable-mapfile"));
55  fTrimHistoEnable = options.GetValue<bool>("enable-histo-trim") || options.GetValue<bool>("enable-mapfile");
56 
57  if (fTrimDisable)
58  QwMessage <<"tree-trim is disabled"<<QwLog::endl;
59  else
60  QwMessage <<"tree-trim is enabled"<<QwLog::endl;
61 
62  if (fTrimHistoEnable)
63  QwMessage <<"RT Mode: histo-trim is enabled "<<QwLog::endl;
64  else
65  QwMessage <<"histo-trim is disabled "<<QwLog::endl;
66 
67  // Process trim file options
68  if (options.HasValue("tree-trim-file"))
69  LoadTreeParamsFromFile(options.GetValue<string>("tree-trim-file"));
70  if (options.HasValue("histo-trim-file"))
71  LoadHistParamsFromFile(options.GetValue<string>("histo-trim-file"));
72 }
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
bool HasValue(const std::string &key)
Has this key been defined.
Definition: QwOptions.h:233
void LoadTreeParamsFromFile(const std::string &filename)
T GetValue(const std::string &key)
Get a templated value.
Definition: QwOptions.h:240
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
void LoadHistParamsFromFile(const std::string &filename)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

std::vector<HistParams> QwHistogramHelper::fHistParams
protected
std::string QwHistogramHelper::fInputFile
protected

Definition at line 149 of file QwHistogramHelper.h.

Referenced by GetHistParamsFromList(), and LoadHistParamsFromFile().

const TString QwHistogramHelper::fInvalidName = "EmptyEmpty"
staticprotected
const Double_t QwHistogramHelper::fInvalidNumber = -1.0e7
staticprotected

Definition at line 142 of file QwHistogramHelper.h.

Referenced by GetHistParamsFromLine().

std::vector<std::vector<TString> > QwHistogramHelper::fModuleList
protected

Definition at line 154 of file QwHistogramHelper.h.

Referenced by LoadTreeParamsFromFile(), and MatchVQWKElementFromList().

std::vector<TString> QwHistogramHelper::fSubsystemList
protected

Definition at line 153 of file QwHistogramHelper.h.

Referenced by LoadTreeParamsFromFile(), and MatchVQWKElementFromList().

std::vector< std::pair< TString,TRegexp > > QwHistogramHelper::fTreeParams
protected

Definition at line 151 of file QwHistogramHelper.h.

Referenced by LoadTreeParamsFromFile(), and MatchDeviceParamsFromList().

Bool_t QwHistogramHelper::fTreeTrimFileLoaded
protected
Bool_t QwHistogramHelper::fTrimDisable
protected
Bool_t QwHistogramHelper::fTrimHistoEnable
protected
std::vector<std::vector<std::vector<TString> > > QwHistogramHelper::fVQWKTrimmedList
protected

Definition at line 155 of file QwHistogramHelper.h.

Referenced by LoadTreeParamsFromFile(), and MatchVQWKElementFromList().


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