Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-01 23:54:03

0001 // -*- C++ -*-
0002 //
0003 // Package:    L1Trigger/DemonstratorTools
0004 // Class:      GTTFileReader
0005 //
0006 /**\class GTTFileReader GTTFileReader.cc L1Trigger/DemonstratorTools/plugins/GTTFileReader.cc
0007 
0008  Description: Example EDProducer class, illustrating how BoardDataReader can be used to
0009    read I/O buffer files (that have been created in hardware/firmware tests), decode
0010    the contained data, and store this in EDM collections.
0011 
0012  Implementation:
0013      [Notes on implementation]
0014 */
0015 //
0016 // Original Author:  Thomas Williams <thomas.williams@stfc.ac.uk>
0017 //         Created:  Fri, 19 Feb 2021 01:10:55 GMT
0018 //
0019 //
0020 
0021 // system include files
0022 #include <memory>
0023 
0024 // user include files
0025 #include "FWCore/Framework/interface/Frameworkfwd.h"
0026 #include "FWCore/Framework/interface/stream/EDProducer.h"
0027 
0028 #include "FWCore/Framework/interface/Event.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0032 #include "FWCore/Utilities/interface/StreamID.h"
0033 
0034 #include "DataFormats/L1Trigger/interface/Vertex.h"
0035 #include "L1Trigger/DemonstratorTools/interface/BoardDataReader.h"
0036 #include "L1Trigger/DemonstratorTools/interface/codecs/vertices.h"
0037 #include "L1Trigger/DemonstratorTools/interface/utilities.h"
0038 
0039 //
0040 // class declaration
0041 //
0042 
0043 class GTTFileReader : public edm::stream::EDProducer<> {
0044 public:
0045   explicit GTTFileReader(const edm::ParameterSet&);
0046 
0047   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0048 
0049 private:
0050   // ----------constants, enums and typedefs ---------
0051   // NOTE: At least some of the info from these constants will eventually come from config files
0052   static constexpr size_t kFramesPerTMUXPeriod = 9;
0053   static constexpr size_t kGapLength = 44;
0054   static constexpr size_t kVertexTMUX = 6;
0055   static constexpr size_t kVertexChanIndex = 0;
0056   static constexpr size_t kEmptyFrames = 10;
0057 
0058   const l1t::demo::BoardDataReader::ChannelMap_t kChannelSpecs = {
0059       /* logical channel within time slice -> {{link TMUX, inter-packet gap}, vector of channel indices} */
0060       {{"vertices", 0}, {{kVertexTMUX, kGapLength}, {kVertexChanIndex}}}};
0061 
0062   // ----------member functions ----------------------
0063   void produce(edm::Event&, const edm::EventSetup&) override;
0064 
0065   // ----------member data ---------------------------
0066   l1t::demo::BoardDataReader fileReader_;
0067 };
0068 
0069 //
0070 // class implementation
0071 //
0072 
0073 GTTFileReader::GTTFileReader(const edm::ParameterSet& iConfig)
0074     : fileReader_(l1t::demo::parseFileFormat(iConfig.getUntrackedParameter<std::string>("format")),
0075                   iConfig.getParameter<std::vector<std::string>>("files"),
0076                   kFramesPerTMUXPeriod,
0077                   kVertexTMUX,
0078                   kEmptyFrames,
0079                   kChannelSpecs) {
0080   produces<l1t::VertexWordCollection>();
0081 }
0082 
0083 // ------------ method called to produce the data  ------------
0084 void GTTFileReader::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0085   using namespace edm;
0086   using namespace l1t::demo::codecs;
0087 
0088   l1t::demo::EventData eventData(fileReader_.getNextEvent());
0089 
0090   l1t::VertexWordCollection vertices(decodeVertices(eventData.at({"vertices", 0})));
0091 
0092   edm::LogInfo("GTTFileReader") << vertices.size() << " vertices found";
0093 
0094   iEvent.put(std::make_unique<l1t::VertexWordCollection>(vertices));
0095 }
0096 
0097 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0098 void GTTFileReader::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0099   // GTTFileReader
0100   edm::ParameterSetDescription desc;
0101   desc.add<std::vector<std::string>>("files",
0102                                      {
0103                                          "gttOutput_0.txt",
0104                                      });
0105   desc.addUntracked<std::string>("format", "APx");
0106   descriptions.add("GTTFileReader", desc);
0107 }
0108 
0109 //define this as a plug-in
0110 DEFINE_FWK_MODULE(GTTFileReader);