CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/Fireworks/Core/src/FWCollectionSummaryTableManager.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWCollectionSummaryTableManager
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Sun Feb 22 10:13:39 CST 2009
00011 // $Id: FWCollectionSummaryTableManager.cc,v 1.14 2012/08/03 18:20:28 wmtan Exp $
00012 //
00013 
00014 // system include files
00015 #include <sstream>
00016 #include <boost/bind.hpp>
00017 #include "TClass.h"
00018 
00019 // user include files
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 // constants, enums and typedefs
00027 //
00028 
00029 //
00030 // static data member definitions
00031 //
00032 
00033 //
00034 // constructors and destructor
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    //try to find the default columns
00047    std::vector<std::pair<std::string,std::string> > s_names;
00048    edm::TypeWithDict type(*(m_collection->modelType()->GetTypeInfo()));
00049 
00050    
00051    dataChanged();
00052 }
00053 
00054 // FWCollectionSummaryTableManager::FWCollectionSummaryTableManager(const FWCollectionSummaryTableManager& rhs)
00055 // {
00056 //    // do actual copying here;
00057 // }
00058 
00059 FWCollectionSummaryTableManager::~FWCollectionSummaryTableManager()
00060 {
00061 }
00062 
00063 //
00064 // assignment operators
00065 //
00066 // const FWCollectionSummaryTableManager& FWCollectionSummaryTableManager::operator=(const FWCollectionSummaryTableManager& rhs)
00067 // {
00068 //   //An exception safe implementation is
00069 //   FWCollectionSummaryTableManager temp(rhs);
00070 //   swap(rhs);
00071 //
00072 //   return *this;
00073 // }
00074 
00075 //
00076 // member functions
00077 //
00078 namespace {
00079    template<typename S>
00080    void doSort(const FWEventItem& iItem,
00081               const FWItemValueGetter& iGetter, int iCol,
00082                std::multimap<double,int,S>& iMap, 
00083                std::vector<int>& oNewSort) {
00084       int size = iItem.size();
00085       for(int index = 0; index < size; ++index) {
00086          iMap.insert(std::make_pair(iGetter.valueFor(iItem.modelData(index), iCol),
00087                                        index));
00088       }
00089       std::vector<int>::iterator itVec = oNewSort.begin();
00090       for(typename std::map<double,int,S>::iterator it = iMap.begin(), itEnd = iMap.end();
00091           it != itEnd;
00092           ++it,++itVec) {
00093          *itVec = it->second;
00094       }
00095    }
00096 }
00097 
00098 void 
00099 FWCollectionSummaryTableManager::implSort(int iCol, bool iSortOrder)
00100 {
00101    if(iSortOrder) {
00102       std::multimap<double,int, std::greater<double> > s;
00103       doSort(*m_collection, m_collection->valueGetter(), iCol, s, m_sortedToUnsortedIndicies);
00104    } else {
00105       std::multimap<double,int, std::less<double> > s;
00106       doSort(*m_collection, m_collection->valueGetter(), iCol, s, m_sortedToUnsortedIndicies);
00107    }
00108 }
00109 
00110 void 
00111 FWCollectionSummaryTableManager::buttonReleasedInRowHeader(Int_t row, Event_t* event, Int_t relX, Int_t relY)
00112 {
00113    Int_t realRow = unsortedRowNumber(row);
00114    int hit = m_renderer.clickHit(relX,relY);
00115    if(hit == FWCollectionSummaryModelCellRenderer::kMiss) {
00116       return;
00117    }
00118    if(hit == FWCollectionSummaryModelCellRenderer::kHitColor) {
00119       m_widget->itemColorClicked(realRow,event->fXRoot, event->fYRoot+12-relY);
00120       return;
00121    }
00122    FWEventItem::ModelInfo mi = m_collection->modelInfo(realRow);
00123    FWDisplayProperties dp = mi.displayProperties();
00124    if(hit == FWCollectionSummaryModelCellRenderer::kHitCheck) {
00125       dp.setIsVisible(!dp.isVisible());
00126    }
00127    m_collection->setDisplayProperties(realRow,dp);
00128 }
00129 
00130 //
00131 // const member functions
00132 //
00133 int 
00134 FWCollectionSummaryTableManager::numberOfRows() const
00135 {
00136    return m_collection->size();
00137 }
00138 
00139 int 
00140 FWCollectionSummaryTableManager::numberOfColumns() const {
00141    return m_collection->valueGetter().numValues();
00142 }
00143 
00144 std::vector<std::string> 
00145 FWCollectionSummaryTableManager::getTitles() const {
00146 
00147 
00148 
00149    //return titles;
00150       return  m_collection->valueGetter().getTitles();
00151 }
00152 
00153 int 
00154 FWCollectionSummaryTableManager::unsortedRowNumber(int iSortedRowNumber) const
00155 {
00156    return m_sortedToUnsortedIndicies[iSortedRowNumber];
00157 }
00158 
00159 FWTableCellRendererBase* 
00160 FWCollectionSummaryTableManager::cellRenderer(int iSortedRowNumber, int iCol) const
00161 {
00162    if(!m_collection->valueGetter().numValues()) {
00163       return 0;
00164    }
00165    if(iSortedRowNumber >= static_cast<int>(m_collection->size())) {
00166       m_bodyRenderer.setData("",false);
00167       return &m_bodyRenderer;
00168    }
00169    int index = m_sortedToUnsortedIndicies[iSortedRowNumber];
00170    std::stringstream s;
00171    s.setf(std::ios_base::fixed,std::ios_base::floatfield);
00172    s.precision( m_collection->valueGetter().precision(iCol));
00173    double v = m_collection->valueGetter().valueFor(m_collection->modelData(index), iCol);
00174    s <<v;
00175    m_bodyRenderer.setData(s.str(), m_collection->modelInfo(index).isSelected());
00176    return &m_bodyRenderer;
00177 }
00178 
00179 bool 
00180 FWCollectionSummaryTableManager::hasRowHeaders() const
00181 {
00182    return true;
00183 }
00184 
00185 FWTableCellRendererBase* 
00186 FWCollectionSummaryTableManager::rowHeader(int iSortedRowNumber) const
00187 {
00188    if(iSortedRowNumber >= static_cast<int>(m_collection->size())) {
00189       return 0;
00190    }
00191    int index = m_sortedToUnsortedIndicies[iSortedRowNumber];
00192    m_renderer.setData(m_collection,
00193                       index);
00194    return &m_renderer;
00195 }
00196 
00197 void
00198 FWCollectionSummaryTableManager::dataChanged() 
00199 {
00200    m_sortedToUnsortedIndicies.clear();
00201    m_sortedToUnsortedIndicies.reserve(m_collection->size());
00202    for(int i=0; i< static_cast<int>(m_collection->size());++i) {
00203       m_sortedToUnsortedIndicies.push_back(i);
00204    }
00205    FWTableManagerBase::dataChanged();
00206 }
00207 //
00208 // static member functions
00209 //