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

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-12-03/OnlineMonitoring/viewer/HistogramBrowser.h"

Inheritance diagram for om::HistogramBrowser:
om::GUIModelSubscriber

Public Member Functions

 HistogramBrowser (const TGWindow *p, unsigned int w, unsigned int h, unsigned int opt)
 
 ~HistogramBrowser ()
 
TGListTreeItem * FindCategory (const char *nm)
 
TGListTreeItem * MakeCategory (const char *nm)
 
void DoubleClicked (TGListTreeItem *, Int_t i)
 
void HandleRefresh ()
 
void GUIModelDataIssue (const GUIModelData &d, unsigned int which)
 
bool GetLock ()
 
void ReleaseLock ()
 

Private Member Functions

void BuildTree ()
 
void ClearBrowser ()
 
void MakeCategories ()
 
void Populate ()
 

Private Attributes

TGCanvas * fCanvas
 
TGListTree * fListTree
 
std::map< std::string, TGListTreeItem * > fCategories
 
std::map< std::string, TGListTreeItem * > fHistograms
 
TGTextButton * fRefresh
 

Detailed Description

Definition at line 18 of file HistogramBrowser.h.

Constructor & Destructor Documentation

HistogramBrowser::HistogramBrowser ( const TGWindow *  p,
unsigned int  w,
unsigned int  h,
unsigned int  opt 
)

Definition at line 14 of file HistogramBrowser.cxx.

References fCanvas, fListTree, fRefresh, and xx.

17  :
18  TGCompositeFrame(p, w, h, opt),
20  fCanvas(0),
21  fListTree(0)
22 {
23  fCanvas = new TGCanvas(this, w, h);
24  TGLayoutHints* hints = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY,
25  2, 2, 2, 2);
26  fListTree = new TGListTree(fCanvas, kHorizontalFrame);
27  this->AddFrame(fCanvas, hints);
28 
29  fListTree->Connect("DoubleClicked(TGListTreeItem*,Int_t)",
30  "om::HistogramBrowser",
31  this,
32  "DoubleClicked(TGListTreeItem*,Int_t)");
33 
34  TGLayoutHints* xx = new TGLayoutHints(kLHintsExpandX);
35  fRefresh = new TGTextButton(this, "Refresh Histogram List");
36  fRefresh->SetToolTipText("Request the current histogram list from the histogram source and refresh the browser.");
37  fRefresh->Connect("Clicked()",
38  "om::HistogramBrowser",
39  this,
40  "HandleRefresh()");
41  this->AddFrame(fRefresh, xx);
42 }
Double_t xx
Definition: macro.C:12
static const unsigned int kWatchListUpdateID
Definition: GUIModelData.h:26
GUIModelSubscriber(unsigned int which)
static const unsigned int kCurrentHistogramID
Definition: GUIModelData.h:15
const char * p
Definition: xmltok.h:285
TGTextButton * fRefresh
static const unsigned int kHistogramSourceID
Definition: GUIModelData.h:22
Float_t w
Definition: plot.C:20
HistogramBrowser::~HistogramBrowser ( )

Definition at line 312 of file HistogramBrowser.cxx.

References fCanvas, fListTree, and fRefresh.

313 {
314 
315  if (fCanvas) {
316  delete fCanvas;
317  fCanvas = 0;
318  }
319  if (fListTree) {
320  delete fListTree;
321  fListTree = 0;
322  }
323  if (fRefresh) {
324  delete fRefresh;
325  fRefresh = 0;
326  }
327 
328 }
TGTextButton * fRefresh

Member Function Documentation

void HistogramBrowser::BuildTree ( )
private

Definition at line 96 of file HistogramBrowser.cxx.

References ClearBrowser(), MakeCategories(), and Populate().

Referenced by GUIModelDataIssue(), and HandleRefresh().

97 {
98  this->ClearBrowser();
99  this->MakeCategories();
100  this->Populate();
101 }
void HistogramBrowser::ClearBrowser ( )
private

Definition at line 105 of file HistogramBrowser.cxx.

References fCategories, fHistograms, fListTree, and MECModelEnuComparisons::i.

Referenced by BuildTree().

106 {
107  if (fListTree==0) return;
108 
109  //
110  // How to completely delete the browser tree? Try traversing all the
111  // top items and deleting all their children. Then delete all the
112  // top level items
113  //
114  std::vector<TGListTreeItem*> item;
115  TGListTreeItem* i1 = fListTree->GetFirstItem();
116  if (i1!=0) {
117  for (; i1!=0; i1=i1->GetNextSibling()) item.push_back(i1);
118  for (unsigned int i=0; i<item.size(); ++i) {
119  fListTree->DeleteItem(item[i]);
120  }
121  }
122  fCategories.clear();
123  fHistograms.clear();
124 }
std::map< std::string, TGListTreeItem * > fCategories
std::map< std::string, TGListTreeItem * > fHistograms
void HistogramBrowser::DoubleClicked ( TGListTreeItem *  item,
Int_t  i 
)

