CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/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.8 2010/12/16 12:04:43 amraktad 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    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    } else {
00067      s_names.push_back(std::pair<std::string,std::string>("pt","GeV"));
00068      s_names.push_back(std::pair<std::string,std::string>("et","GeV"));
00069      s_names.push_back(std::pair<std::string,std::string>("energy","GeV"));
00070      boost::shared_ptr<FWItemValueGetter> trans( new FWItemValueGetter(type,s_names));
00071      if(trans->isValid()) m_valueGetters.push_back(trans);
00072    }
00073 
00074    
00075    s_names.clear();
00076    s_names.push_back(std::pair<std::string,std::string>("eta",""));
00077    boost::shared_ptr<FWItemValueGetter> eta( new FWItemValueGetter(type,s_names));
00078    if(eta->isValid()) {
00079       s_names.clear();
00080       s_names.push_back(std::pair<std::string,std::string>("phi",""));
00081       boost::shared_ptr<FWItemValueGetter> phi( new FWItemValueGetter(type,s_names));
00082       if(phi->isValid()) {
00083          m_valueGetters.push_back(eta);
00084          m_valueGetters.push_back(phi);
00085       }
00086    }
00087    
00088    dataChanged();
00089 }
00090 
00091 // FWCollectionSummaryTableManager::FWCollectionSummaryTableManager(const FWCollectionSummaryTableManager& rhs)
00092 // {
00093 //    // do actual copying here;
00094 // }
00095 
00096 FWCollectionSummaryTableManager::~FWCollectionSummaryTableManager()
00097 {
00098 }
00099 
00100 //
00101 // assignment operators
00102 //
00103 // const FWCollectionSummaryTableManager& FWCollectionSummaryTableManager::operator=(const FWCollectionSummaryTableManager& rhs)
00104 // {
00105 //   //An exception safe implementation is
00106 //   FWCollectionSummaryTableManager temp(rhs);
00107 //   swap(rhs);
00108 //
00109 //   return *this;
00110 // }
00111 
00112 //
00113 // member functions
00114 //
00115 namespace {
00116    template<typename S>
00117    void doSort(const FWEventItem& iItem,
00118                FWItemValueGetter& iGetter,
00119                std::multimap<double,int,S>& iMap,
00120                std::vector<int>& oNewSort) {
00121       int size = iItem.size();
00122       for(int index = 0; index < size; ++index) {
00123          iMap.insert(std::make_pair(iGetter.valueFor(iItem.modelData(index)),
00124                                        index));
00125       }
00126       std::vector<int>::iterator itVec = oNewSort.begin();
00127       for(typename std::map<double,int,S>::iterator it = iMap.begin(), itEnd = iMap.end();
00128           it != itEnd;
00129           ++it,++itVec) {
00130          *itVec = it->second;
00131       }
00132    }
00133 }
00134 
00135 void 
00136 FWCollectionSummaryTableManager::implSort(int iCol, bool iSortOrder)
00137 {
00138    if(iSortOrder) {
00139       std::multimap<double,int, std::greater<double> > s;
00140       doSort(*m_collection, *(m_valueGetters[iCol]), s, m_sortedToUnsortedIndicies);
00141    } else {
00142       std::multimap<double,int, std::less<double> > s;
00143       doSort(*m_collection, *(m_valueGetters[iCol]), s, m_sortedToUnsortedIndicies);
00144    }
00145 }
00146 
00147 void 
00148 FWCollectionSummaryTableManager::buttonReleasedInRowHeader(Int_t row, Event_t* event, Int_t relX, Int_t relY)
00149 {
00150    Int_t realRow = unsortedRowNumber(row);
00151    int hit = m_renderer.clickHit(relX,relY);
00152    if(hit == FWCollectionSummaryModelCellRenderer::kMiss) {
00153       return;
00154    }
00155    if(hit == FWCollectionSummaryModelCellRenderer::kHitColor) {
00156       m_widget->itemColorClicked(realRow,event->fXRoot, event->fYRoot+12-relY);
00157       return;
00158    }
00159    FWEventItem::ModelInfo mi = m_collection->modelInfo(realRow);
00160    FWDisplayProperties dp = mi.displayProperties();
00161    if(hit == FWCollectionSummaryModelCellRenderer::kHitCheck) {
00162       dp.setIsVisible(!dp.isVisible());
00163    }
00164    m_collection->setDisplayProperties(realRow,dp);
00165 }
00166 
00167 //
00168 // const member functions
00169 //
00170 int 
00171 FWCollectionSummaryTableManager::numberOfRows() const
00172 {
00173    return m_collection->size();
00174 }
00175 
00176 int 
00177 FWCollectionSummaryTableManager::numberOfColumns() const {
00178    return m_valueGetters.size();
00179 }
00180 
00181 std::vector<std::string> 
00182 FWCollectionSummaryTableManager::getTitles() const {
00183    std::vector<std::string> titles;
00184    titles.reserve(m_valueGetters.size());
00185    for(std::vector<boost::shared_ptr<FWItemValueGetter> >::const_iterator it = m_valueGetters.begin(), itEnd=m_valueGetters.end();
00186        it != itEnd;
00187        ++it) {
00188       titles.push_back((*it)->valueName());
00189    }
00190    return titles;
00191 }
00192 
00193 int 
00194 FWCollectionSummaryTableManager::unsortedRowNumber(int iSortedRowNumber) const
00195 {
00196    return m_sortedToUnsortedIndicies[iSortedRowNumber];
00197 }
00198 
00199 FWTableCellRendererBase* 
00200 FWCollectionSummaryTableManager::cellRenderer(int iSortedRowNumber, int iCol) const
00201 {
00202    if(iCol >= static_cast<int>(m_valueGetters.size())) {
00203       return 0;
00204    }
00205    if(iSortedRowNumber >= static_cast<int>(m_collection->size())) {
00206       m_bodyRenderer.setData("",false);
00207       return &m_bodyRenderer;
00208    }
00209    int index = m_sortedToUnsortedIndicies[iSortedRowNumber];
00210    std::stringstream s;
00211    s.setf(std::ios_base::fixed,std::ios_base::floatfield);
00212    s.precision(1);
00213    double v = m_valueGetters[iCol]->valueFor(m_collection->modelData(index));
00214    s <<v;
00215    m_bodyRenderer.setData(s.str(),
00216                           m_collection->modelInfo(index).isSelected());
00217    return &m_bodyRenderer;
00218 }
00219 
00220 bool 
00221 FWCollectionSummaryTableManager::hasRowHeaders() const
00222 {
00223    return true;
00224 }
00225 
00226 FWTableCellRendererBase* 
00227 FWCollectionSummaryTableManager::rowHeader(int iSortedRowNumber) const
00228 {
00229    if(iSortedRowNumber >= static_cast<int>(m_collection->size())) {
00230       return 0;
00231    }
00232    int index = m_sortedToUnsortedIndicies[iSortedRowNumber];
00233    m_renderer.setData(m_collection,
00234                       index);
00235    return &m_renderer;
00236 }
00237 
00238 void
00239 FWCollectionSummaryTableManager::dataChanged() 
00240 {
00241    m_sortedToUnsortedIndicies.clear();
00242    m_sortedToUnsortedIndicies.reserve(m_collection->size());
00243    for(int i=0; i< static_cast<int>(m_collection->size());++i) {
00244       m_sortedToUnsortedIndicies.push_back(i);
00245    }
00246    FWTableManagerBase::dataChanged();
00247 }
00248 //
00249 // static member functions
00250 //