CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWCollectionSummaryTableManager.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWCollectionSummaryTableManager
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Sun Feb 22 10:13:39 CST 2009
11 // $Id: FWCollectionSummaryTableManager.cc,v 1.8 2010/12/16 12:04:43 amraktad Exp $
12 //
13 
14 // system include files
15 #include <sstream>
16 #include <boost/bind.hpp>
17 #include "TClass.h"
18 
19 // user include files
24 
25 //
26 // constants, enums and typedefs
27 //
28 
29 //
30 // static data member definitions
31 //
32 
33 //
34 // constructors and destructor
35 //
36 FWCollectionSummaryTableManager::FWCollectionSummaryTableManager(FWEventItem* iItem, const TGGC* iContext, const TGGC* iHighlightContext,
37  FWCollectionSummaryWidget* iWidget):
38  m_collection(iItem),
39  m_renderer(iContext,iHighlightContext),
40  m_bodyRenderer(iContext, iHighlightContext, FWTextTableCellRenderer::kJustifyRight),
41  m_widget(iWidget)
42 {
43  m_collection->changed_.connect(boost::bind(&FWTableManagerBase::dataChanged,this));
45 
46  //try to find the default columns
47  std::vector<std::pair<std::string,std::string> > s_names;
48  ROOT::Reflex::Type type = ROOT::Reflex::Type::ByTypeInfo(*(m_collection->modelType()->GetTypeInfo()));
49 
50  if ( type.Name() == "CaloTower" ){
51  if ( m_collection->purpose() == "ECal" ){
52  s_names.push_back(std::pair<std::string,std::string>("emEt","GeV"));
53  boost::shared_ptr<FWItemValueGetter> trans( new FWItemValueGetter(type,s_names));
54  if(trans->isValid()) m_valueGetters.push_back(trans);
55  }
56  else if ( m_collection->purpose() == "HCal" ){
57  s_names.push_back(std::pair<std::string,std::string>("hadEt","GeV"));
58  boost::shared_ptr<FWItemValueGetter> hadEt( new FWItemValueGetter(type,s_names));
59  if(hadEt->isValid()) m_valueGetters.push_back(hadEt);
60  }
61  else if (m_collection->purpose() == "HCal Outer"){
62  s_names.push_back(std::pair<std::string,std::string>("outerEt","GeV"));
63  boost::shared_ptr<FWItemValueGetter> outerEt( new FWItemValueGetter(type,s_names));
64  if(outerEt->isValid()) m_valueGetters.push_back(outerEt);
65  }
66  }
67  else if (strstr(m_collection->purpose().c_str(), "Beam Spot") ){
68 
69  s_names.push_back(std::pair<std::string,std::string>("x0","cm"));
70  {
71  boost::shared_ptr<FWItemValueGetter> pos( new FWItemValueGetter(type,s_names));
72  if(pos->isValid()) m_valueGetters.push_back(pos);
73  }
74  {
75  s_names.begin()->first = "y0";
76  boost::shared_ptr<FWItemValueGetter> pos( new FWItemValueGetter(type,s_names));
77  if(pos->isValid()) m_valueGetters.push_back(pos);
78  }
79  {
80  s_names.begin()->first = "z0";
81  boost::shared_ptr<FWItemValueGetter> pos( new FWItemValueGetter(type,s_names));
82  if(pos->isValid()) m_valueGetters.push_back(pos);
83  }
84 
85  }
86  else {
87  s_names.push_back(std::pair<std::string,std::string>("pt","GeV"));
88  s_names.push_back(std::pair<std::string,std::string>("et","GeV"));
89  s_names.push_back(std::pair<std::string,std::string>("energy","GeV"));
90  boost::shared_ptr<FWItemValueGetter> trans( new FWItemValueGetter(type,s_names));
91  if(trans->isValid()) m_valueGetters.push_back(trans);
92  }
93 
94 
95  s_names.clear();
96  s_names.push_back(std::pair<std::string,std::string>("eta",""));
97  boost::shared_ptr<FWItemValueGetter> eta( new FWItemValueGetter(type,s_names));
98  if(eta->isValid()) {
99  s_names.clear();
100  s_names.push_back(std::pair<std::string,std::string>("phi",""));
101  boost::shared_ptr<FWItemValueGetter> phi( new FWItemValueGetter(type,s_names));
102  if(phi->isValid()) {
103  m_valueGetters.push_back(eta);
104  m_valueGetters.push_back(phi);
105  }
106  }
107 
108  dataChanged();
109 }
110 
111 // FWCollectionSummaryTableManager::FWCollectionSummaryTableManager(const FWCollectionSummaryTableManager& rhs)
112 // {
113 // // do actual copying here;
114 // }
115 
117 {
118 }
119 
120 //
121 // assignment operators
122 //
123 // const FWCollectionSummaryTableManager& FWCollectionSummaryTableManager::operator=(const FWCollectionSummaryTableManager& rhs)
124 // {
125 // //An exception safe implementation is
126 // FWCollectionSummaryTableManager temp(rhs);
127 // swap(rhs);
128 //
129 // return *this;
130 // }
131 
132 //
133 // member functions
134 //
135 namespace {
136  template<typename S>
137  void doSort(const FWEventItem& iItem,
138  FWItemValueGetter& iGetter,
139  std::multimap<double,int,S>& iMap,
140  std::vector<int>& oNewSort) {
141  int size = iItem.size();
142  for(int index = 0; index < size; ++index) {
143  iMap.insert(std::make_pair(iGetter.valueFor(iItem.modelData(index)),
144  index));
145  }
146  std::vector<int>::iterator itVec = oNewSort.begin();
147  for(typename std::map<double,int,S>::iterator it = iMap.begin(), itEnd = iMap.end();
148  it != itEnd;
149  ++it,++itVec) {
150  *itVec = it->second;
151  }
152  }
153 }
154 
155 void
157 {
158  if(iSortOrder) {
159  std::multimap<double,int, std::greater<double> > s;
161  } else {
162  std::multimap<double,int, std::less<double> > s;
164  }
165 }
166 
167 void
168 FWCollectionSummaryTableManager::buttonReleasedInRowHeader(Int_t row, Event_t* event, Int_t relX, Int_t relY)
169 {
170  Int_t realRow = unsortedRowNumber(row);
171  int hit = m_renderer.clickHit(relX,relY);
173  return;
174  }
176  m_widget->itemColorClicked(realRow,event->fXRoot, event->fYRoot+12-relY);
177  return;
178  }
182  dp.setIsVisible(!dp.isVisible());
183  }
184  m_collection->setDisplayProperties(realRow,dp);
185 }
186 
187 //
188 // const member functions
189 //
190 int
192 {
193  return m_collection->size();
194 }
195 
196 int
198  return m_valueGetters.size();
199 }
200 
201 std::vector<std::string>
203  std::vector<std::string> titles;
204  titles.reserve(m_valueGetters.size());
205  for(std::vector<boost::shared_ptr<FWItemValueGetter> >::const_iterator it = m_valueGetters.begin(), itEnd=m_valueGetters.end();
206  it != itEnd;
207  ++it) {
208  titles.push_back((*it)->valueName());
209  }
210  return titles;
211 }
212 
213 int
215 {
216  return m_sortedToUnsortedIndicies[iSortedRowNumber];
217 }
218 
220 FWCollectionSummaryTableManager::cellRenderer(int iSortedRowNumber, int iCol) const
221 {
222  if(iCol >= static_cast<int>(m_valueGetters.size())) {
223  return 0;
224  }
225  if(iSortedRowNumber >= static_cast<int>(m_collection->size())) {
226  m_bodyRenderer.setData("",false);
227  return &m_bodyRenderer;
228  }
229  int index = m_sortedToUnsortedIndicies[iSortedRowNumber];
230  std::stringstream s;
231  s.setf(std::ios_base::fixed,std::ios_base::floatfield);
232  s.precision(1);
233  double v = m_valueGetters[iCol]->valueFor(m_collection->modelData(index));
234  s <<v;
235  m_bodyRenderer.setData(s.str(),
236  m_collection->modelInfo(index).isSelected());
237  return &m_bodyRenderer;
238 }
239 
240 bool
242 {
243  return true;
244 }
245 
248 {
249  if(iSortedRowNumber >= static_cast<int>(m_collection->size())) {
250  return 0;
251  }
252  int index = m_sortedToUnsortedIndicies[iSortedRowNumber];
254  index);
255  return &m_renderer;
256 }
257 
258 void
260 {
263  for(int i=0; i< static_cast<int>(m_collection->size());++i) {
264  m_sortedToUnsortedIndicies.push_back(i);
265  }
267 }
268 //
269 // static member functions
270 //
virtual FWTableCellRendererBase * rowHeader(int iSortedRowNumber) const
Returns the renderer for the row header for the sorted row number iSortedRowNumber.
type
Definition: HCALResponse.h:22
FWCollectionSummaryModelCellRenderer m_renderer
int i
Definition: DBlmapReader.cc:9
const FWDisplayProperties & displayProperties() const
Definition: FWEventItem.h:67
virtual void implSort(int iCol, bool iSortOrder)
Called by &#39;sort&#39; method to actually handle the sorting of the rows. Arguments are the same as &#39;sort&#39;...
bool isSelected() const
Definition: FWEventItem.h:70
void setDisplayProperties(int iIndex, const FWDisplayProperties &) const
Definition: FWEventItem.cc:286
void dataChanged()
Classes which inherit from FWTableManagerBase must call this when their underlying data changes...
T eta() const
virtual bool hasRowHeaders() const
Returns &#39;true&#39; if this table has row headers. Defaults return value is false.
virtual std::vector< std::string > getTitles() const
returns the title names for each column
virtual int numberOfRows() const
Number of rows in the table.
void itemColorClicked(int iIndex, Int_t iRootX, Int_t iRootY)
FWItemChangeSignal itemChanged_
Definition: FWEventItem.h:195
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
std::vector< boost::shared_ptr< FWItemValueGetter > > m_valueGetters
virtual int unsortedRowNumber(int iSortedRowNumber) const
when passed the index to the sorted order of the rows it returns the original row number from the und...
void setData(const std::string &, bool isSelected)
size_t size() const
Definition: FWEventItem.cc:548
void setData(const FWEventItem *iItem, int iIndex)
double valueFor(const void *) const
virtual void buttonReleasedInRowHeader(Int_t row, Event_t *event, Int_t relX, Int_t relY)
FWModelChangeSignal changed_
Definition: FWEventItem.h:192
virtual int numberOfColumns() const
Number of columns in the table.
const TClass * modelType() const
Definition: FWEventItem.cc:561
FWCollectionSummaryTableManager(FWEventItem *iCollection, const TGGC *iContext, const TGGC *iHighlightContext, FWCollectionSummaryWidget *)
string s
Definition: asciidump.py:422
const void * modelData(int iIndex) const
Definition: FWEventItem.cc:567
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:535
void setIsVisible(bool iSet)
const std::string & purpose() const
Definition: FWEventItem.cc:512
virtual FWTableCellRendererBase * cellRenderer(int iSortedRowNumber, int iCol) const
tuple size
Write out results.
mathSSE::Vec4< T > v
Definition: DDAxes.h:10