Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:44

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     unittest_changemanager
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Fri Jan 18 10:19:07 EST 2008
0011 //
0012 
0013 // system include files
0014 #include <boost/test/unit_test.hpp>
0015 #include <boost/test/test_tools.hpp>
0016 #include "TClass.h"
0017 
0018 // user include files
0019 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0020 #include "DataFormats/TrackReco/interface/Track.h"
0021 #include "FWCore/Reflection/interface/ObjectWithDict.h"
0022 #include "Fireworks/Core/interface/FWEventItem.h"
0023 
0024 #include "Fireworks/Core/interface/FWModelChangeManager.h"
0025 
0026 #include "Fireworks/Core/interface/FWSelectionManager.h"
0027 #include "Fireworks/Core/interface/FWModelExpressionSelector.h"
0028 
0029 #include "Fireworks/Core/interface/FWItemAccessorBase.h"
0030 
0031 //
0032 // constants, enums and typedefs
0033 //
0034 
0035 namespace {
0036   class TestAccessor : public FWItemAccessorBase {
0037   public:
0038     TestAccessor(const reco::TrackCollection* iCollection) : m_collection(iCollection) {}
0039     virtual const void* modelData(int iIndex) const { return &((*m_collection)[iIndex]); }
0040     virtual const void* data() const { return m_collection; }
0041     virtual unsigned int size() const { return m_collection->size(); }
0042     virtual const TClass* modelType() const { return TClass::GetClass("reco::Track"); }
0043     virtual const TClass* type() const { return TClass::GetClass("std::vector<reco::Track>"); }
0044 
0045     virtual bool isCollection() const { return true; }
0046 
0047     ///override if id of an object should be different than the index
0048     //virtual std::string idForIndex(int iIndex) const;
0049     // ---------- member functions ---------------------------
0050     virtual void setData(const edm::ObjectWithDict&) {}
0051     virtual void reset() {}
0052 
0053   private:
0054     const reco::TrackCollection* m_collection;
0055   };
0056 }  // namespace
0057 
0058 BOOST_AUTO_TEST_CASE(modelexpressionselector) {
0059   FWModelChangeManager cm;
0060 
0061   FWSelectionManager sm(&cm);
0062 
0063   reco::TrackCollection fVector;
0064   fVector.push_back(reco::Track());
0065   fVector.push_back(
0066       reco::Track(20, 20, reco::Track::Point(), reco::Track::Vector(20, 0, 0), -1, reco::Track::CovarianceMatrix()));
0067   fVector.push_back(reco::Track());
0068 
0069   TClass* cls = TClass::GetClass("std::vector<reco::Track>");
0070   assert(0 != cls);
0071 
0072   fireworks::Context context(&cm, &sm, 0, 0, 0);
0073 
0074   auto accessor = std::make_shared<TestAccessor>(&fVector);
0075   FWPhysicsObjectDesc pObj("Tracks", cls, "Tracks");
0076 
0077   FWEventItem item(&context, 0, accessor, pObj);
0078   //hack to force update of data
0079   edm::ObjectWithDict dummy;
0080   item.setData(dummy);
0081 
0082   cm.newItemSlot(&item);
0083 
0084   FWModelExpressionSelector selector;
0085   {
0086     FWChangeSentry sentry(cm);
0087     selector.select(&item, "$.pt() > 10");
0088   }
0089   BOOST_CHECK(1 == sm.selected().size());
0090   BOOST_CHECK(not item.modelInfo(0).m_isSelected);
0091   BOOST_CHECK(item.modelInfo(1).m_isSelected);
0092   BOOST_CHECK(not item.modelInfo(2).m_isSelected);
0093 }