36 #define COUT std::cout << "VI " 38 #define COUT LogDebug("") 43 std::unique_ptr<sistrip::FEDBuffer>
buffer;
53 <<
" NULL pointer to FEDRawData for FED id " <<
fedId;
63 <<
" FEDRawData has zero size for FED id " <<
fedId;
73 throw cms::Exception(
"FEDBuffer") <<
"FED Buffer check fails for FED ID" << fedId <<
".";
77 <<
"Exception caught when creating FEDBuffer object for FED " << fedId <<
": " << e.
what();
79 return std::unique_ptr<sistrip::FEDBuffer>();
100 bool idoAPVEmulatorCheck,
102 bool hybridZeroSuppressed)
106 doAPVEmulatorCheck(idoAPVEmulatorCheck),
108 hybridZeroSuppressed_(hybridZeroSuppressed) {
114 ~ClusterFiller()
override { printStat(); }
119 std::unique_ptr<sistrip::FEDBuffer> buffers[1024];
120 std::atomic<sistrip::FEDBuffer*>
done[1024];
128 bool doAPVEmulatorCheck;
131 bool hybridZeroSuppressed_;
135 Stat() : totDet(0), detReady(0), detSet(0), detAct(0), detNoZ(0), detAbrt(0), totClus(0) {}
136 std::atomic<int> totDet;
137 std::atomic<int> detReady;
138 std::atomic<int> detSet;
139 std::atomic<int> detAct;
140 std::atomic<int> detNoZ;
141 std::atomic<int> detAbrt;
142 std::atomic<int> totClus;
147 void incTot(
int n)
const { stat.totDet =
n; }
148 void incReady()
const { stat.detReady++; }
149 void incSet()
const { stat.detSet++; }
150 void incAct()
const { stat.detAct++; }
151 void incNoZ()
const { stat.detNoZ++; }
152 void incAbrt()
const { stat.detAbrt++; }
153 void incClus(
int n)
const { stat.totClus +=
n; }
154 void printStat()
const {
155 COUT <<
"VI clusters " << stat.totDet <<
',' << stat.detReady <<
',' << stat.detSet <<
',' << stat.detAct <<
',' 156 << stat.detNoZ <<
',' << stat.detAbrt <<
',' << stat.totClus << std::endl;
160 static void zeroStat() {}
161 static void incTot(
int) {}
162 static void incReady() {}
163 static void incSet() {}
164 static void incAct() {}
165 static void incNoZ() {}
166 static void incAbrt() {}
167 static void incClus(
int) {}
168 static void printStat() {}
180 doAPVEmulatorCheck_(conf.existsAs<
bool>(
"DoAPVEmulatorCheck") ? conf.getParameter<
bool>(
"DoAPVEmulatorCheck")
182 legacy_(conf.existsAs<
bool>(
"LegacyUnpacker") ? conf.getParameter<
bool>(
"LegacyUnpacker") :
false),
183 hybridZeroSuppressed_(conf.getParameter<
bool>(
"HybridZeroSuppressed")) {
185 produces<edmNew::DetSetVector<SiStripCluster> >();
186 assert(clusterizer_.get());
187 assert(rawAlgos_.get());
199 std::unique_ptr<edmNew::DetSetVector<SiStripCluster> >
output(
202 *rawData, *clusterizer_, *rawAlgos_, doAPVEmulatorCheck_, legacy_, hybridZeroSuppressed_)),
203 clusterizer_->allDetIds())
207 assert(
output->onDemand());
209 output->reserve(15000, 24 * 10000);
214 COUT <<
output->dataSize() <<
" clusters from " <<
output->size() <<
" modules" << std::endl;
233 std::unique_ptr<SiStripRawProcessingAlgorithms>
rawAlgos_;
246 (*clusterizer_).initialize(es);
247 cabling_ = (*clusterizer_).cabling();
248 (*rawAlgos_).initialize(es);
252 ClusterFiller
filler(rawColl, *clusterizer_, *rawAlgos_, doAPVEmulatorCheck_, legacy_, hybridZeroSuppressed_);
255 for (
auto idet : clusterizer_->allDetIds()) {
267 template <
typename OUT>
273 auto unpacker = FEDZSChannelUnpacker::zeroSuppressedLiteModeUnpacker(chan);
274 while (unpacker.hasData()) {
275 *out++ =
SiStripDigi(stripOffset + unpacker.sampleNumber(), unpacker.adc());
281 auto unpacker = FEDBSChannelUnpacker::zeroSuppressedLiteModeUnpacker(chan, 10);
282 while (unpacker.hasData()) {
283 *out++ =
SiStripDigi(stripOffset + unpacker.sampleNumber(), unpacker.adc());
291 auto unpacker = FEDZSChannelUnpacker::zeroSuppressedModeUnpacker(chan);
292 while (unpacker.hasData()) {
293 *out++ =
SiStripDigi(stripOffset + unpacker.sampleNumber(), unpacker.adc());
298 auto unpacker = FEDBSChannelUnpacker::zeroSuppressedModeUnpacker(chan, 10);
299 while (unpacker.hasData()) {
300 *out++ =
SiStripDigi(stripOffset + unpacker.sampleNumber(), unpacker.adc());
305 auto unpacker = FEDBSChannelUnpacker::zeroSuppressedModeUnpacker(chan, 8);
306 while (unpacker.hasData()) {
307 *out++ =
SiStripDigi(stripOffset + unpacker.sampleNumber(), unpacker.adc() << 2);
312 auto unpacker = FEDBSChannelUnpacker::zeroSuppressedModeUnpacker(chan, 8);
313 while (unpacker.hasData()) {
314 *out++ =
SiStripDigi(stripOffset + unpacker.sampleNumber(), unpacker.adc() << 1);
320 <<
" invalid packet code " << chan.
packetCode() <<
" for zero-suppressed.";
325 auto unpacker = FEDZSChannelUnpacker::zeroSuppressedLiteModeUnpacker(chan);
326 while (unpacker.hasData()) {
327 *out++ =
SiStripDigi(stripOffset + unpacker.sampleNumber(), unpacker.adc() << 1);
333 auto unpacker = FEDZSChannelUnpacker::zeroSuppressedLiteModeUnpacker(chan);
334 while (unpacker.hasData()) {
335 *out++ =
SiStripDigi(stripOffset + unpacker.sampleNumber(), unpacker.adc() << 2);
344 class StripByStripAdder {
346 typedef std::output_iterator_tag iterator_category;
348 typedef void difference_type;
349 typedef void pointer;
355 : clusterizer_(clusterizer), state_(state), record_(record) {}
358 clusterizer_.stripByStripAdd(state_, digi.
strip(), digi.
adc(), record_);
362 StripByStripAdder&
operator*() {
return *
this; }
363 StripByStripAdder& operator++() {
return *
this; }
364 StripByStripAdder& operator++(
int) {
return *
this; }
377 auto idet = record.
id();
379 COUT <<
"filling " << idet << std::endl;
381 auto const& det =
clusterizer.stripByStripBegin(idet);
402 buffer = fillBuffer(fedId, rawColl).release();
407 if (
done[fedId].compare_exchange_strong(exp, buffer))
408 buffers[
fedId].reset(buffer);
419 const uint8_t fedCh =
conn->fedCh();
424 std::ostringstream
ss;
425 ss <<
"Problem unpacking channel " << fedCh <<
" on FED " <<
fedId;
432 uint16_t ipair =
conn->apvPairNumber();
443 auto perStripAdder = StripByStripAdder(
clusterizer, state, record);
445 LIKELY(!hybridZeroSuppressed_) { unpackZS(buffer->
channel(fedCh),
mode, ipair * 256, perStripAdder); }
447 const uint32_t
id =
conn->detId();
450 unpackZS(buffer->
channel(fedCh),
mode, ipair * 256, std::back_inserter(unpDigis));
452 rawAlgos.convertHybridDigiToRawDigiVector(unpDigis, workRawDigis);
454 rawAlgos.suppressHybridData(
id, ipair * 2, workRawDigis, suppDigis);
462 <<
"Unordered clusters for channel " << fedCh <<
" on FED " << fedId <<
": " << e.
what();
470 clusterizer.addFed(state, unpacker, ipair, record);
474 while (unpacker.hasData()) {
475 clusterizer.stripByStripAdd(state, ipair * 256 + unpacker.sampleNumber(), unpacker.adc(),
record);
485 while (unpacker.hasData()) {
486 samples.push_back(unpacker.adc());
492 while (unpacker.hasData()) {
493 samples.push_back(unpacker.adc());
499 while (unpacker.hasData()) {
500 samples.push_back(unpacker.adc() << 2);
506 while (unpacker.hasData()) {
507 samples.push_back(unpacker.adc() << 1);
513 <<
"[ClustersFromRawProducer::" << __func__ <<
"]" 514 <<
" invalid packet code " << buffer->
channel(fedCh).
packetCode() <<
" for virgin raw.";
517 std::vector<int16_t> digis;
518 for (uint16_t
i = 0;
i != samples.size(); ++
i) {
520 const auto readout = ((
i & 0x7) << 5) + (
i & (0x3 << 3)) + ((
i & (0x3 << 5)) >> 4) + ((
i & (0
x1 << 7)) >> 7);
521 digis.push_back(samples[readout]);
524 uint32_t
id =
conn->detId();
529 uint16_t firstAPV = ipair * 2;
530 rawAlgos.suppressVirginRawData(
id, firstAPV, digis, zsdigis);
531 for (
const auto digi : zsdigis) {
543 std::vector<int16_t> digis;
545 digis.push_back(unpacker.
adc());
550 uint32_t
id =
conn->detId();
554 uint16_t firstAPV = ipair * 2;
555 rawAlgos.suppressProcessedRawData(
id, firstAPV, digis, zsdigis);
561 <<
"[ClustersFromRawProducer::" << __func__ <<
"]" 562 <<
" FEDRawData readout mode " << mode <<
" from FED id " << fedId <<
" not supported.";
573 << record.
id() <<
' ' << record.
size();
581 COUT <<
"filled " << record.
size() << std::endl;
582 for (
auto const&
cl : record)
583 COUT <<
cl.firstStrip() <<
',' <<
cl.amplitudes().size() << std::endl;
584 incClus(record.size());
static FEDRawChannelUnpacker procRawModeUnpacker(const FEDChannel &channel)
T getParameter(std::string const &) const
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED8_BOTBOT
static AlgebraicMatrix initialize()
static FEDZSChannelUnpacker zeroSuppressedModeUnpacker(const FEDChannel &channel)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
static std::unique_ptr< StripClusterizerAlgorithm > create(const edm::ParameterSet &)
void beginRun(const edm::Run &, const edm::EventSetup &es) override
void run(const FEDRawDataCollection &rawColl, edmNew::DetSetVector< SiStripCluster > &output)
static const char mlRawToCluster_[]
bool getByToken(EDGetToken token, Handle< PROD > &result) const
SiStripAPVRestorer::digivector_t digivector_t
static FEDRawChannelUnpacker virginRawModeUnpacker(const FEDChannel &channel)
FEDReadoutMode readoutMode() const
char const * what() const override
void initialize(const edm::EventSetup &es)
static FEDBSChannelUnpacker virginRawModeUnpacker(const FEDChannel &channel, uint16_t num_bits)
virtual bool channelGood(const uint8_t internalFEDannelNum, const bool doAPVeCheck=true) const
size_t size() const
Lenght of the data buffer in bytes.
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED8_TOPBOT
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED10
void setLegacyMode(bool legacy)
static const uint8_t PACKET_CODE_VIRGIN_RAW10
void produce(edm::Event &ev, const edm::EventSetup &es) override
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED
#define DEFINE_FWK_MODULE(type)
Container::value_type value_type
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
const uint16_t & strip() const
FEDLegacyReadoutMode legacyReadoutMode() const
std::unique_ptr< StripClusterizerAlgorithm > clusterizer_
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
const FEDChannel & channel(const uint8_t internalFEDChannelNum) const
static const uint8_t PACKET_CODE_VIRGIN_RAW8_TOPBOT
static const uint8_t PACKET_CODE_VIRGIN_RAW8_BOTBOT
static FEDZSChannelUnpacker zeroSuppressedLiteModeUnpacker(const FEDChannel &channel)
SiStripDetCabling const * cabling_
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
uint8_t packetCode() const
SiStripClusterizerFromRaw(const edm::ParameterSet &conf)
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
MatrixMeschach operator*(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
collection_type::const_iterator const_iterator
const uint16_t & adc() const
bool hybridZeroSuppressed_
std::unique_ptr< SiStripRawProcessingAlgorithms > rawAlgos_
edm::EDGetTokenT< FEDRawDataCollection > productToken_
static const uint8_t PACKET_CODE_VIRGIN_RAW