Definition at line 220 of file HistogramBrowser.cxx.

References om::GUIModel::Instance(), Munits::nm, om::GUIModel::SetCurrentHistogram(), and string.

221 {
222  //
223  // Check if clicked item is an end of a branch. If it is, then it
224  // must be a plot object and not a container.
225  //
226  if (item->GetFirstChild()==0) {
227  std::string nm = item->GetText();
228 
229  //
230  // Wildcarded names are never displayable histograms. Skip those.
231  //
232  bool iswildcard = (nm.find('*')!=nm.npos);
233  if (iswildcard) return;
234 
236  }
237 }
static constexpr Double_t nm
Definition: Munits.h:133
static GUIModel & Instance()
Definition: GUIModel.cxx:11
void SetCurrentHistogram(const char *h)
Definition: GUIModel.cxx:102
enum BeamMode string
TGListTreeItem * HistogramBrowser::FindCategory ( const char *  nm)

Definition at line 165 of file HistogramBrowser.cxx.

References fCategories.

Referenced by MakeCategory(), and Populate().

166 {
167  std::map<std::string, TGListTreeItem*>::iterator itr;
168  itr = fCategories.find(nm);
169  if (itr==fCategories.end()) return 0;
170  return itr->second;
171 }
std::map< std::string, TGListTreeItem * > fCategories
static constexpr Double_t nm
Definition: Munits.h:133
bool GUIModelSubscriber::GetLock ( )
inherited

Definition at line 24 of file GUIModelSubscriber.cxx.

References gsLock, MECModelEnuComparisons::i, and kSleep.

Referenced by om::CaptionBox::GUIModelDataIssue(), om::HistogramInfo::GUIModelDataIssue(), om::ButtonBank::GUIModelDataIssue(), GUIModelDataIssue(), om::PlotViewer::GUIModelDataIssue(), and om::WatchListBox::GUIModelDataIssue().

25 {
26  unsigned int i;
27  const unsigned int kSleep = 1000; // 1 msec
28  const unsigned int kCount = 10000; // 10k tries at 1 msec = 10 seconds
29  for (i=0; i<kCount; ++i) {
30  if (gsLock==false) {
31  gsLock = true;
32  return true;
33  }
34  usleep(kSleep);
35  }
36  return false;
37 }
static bool gsLock
static const unsigned int kSleep
Definition: IPC.cxx:21
void HistogramBrowser::GUIModelDataIssue ( const GUIModelData m,
unsigned int  which 
)
virtual

Receive notifications when the GUI model data has changed

Parameters
m- The new model data
which- Which element of the data has changed

See GUIModel.h for the definitions of "which".

Note: To prevent collisions between threads, users should implement their "GUIModelDataIssue" methods following this pattern:

{ book aok = this->GetLock(); if (!aok) return;

...your code here...

this->ReleaseLock(); }

Implements om::GUIModelSubscriber.

Definition at line 248 of file HistogramBrowser.cxx.

References BuildTree(), om::CurrentHistogram::Current(), om::GUIModelData::fCurrentHistogram, fHistograms, fListTree, om::GUIModelSubscriber::GetLock(), om::kCurrentHistogramID, om::kHistogramSourceID, om::kWatchListUpdateID, om::GUIModelSubscriber::ReleaseLock(), and string.

