CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/Fireworks/Calo/src/FWCaloDataProxyBuilderBase.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Calo
00004 // Class  :     FWCaloDataProxyBuilderBase
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Original Author:  
00010 //         Created:  Mon May 31 15:09:39 CEST 2010
00011 // $Id: FWCaloDataProxyBuilderBase.cc,v 1.5 2010/11/09 16:56:23 amraktad Exp $
00012 //
00013 
00014 // system include files
00015 
00016 #include <math.h>
00017 
00018 // user includes
00019 #include "TEveCaloData.h"
00020 #include "TEveCalo.h"
00021 #include "TH2F.h"
00022 #include "TEveManager.h"
00023 #include "TEveSelection.h"
00024 
00025 #include "Fireworks/Core/interface/Context.h"
00026 #include "Fireworks/Core/interface/FWEventItem.h"
00027 
00028 #include "Fireworks/Calo/interface/FWCaloDataProxyBuilderBase.h"
00029 #include "Fireworks/Calo/src/FWFromTEveCaloDataSelector.h"
00030 
00031 #include "DataFormats/CaloTowers/interface/CaloTower.h"
00032 
00033 
00034 //
00035 // constants, enums and typedefs
00036 //
00037 
00038 //
00039 // static data member definitions
00040 //
00041 
00042 //
00043 // constructors and destructor
00044 //
00045 FWCaloDataProxyBuilderBase::FWCaloDataProxyBuilderBase() :
00046    m_caloData(0),
00047    m_sliceIndex(-1)
00048 {
00049 }
00050 
00051 // FWCaloDataProxyBuilderBase::FWCaloDataProxyBuilderBase(const FWCaloDataProxyBuilderBase& rhs)
00052 // {
00053 //    // do actual copying here;
00054 // }
00055 
00056 FWCaloDataProxyBuilderBase::~FWCaloDataProxyBuilderBase()
00057 {
00058 }
00059 
00060 //
00061 // assignment operators
00062 //
00063 // const FWCaloDataProxyBuilderBase& FWCaloDataProxyBuilderBase::operator=(const FWCaloDataProxyBuilderBase& rhs)
00064 // {
00065 //   //An exception safe implementation is
00066 //   FWCaloDataProxyBuilderBase temp(rhs);
00067 //   swap(rhs);
00068 //
00069 //   return *this;
00070 // }
00071 
00072 //
00073 // member functions
00074 //
00075 
00076 void
00077 FWCaloDataProxyBuilderBase::build(const FWEventItem* iItem,
00078                                   TEveElementList*, const FWViewContext*)
00079 {
00080    setCaloData(iItem->context());
00081 
00082    assertCaloDataSlice();
00083    fillCaloData();
00084 
00085    m_caloData->SetSliceColor(m_sliceIndex,item()->defaultDisplayProperties().color());
00086    m_caloData->SetSliceTransparency(m_sliceIndex,item()->defaultDisplayProperties().transparency());
00087    m_caloData->DataChanged();
00088    m_caloData->CellSelectionChanged();
00089 }
00090 
00091 //______________________________________________________________________________
00092 
00093 void
00094 FWCaloDataProxyBuilderBase::modelChanges(const FWModelIds&, Product* p)
00095 {
00096    if(m_caloData && item())
00097    {      
00098       clearCaloDataSelection();
00099       fillCaloData();    
00100 
00101       TEveCaloData::vCellId_t& selected = m_caloData->GetCellsSelected();
00102       if(!selected.empty()) {
00103          if(0==m_caloData->GetSelectedLevel()) {
00104             gEve->GetSelection()->AddElement(m_caloData);
00105          }
00106       } else {
00107          if(1==m_caloData->GetSelectedLevel()||2==m_caloData->GetSelectedLevel()) {
00108             gEve->GetSelection()->RemoveElement(m_caloData);
00109          }
00110       }   
00111 
00112       m_caloData->SetSliceColor(m_sliceIndex,item()->defaultDisplayProperties().color());
00113       m_caloData->SetSliceTransparency(m_sliceIndex,item()->defaultDisplayProperties().transparency());
00114       m_caloData->DataChanged();
00115       m_caloData->CellSelectionChanged();
00116    }
00117 }
00118 //______________________________________________________________________________
00119 
00120 void
00121 FWCaloDataProxyBuilderBase::itemBeingDestroyed(const FWEventItem* iItem)
00122 {
00123    FWProxyBuilderBase::itemBeingDestroyed(iItem);
00124    if (m_caloData)
00125    {
00126       clearCaloDataSelection();
00127       FWFromTEveCaloDataSelector* sel = reinterpret_cast<FWFromTEveCaloDataSelector*>(m_caloData->GetUserData());
00128       sel->resetSliceSelector(m_sliceIndex);
00129       m_caloData->DataChanged();
00130    }
00131 }
00132 
00133 
00134 
00135 void
00136 FWCaloDataProxyBuilderBase::clearCaloDataSelection()
00137 {
00138    //find all selected cell ids which are not from this FWEventItem and preserve only them
00139    // do this by moving them to the end of the list and then clearing only the end of the list
00140    // this avoids needing any additional memory
00141 
00142    TEveCaloData::vCellId_t& selected = m_caloData->GetCellsSelected();
00143 
00144    TEveCaloData::vCellId_t::iterator itEnd = selected.end();
00145    for(TEveCaloData::vCellId_t::iterator it = selected.begin();
00146        it != itEnd;
00147        ++it) {
00148       if(it->fSlice ==m_sliceIndex) {
00149          //we have found one we want to get rid of, so we swap it with the
00150          // one closest to the end which is not of this slice
00151          do {
00152             TEveCaloData::vCellId_t::iterator itLast = itEnd-1;
00153             itEnd = itLast;
00154          } while (itEnd != it && itEnd->fSlice==m_sliceIndex);
00155             
00156          if(itEnd != it) {
00157             std::swap(*it,*itEnd);
00158          } else {
00159             //shouldn't go on since advancing 'it' will put us past itEnd
00160             break;
00161          }
00162          //std::cout <<"keeping "<<it->fTower<<" "<<it->fSlice<<std::endl;
00163       }
00164    }
00165    selected.erase(itEnd,selected.end());
00166 
00167 
00168    // reset higlight
00169    m_caloData->GetCellsHighlighted().clear();
00170 }