File indexing completed on 2024-04-06 12:04:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
0019 #include "DataFormats/HLTReco/interface/TriggerObject.h"
0020 #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
0021 #include "FWCore/Framework/interface/Event.h"
0022 #include "FWCore/Framework/interface/Frameworkfwd.h"
0023 #include "FWCore/Framework/interface/global/EDProducer.h"
0024 #include "FWCore/Framework/interface/MakerMacros.h"
0025 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0027 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0028 #include "FWCore/Utilities/interface/EDPutToken.h"
0029 #include "FWCore/Utilities/interface/Exception.h"
0030 #include "FWCore/Utilities/interface/StreamID.h"
0031
0032 #include <memory>
0033 #include <string>
0034 #include <utility>
0035 #include <vector>
0036
0037 namespace edmtest {
0038
0039 class TestWriteTriggerEvent : public edm::global::EDProducer<> {
0040 public:
0041 TestWriteTriggerEvent(edm::ParameterSet const&);
0042 void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
0043 static void fillDescriptions(edm::ConfigurationDescriptions&);
0044
0045 private:
0046 std::string usedProcessName_;
0047 std::vector<std::string> collectionTags_;
0048 std::vector<unsigned int> collectionKeys_;
0049 std::vector<int> ids_;
0050 std::vector<double> pts_;
0051 std::vector<double> etas_;
0052 std::vector<double> phis_;
0053 std::vector<double> masses_;
0054 std::vector<std::string> filterTags_;
0055 unsigned int elementsPerVector_;
0056 std::vector<int> filterIds_;
0057 std::vector<unsigned int> filterKeys_;
0058
0059 edm::EDPutTokenT<trigger::TriggerEvent> triggerEventPutToken_;
0060 };
0061
0062 TestWriteTriggerEvent::TestWriteTriggerEvent(edm::ParameterSet const& iPSet)
0063 : usedProcessName_(iPSet.getParameter<std::string>("usedProcessName")),
0064 collectionTags_(iPSet.getParameter<std::vector<std::string>>("collectionTags")),
0065 collectionKeys_(iPSet.getParameter<std::vector<unsigned int>>("collectionKeys")),
0066 ids_(iPSet.getParameter<std::vector<int>>("ids")),
0067 pts_(iPSet.getParameter<std::vector<double>>("pts")),
0068 etas_(iPSet.getParameter<std::vector<double>>("etas")),
0069 phis_(iPSet.getParameter<std::vector<double>>("phis")),
0070 masses_(iPSet.getParameter<std::vector<double>>("masses")),
0071 filterTags_(iPSet.getParameter<std::vector<std::string>>("filterTags")),
0072 elementsPerVector_(iPSet.getParameter<unsigned int>("elementsPerVector")),
0073 filterIds_(iPSet.getParameter<std::vector<int>>("filterIds")),
0074 filterKeys_(iPSet.getParameter<std::vector<unsigned int>>("filterKeys")),
0075
0076 triggerEventPutToken_(produces()) {
0077 if (ids_.size() != pts_.size() || ids_.size() != etas_.size() || ids_.size() != phis_.size() ||
0078 ids_.size() != masses_.size()) {
0079 throw cms::Exception("TestFailure") << "TestWriteTriggerEvent, test configuration error: "
0080 "ids, pts, etas, phis, and masses should have the same size.";
0081 }
0082 if (filterIds_.size() != elementsPerVector_ * filterTags_.size() ||
0083 filterKeys_.size() != elementsPerVector_ * filterTags_.size()) {
0084 throw cms::Exception("TestFailure")
0085 << "TestWriteTriggerEvent, test configuration error: "
0086 "size of filterIds and size of filterKeys should equal size of filterTags times elementsPerVector";
0087 }
0088 }
0089
0090 void TestWriteTriggerEvent::produce(edm::StreamID, edm::Event& iEvent, edm::EventSetup const&) const {
0091
0092
0093
0094
0095
0096
0097 auto triggerEvent = std::make_unique<trigger::TriggerEvent>(
0098 usedProcessName_, collectionTags_.size(), ids_.size(), filterTags_.size());
0099 trigger::Keys keys;
0100 keys.reserve(collectionKeys_.size());
0101 for (auto const& element : collectionKeys_) {
0102 keys.push_back(static_cast<trigger::size_type>(element));
0103 }
0104 triggerEvent->addCollections(collectionTags_, keys);
0105
0106 trigger::TriggerObjectCollection triggerObjectCollection;
0107 triggerObjectCollection.reserve(ids_.size());
0108 for (unsigned int i = 0; i < ids_.size(); ++i) {
0109 triggerObjectCollection.emplace_back(ids_[i],
0110 static_cast<float>(pts_[i]),
0111 static_cast<float>(etas_[i]),
0112 static_cast<float>(phis_[i]),
0113 static_cast<float>(masses_[i]));
0114 }
0115 triggerEvent->addObjects(triggerObjectCollection);
0116
0117 for (unsigned int i = 0; i < filterTags_.size(); ++i) {
0118 trigger::Vids filterIds;
0119 filterIds.reserve(elementsPerVector_);
0120 trigger::Keys filterKeys;
0121 filterKeys.reserve(elementsPerVector_);
0122 for (unsigned int j = 0; j < elementsPerVector_; ++j) {
0123 filterIds.push_back(filterIds_[i * elementsPerVector_ + j]);
0124 filterKeys.push_back(filterKeys_[i * elementsPerVector_ + j]);
0125 }
0126 triggerEvent->addFilter(edm::InputTag(filterTags_[i]), filterIds, filterKeys);
0127 }
0128
0129 iEvent.put(triggerEventPutToken_, std::move(triggerEvent));
0130 }
0131
0132 void TestWriteTriggerEvent::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0133 edm::ParameterSetDescription desc;
0134 desc.add<std::string>("usedProcessName");
0135 desc.add<std::vector<std::string>>("collectionTags");
0136 desc.add<std::vector<unsigned int>>("collectionKeys");
0137 desc.add<std::vector<int>>("ids");
0138 desc.add<std::vector<double>>("pts");
0139 desc.add<std::vector<double>>("etas");
0140 desc.add<std::vector<double>>("phis");
0141 desc.add<std::vector<double>>("masses");
0142 desc.add<std::vector<std::string>>("filterTags");
0143 desc.add<unsigned int>("elementsPerVector");
0144 desc.add<std::vector<int>>("filterIds");
0145 desc.add<std::vector<unsigned int>>("filterKeys");
0146 descriptions.addDefault(desc);
0147 }
0148 }
0149
0150 using edmtest::TestWriteTriggerEvent;
0151 DEFINE_FWK_MODULE(TestWriteTriggerEvent);