250 {
251  if (this->GetLock()==false) return;
252 
253  if ( ((which&kCurrentHistogramID)==0) &&
254  ((which&kHistogramSourceID) ==0) &&
255  ((which&kWatchListUpdateID) ==0) ) {
256  this->ReleaseLock();
257  return;
258  }
259 
260  if ( (which&kHistogramSourceID) || (which&kWatchListUpdateID) ) {
261  this->BuildTree();
262  }
263 
264  //
265  // When the histogram changes, change the state of the browser to
266  // avoid presenting conflicting information to the user
267  //
268  if ( (which&kCurrentHistogramID) ) {
269  //
270  // If there is no current histogram, there is nothing to do
271  //
272  static const std::string empty("");
273  if (empty == d.fCurrentHistogram.Current()) {
274  this->ReleaseLock();
275  return;
276  }
277 
278  //
279  // Try to find the currently selected histogram in the collection
280  // of histograms in the browser. If we fail for some reason
281  // (shouldn't ever happen), bail.
282  //
283  std::map<std::string,TGListTreeItem*>::iterator itr;
284  itr = fHistograms.find(d.fCurrentHistogram.Current());
285  if (itr==fHistograms.end()) {
286  this->ReleaseLock();
287  return;
288  }
289 
290  //
291  // If the current histogram is the one already selected, there is
292  // nothing to do
293  //
294  if (itr->second == fListTree->GetSelected()) {
295  this->ReleaseLock();
296  return;
297  }
298 
299  //
300  // Clear whatever is currently highlighted and try to highlight the new
301  //
302  fListTree->ClearHighlighted();
303  if ( (itr->second->IsOpen()==1) && (itr->second->IsActive()==0) ) {
304  fListTree->HighlightItem(itr->second);
305  }
306  }
307  this->ReleaseLock();
308 }
static const unsigned int kWatchListUpdateID
Definition: GUIModelData.h:26
static const unsigned int kCurrentHistogramID
Definition: GUIModelData.h:15
std::map< std::string, TGListTreeItem * > fHistograms
Float_t d
Definition: plot.C:236
static const unsigned int kHistogramSourceID
Definition: GUIModelData.h:22
enum BeamMode string
void HistogramBrowser::HandleRefresh ( )

Definition at line 241 of file HistogramBrowser.cxx.

References BuildTree().

242 {
243  this->BuildTree();
244 }
void HistogramBrowser::MakeCategories ( )
private

Definition at line 131 of file HistogramBrowser.cxx.

References om::GUIModel::Data(), om::HistoData::fCategory, om::GUIModelData::fDetector, om::GUIModelData::fHistoCSVFile, om::HistoTable::fTable, hd, MECModelEnuComparisons::i, om::GUIModel::Instance(), om::HistoTable::Instance(), and MakeCategory().

Referenced by BuildTree().

132 {
133  //
134  // Load the table of histograms so we can extract the list of
135  // histogram categories
136  //
138  HistoTable& ht = HistoTable::Instance(model.fHistoCSVFile.c_str(),
139  model.fDetector);
140 
141  std::map<std::string,HistoData>::iterator itr (ht.fTable.begin());
142  std::map<std::string,HistoData>::iterator itrEnd(ht.fTable.end());
143  std::list<std::string> cats;
144  for (; itr!=itrEnd; ++itr) {
145  const HistoData& hd = itr->second;
146  for (unsigned int i=0; i<hd.fCategory.size(); ++i) {
147  cats.push_back(hd.fCategory[i]);
148  }
149  }
150 
151  //
152  // Sort the list and make the category. We count on "MakeCategory"
153  // to be smart enough to avoid duplicate categories.
154  //
155  cats.sort();
156  std::list<std::string>::iterator iCat(cats.begin());
157  std::list<std::string>::iterator iCatEnd(cats.end());
158  for (; iCat!=iCatEnd; ++iCat) {
159  this->MakeCategory(iCat->c_str());
160  }
161 }
TGListTreeItem * MakeCategory(const char *nm)
std::string fHistoCSVFile
Definition: GUIModelData.h:40
std::vector< std::string > fCategory
Categories this hist. belongs to.
Definition: HistoData.h:41
Detector_t fDetector
Definition: GUIModelData.h:34
static GUIModel & Instance()
Definition: GUIModel.cxx:11
std::map< std::string, HistoData > fTable
Histogram data by C++ name.
Definition: HistoTable.h:34
static HistoTable & Instance(const char *f=0, Detector_t d=kALLDET)
Definition: HistoTable.cxx:21
TH1F * hd
Definition: Xdiff_gwt.C:57
const XML_Char XML_Content * model
Definition: expat.h:151
const GUIModelData & Data() const
Definition: GUIModel.h:15
TGListTreeItem * HistogramBrowser::MakeCategory ( const char *  nm)

Definition at line 175 of file HistogramBrowser.cxx.

References plot_validation_datamc::c, fCategories, FindCategory(), fListTree, getGoodRuns4SAM::n, file_size_ana::parent, elec2geo::pos, and string.

Referenced by MakeCategories().

