Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-08 02:27:17

0001 
0002 /*----------------------------------------------------------------------
0003 
0004  EDAnalyzer for testing EventSelectionID class and tracking mechanism.
0005 
0006 ----------------------------------------------------------------------*/
0007 
0008 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0009 
0010 #include "DataFormats/Provenance/interface/EventSelectionID.h"
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/Framework/interface/MakerMacros.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "DataFormats/Provenance/interface/ParameterSetID.h"
0015 #include "FWCore/ParameterSet/interface/Registry.h"
0016 
0017 #include <string>
0018 #include <vector>
0019 #include <cassert>
0020 #include <iostream>
0021 #include <algorithm>
0022 #include <iterator>
0023 
0024 namespace edm {
0025   class EventSetup;
0026 }
0027 
0028 namespace edmtest {
0029 
0030   class HistoryAnalyzer : public edm::one::EDAnalyzer<> {
0031   public:
0032     explicit HistoryAnalyzer(edm::ParameterSet const& params);
0033     void analyze(edm::Event const& event, edm::EventSetup const&);
0034     void endJob();
0035 
0036   private:
0037     typedef std::vector<std::string> vstring;
0038 
0039     int expectedSize_;
0040     int eventCount_;
0041     int expectedCount_;
0042 
0043     std::vector<edm::ParameterSet> expectedSelectEventsInfo_;
0044     vstring expectedPaths_;
0045     vstring expectedEndPaths_;
0046     vstring expectedModules_;
0047     vstring expectedDroppedEndPaths_;
0048     vstring expectedDroppedModules_;
0049     vstring expectedDropFromProcPSet_;
0050     edm::ParameterSet expectedModulesOnEndPaths_;
0051   };
0052 
0053   HistoryAnalyzer::HistoryAnalyzer(edm::ParameterSet const& params)
0054       : expectedSize_(params.getParameter<int>("expectedSize")),
0055         eventCount_(0),
0056         expectedCount_(params.getParameter<int>("expectedCount")),
0057         expectedSelectEventsInfo_(params.getParameter<std::vector<edm::ParameterSet> >("expectedSelectEventsInfo")),
0058         expectedPaths_(params.getParameter<vstring>("expectedPaths")),
0059         expectedEndPaths_(params.getParameter<vstring>("expectedEndPaths")),
0060         expectedModules_(params.getParameter<vstring>("expectedModules")),
0061         expectedDroppedEndPaths_(params.getParameter<vstring>("expectedDroppedEndPaths")),
0062         expectedDroppedModules_(params.getParameter<vstring>("expectedDroppedModules")),
0063         expectedDropFromProcPSet_(params.getParameter<vstring>("expectedDropFromProcPSet")),
0064         expectedModulesOnEndPaths_(params.getParameter<edm::ParameterSet>("expectedModulesOnEndPaths")) {}
0065 
0066   void HistoryAnalyzer::analyze(edm::Event const& event, edm::EventSetup const&) {
0067     edm::EventSelectionIDVector const& esv = event.eventSelectionIDs();
0068     assert(esv.size() == static_cast<size_t>(expectedSize_));
0069 
0070     for (unsigned i = 0; i < esv.size(); ++i) {
0071       edm::ParameterSet selectEventsInfo = getParameterSet(esv[i]);
0072       if (eventCount_ == 0) {
0073         std::cout << selectEventsInfo << std::endl;
0074       }
0075       if (i < expectedSelectEventsInfo_.size()) {
0076         assert(selectEventsInfo == expectedSelectEventsInfo_[i]);
0077       }
0078     }
0079 
0080     if (eventCount_ == 0) {
0081       edm::ParameterSet proc_pset;
0082       event.getProcessParameterSet(event.processHistory().rbegin()->processName(), proc_pset);
0083 
0084       {
0085         // test the function getProcessParameterSetContainingModule this is a
0086         // convenient spot to test because this module is run in both a
0087         // a single process and in a subprocess.
0088         edm::ParameterSet proc_pset2 = edm::getProcessParameterSetContainingModule(moduleDescription());
0089         assert(proc_pset2.id() == proc_pset.id());
0090         vstring paths1 = proc_pset.getParameter<vstring>("@paths");
0091         vstring paths2 = proc_pset2.getParameter<vstring>("@paths");
0092         assert(paths1 == paths2);
0093       }
0094 
0095       edm::pset::Registry* reg = edm::pset::Registry::instance();
0096 
0097       if (!expectedPaths_.empty()) {
0098         vstring paths = proc_pset.getParameter<vstring>("@paths");
0099         assert(paths == expectedPaths_);
0100 
0101         for (vstring::const_iterator i = paths.begin(), iEnd = paths.end(); i != iEnd; ++i) {
0102           vstring modulesOnPath = proc_pset.getParameter<std::vector<std::string> >(*i);
0103           assert(!modulesOnPath.empty());
0104         }
0105       }
0106 
0107       if (!expectedEndPaths_.empty()) {
0108         vstring end_paths = proc_pset.getParameter<vstring>("@end_paths");
0109         assert(end_paths == expectedEndPaths_);
0110 
0111         for (vstring::const_iterator i = end_paths.begin(), iEnd = end_paths.end(); i != iEnd; ++i) {
0112           vstring modulesOnEndPath = proc_pset.getParameter<vstring>(*i);
0113           assert(!modulesOnEndPath.empty());
0114           vstring expectedModulesOnEndPath = expectedModulesOnEndPaths_.getParameter<vstring>(*i);
0115           if (expectedModulesOnEndPath != modulesOnEndPath) {
0116             std::copy(expectedModulesOnEndPath.begin(),
0117                       expectedModulesOnEndPath.end(),
0118                       std::ostream_iterator<std::string>(std::cout, " "));
0119             std::cout << std::endl;
0120             std::copy(
0121                 modulesOnEndPath.begin(), modulesOnEndPath.end(), std::ostream_iterator<std::string>(std::cout, " "));
0122             std::cout << std::endl;
0123             assert(expectedModulesOnEndPath == modulesOnEndPath);
0124           }
0125         }
0126       }
0127 
0128       if (!expectedModules_.empty()) {
0129         vstring all_modules = proc_pset.getParameter<vstring>("@all_modules");
0130 
0131         if (all_modules != expectedModules_) {
0132           std::copy(all_modules.begin(), all_modules.end(), std::ostream_iterator<std::string>(std::cout, " "));
0133           std::cout << std::endl;
0134           std::copy(
0135               expectedModules_.begin(), expectedModules_.end(), std::ostream_iterator<std::string>(std::cout, " "));
0136           std::cout << std::endl;
0137           assert(all_modules == expectedModules_);
0138         }
0139         for (vstring::const_iterator i = all_modules.begin(), iEnd = all_modules.end(); i != iEnd; ++i) {
0140           // Make sure the ParameterSet for the module is also present
0141           edm::ParameterSet const& pset = proc_pset.getParameterSet(*i);
0142           // This is probably overkill, but also check it can be retrieved by ID from the registry
0143           edm::ParameterSetID id = pset.id();
0144           edm::ParameterSet const* result = reg->getMapped(id);
0145           assert(result != 0);
0146         }
0147       }
0148 
0149       for (vstring::const_iterator i = expectedDroppedEndPaths_.begin(), iEnd = expectedDroppedEndPaths_.end();
0150            i != iEnd;
0151            ++i) {
0152         assert(!proc_pset.exists(*i));
0153       }
0154 
0155       for (vstring::const_iterator i = expectedDroppedModules_.begin(), iEnd = expectedDroppedModules_.end(); i != iEnd;
0156            ++i) {
0157         assert(!proc_pset.exists(*i));
0158 
0159         for (edm::pset::Registry::const_iterator j = reg->begin(), jEnd = reg->end(); j != jEnd; ++j) {
0160           if (j->second.exists("@module_label")) {
0161             assert(j->second.getParameter<std::string>("@module_label") != *i);
0162           }
0163         }
0164       }
0165       for (vstring::const_iterator i = expectedDropFromProcPSet_.begin(), iEnd = expectedDropFromProcPSet_.end();
0166            i != iEnd;
0167            ++i) {
0168         assert(!proc_pset.existsAs<edm::ParameterSet>(*i, true));
0169         assert(proc_pset.existsAs<edm::ParameterSet>(*i, false));
0170         bool isInRegistry = false;
0171         for (edm::pset::Registry::const_iterator j = reg->begin(), jEnd = reg->end(); j != jEnd; ++j) {
0172           if (j->second.exists("@module_label")) {
0173             if (j->second.getParameter<std::string>("@module_label") == *i)
0174               isInRegistry = true;
0175           }
0176         }
0177         assert(isInRegistry);
0178       }
0179     }
0180     ++eventCount_;
0181   }
0182 
0183   void HistoryAnalyzer::endJob() {
0184     // std::cout << "Expected count is: " << expectedCount_ << std::endl;
0185     // std::cout << "Event count is:    " << eventCount_ << std::endl;
0186     assert(eventCount_ == expectedCount_);
0187   }
0188 }  // namespace edmtest
0189 
0190 using edmtest::HistoryAnalyzer;
0191 DEFINE_FWK_MODULE(HistoryAnalyzer);