Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:    DataFormats/SiStripCluster
0004 // Class:      TestWriteSiStripApproximateClusterCollection
0005 //
0006 /**\class edmtest::TestWriteSiStripApproximateClusterCollection
0007   Description: Used as part of tests that ensure the SiStripApproximateClusterCollection
0008   data format 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 SiStripApproximateClusterCollection 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:  20 Sep 2023
0017 
0018 #include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h"
0019 #include "DataFormats/SiStripCluster/interface/SiStripApproximateClusterCollection.h"
0020 #include "FWCore/Framework/interface/Event.h"
0021 #include "FWCore/Framework/interface/Frameworkfwd.h"
0022 #include "FWCore/Framework/interface/global/EDProducer.h"
0023 #include "FWCore/Framework/interface/MakerMacros.h"
0024 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0027 #include "FWCore/Utilities/interface/EDPutToken.h"
0028 #include "FWCore/Utilities/interface/Exception.h"
0029 #include "FWCore/Utilities/interface/StreamID.h"
0030 
0031 #include <memory>
0032 #include <utility>
0033 #include <vector>
0034 
0035 namespace edmtest {
0036 
0037   class TestWriteSiStripApproximateClusterCollection : public edm::global::EDProducer<> {
0038   public:
0039     TestWriteSiStripApproximateClusterCollection(edm::ParameterSet const&);
0040     void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
0041     static void fillDescriptions(edm::ConfigurationDescriptions&);
0042 
0043   private:
0044     std::vector<unsigned int> integralValues_;
0045     edm::EDPutTokenT<SiStripApproximateClusterCollection> collectionPutToken_;
0046   };
0047 
0048   TestWriteSiStripApproximateClusterCollection::TestWriteSiStripApproximateClusterCollection(
0049       edm::ParameterSet const& iPSet)
0050       : integralValues_(iPSet.getParameter<std::vector<unsigned int>>("integralValues")),
0051         collectionPutToken_(produces()) {
0052     if (integralValues_.size() != 7) {
0053       throw cms::Exception("TestFailure") << "TestWriteSiStripApproximateClusterCollection, test configuration error: "
0054                                              "integralValues should have size 7 and it doesn't";
0055     }
0056   }
0057 
0058   void TestWriteSiStripApproximateClusterCollection::produce(edm::StreamID,
0059                                                              edm::Event& iEvent,
0060                                                              edm::EventSetup const&) const {
0061     // Fill a SiStripApproximateClusterCollection. Make sure all the containers inside
0062     // of it have something in them (not empty). There is a little complexity here
0063     // to vary the values written and the sizes of the containers, but the values and
0064     // sizes are meaningless other than we want test patterns that aren't all the same
0065     // value and same size for a better test.
0066     // We will later check that after writing this object to persistent storage
0067     // and then reading it in a later process we obtain matching values for
0068     // all this content. I imagine if you tried to run reconstruction on these
0069     // objects it would crash badly. Here, the only purpose is to test that ROOT
0070     // can read the bits properly (maybe years and many ROOT and CSSSW versions
0071     // after the files were written).
0072 
0073     auto siStripApproximateClusterCollection = std::make_unique<SiStripApproximateClusterCollection>();
0074 
0075     unsigned int numberDetIds = (iEvent.id().event() - 1) % 10;
0076     unsigned int detId = integralValues_[0] + iEvent.id().event();
0077     for (unsigned int i = 0; i < numberDetIds; ++i) {
0078       detId += iEvent.id().event();
0079       auto filler = siStripApproximateClusterCollection->beginDet(detId);
0080       unsigned int numberOfClustersPerDetId = (iEvent.id().event() - 1) % 10;
0081       for (unsigned int j = 0; j < numberOfClustersPerDetId; ++j) {
0082         unsigned int iOffset = j + iEvent.id().event();
0083         cms_uint16_t barycenter = integralValues_[1] + iOffset;
0084         cms_uint8_t width = integralValues_[2] + iOffset;
0085         cms_uint8_t avgCharge = integralValues_[3] + iOffset;
0086         bool filter = j < (integralValues_[4] + iEvent.id().event()) % 10;
0087         bool isSaturated = j < (integralValues_[5] + iEvent.id().event()) % 10;
0088         bool peakFilter = j < (integralValues_[6] + iEvent.id().event()) % 10;
0089         SiStripApproximateCluster cluster(barycenter, width, avgCharge, filter, isSaturated, peakFilter);
0090         filler.push_back(cluster);
0091       }
0092     }
0093     iEvent.put(collectionPutToken_, std::move(siStripApproximateClusterCollection));
0094   }
0095 
0096   void TestWriteSiStripApproximateClusterCollection::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0097     edm::ParameterSetDescription desc;
0098     desc.add<std::vector<unsigned int>>("integralValues");
0099     descriptions.addDefault(desc);
0100   }
0101 }  // namespace edmtest
0102 
0103 using edmtest::TestWriteSiStripApproximateClusterCollection;
0104 DEFINE_FWK_MODULE(TestWriteSiStripApproximateClusterCollection);