Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-29 01:21:25

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 "Fireworks/Core/interface/FWEventItem.h"
0022 #include "Fireworks/Core/interface/FWModelChangeManager.h"
0023 #include "Fireworks/Core/interface/FWSelectionManager.h"
0024 #include "Fireworks/Core/interface/FWItemAccessorBase.h"
0025 #include "Fireworks/Core/interface/FWModelFilter.h"
0026 
0027 //
0028 // constants, enums and typedefs
0029 //
0030 namespace {
0031   class TestAccessor : public FWItemAccessorBase {
0032   public:
0033     TestAccessor(const reco::TrackCollection* iCollection) : m_collection(iCollection) {}
0034     virtual const void* modelData(int iIndex) const { return &((*m_collection)[iIndex]); }
0035     virtual const void* data() const { return m_collection; }
0036     virtual unsigned int size() const { return m_collection->size(); }
0037     virtual const TClass* modelType() const { return TClass::GetClass("reco::Track"); }
0038     virtual const TClass* type() const { return TClass::GetClass("reco::TrackCollection"); }
0039 
0040     virtual bool isCollection() const { return true; }
0041 
0042     ///override if id of an object should be different than the index
0043     //virtual std::string idForIndex(int iIndex) const;
0044     // ---------- member functions ---------------------------
0045     virtual void setData(const edm::ObjectWithDict&) {}
0046     virtual void reset() {}
0047 
0048   private:
0049     const reco::TrackCollection* m_collection;
0050   };
0051 }  // namespace
0052 
0053 BOOST_AUTO_TEST_CASE(itemfilter) {
0054   FWModelChangeManager cm;
0055 
0056   FWSelectionManager sm(&cm);
0057 
0058   reco::TrackCollection fVector;
0059   fVector.push_back(reco::Track());
0060   fVector.push_back(
0061       reco::Track(20, 20, reco::Track::Point(), reco::Track::Vector(20, 0, 0), -1, reco::Track::CovarianceMatrix()));
0062   fVector.push_back(reco::Track());
0063 
0064   TClass* cls = TClass::GetClass("std::vector<reco::Track>");
0065   assert(0 != cls);
0066 
0067   fireworks::Context context(&cm, &sm, 0, 0, 0);
0068 
0069   auto accessor = std::make_shared<TestAccessor>(&fVector);
0070   FWPhysicsObjectDesc pObj("Tracks", cls, "Tracks");
0071   FWEventItem item(&context, 0, accessor, pObj);
0072 
0073   cm.newItemSlot(&item);
0074 
0075   FWModelFilter filter("$.pt() > 10", "reco::Track");
0076   BOOST_CHECK(not filter.passesFilter(item.modelData(0)));
0077   BOOST_CHECK(filter.passesFilter(item.modelData(1)));
0078 
0079   filter.setExpression(std::string());
0080   BOOST_CHECK(filter.passesFilter(item.modelData(0)));
0081   BOOST_CHECK(filter.passesFilter(item.modelData(1)));
0082 }