00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <sstream>
00016 #include <boost/bind.hpp>
00017 #include "TClass.h"
00018
00019
00020 #include "Fireworks/Core/src/FWCollectionSummaryTableManager.h"
00021 #include "Fireworks/Core/interface/FWEventItem.h"
00022 #include "Fireworks/Core/interface/FWItemValueGetter.h"
00023 #include "Fireworks/Core/src/FWCollectionSummaryWidget.h"
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 FWCollectionSummaryTableManager::FWCollectionSummaryTableManager(FWEventItem* iItem, const TGGC* iContext, const TGGC* iHighlightContext,
00037 FWCollectionSummaryWidget* iWidget):
00038 m_collection(iItem),
00039 m_renderer(iContext,iHighlightContext),
00040 m_bodyRenderer(iContext, iHighlightContext, FWTextTableCellRenderer::kJustifyRight),
00041 m_widget(iWidget)
00042 {
00043 m_collection->changed_.connect(boost::bind(&FWTableManagerBase::dataChanged,this));
00044 m_collection->itemChanged_.connect(boost::bind(&FWCollectionSummaryTableManager::dataChanged,this));
00045
00046
00047 std::vector<std::pair<std::string,std::string> > s_names;
00048 ROOT::Reflex::Type type = ROOT::Reflex::Type::ByTypeInfo(*(m_collection->modelType()->GetTypeInfo()));
00049
00050 if ( type.Name() == "CaloTower" ){
00051 if ( m_collection->purpose() == "ECal" ){
00052 s_names.push_back(std::pair<std::string,std::string>("emEt","GeV"));
00053 boost::shared_ptr<FWItemValueGetter> trans( new FWItemValueGetter(type,s_names));
00054 if(trans->isValid()) m_valueGetters.push_back(trans);
00055 }
00056 else if ( m_collection->purpose() == "HCal" ){
00057 s_names.push_back(std::pair<std::string,std::string>("hadEt","GeV"));
00058 boost::shared_ptr<FWItemValueGetter> hadEt( new FWItemValueGetter(type,s_names));
00059 if(hadEt->isValid()) m_valueGetters.push_back(hadEt);
00060 }
00061 else if (m_collection->purpose() == "HCal Outer"){
00062 s_names.push_back(std::pair<std::string,std::string>("outerEt","GeV"));
00063 boost::shared_ptr<FWItemValueGetter> outerEt( new FWItemValueGetter(type,s_names));
00064 if(outerEt->isValid()) m_valueGetters.push_back(outerEt);
00065 }
00066 }
00067 else if (strstr(m_collection->purpose().c_str(), "Beam Spot") ){
00068
00069 s_names.push_back(std::pair<std::string,std::string>("x0","cm"));
00070 {
00071 boost::shared_ptr<FWItemValueGetter> pos( new FWItemValueGetter(type,s_names));
00072 if(pos->isValid()) m_valueGetters.push_back(pos);
00073 }
00074 {
00075 s_names.begin()->first = "y0";
00076 boost::shared_ptr<FWItemValueGetter> pos( new FWItemValueGetter(type,s_names));
00077 if(pos->isValid()) m_valueGetters.push_back(pos);
00078 }
00079 {
00080 s_names.begin()->first = "z0";
00081 boost::shared_ptr<FWItemValueGetter> pos( new FWItemValueGetter(type,s_names));
00082 if(pos->isValid()) m_valueGetters.push_back(pos);
00083 }
00084
00085 }
00086 else {
00087 s_names.push_back(std::pair<std::string,std::string>("pt","GeV"));
00088 s_names.push_back(std::pair<std::string,std::string>("et","GeV"));
00089 s_names.push_back(std::pair<std::string,std::string>("energy","GeV"));
00090 boost::shared_ptr<FWItemValueGetter> trans( new FWItemValueGetter(type,s_names));
00091 if(trans->isValid()) m_valueGetters.push_back(trans);
00092 }
00093
00094
00095 s_names.clear();
00096 s_names.push_back(std::pair<std::string,std::string>("eta",""));
00097 boost::shared_ptr<FWItemValueGetter> eta( new FWItemValueGetter(type,s_names));
00098 if(eta->isValid()) {
00099 s_names.clear();
00100 s_names.push_back(std::pair<std::string,std::string>("phi",""));
00101 boost::shared_ptr<FWItemValueGetter> phi( new FWItemValueGetter(type,s_names));
00102 if(phi->isValid()) {
00103 m_valueGetters.push_back(eta);
00104 m_valueGetters.push_back(phi);
00105 }
00106 }
00107
00108 dataChanged();
00109 }
00110
00111
00112
00113
00114
00115
00116 FWCollectionSummaryTableManager::~FWCollectionSummaryTableManager()
00117 {
00118 }
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 namespace {
00136 template<typename S>
00137 void doSort(const FWEventItem& iItem,
00138 FWItemValueGetter& iGetter,
00139 std::multimap<double,int,S>& iMap,
00140 std::vector<int>& oNewSort) {
00141 int size = iItem.size();
00142 for(int index = 0; index < size; ++index) {
00143 iMap.insert(std::make_pair(iGetter.valueFor(iItem.modelData(index)),
00144 index));
00145 }
00146 std::vector<int>::iterator itVec = oNewSort.begin();
00147 for(typename std::map<double,int,S>::iterator it = iMap.begin(), itEnd = iMap.end();
00148 it != itEnd;
00149 ++it,++itVec) {
00150 *itVec = it->second;
00151 }
00152 }
00153 }
00154
00155 void
00156 FWCollectionSummaryTableManager::implSort(int iCol, bool iSortOrder)
00157 {
00158 if(iSortOrder) {
00159 std::multimap<double,int, std::greater<double> > s;
00160 doSort(*m_collection, *(m_valueGetters[iCol]), s, m_sortedToUnsortedIndicies);
00161 } else {
00162 std::multimap<double,int, std::less<double> > s;
00163 doSort(*m_collection, *(m_valueGetters[iCol]), s, m_sortedToUnsortedIndicies);
00164 }
00165 }
00166
00167 void
00168 FWCollectionSummaryTableManager::buttonReleasedInRowHeader(Int_t row, Event_t* event, Int_t relX, Int_t relY)
00169 {
00170 Int_t realRow = unsortedRowNumber(row);
00171 int hit = m_renderer.clickHit(relX,relY);
00172 if(hit == FWCollectionSummaryModelCellRenderer::kMiss) {
00173 return;
00174 }
00175 if(hit == FWCollectionSummaryModelCellRenderer::kHitColor) {
00176 m_widget->itemColorClicked(realRow,event->fXRoot, event->fYRoot+12-relY);
00177 return;
00178 }
00179 FWEventItem::ModelInfo mi = m_collection->modelInfo(realRow);
00180 FWDisplayProperties dp = mi.displayProperties();
00181 if(hit == FWCollectionSummaryModelCellRenderer::kHitCheck) {
00182 dp.setIsVisible(!dp.isVisible());
00183 }
00184 m_collection->setDisplayProperties(realRow,dp);
00185 }
00186
00187
00188
00189
00190 int
00191 FWCollectionSummaryTableManager::numberOfRows() const
00192 {
00193 return m_collection->size();
00194 }
00195
00196 int
00197 FWCollectionSummaryTableManager::numberOfColumns() const {
00198 return m_valueGetters.size();
00199 }
00200
00201 std::vector<std::string>
00202 FWCollectionSummaryTableManager::getTitles() const {
00203 std::vector<std::string> titles;
00204 titles.reserve(m_valueGetters.size());
00205 for(std::vector<boost::shared_ptr<FWItemValueGetter> >::const_iterator it = m_valueGetters.begin(), itEnd=m_valueGetters.end();
00206 it != itEnd;
00207 ++it) {
00208 titles.push_back((*it)->valueName());
00209 }
00210 return titles;
00211 }
00212
00213 int
00214 FWCollectionSummaryTableManager::unsortedRowNumber(int iSortedRowNumber) const
00215 {
00216 return m_sortedToUnsortedIndicies[iSortedRowNumber];
00217 }
00218
00219 FWTableCellRendererBase*
00220 FWCollectionSummaryTableManager::cellRenderer(int iSortedRowNumber, int iCol) const
00221 {
00222 if(iCol >= static_cast<int>(m_valueGetters.size())) {
00223 return 0;
00224 }
00225 if(iSortedRowNumber >= static_cast<int>(m_collection->size())) {
00226 m_bodyRenderer.setData("",false);
00227 return &m_bodyRenderer;
00228 }
00229 int index = m_sortedToUnsortedIndicies[iSortedRowNumber];
00230 std::stringstream s;
00231 s.setf(std::ios_base::fixed,std::ios_base::floatfield);
00232 s.precision(1);
00233 double v = m_valueGetters[iCol]->valueFor(m_collection->modelData(index));
00234 s <<v;
00235 m_bodyRenderer.setData(s.str(),
00236 m_collection->modelInfo(index).isSelected());
00237 return &m_bodyRenderer;
00238 }
00239
00240 bool
00241 FWCollectionSummaryTableManager::hasRowHeaders() const
00242 {
00243 return true;
00244 }
00245
00246 FWTableCellRendererBase*
00247 FWCollectionSummaryTableManager::rowHeader(int iSortedRowNumber) const
00248 {
00249 if(iSortedRowNumber >= static_cast<int>(m_collection->size())) {
00250 return 0;
00251 }
00252 int index = m_sortedToUnsortedIndicies[iSortedRowNumber];
00253 m_renderer.setData(m_collection,
00254 index);
00255 return &m_renderer;
00256 }
00257
00258 void
00259 FWCollectionSummaryTableManager::dataChanged()
00260 {
00261 m_sortedToUnsortedIndicies.clear();
00262 m_sortedToUnsortedIndicies.reserve(m_collection->size());
00263 for(int i=0; i< static_cast<int>(m_collection->size());++i) {
00264 m_sortedToUnsortedIndicies.push_back(i);
00265 }
00266 FWTableManagerBase::dataChanged();
00267 }
00268
00269
00270