176 {
177  TGListTreeItem* lti = 0;
178 
179  //
180  // Test if this category already exists - if it does, we're done
181  //
182  lti = this->FindCategory(nm);
183  if (lti!=0) return lti;
184 
185  // Split the category into parent and child pieces.
186  std::string n(nm);
187  std::string p;
188  std::string c;
189  TGListTreeItem* parent;
190 
191  size_t pos = n.find_last_of("/");
192  if (pos<n.length()) {
193  //
194  // Found a "/". Everything before is parent, everything after is child
195  //
196  c = n.substr(pos+1, n.length());
197  p = n.substr(0, pos);
198  parent = this->FindCategory(p.c_str());
199  if (parent==0) parent = this->MakeCategory(p.c_str());
200  }
201  else {
202  //
203  // No "/" found. Must be a top-level category.
204  //
205  c = n;
206  p = "";
207  parent = 0;
208  }
209  //
210  // Add the item to the tree and category list
211  //
212  lti = fListTree->AddItem(parent, c.c_str());
213  fCategories[n] = lti;
214 
215  return lti;
216 }
TGListTreeItem * MakeCategory(const char *nm)
std::map< std::string, TGListTreeItem * > fCategories
const char * p
Definition: xmltok.h:285
static constexpr Double_t nm
Definition: Munits.h:133
TGListTreeItem * FindCategory(const char *nm)
enum BeamMode string
void HistogramBrowser::Populate ( )
private

Definition at line 49 of file HistogramBrowser.cxx.

References om::cerr, febshutoff_auto::end, allTimeWatchdog::endl, om::HistoData::fCaption, om::HistoData::fCategory, fHistograms, FindCategory(), fListTree, om::HistoData::fType, make_syst_table_plots::h, hd, MECModelEnuComparisons::i, om::GUIModel::Instance(), om::HistoTable::Instance(), om::kTH1F, and om::kTH2F.

Referenced by BuildTree().

50 {
51  HistoSource hs(GUIModel::Instance().Data().fHistogramSource.c_str());
52  const HistoTable& ht = HistoTable::Instance();
53 
54  //
55  // Pull out all the histograms from the producer
56  //
57  std::list<std::string> obj;
58  hs.FindAllMatches("*","*_prev_*",obj);
59  obj.sort();
60 
61  //
62  // Loop over histograms and place them in the correct categories
63  //
64  const TGPicture* pic1d = gClient->GetPicture("h1_t.xpm");
65  const TGPicture* pic2d = gClient->GetPicture("h2_t.xpm");
66  const TGPicture* pic = 0;
67  TGListTreeItem* h;
68  std::list<std::string>::const_iterator itr(obj.begin());
69  std::list<std::string>::const_iterator end(obj.end());
70  for (; itr!=end; ++itr) {
71 
72  // Skip the header object (for now...)
73  if((*itr) == "Header") continue;
74 
75  const HistoData* hd = ht.LookUp(itr->c_str());
76  if (hd==0) {
77  std::cerr << " Histogram " << (*itr) << " not found." << std::endl;
78  continue;
79  }
80  if (hd->fType==kTH1F) pic = pic1d;
81  if (hd->fType==kTH2F) pic = pic2d;
82  if (pic==0) pic = pic1d;
83  for (unsigned int i=0; i<hd->fCategory.size(); ++i) {
84  TGListTreeItem* p = this->FindCategory(hd->fCategory[i].c_str());
85  h = fListTree->AddItem(p, itr->c_str(), pic, pic);
86  if (h) {
87  h->SetTipText(hd->fCaption.c_str());
88  fHistograms[*itr] = h;
89  }
90  }
91  }
92 }
std::vector< std::string > fCategory
Categories this hist. belongs to.
Definition: HistoData.h:41
const char * p
Definition: xmltok.h:285
OStream cerr
Definition: OStream.cxx:7
std::string fCaption
What does this histogram show?
Definition: HistoData.h:56
TGListTreeItem * FindCategory(const char *nm)
static GUIModel & Instance()
Definition: GUIModel.cxx:11
std::map< std::string, TGListTreeItem * > fHistograms
Histo_t fType
What kind of histogram is this?
Definition: HistoData.h:46
static HistoTable & Instance(const char *f=0, Detector_t d=kALLDET)
Definition: HistoTable.cxx:21
TH1F * hd
Definition: Xdiff_gwt.C:57
void GUIModelSubscriber::ReleaseLock ( )
inherited

Member Data Documentation

TGCanvas* om::HistogramBrowser::fCanvas
private

Definition at line 44 of file HistogramBrowser.h.

Referenced by HistogramBrowser(), and ~HistogramBrowser().

std::map<std::string,TGListTreeItem*> om::HistogramBrowser::fCategories
private

Definition at line 46 of file HistogramBrowser.h.

Referenced by ClearBrowser(), FindCategory(), and MakeCategory().

std::map<std::string,TGListTreeItem*> om::HistogramBrowser::fHistograms
private

Definition at line 47 of file HistogramBrowser.h.

Referenced by ClearBrowser(), GUIModelDataIssue(), and Populate().

TGListTree* om::HistogramBrowser::fListTree
private
TGTextButton* om::HistogramBrowser::fRefresh
private

Definition at line 49 of file HistogramBrowser.h.

Referenced by HistogramBrowser(), and ~HistogramBrowser().


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