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/FWColorManager.h"
0025 #include "Fireworks/Core/interface/FWEventItemsManager.h"
0026 #include "Fireworks/Core/interface/FWConfiguration.h"
0027 
0028 //
0029 // constants, enums and typedefs
0030 //
0031 namespace {
0032   struct Listener {
0033     Listener() : nMessages_(0), item_(0) {}
0034     int nMessages_;
0035     const FWEventItem* item_;
0036 
0037     void reset() {
0038       nMessages_ = 0;
0039       item_ = 0;
0040     }
0041     void newItem(const FWEventItem* iItem) {
0042       ++nMessages_;
0043       item_ = iItem;
0044     }
0045   };
0046 }  // namespace
0047 
0048 BOOST_AUTO_TEST_CASE(eventitemmanager) {
0049   FWModelChangeManager cm;
0050 
0051   FWSelectionManager sm(&cm);
0052   FWEventItemsManager eim(&cm);
0053   FWColorManager colm(&cm);
0054   colm.initialize();
0055 
0056   // !!!! Passing 0 for FWJobMetadataManager
0057   fireworks::Context context(&cm, &sm, &eim, &colm, 0);
0058   eim.setContext(&context);
0059 
0060   Listener listener;
0061   //NOTE: have to pass a pointer to the listener else the bind will
0062   // create a copy of the listener and the original one will never
0063   // 'hear' any signal
0064   eim.newItem_.connect(std::bind(&Listener::newItem, &listener, std::placeholders::_1));
0065 
0066   TClass* cls = TClass::GetClass("std::vector<reco::Track>");
0067   assert(0 != cls);
0068 
0069   Color_t color1 = FWColorManager::getDefaultStartColorIndex() + 1;
0070   FWPhysicsObjectDesc tracks(
0071       "Tracks", cls, "Tracks", FWDisplayProperties(color1, true, 100), "label", "instance", "proc");
0072 
0073   BOOST_REQUIRE(listener.nMessages_ == 0);
0074   BOOST_REQUIRE(eim.begin() == eim.end());
0075 
0076   eim.add(tracks);
0077   BOOST_CHECK(listener.nMessages_ == 1);
0078   BOOST_CHECK(eim.end() - eim.begin() == 1);
0079   const FWEventItem* item = *(eim.begin());
0080   BOOST_REQUIRE(item != 0);
0081   BOOST_CHECK(item == listener.item_);
0082   BOOST_CHECK(item->name() == "Tracks");
0083   BOOST_CHECK(item->type() == cls);
0084   BOOST_CHECK(item->defaultDisplayProperties().color() == color1);
0085   BOOST_CHECK(item->defaultDisplayProperties().isVisible());
0086   BOOST_CHECK(item->moduleLabel() == "label");
0087   BOOST_CHECK(item->productInstanceLabel() == "instance");
0088   BOOST_CHECK(item->processName() == "proc");
0089 
0090   FWConfiguration config;
0091   eim.addTo(config);
0092 
0093   eim.clearItems();
0094   listener.reset();
0095 
0096   BOOST_REQUIRE(listener.nMessages_ == 0);
0097   BOOST_REQUIRE(eim.begin() == eim.end());
0098 
0099   eim.setFrom(config);
0100 
0101   BOOST_CHECK(listener.nMessages_ == 1);
0102   BOOST_CHECK(eim.end() - eim.begin() == 1);
0103   item = *(eim.begin());
0104   BOOST_REQUIRE(item != 0);
0105   BOOST_CHECK(item == listener.item_);
0106   BOOST_CHECK(item->name() == "Tracks");
0107   BOOST_CHECK(item->type() == cls);
0108   BOOST_CHECK(item->defaultDisplayProperties().color() == color1);
0109   BOOST_CHECK(item->defaultDisplayProperties().isVisible());
0110   BOOST_CHECK(item->moduleLabel() == "label");
0111   BOOST_CHECK(item->productInstanceLabel() == "instance");
0112   BOOST_CHECK(item->processName() == "proc");
0113 }