Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-17 23:10:43

0001 // -*- C++ -*-
0002 //
0003 // Package:     Calo
0004 // Class  :     FWFromTEveCaloDataSelector
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Fri Oct 23 14:44:33 CDT 2009
0011 //
0012 
0013 // system include files
0014 #include <algorithm>
0015 #include <cassert>
0016 #include <functional>
0017 
0018 // user include files
0019 #include "Fireworks/Calo/interface/FWFromTEveCaloDataSelector.h"
0020 #include "Fireworks/Core/interface/FWModelChangeManager.h"
0021 #include "Fireworks/Core/interface/FWEventItem.h"
0022 
0023 //
0024 // static data member definitions
0025 //
0026 
0027 //
0028 // constructors and destructor
0029 //
0030 FWFromTEveCaloDataSelector::FWFromTEveCaloDataSelector(TEveCaloData* iData) : m_data(iData), m_changeManager(nullptr) {
0031   // reserve 3 , first slice is background
0032   m_sliceSelectors.reserve(3);
0033   m_sliceSelectors.push_back(new FWFromSliceSelector(nullptr));
0034 }
0035 
0036 // FWFromTEveCaloDataSelector::FWFromTEveCaloDataSelector(const FWFromTEveCaloDataSelector& rhs)
0037 // {
0038 //    // do actual copying here;
0039 // }
0040 
0041 FWFromTEveCaloDataSelector::~FWFromTEveCaloDataSelector() {
0042   for (std::vector<FWFromSliceSelector*>::iterator i = m_sliceSelectors.begin(); i != m_sliceSelectors.end(); ++i) {
0043     delete *i;
0044   }
0045   m_sliceSelectors.clear();
0046 }
0047 
0048 //
0049 // assignment operators
0050 //
0051 // const FWFromTEveCaloDataSelector& FWFromTEveCaloDataSelector::operator=(const FWFromTEveCaloDataSelector& rhs)
0052 // {
0053 //   //An exception safe implementation is
0054 //   FWFromTEveCaloDataSelector temp(rhs);
0055 //   swap(rhs);
0056 //
0057 //   return *this;
0058 // }
0059 
0060 //
0061 // member functions
0062 //
0063 void FWFromTEveCaloDataSelector::doSelect() {
0064   assert(m_changeManager);
0065   FWChangeSentry sentry(*m_changeManager);
0066   std::for_each(
0067       m_sliceSelectors.begin(), m_sliceSelectors.end(), std::bind(&FWFromSliceSelector::clear, std::placeholders::_1));
0068   const TEveCaloData::vCellId_t& cellIds = m_data->GetCellsSelected();
0069   for (TEveCaloData::vCellId_t::const_iterator it = cellIds.begin(), itEnd = cellIds.end(); it != itEnd; ++it) {
0070     assert(it->fSlice < static_cast<int>(m_sliceSelectors.size()));
0071     m_sliceSelectors[it->fSlice]->doSelect(*it);
0072   }
0073 }
0074 
0075 void FWFromTEveCaloDataSelector::doUnselect() {
0076   assert(m_changeManager);
0077   //std::cout <<"FWFromTEveCaloDataSelector::doUnselect()"<<std::endl;
0078 
0079   FWChangeSentry sentry(*m_changeManager);
0080   const TEveCaloData::vCellId_t& cellIds = m_data->GetCellsSelected();
0081   for (TEveCaloData::vCellId_t::const_iterator it = cellIds.begin(), itEnd = cellIds.end(); it != itEnd; ++it) {
0082     assert(it->fSlice < static_cast<int>(m_sliceSelectors.size()));
0083     m_sliceSelectors[it->fSlice]->doUnselect(*it);
0084   }
0085 }
0086 
0087 void FWFromTEveCaloDataSelector::addSliceSelector(int iSlice, FWFromSliceSelector* iSelector) {
0088   assert(iSlice > 0 && (iSlice <= static_cast<int>(m_sliceSelectors.size())));
0089 
0090   if (nullptr == m_changeManager) {
0091     m_changeManager = iSelector->changeManager();
0092   }
0093 
0094   if (iSlice == static_cast<int>(m_sliceSelectors.size())) {
0095     m_sliceSelectors.push_back(iSelector);
0096   } else {
0097     assert(iSlice < static_cast<int>(m_sliceSelectors.size()));
0098     m_sliceSelectors[iSlice] = iSelector;
0099   }
0100 }
0101 
0102 void FWFromTEveCaloDataSelector::resetSliceSelector(int iSlice) { m_sliceSelectors[iSlice]->reset(); }
0103 //
0104 // const member functions
0105 //
0106 
0107 //
0108 // static member functions
0109 //