File indexing completed on 2024-04-06 12:12:50
0001 #include "FWCore/Framework/interface/Frameworkfwd.h"
0002 #include "FWCore/Framework/interface/InputSourceMacros.h"
0003 #include "FWCore/Framework/interface/EventPrincipal.h"
0004 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0006 #include "FWCore/Sources/interface/ProducerSourceBase.h"
0007
0008 #include <vector>
0009 #include <utility>
0010
0011 namespace edm {
0012 class TestSource : public InputSource {
0013 public:
0014 explicit TestSource(ParameterSet const&, InputSourceDescription const&);
0015 static void fillDescriptions(ConfigurationDescriptions& descriptions);
0016
0017 private:
0018 ItemTypeInfo getNextItemType() final;
0019 std::shared_ptr<RunAuxiliary> readRunAuxiliary_() final;
0020 std::shared_ptr<LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_() final;
0021 void readEvent_(EventPrincipal& eventPrincipal) final;
0022
0023 std::vector<std::pair<ItemType, EventID>> m_transitions;
0024 std::vector<std::pair<ItemType, EventID>>::const_iterator m_nextTransition;
0025
0026 static ItemType stringToType(const std::string&);
0027 };
0028
0029 TestSource::TestSource(ParameterSet const& pset, InputSourceDescription const& desc) : InputSource(pset, desc) {
0030 for (auto const& p : pset.getUntrackedParameter<std::vector<edm::ParameterSet>>("transitions")) {
0031 m_transitions.emplace_back(stringToType(p.getUntrackedParameter<std::string>("type")),
0032 p.getUntrackedParameter<EventID>("id"));
0033 }
0034 m_nextTransition = m_transitions.begin();
0035 }
0036
0037 TestSource::ItemType TestSource::stringToType(const std::string& iTrans) {
0038 if (iTrans == "IsStop") {
0039 return ItemType::IsStop;
0040 }
0041 if (iTrans == "IsFile") {
0042 return ItemType::IsFile;
0043 }
0044 if (iTrans == "IsRun") {
0045 return ItemType::IsRun;
0046 }
0047 if (iTrans == "IsLumi") {
0048 return ItemType::IsLumi;
0049 }
0050 if (iTrans == "IsEvent") {
0051 return ItemType::IsEvent;
0052 }
0053 if (iTrans == "IsSynchronize") {
0054 return ItemType::IsSynchronize;
0055 }
0056
0057 throw edm::Exception(errors::Configuration) << "Unknown transition type \'" << iTrans << "\'";
0058
0059 return ItemType::IsInvalid;
0060 }
0061
0062 TestSource::ItemTypeInfo TestSource::getNextItemType() {
0063 if (m_nextTransition == m_transitions.end()) {
0064 return ItemType::IsStop;
0065 }
0066 auto trans = m_nextTransition->first;
0067 ++m_nextTransition;
0068 return trans;
0069 }
0070
0071 std::shared_ptr<RunAuxiliary> TestSource::readRunAuxiliary_() {
0072 auto it = m_nextTransition;
0073 --it;
0074 return std::make_shared<RunAuxiliary>(it->second.run(), Timestamp(0), Timestamp(10));
0075 }
0076
0077 std::shared_ptr<LuminosityBlockAuxiliary> TestSource::readLuminosityBlockAuxiliary_() {
0078 auto it = m_nextTransition;
0079 --it;
0080 return std::make_shared<LuminosityBlockAuxiliary>(
0081 it->second.run(), it->second.luminosityBlock(), Timestamp(0), Timestamp(10));
0082 }
0083
0084 void TestSource::readEvent_(EventPrincipal& eventPrincipal) {
0085 auto it = m_nextTransition;
0086 --it;
0087 EventAuxiliary aux(it->second, processGUID(), Timestamp(0), false);
0088 auto history = processHistoryRegistry().getMapped(aux.processHistoryID());
0089
0090 eventPrincipal.fillEventPrincipal(aux, history);
0091 }
0092
0093 void TestSource::fillDescriptions(ConfigurationDescriptions& descriptions) {
0094 ParameterSetDescription desc;
0095 desc.setComment("Generates the specified sequence of transitions.");
0096 ProducerSourceBase::fillDescription(desc);
0097
0098 ParameterSetDescription trans;
0099 trans.addUntracked<std::string>("type");
0100 trans.addUntracked<edm::EventID>("id");
0101 desc.addVPSetUntracked("transitions", trans, {{}});
0102 descriptions.add("source", desc);
0103 }
0104 }
0105
0106 using edm::TestSource;
0107 DEFINE_FWK_INPUT_SOURCE(TestSource);