CMS 3D CMS Logo

CTPPSPixelDigiToRaw.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CTPPSPixelDigiToRaw
4 // Class: CTPPSPixelDigiToRaw
5 //
13 //
14 // Original Author: Dilson De Jesus Damiao
15 // Maria Elena Pol
16 // Created: Wed, 12 Sep 2018 12:59:49 GMT
17 //
18 //
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
32 
39 
41 
43 
48 
50 
54 
57 
58 //
59 // class declaration
60 //
61 
63 public:
64  explicit CTPPSPixelDigiToRaw(const edm::ParameterSet&);
65  ~CTPPSPixelDigiToRaw() override;
66 
67  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
68 
69 private:
70  void produce(edm::Event&, const edm::EventSetup&) override;
71 
72  // ----------member data ---------------------------
73  unsigned long eventCounter_;
76  bool debug_;
77  std::set<unsigned int> fedIds_;
81  std::vector<CTPPSPixelDataFormatter::PPSPixelIndex> v_iDdet2fed_;
83 };
84 
85 //
86 // constants, enums and typedefs
87 //
88 
89 //
90 // static data member definitions
91 //
92 
93 //
94 // constructors and destructor
95 //
97  : eventCounter_(0),
98  allDigiCounter_(0),
99  allWordCounter_(0),
100  mappingLabel_(iConfig.getParameter<std::string>("mappingLabel")) {
101  //register your products
102  tCTPPSPixelDigi_ = consumes<edm::DetSetVector<CTPPSPixelDigi>>(iConfig.getParameter<edm::InputTag>("InputLabel"));
103 
104  // Define EDProduct type
105  produces<FEDRawDataCollection>();
106 }
107 
109 
110 //
111 // member functions
112 //
113 
114 // ------------ method called to produce the data ------------
116  using namespace edm;
117  using namespace std;
118 
119  eventCounter_++;
120 
122  iEvent.getByToken(tCTPPSPixelDigi_, digiCollection);
123 
126 
127  int digiCounter = 0;
128  for (auto const& di : *digiCollection) {
129  digiCounter += (di.data).size();
130  digis[di.id] = di.data;
131  }
132  allDigiCounter_ += digiCounter;
134  if (recordWatcher_.check(iSetup)) {
135  iSetup.get<CTPPSPixelDAQMappingRcd>().get(mapping);
136  for (const auto& p : mapping->ROCMapping)
138  p.second.iD, p.second.roc, p.first.getROC(), p.first.getFEDId(), p.first.getChannelIdx()});
139  fedIds_ = mapping->fedIds();
140  }
141  CTPPSPixelDataFormatter formatter(mapping->ROCMapping);
142 
143  // create product (raw data)
144  auto buffers = std::make_unique<FEDRawDataCollection>();
145 
147 
148  // convert data to raw
149  formatter.formatRawData(iEvent.id().event(), rawdata, digis, v_iDdet2fed_);
150 
151  // pack raw data into collection
152  for (auto it = fedIds_.begin(); it != fedIds_.end(); it++) {
153  FEDRawData& fedRawData = buffers->FEDData(*it);
154  CTPPSPixelDataFormatter::RawData::iterator fedbuffer = rawdata.find(*it);
155  if (fedbuffer != rawdata.end())
156  fedRawData = fedbuffer->second;
157  }
158  allWordCounter_ += formatter.nWords();
159 
160  if (debug_)
161  LogDebug("CTPPSPixelDigiToRaw") << "Words/Digis this iEvent: " << digiCounter << "(fm:" << formatter.nDigis()
162  << ")/" << formatter.nWords() << " all: " << allDigiCounter_ << "/"
163  << allWordCounter_;
164 
165  iEvent.put(std::move(buffers));
166 }
167 
168 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
171  desc.add<edm::InputTag>("InputLabel", edm::InputTag("RPixDetDigitizer"));
172  desc.add<std::string>("mappingLabel", "RPix");
173  descriptions.add("ctppsPixelRawData", desc);
174 }
175 
176 //define this as a plug-in
#define LogDebug(id)
size
Write out results.
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:40
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
std::set< unsigned int > fedIds() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
std::unordered_map< int, FEDRawData > RawData
edm::ESWatcher< CTPPSPixelDAQMappingRcd > recordWatcher_
static bool compare(const PPSPixelIndex &a, const PPSPixelIndex &b)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::unordered_map< cms_uint32_t, DetDigis > Digis
std::vector< CTPPSPixelDataFormatter::PPSPixelIndex > v_iDdet2fed_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::EDGetTokenT< edm::DetSetVector< CTPPSPixelDigi > > tCTPPSPixelDigi_
void produce(edm::Event &, const edm::EventSetup &) override
std::map< CTPPSPixelFramePosition, CTPPSPixelROCInfo > ROCMapping
void formatRawData(unsigned int lvl1_ID, RawData &fedRawData, const Digis &digis, std::vector< PPSPixelIndex > v_iDdet2fed)
CTPPSPixelFramePosition fPos_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
CTPPSPixelDigiToRaw(const edm::ParameterSet &)
std::set< unsigned int > fedIds_
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
T get() const
Definition: EventSetup.h:73
def move(src, dest)
Definition: eostools.py:511