WatchListManager.cxx
Go to the documentation of this file.
3 
4 #include "TH1F.h"
5 #include "TH2F.h"
6 #include "TGString.h"
7 
8 using namespace om;
9 
10 //......................................................................
11 
13 {
14  static WatchListManager freddiemercury;
15  return freddiemercury;
16 }
17 
18 //......................................................................
19 
21  fCurrentWL()
22 { }
23 
24 //......................................................................
25 
27 { }
28 
29 //......................................................................
30 
31 void WatchListManager::Add(int db, int dcm, int feb, int pix)
32 {
33 
34  ///\ todo: send some kind of message to the viewer that the max WL
35  // size has been exceeded???
36  if(fCurrentWL.fDB.size() >= NMAX_WATCHLIST) return;
37 
38  // test to see if item is already on the list
39  bool IsOnList = false;
40  unsigned int id;
41  for(unsigned int i = 0; i < fCurrentWL.fDB.size(); ++i) {
42  if(db == fCurrentWL.fDB[i] && dcm == fCurrentWL.fDCM[i] &&
43  feb == fCurrentWL.fFEB[i] && pix == fCurrentWL.fPIX[i]) {
44  IsOnList = true;
45  id = i;
46  break;
47  }
48  }
49 
50  if(IsOnList && fCurrentWL.fActive[id] == 1) return;
51  if(IsOnList && fCurrentWL.fActive[id] == 0)
52  fCurrentWL.fActive[id] = 1;
53  if(!IsOnList) {
54  // book the new histograms
56 
57  TGString WLlabel;
58  if(db < 0) WLlabel += "XX";
59  else {
60  char temp[64];
61  sprintf(temp, "%.2u", db);
62  WLlabel += temp;
63  }
64  WLlabel += "-";
65  if(dcm < 0) WLlabel += "XX";
66  else {
67  char temp[64];
68  sprintf(temp, "%.2u", dcm);
69  WLlabel += temp;
70  }
71  WLlabel += "-";
72  if(feb < 0) WLlabel += "XX";
73  else {
74  char temp[64];
75  sprintf(temp, "%.2u", feb);
76  WLlabel += temp;
77  }
78  WLlabel += "-";
79  if(pix < 0) WLlabel += "XX";
80  else {
81  char temp[64];
82  sprintf(temp, "%.2u", pix);
83  WLlabel += temp;
84  }
85 
86  TGString WLTQname = "WLTQPlot_";
87  TGString WLTname = "WLTPlot_";
88  TGString WLQname = "WLQPlot_";
89 
90  WLTQname += WLlabel;
91  fWLTQ.push_back(h.GetTH2F(WLTQname));
92 
93  WLTname += WLlabel;
94  fWLT.push_back(h.GetTH1F(WLTname));
95 
96  WLQname += WLlabel;
97  fWLQ.push_back(h.GetTH1F(WLQname));
98 
99  // add to list
100  fCurrentWL.fDB .push_back(db);
101  fCurrentWL.fDCM.push_back(dcm);
102  fCurrentWL.fFEB.push_back(feb);
103  fCurrentWL.fPIX.push_back(pix);
104  fCurrentWL.fActive.push_back(1);
105  }
106 
107 }
108 
109 //......................................................................
110 
111 void WatchListManager::Remove(int db, int dcm, int feb, int pix)
112 {
113  // find location of item on the list
114  bool IsOnList = false;
115  unsigned int id;
116  for(unsigned int i = 0; i < fCurrentWL.fDB.size(); ++i) {
117  if(db == fCurrentWL.fDB[i] && dcm == fCurrentWL.fDCM[i] &&
118  feb == fCurrentWL.fFEB[i] && pix == fCurrentWL.fPIX[i]) {
119  IsOnList = true;
120  id = i;
121  break;
122  }
123  }
124 
125  if(IsOnList && fCurrentWL.fActive[id] == 0) return;
126  if(IsOnList && fCurrentWL.fActive[id] == 1)
127  fCurrentWL.fActive[id] = 0;
128 
129 }
130 
131 //......................................................................
132 
133 void WatchListManager::GetList(std::vector<int>& db,
134  std::vector<int>& dcm,
135  std::vector<int>& feb,
136  std::vector<int>& pix)
137 {
138  for(unsigned int i = 0; i < fCurrentWL.fDB.size(); ++i) {
139  if(fCurrentWL.fActive[i] == 1) {
140  db .push_back(fCurrentWL.fDB [i]);
141  dcm.push_back(fCurrentWL.fDCM[i]);
142  feb.push_back(fCurrentWL.fFEB[i]);
143  pix.push_back(fCurrentWL.fPIX[i]);
144  }
145  }
146 }
147 
148 //......................................................................
149 
150 void WatchListManager::FillPlots(int db, int dcm, int feb, int pix,
151  double time, unsigned int adc)
152 {
153 
154  for(unsigned int i = 0; i < fCurrentWL.fDB.size(); ++i) {
155  if(fCurrentWL.fActive[i] == 1) {
156  if((db == fCurrentWL.fDB[i] || fCurrentWL.fDB[i] == -1) &&
157  (dcm == fCurrentWL.fDCM[i] || fCurrentWL.fDCM[i] == -1) &&
158  (feb == fCurrentWL.fFEB[i] || fCurrentWL.fFEB[i] == -1) &&
159  (pix == fCurrentWL.fPIX[i] || fCurrentWL.fPIX[i] == -1)) {
160 
161  fWLTQ[i]->Fill(time, adc);
162  fWLT [i]->Fill(time);
163  fWLQ [i]->Fill(adc);
164 
165  } // end if match to CurrentWL
166  } // end if fActive == 1
167  } // end loop over i
168 
169 }
170 
171 //......................................................................
172 
174 {
175  // Clean up watchlist items marked as inactive and delete the associated
176  // histograms.
178 
179  std::vector< unsigned int > remove;
180 
181  for(unsigned int i = 0; i < fCurrentWL.fDB.size(); ++i) {
182  if(fCurrentWL.fActive[i] == 0) remove.push_back(i);
183  }
184 
185  for(unsigned int i = remove.size(); i > 0; i--) {
186  fCurrentWL.fDB .erase(fCurrentWL.fDB .begin()+remove[i-1]);
187  fCurrentWL.fDCM.erase(fCurrentWL.fDCM.begin()+remove[i-1]);
188  fCurrentWL.fFEB.erase(fCurrentWL.fFEB.begin()+remove[i-1]);
189  fCurrentWL.fPIX.erase(fCurrentWL.fPIX.begin()+remove[i-1]);
190  fCurrentWL.fActive.erase(fCurrentWL.fActive.begin()+remove[i-1]);
191 
192  h.DeleteTH2F(fWLTQ[remove[i-1]]);
193  fWLTQ.erase(fWLTQ.begin()+remove[i-1]);
194 
195  h.DeleteTH1F(fWLT[remove[i-1]]);
196  fWLT.erase(fWLT.begin()+remove[i-1]);
197 
198  h.DeleteTH1F(fWLQ[remove[i-1]]);
199  fWLQ.erase(fWLQ.begin()+remove[i-1]);
200  }
201 
202 }
203 
204 ////////////////////////////////////////////////////////////////////////
::xsd::cxx::tree::id< char, ncname > id
Definition: Database.h:165
void FillPlots(int db, int dcm, int feb, int pix, double time, unsigned int adc)
std::vector< int > fDCM
TH1F * GetTH1F(const char *nm)
Definition: HistoSet.cxx:68
static const unsigned int NMAX_WATCHLIST
void Remove(int db, int dcm, int feb, int pix)
std::vector< TH1F * > fWLQ
void GetList(std::vector< int > &db, std::vector< int > &dcm, std::vector< int > &feb, std::vector< int > &pix)
std::vector< TH1F * > fWLT
void DeleteTH1F(TH1F *h)
Definition: HistoSet.cxx:556
void Add(int db, int dcm, int feb, int pix)
TH2F * GetTH2F(const char *nm)
Definition: HistoSet.cxx:89
std::vector< int > fPIX
std::vector< int > fDB
void DeleteTH2F(TH2F *h)
Definition: HistoSet.cxx:575
std::vector< int > fActive
static WatchListManager & Instance()
static HistoSet & Instance()
Definition: HistoSet.cxx:24
std::vector< TH2F * > fWLTQ
Hold the collection of histograms created by the producer.
std::vector< int > fFEB
struct WatchList fCurrentWL
Online Monitoring package header.