Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:02

0001 // -*- C++ -*-
0002 //
0003 // Package:    DataFormats/DetId
0004 // Class:      TestWriteVectorDetId
0005 //
0006 /**\class edmtest::TestWriteVectorDetId
0007   Description: Used as part of tests that ensure the std::vector<DetId> raw
0008   data format type can be persistently written and in a subsequent process
0009   read. First, this is done using the current release version for writing
0010   and reading. In addition, the output file of the write process should
0011   be saved permanently each time the std::vector<DetId> persistent data
0012   format changes. In unit tests, we read each of those saved files to verify
0013   that the current releases can read older versions of the data format.
0014 */
0015 // Original Author:  W. David Dagenhart
0016 //         Created:  25 Sep 2023
0017 
0018 #include "DataFormats/DetId/interface/DetId.h"
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/Frameworkfwd.h"
0021 #include "FWCore/Framework/interface/global/EDProducer.h"
0022 #include "FWCore/Framework/interface/MakerMacros.h"
0023 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0026 #include "FWCore/Utilities/interface/EDPutToken.h"
0027 #include "FWCore/Utilities/interface/StreamID.h"
0028 
0029 #include <memory>
0030 #include <utility>
0031 #include <vector>
0032 
0033 namespace edmtest {
0034 
0035   class TestWriteVectorDetId : public edm::global::EDProducer<> {
0036   public:
0037     TestWriteVectorDetId(edm::ParameterSet const&);
0038     void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
0039     static void fillDescriptions(edm::ConfigurationDescriptions&);
0040 
0041   private:
0042     unsigned int testValue_;
0043     edm::EDPutTokenT<std::vector<DetId>> putToken_;
0044   };
0045 
0046   TestWriteVectorDetId::TestWriteVectorDetId(edm::ParameterSet const& iPSet)
0047       : testValue_(iPSet.getParameter<unsigned int>("testValue")), putToken_(produces()) {}
0048 
0049   void TestWriteVectorDetId::produce(edm::StreamID, edm::Event& iEvent, edm::EventSetup const&) const {
0050     // Fill a std::vector<DetId>. Make sure it is not empty.
0051     // We will test in a later process that we read the same
0052     // value we wrote, but the value is otherwise meaningless.
0053     // The only purpose is to test that ROOT can read the bits
0054     // properly (maybe years and many ROOT and CSSSW versions
0055     // after the files were written).
0056 
0057     auto vectorDetIds = std::make_unique<std::vector<DetId>>();
0058 
0059     unsigned int numberDetIds = (iEvent.id().event() - 1) % 10;
0060     unsigned int detId = testValue_ + iEvent.id().event();
0061     for (unsigned int i = 0; i < numberDetIds; ++i) {
0062       detId += iEvent.id().event();
0063       vectorDetIds->emplace_back(detId);
0064     }
0065     iEvent.put(putToken_, std::move(vectorDetIds));
0066   }
0067 
0068   void TestWriteVectorDetId::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0069     edm::ParameterSetDescription desc;
0070     desc.add<unsigned int>("testValue");
0071     descriptions.addDefault(desc);
0072   }
0073 }  // namespace edmtest
0074 
0075 using edmtest::TestWriteVectorDetId;
0076 DEFINE_FWK_MODULE(TestWriteVectorDetId);