File indexing completed on 2024-04-06 12:10:56
0001
0002
0003
0004
0005
0006 #include "DataFormats/Provenance/interface/ProcessHistory.h"
0007 #include "DataFormats/Common/interface/Handle.h"
0008 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0009 #include "DataFormats/Common/interface/Handle.h"
0010
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/Framework/interface/ESHandle.h"
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0015 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0017 #include "FWCore/Framework/interface/MakerMacros.h"
0018 #include "FWCore/Framework/interface/stream/EDProducer.h"
0019 #include "FWCore/Utilities/interface/InputTag.h"
0020
0021 #include <iostream>
0022
0023 using namespace edm;
0024
0025 class RawDataMapperByLabel : public edm::stream::EDProducer<> {
0026 public:
0027
0028 RawDataMapperByLabel(const edm::ParameterSet& pset);
0029
0030
0031 ~RawDataMapperByLabel() override;
0032
0033 void produce(edm::Event& e, const edm::EventSetup& c) override;
0034
0035 static void fillDescriptions(edm::ConfigurationDescriptions&);
0036
0037 private:
0038 typedef std::vector<edm::InputTag>::const_iterator tag_iterator_t;
0039 typedef std::vector<edm::EDGetTokenT<FEDRawDataCollection>>::const_iterator tok_iterator_t;
0040
0041 std::vector<edm::InputTag> inputTags_;
0042 std::vector<edm::EDGetTokenT<FEDRawDataCollection>> inputTokens_;
0043
0044 edm::InputTag mainCollectionTag_;
0045 edm::InputTag filledCollectionName_;
0046 bool firstEvent_;
0047 };
0048
0049 RawDataMapperByLabel::RawDataMapperByLabel(const edm::ParameterSet& pset)
0050 : inputTags_(pset.getParameter<std::vector<edm::InputTag>>("rawCollectionList")),
0051 mainCollectionTag_(pset.getParameter<edm::InputTag>("mainCollection")),
0052 filledCollectionName_(edm::InputTag("")),
0053 firstEvent_(true) {
0054 inputTokens_.reserve(inputTags_.size());
0055 for (auto const& inputTag : inputTags_) {
0056 inputTokens_.push_back(consumes<FEDRawDataCollection>(inputTag));
0057 }
0058
0059 produces<FEDRawDataCollection>();
0060 }
0061
0062 RawDataMapperByLabel::~RawDataMapperByLabel() {}
0063
0064 void RawDataMapperByLabel::produce(Event& e, const EventSetup& c) {
0065 bool alreadyACollectionFilled = false;
0066 tag_iterator_t inputTag = inputTags_.begin();
0067 for (tok_iterator_t inputTok = inputTokens_.begin(); inputTok != inputTokens_.end(); ++inputTok, ++inputTag) {
0068 Handle<FEDRawDataCollection> input;
0069 if (e.getByToken(*inputTok, input)) {
0070 if (input.isValid()) {
0071 if (alreadyACollectionFilled)
0072 throw cms::Exception("BadInput")
0073 << "Two input collections are present." << std::endl
0074 << "Please make sure that the input dataset has only one FEDRawDataCollector collection filled";
0075
0076 if (firstEvent_) {
0077 filledCollectionName_ = *inputTag;
0078 alreadyACollectionFilled = true;
0079 firstEvent_ = false;
0080 }
0081
0082 if (!(filledCollectionName_ == *inputTag))
0083 throw cms::Exception("BadInput") << "The filled collection has changed!";
0084
0085 if (!(mainCollectionTag_ == filledCollectionName_))
0086 e.put(std::make_unique<FEDRawDataCollection>(*input.product()));
0087 }
0088 }
0089 }
0090 }
0091
0092 void RawDataMapperByLabel::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0093 edm::ParameterSetDescription desc;
0094
0095 desc.add<std::vector<edm::InputTag>>("rawCollectionList",
0096 {{"rawDataCollector", "", "@skipCurrentProcess"},
0097 {"rawDataRepacker"},
0098 {"rawPrimeDataRepacker"},
0099 {"rawDataReducedFormat"}});
0100 desc.add<edm::InputTag>("mainCollection", edm::InputTag("rawDataCollector"));
0101
0102 descriptions.add("rawDataMapperByLabel", desc);
0103 }
0104
0105 DEFINE_FWK_MODULE(RawDataMapperByLabel);