CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SiStripDigiToRawModule.cc
Go to the documentation of this file.
2 #include "SiStripDigiToRaw.h"
3 
15 #include <cstdlib>
16 
17 namespace sistrip {
18 
19  //fill Descriptions needed to define default parameters
22  desc.add<std::string>("FedReadoutMode", "ZERO_SUPPRESSED");
23  desc.add<std::string>("PacketCode", "ZERO_SUPPRESSED");
24  desc.add<bool>("UseFedKey", false);
25  desc.add<bool>("UseWrongDigiType", false);
26  desc.add<bool>("CopyBufferHeader", false);
27  desc.add<edm::InputTag>("InputDigis", edm::InputTag("simSiStripDigis", "ZeroSuppressed"));
28  desc.add<edm::InputTag>("RawDataTag", edm::InputTag("rawDataCollector"));
29  descriptions.add("SiStripDigiToRawModule", desc);
30  }
31 
32  // -----------------------------------------------------------------------------
37  : copyBufferHeader_(pset.getParameter<bool>("CopyBufferHeader")),
38  mode_(fedReadoutModeFromString(pset.getParameter<std::string>("FedReadoutMode"))),
39  packetCode_(packetCodeFromString(pset.getParameter<std::string>("PacketCode"), mode_)),
40  rawdigi_(false),
41  digiToRaw_(nullptr),
42  eventCounter_(0),
43  inputDigiTag_(pset.getParameter<edm::InputTag>("InputDigis")),
44  rawDataTag_(pset.getParameter<edm::InputTag>("RawDataTag")),
46  if (edm::isDebugEnabled()) {
47  LogDebug("DigiToRawModule") << "[sistrip::DigiToRawModule::DigiToRawModule]"
48  << " Constructing object...";
49  }
50 
51  switch (mode_) {
53  rawdigi_ = false;
54  break;
56  rawdigi_ = false;
57  break;
59  rawdigi_ = false;
60  break;
62  rawdigi_ = false;
63  break;
65  rawdigi_ = false;
66  break;
68  rawdigi_ = false;
69  break;
71  rawdigi_ = false;
72  break;
74  rawdigi_ = false;
75  break;
77  rawdigi_ = false;
78  break;
80  rawdigi_ = false;
81  break;
83  rawdigi_ = false;
84  break;
86  rawdigi_ = true;
87  break;
89  rawdigi_ = true;
90  break;
91  case READOUT_MODE_SCOPE:
92  rawdigi_ = true;
93  break;
94  case READOUT_MODE_INVALID: {
95  if (edm::isDebugEnabled()) {
96  edm::LogWarning("DigiToRawModule")
97  << "[sistrip::DigiToRawModule::DigiToRawModule]"
98  << " UNKNOWN readout mode: " << pset.getParameter<std::string>("FedReadoutMode");
99  }
100  } break;
101  case READOUT_MODE_SPY: {
102  if (edm::isDebugEnabled()) {
103  edm::LogWarning("DigiToRawModule") << "[sistrip::DigiToRawModule::DigiToRawModule]"
104  << " Digi to raw is not supported for spy channel data";
105  }
106  } break;
107  }
108  if (pset.getParameter<bool>("UseWrongDigiType")) {
109  rawdigi_ = !rawdigi_;
110  if (edm::isDebugEnabled()) {
111  edm::LogWarning("DigiToRawModule") << "[sistrip::DigiToRawModule::DigiToRawModule]"
112  << " You are using the wrong type of digis!";
113  }
114  }
115 
116  // Create instance of DigiToRaw formatter
117  digiToRaw_ = new DigiToRaw(mode_, packetCode_, pset.getParameter<bool>("UseFedKey"));
118 
119  if (rawdigi_) {
120  tokenRawDigi = consumes<edm::DetSetVector<SiStripRawDigi> >(inputDigiTag_);
121  } else {
122  tokenDigi = consumes<edm::DetSetVector<SiStripDigi> >(inputDigiTag_);
123  }
124  if (copyBufferHeader_) {
125  //CAMM input raw module label or same as digi ????
126  if (edm::isDebugEnabled()) {
127  edm::LogWarning("DigiToRawModule") << "[sistrip::DigiToRawModule::DigiToRawModule]"
128  << "Copying buffer header from collection " << rawDataTag_;
129  }
130  tokenRawBuffer = consumes<FEDRawDataCollection>(rawDataTag_);
131  }
132 
133  produces<FEDRawDataCollection>();
134  }
135 
136  // -----------------------------------------------------------------------------
139  if (edm::isDebugEnabled()) {
140  LogDebug("DigiToRaw") << "[sistrip::DigiToRawModule::~DigiToRawModule]"
141  << " Destructing object...";
142  }
143  if (digiToRaw_)
144  delete digiToRaw_;
145  }
146 
147  // -----------------------------------------------------------------------------
155  eventCounter_++;
156 
157  auto buffers = std::make_unique<FEDRawDataCollection>();
158 
160 
161  //get buffer header from original rawdata
163  if (copyBufferHeader_) {
164  if (edm::isDebugEnabled()) {
165  edm::LogWarning("DigiToRawModule") << "[sistrip::DigiToRawModule::DigiToRawModule]"
166  << "Getting raw buffer: ";
167  }
168  try {
169  iEvent.getByToken(tokenRawBuffer, rawbuffers);
170  } catch (const cms::Exception& e) {
171  if (edm::isDebugEnabled()) {
172  edm::LogWarning("DigiToRawModule") << "[sistrip::DigiToRawModule::DigiToRawModule]"
173  << " Failed to get collection " << rawDataTag_;
174  }
175  }
176  }
177 
178  if (rawdigi_) {
180  iEvent.getByToken(tokenRawDigi, rawdigis);
181  if (copyBufferHeader_)
182  digiToRaw_->createFedBuffers(iEvent, cabling, rawbuffers, rawdigis, buffers);
183  else
184  digiToRaw_->createFedBuffers(iEvent, cabling, rawdigis, buffers);
185  } else {
187  iEvent.getByToken(tokenDigi, digis);
188  if (copyBufferHeader_)
189  digiToRaw_->createFedBuffers(iEvent, cabling, rawbuffers, digis, buffers);
190  else
191  digiToRaw_->createFedBuffers(iEvent, cabling, digis, buffers);
192  }
193 
194  iEvent.put(std::move(buffers));
195  }
196 
198 } // namespace sistrip
bool isDebugEnabled()
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::EDGetTokenT< FEDRawDataCollection > tokenRawBuffer
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
uint8_t packetCodeFromString(const std::string &packetCodeString, FEDReadoutMode mode)
void printWarningSummary() const
edm::ESGetToken< SiStripFedCabling, SiStripFedCablingRcd > tokenCabling
FEDReadoutMode fedReadoutModeFromString(const std::string &readoutModeString)
DigiToRawModule(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
def move
Definition: eostools.py:511
edm::EDGetTokenT< edm::DetSetVector< SiStripRawDigi > > tokenRawDigi
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void createFedBuffers(edm::Event &, edm::ESHandle< SiStripFedCabling > &cabling, edm::Handle< edm::DetSetVector< SiStripDigi > > &digis, std::unique_ptr< FEDRawDataCollection > &buffers)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
edm::EDGetTokenT< edm::DetSetVector< SiStripDigi > > tokenDigi
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
Log< level::Warning, false > LogWarning
void produce(edm::Event &, const edm::EventSetup &) override
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
#define LogDebug(id)