CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
40 
42 
44 
49 
51 
55 
58 
59 //
60 // class declaration
61 //
62 
64 public:
65  explicit CTPPSPixelDigiToRaw(const edm::ParameterSet&);
66  ~CTPPSPixelDigiToRaw() override;
67 
68  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
69 
70 private:
71  void produce(edm::Event&, const edm::EventSetup&) override;
72 
73  // ----------member data ---------------------------
74  unsigned long eventCounter_;
77  bool debug_;
78  std::set<unsigned int> fedIds_;
83  std::vector<CTPPSPixelDataFormatter::PPSPixelIndex> v_iDdet2fed_;
85  bool isRun3_;
86 };
87 
88 //
89 // constants, enums and typedefs
90 //
91 
92 //
93 // static data member definitions
94 //
95 
96 //
97 // constructors and destructor
98 //
100  : eventCounter_(0),
101  allDigiCounter_(0),
102  allWordCounter_(0),
103  debug_(false),
104  mappingLabel_(iConfig.getParameter<std::string>("mappingLabel")) {
105  //register your products
106  tCTPPSPixelDigi_ = consumes<edm::DetSetVector<CTPPSPixelDigi>>(iConfig.getParameter<edm::InputTag>("InputLabel"));
107  tCTPPSPixelDAQMapping_ = esConsumes<CTPPSPixelDAQMapping, CTPPSPixelDAQMappingRcd>();
108 
109  // Define EDProduct type
110  produces<FEDRawDataCollection>();
111 
112  isRun3_ = iConfig.getParameter<bool>("isRun3");
113 }
114 
116 
117 //
118 // member functions
119 //
120 
121 // ------------ method called to produce the data ------------
123  using namespace edm;
124  using namespace std;
125 
126  eventCounter_++;
127 
130 
133 
134  int digiCounter = 0;
135  for (auto const& di : *digiCollection) {
136  digiCounter += (di.data).size();
137  digis[di.id] = di.data;
138  }
139  allDigiCounter_ += digiCounter;
141 
142  mapping = iSetup.getHandle(tCTPPSPixelDAQMapping_);
143  for (const auto& p : mapping->ROCMapping)
145  p.second.iD, p.second.roc, p.first.getROC(), p.first.getFEDId(), p.first.getChannelIdx()});
146  fedIds_ = mapping->fedIds();
147 
148  CTPPSPixelDataFormatter formatter(mapping->ROCMapping);
149 
150  // create product (raw data)
151  auto buffers = std::make_unique<FEDRawDataCollection>();
152 
154 
155  // convert data to raw
156  formatter.formatRawData(isRun3_, iEvent.id().event(), rawdata, digis, v_iDdet2fed_);
157 
158  // pack raw data into collection
159  for (auto it = fedIds_.begin(); it != fedIds_.end(); it++) {
160  FEDRawData& fedRawData = buffers->FEDData(*it);
161  CTPPSPixelDataFormatter::RawData::iterator fedbuffer = rawdata.find(*it);
162  if (fedbuffer != rawdata.end())
163  fedRawData = fedbuffer->second;
164  }
165  allWordCounter_ += formatter.nWords();
166 
167  if (debug_)
168  LogDebug("CTPPSPixelDigiToRaw") << "Words/Digis this iEvent: " << digiCounter << "(fm:" << formatter.nDigis()
169  << ")/" << formatter.nWords() << " all: " << allDigiCounter_ << "/"
170  << allWordCounter_;
171 
172  iEvent.put(std::move(buffers));
173 }
174 
175 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
178  desc.add<bool>("isRun3", true);
179  desc.add<edm::InputTag>("InputLabel", edm::InputTag("RPixDetDigitizer"));
180  desc.add<std::string>("mappingLabel", "RPix");
181  descriptions.add("ctppsPixelRawData", desc);
182 }
183 
184 //define this as a plug-in
EventNumber_t event() const
Definition: EventID.h:40
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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
std::unordered_map< cms_uint32_t, DetDigis > Digis
std::vector< CTPPSPixelDataFormatter::PPSPixelIndex > v_iDdet2fed_
def move
Definition: eostools.py:511
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::EDGetTokenT< edm::DetSetVector< CTPPSPixelDigi > > tCTPPSPixelDigi_
void formatRawData(const bool &isRun3, unsigned int lvl1_ID, RawData &fedRawData, const Digis &digis, std::vector< PPSPixelIndex > v_iDdet2fed)
void produce(edm::Event &, const edm::EventSetup &) override
edm::ESGetToken< CTPPSPixelDAQMapping, CTPPSPixelDAQMappingRcd > tCTPPSPixelDAQMapping_
CTPPSPixelFramePosition fPos_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void add(std::string const &label, ParameterSetDescription const &psetDescription)
CTPPSPixelDigiToRaw(const edm::ParameterSet &)
std::set< unsigned int > fedIds_
edm::EventID id() const
Definition: EventBase.h:59
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
tuple size
Write out results.
#define LogDebug(id)