CMS 3D CMS Logo

SiPixelRawToDigi.cc
Go to the documentation of this file.
1 // Skip FED40 pilot-blade
2 // Include parameter driven interface to SiPixelQuality for study purposes
3 // exclude ROC(raw) based on bad ROC list in SiPixelQuality
4 // enabled by: process.siPixelDigis.useQualityInfo = True (BY DEFAULT NOT USED)
5 // 20-10-2010 Andrew York (Tennessee)
6 // Jan 2016 Tamas Almos Vami (Tav) (Wigner RCP) -- Cabling Map label option
7 // Jul 2017 Viktor Veszpremi -- added PixelFEDChannel
8 
9 #include <memory>
10 
24 
30 
40 
43 
44 using namespace sipixelconstants;
45 
52 public:
54  explicit SiPixelRawToDigi(const edm::ParameterSet&);
55 
57  ~SiPixelRawToDigi() override;
58 
59  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
60 
62  void produce(edm::Event&, const edm::EventSetup&) override;
63 
64 private:
66  std::unique_ptr<SiPixelFedCablingTree> cabling_;
69  const std::vector<int> tkerrorlist_;
70  const std::vector<int> usererrorlist_;
71  std::vector<unsigned int> fedIds_;
74  // always consumed
77  // consume only if pixel quality is used -> useQuality_
79  // always produced
81  // produce only if error collections are included -> includeErrors_
86  const bool includeErrors_;
87  const bool useQuality_;
88  const bool usePilotBlade_;
89  const bool usePhase1_;
90 };
91 
92 // -----------------------------------------------------------------------------
94  : config_(conf),
95  badPixelInfo_(nullptr),
96  regions_(nullptr),
97  tkerrorlist_(config_.getParameter<std::vector<int>>("ErrorList")),
98  usererrorlist_(config_.getParameter<std::vector<int>>("UserErrorList")),
99  fedRawDataCollectionToken_{consumes<FEDRawDataCollection>(config_.getParameter<edm::InputTag>("InputLabel"))},
100  cablingMapToken_{esConsumes<SiPixelFedCablingMap, SiPixelFedCablingMapRcd>(
101  edm::ESInputTag("", config_.getParameter<std::string>("CablingMapLabel")))},
102  siPixelDigiCollectionToken_{produces<edm::DetSetVector<PixelDigi>>()},
103  includeErrors_(config_.getParameter<bool>("IncludeErrors")),
104  useQuality_(config_.getParameter<bool>("UseQualityInfo")),
105  usePilotBlade_(config_.getParameter<bool>("UsePilotBlade")),
106  usePhase1_(config_.getParameter<bool>("UsePhase1"))
107 
108 {
109  if (useQuality_) {
110  siPixelQualityToken_ = esConsumes<SiPixelQuality, SiPixelQualityRcd>(
111  edm::ESInputTag("", config_.getParameter<std::string>("SiPixelQualityLabel")));
112  }
113 
114  // Products
115  if (includeErrors_) {
116  errorPutToken_ = produces<edm::DetSetVector<SiPixelRawDataError>>();
117  tkErrorPutToken_ = produces<DetIdCollection>();
118  userErrorPutToken_ = produces<DetIdCollection>("UserErrorModules");
119  disabledChannelPutToken_ = produces<edmNew::DetSetVector<PixelFEDChannel>>();
120  }
121 
122  // regions
123  if (!config_.getParameter<edm::ParameterSet>("Regions").getParameterNames().empty()) {
124  regions_ = new PixelUnpackingRegions(config_, consumesCollector());
125  }
126 
127  // Control the usage of pilot-blade data, FED=40
128  if (usePilotBlade_)
129  edm::LogInfo("SiPixelRawToDigi") << " Use pilot blade data (FED 40)";
130 
131  // Control the usage of phase1
132  if (usePhase1_)
133  edm::LogInfo("SiPixelRawToDigi") << " Using phase1";
134 }
135 
136 // -----------------------------------------------------------------------------
138  edm::LogInfo("SiPixelRawToDigi") << " HERE ** SiPixelRawToDigi destructor!";
139  if (regions_)
140  delete regions_;
141 }
142 
145  desc.add<bool>("IncludeErrors", true);
146  desc.add<bool>("UseQualityInfo", false);
147  {
148  desc.add<std::vector<int>>("ErrorList", std::vector<int>{29})
149  ->setComment("## ErrorList: list of error codes used by tracking to invalidate modules");
150  }
151  {
152  desc.add<std::vector<int>>("UserErrorList", std::vector<int>{40})
153  ->setComment("## UserErrorList: list of error codes used by Pixel experts for investigation");
154  }
155  desc.add<edm::InputTag>("InputLabel", edm::InputTag("siPixelRawData"));
156  {
158  psd0.addOptional<std::vector<edm::InputTag>>("inputs");
159  psd0.addOptional<std::vector<double>>("deltaPhi");
160  psd0.addOptional<std::vector<double>>("maxZ");
161  psd0.addOptional<edm::InputTag>("beamSpot");
162  desc.add<edm::ParameterSetDescription>("Regions", psd0)
163  ->setComment("## Empty Regions PSet means complete unpacking");
164  }
165  desc.add<bool>("UsePilotBlade", false)->setComment("## Use pilot blades");
166  desc.add<bool>("UsePhase1", false)->setComment("## Use phase1");
167  desc.add<std::string>("CablingMapLabel", "")->setComment("CablingMap label"); //Tav
168  desc.add<std::string>("SiPixelQualityLabel", "")->setComment("SiPixelQuality label");
169  descriptions.add("siPixelRawToDigi", desc);
170 }
171 
172 // -----------------------------------------------------------------------------
173 
174 // -----------------------------------------------------------------------------
176  const uint32_t dummydetid = 0xffffffff;
177 
178  // initialize cabling map or update if necessary
179  if (recordWatcher_.check(es)) {
180  // cabling map, which maps online address (fed->link->ROC->local pixel) to offline (DetId->global pixel)
182  fedIds_ = cablingMap->fedIds();
183  cabling_ = cablingMap->cablingTree();
184  LogDebug("map version:") << cabling_->version();
185  }
186  // initialize quality record or update if necessary
187  if (qualityWatcher_.check(es) && useQuality_) {
188  // quality info for dead pixel modules or ROCs
190  badPixelInfo_ = qualityInfo.product();
191  if (!badPixelInfo_) {
192  edm::LogError("SiPixelQualityNotPresent") << "Configured to use SiPixelQuality, but SiPixelQuality not present";
193  }
194  }
195 
197  ev.getByToken(fedRawDataCollectionToken_, buffers);
198 
199  // create product (digis & errors)
201  // collection->reserve(8*1024);
202  auto errorcollection = edm::DetSetVector<SiPixelRawDataError>{};
203  auto tkerror_detidcollection = DetIdCollection{};
204  auto usererror_detidcollection = DetIdCollection{};
205  auto disabled_channelcollection = edmNew::DetSetVector<PixelFEDChannel>{};
206 
207  PixelDataFormatter formatter(cabling_.get(), usePhase1_); // for phase 1 & 0
208 
209  formatter.setErrorStatus(includeErrors_);
210 
211  if (useQuality_)
212  formatter.setQualityStatus(useQuality_, badPixelInfo_);
213 
214  bool errorsInEvent = false;
215  PixelDataFormatter::DetErrors nodeterrors;
216 
217  if (regions_) {
218  regions_->run(ev, es);
219  formatter.setModulesToUnpack(regions_->modulesToUnpack());
220  LogDebug("SiPixelRawToDigi") << "region2unpack #feds: " << regions_->nFEDs();
221  LogDebug("SiPixelRawToDigi") << "region2unpack #modules (BPIX,EPIX,total): " << regions_->nBarrelModules() << " "
222  << regions_->nForwardModules() << " " << regions_->nModules();
223  }
224 
225  for (auto aFed = fedIds_.begin(); aFed != fedIds_.end(); ++aFed) {
226  int fedId = *aFed;
227 
228  if (!usePilotBlade_ && (fedId == 40))
229  continue; // skip pilot blade data
230 
232  continue;
233 
234  LogDebug("SiPixelRawToDigi") << "PRODUCE DIGI FOR FED:" << fedId;
235 
237 
238  //get event data for this fed
239  const FEDRawData& fedRawData = buffers->FEDData(fedId);
240 
241  //convert data to digi and strip off errors
242  formatter.interpretRawData(errorsInEvent, fedId, fedRawData, collection, errors);
243 
244  //pack errors into collection
245  if (includeErrors_) {
246  formatter.unpackFEDErrors(errors,
247  tkerrorlist_,
249  errorcollection,
250  tkerror_detidcollection,
251  usererror_detidcollection,
252  disabled_channelcollection,
253  nodeterrors);
254  } // if errors to be included in the event
255  } // loop on FED data to be unpacked
256 
257  if (includeErrors_) {
258  edm::DetSet<SiPixelRawDataError>& errorDetSet = errorcollection.find_or_insert(dummydetid);
259  errorDetSet.data = nodeterrors;
260  }
261  if (errorsInEvent)
262  LogDebug("SiPixelRawToDigi") << "Error words were stored in this event";
263 
265  if (includeErrors_) {
266  ev.emplace(errorPutToken_, std::move(errorcollection));
267  ev.emplace(tkErrorPutToken_, std::move(tkerror_detidcollection));
268  ev.emplace(userErrorPutToken_, std::move(usererror_detidcollection));
269  ev.emplace(disabledChannelPutToken_, std::move(disabled_channelcollection));
270  }
271 }
272 // declare this as a framework plugin
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
std::unique_ptr< SiPixelFedCablingTree > cablingTree() const
edm::EDPutTokenT< edmNew::DetSetVector< PixelFEDChannel > > disabledChannelPutToken_
edm::ESWatcher< SiPixelQualityRcd > qualityWatcher_
std::vector< unsigned int > fedIds_
edm::EDPutTokenT< DetIdCollection > userErrorPutToken_
void produce(edm::Event &, const edm::EventSetup &) override
get data, convert to digis attach againe to Event
Log< level::Error, false > LogError
PixelUnpackingRegions * regions_
unsigned int nForwardModules() const
reference find_or_insert(det_id_type id)
Definition: DetSetVector.h:234
SiPixelRawToDigi(const edm::ParameterSet &)
ctor
edm::EDPutTokenT< edm::DetSetVector< SiPixelRawDataError > > errorPutToken_
T const * product() const
Definition: ESHandle.h:86
const bool usePilotBlade_
const std::vector< int > tkerrorlist_
std::unique_ptr< SiPixelFedCablingTree > cabling_
const edm::ESGetToken< SiPixelFedCablingMap, SiPixelFedCablingMapRcd > cablingMapToken_
edm::ESWatcher< SiPixelFedCablingMapRcd > recordWatcher_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const std::set< unsigned int > * modulesToUnpack() const
full set of module ids to unpack
std::vector< unsigned int > fedIds() const
unsigned int nModules() const
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
~SiPixelRawToDigi() override
dtor
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
const bool useQuality_
const std::vector< int > usererrorlist_
Log< level::Info, false > LogInfo
void run(const edm::Event &e, const edm::EventSetup &es)
has to be run during each event
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
unsigned int nBarrelModules() const
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
edm::ParameterSet config_
collection_type data
Definition: DetSet.h:80
const edm::EDGetTokenT< FEDRawDataCollection > fedRawDataCollectionToken_
edm::ESGetToken< SiPixelQuality, SiPixelQualityRcd > siPixelQualityToken_
Definition: errors.py:1
bool mayUnpackFED(unsigned int fed_n) const
check whether a FED has to be unpacked
unsigned int nFEDs() const
various informational accessors:
edm::EDPutTokenT< DetIdCollection > tkErrorPutToken_
std::vector< std::string > getParameterNames() const
std::vector< SiPixelRawDataError > DetErrors
def move(src, dest)
Definition: eostools.py:511
const SiPixelQuality * badPixelInfo_
std::map< cms_uint32_t, DetErrors > Errors
const edm::EDPutTokenT< edm::DetSetVector< PixelDigi > > siPixelDigiCollectionToken_
#define LogDebug(id)
const bool includeErrors_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)