File indexing completed on 2024-04-06 12:19:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include "DataFormats/TestObjects/interface/VectorVectorTop.h"
0015 #include "FWCore/Framework/interface/Event.h"
0016 #include "FWCore/Framework/interface/Frameworkfwd.h"
0017 #include "FWCore/Framework/interface/global/EDProducer.h"
0018 #include "FWCore/Framework/interface/MakerMacros.h"
0019 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0021 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0022 #include "FWCore/Utilities/interface/EDPutToken.h"
0023 #include "FWCore/Utilities/interface/Exception.h"
0024 #include "FWCore/Utilities/interface/StreamID.h"
0025
0026 #include <memory>
0027 #include <utility>
0028 #include <vector>
0029
0030 namespace edmtest {
0031
0032 class SchemaEvolutionTestWrite : public edm::global::EDProducer<> {
0033 public:
0034 SchemaEvolutionTestWrite(edm::ParameterSet const&);
0035 void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
0036 static void fillDescriptions(edm::ConfigurationDescriptions&);
0037
0038 private:
0039 void produceVectorVector(edm::Event&) const;
0040 void produceVectorVectorNonSplit(edm::Event&) const;
0041
0042 void throwWithMessage(const char*) const;
0043
0044 const std::vector<int> testIntegralValues_;
0045 const edm::EDPutTokenT<VectorVectorTop> vectorVectorPutToken_;
0046 const edm::EDPutTokenT<VectorVectorTopNonSplit> vectorVectorNonSplitPutToken_;
0047 };
0048
0049 SchemaEvolutionTestWrite::SchemaEvolutionTestWrite(edm::ParameterSet const& iPSet)
0050 : testIntegralValues_(iPSet.getParameter<std::vector<int>>("testIntegralValues")),
0051 vectorVectorPutToken_(produces()),
0052 vectorVectorNonSplitPutToken_(produces()) {
0053 if (testIntegralValues_.size() != 15) {
0054 throwWithMessage("testIntegralValues must have 15 elements and it does not");
0055 }
0056 }
0057
0058 void SchemaEvolutionTestWrite::produce(edm::StreamID, edm::Event& iEvent, edm::EventSetup const&) const {
0059
0060
0061
0062
0063
0064
0065 produceVectorVector(iEvent);
0066 produceVectorVectorNonSplit(iEvent);
0067 }
0068
0069 void SchemaEvolutionTestWrite::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0070 edm::ParameterSetDescription desc;
0071 desc.add<std::vector<int>>("testIntegralValues");
0072 descriptions.addDefault(desc);
0073 }
0074
0075 void SchemaEvolutionTestWrite::produceVectorVector(edm::Event& iEvent) const {
0076 auto vectorVector = std::make_unique<VectorVectorTop>();
0077 unsigned int vectorSize = 2 + iEvent.id().event() % 4;
0078 vectorVector->outerVector_.reserve(vectorSize);
0079 for (unsigned int i = 0; i < vectorSize; ++i) {
0080 int iOffset = static_cast<int>(iEvent.id().event() + i);
0081 VectorVectorMiddle middleVector;
0082 middleVector.middleVector_.reserve(vectorSize);
0083 for (int j = 0; j < static_cast<int>(vectorSize); ++j) {
0084 SchemaEvolutionChangeOrder changeOrder(testIntegralValues_[1] + iOffset + j * 11,
0085 testIntegralValues_[1] + iOffset + j * 101);
0086 SchemaEvolutionAddMember addMember(testIntegralValues_[2] + iOffset + j * 12,
0087 testIntegralValues_[2] + iOffset + j * 102,
0088 testIntegralValues_[2] + iOffset + j * 1002);
0089 SchemaEvolutionRemoveMember removeMember(testIntegralValues_[3] + iOffset + j * 13,
0090 testIntegralValues_[3] + iOffset + j * 103);
0091 SchemaEvolutionMoveToBase moveToBase(testIntegralValues_[4] + iOffset + j * 14,
0092 testIntegralValues_[4] + iOffset + j * 104,
0093 testIntegralValues_[4] + iOffset + j * 1004,
0094 testIntegralValues_[4] + iOffset + j * 10004);
0095 SchemaEvolutionChangeType changeType(testIntegralValues_[5] + iOffset + j * 15,
0096 testIntegralValues_[5] + iOffset + j * 105);
0097 SchemaEvolutionAddBase addBase(testIntegralValues_[6] + iOffset + j * 16,
0098 testIntegralValues_[6] + iOffset + j * 106,
0099 testIntegralValues_[6] + iOffset + j * 1006);
0100 SchemaEvolutionPointerToMember pointerToMember(testIntegralValues_[7] + iOffset + j * 17,
0101 testIntegralValues_[7] + iOffset + j * 107,
0102 testIntegralValues_[7] + iOffset + j * 1007);
0103 SchemaEvolutionPointerToUniquePtr pointerToUniquePtr(testIntegralValues_[8] + iOffset + j * 18,
0104 testIntegralValues_[8] + iOffset + j * 108,
0105 testIntegralValues_[8] + iOffset + j * 1008);
0106 SchemaEvolutionCArrayToStdArray cArrayToStdArray(testIntegralValues_[9] + iOffset + j * 19,
0107 testIntegralValues_[9] + iOffset + j * 109,
0108 testIntegralValues_[9] + iOffset + j * 1009);
0109
0110
0111 SchemaEvolutionVectorToList vectorToList(testIntegralValues_[11] + iOffset + j * 21,
0112 testIntegralValues_[11] + iOffset + j * 111,
0113 testIntegralValues_[11] + iOffset + j * 1011);
0114 SchemaEvolutionMapToUnorderedMap mapToUnorderedMap(testIntegralValues_[12] + iOffset + j * 22,
0115 testIntegralValues_[12] + iOffset + j * 112,
0116 testIntegralValues_[12] + iOffset + j * 1012 + 1012,
0117 testIntegralValues_[12] + iOffset + j * 10012,
0118 testIntegralValues_[12] + iOffset + j * 100012 + 100012,
0119 testIntegralValues_[12] + iOffset + j * 1000012);
0120
0121 middleVector.middleVector_.emplace_back(testIntegralValues_[0] + iOffset + j * 10,
0122 testIntegralValues_[0] + iOffset + j * 100,
0123 changeOrder,
0124 addMember,
0125 removeMember,
0126 moveToBase,
0127 changeType,
0128 addBase,
0129 pointerToMember,
0130 pointerToUniquePtr,
0131 cArrayToStdArray,
0132
0133 vectorToList,
0134 mapToUnorderedMap);
0135 }
0136 vectorVector->outerVector_.push_back(std::move(middleVector));
0137 }
0138 iEvent.put(vectorVectorPutToken_, std::move(vectorVector));
0139 }
0140
0141 void SchemaEvolutionTestWrite::produceVectorVectorNonSplit(edm::Event& iEvent) const {
0142 auto vectorVector = std::make_unique<VectorVectorTopNonSplit>();
0143 VectorVectorMiddleNonSplit middleVector;
0144 middleVector.middleVector_.emplace_back(testIntegralValues_[13], testIntegralValues_[14]);
0145 vectorVector->outerVector_.push_back(middleVector);
0146 iEvent.put(vectorVectorNonSplitPutToken_, std::move(vectorVector));
0147 }
0148
0149 void SchemaEvolutionTestWrite::throwWithMessage(const char* msg) const {
0150 throw cms::Exception("TestFailure") << "SchemaEvolutionTestWrite constructor, test configuration error, " << msg;
0151 }
0152
0153 }
0154
0155 using edmtest::SchemaEvolutionTestWrite;
0156 DEFINE_FWK_MODULE(SchemaEvolutionTestWrite);