40 #define COUT std::cout << "VI " 42 #define COUT LogDebug("") 48 std::unique_ptr<sistrip::FEDBuffer>
buffer;
57 <<
"[ClustersFromRawProducer::" 60 <<
" NULL pointer to FEDRawData for FED id " 70 <<
"[ClustersFromRawProducer::" 72 <<
" FEDRawData has zero size for FED id " 81 if UNLIKELY(!buffer->doChecks(
false))
throw cms::Exception(
"FEDBuffer") <<
"FED Buffer check fails for FED ID" << fedId <<
".";
86 <<
"Exception caught when creating FEDBuffer object for FED " << fedId <<
": " << e.
what();
88 return std::unique_ptr<sistrip::FEDBuffer>();
111 bool idoAPVEmulatorCheck,
113 bool hybridZeroSuppressed):
117 doAPVEmulatorCheck(idoAPVEmulatorCheck),
119 hybridZeroSuppressed_(hybridZeroSuppressed){
121 for (
auto &
d : done)
d=
nullptr;
125 ~ClusterFiller()
override { printStat();}
132 std::unique_ptr<sistrip::FEDBuffer> buffers[1024];
133 std::atomic<sistrip::FEDBuffer*> done[1024];
143 bool doAPVEmulatorCheck;
146 bool hybridZeroSuppressed_;
151 Stat() : totDet(0), detReady(0),detSet(0),detAct(0),detNoZ(0),detAbrt(0),totClus(0){}
152 std::atomic<int> totDet;
153 std::atomic<int> detReady;
154 std::atomic<int> detSet;
155 std::atomic<int> detAct;
156 std::atomic<int> detNoZ;
157 std::atomic<int> detAbrt;
158 std::atomic<int> totClus;
163 void incTot(
int n)
const { stat.totDet=
n;}
164 void incReady()
const { stat.detReady++;}
165 void incSet()
const { stat.detSet++;}
166 void incAct()
const { stat.detAct++;}
167 void incNoZ()
const { stat.detNoZ++;}
168 void incAbrt()
const { stat.detAbrt++;}
169 void incClus(
int n)
const { stat.totClus+=
n;}
170 void printStat()
const {
171 COUT <<
"VI clusters " << stat.totDet <<
','<< stat.detReady <<
','<< stat.detSet <<
','<< stat.detAct<<
','<< stat.detNoZ <<
','<<stat.detAbrt <<
','<<stat.totClus << std::endl;
175 static void zeroStat(){}
176 static void incTot(
int){}
177 static void incReady() {}
178 static void incSet() {}
179 static void incAct() {}
180 static void incNoZ() {}
181 static void incAbrt(){}
182 static void incClus(
int){}
183 static void printStat(){}
200 doAPVEmulatorCheck_(conf.existsAs<
bool>(
"DoAPVEmulatorCheck") ? conf.getParameter<
bool>(
"DoAPVEmulatorCheck") :
true),
201 legacy_(conf.existsAs<
bool>(
"LegacyUnpacker") ? conf.getParameter<
bool>(
"LegacyUnpacker") :
false),
202 hybridZeroSuppressed_(conf.getParameter<
bool>(
"HybridZeroSuppressed"))
205 produces< edmNew::DetSetVector<SiStripCluster> > ();
206 assert(clusterizer_.get());
207 assert(rawAlgos_.get());
225 std::unique_ptr< edmNew::DetSetVector<SiStripCluster> >
output(
229 std::make_shared<ClusterFiller>(*rawData, *clusterizer_, *rawAlgos_,
230 doAPVEmulatorCheck_, legacy_, hybridZeroSuppressed_)),
231 clusterizer_->allDetIds())
237 output->reserve(15000,24*10000);
243 COUT <<
output->dataSize() <<
" clusters from " 244 <<
output->size() <<
" modules" 268 std::unique_ptr<SiStripRawProcessingAlgorithms>
rawAlgos_;
286 (*clusterizer_).initialize(es);
287 cabling_ = (*clusterizer_).cabling();
288 (*rawAlgos_).initialize(es);
295 ClusterFiller
filler(rawColl, *clusterizer_, *rawAlgos_, doAPVEmulatorCheck_, legacy_, hybridZeroSuppressed_);
298 for (
auto idet : clusterizer_->allDetIds()) {
310 template<
typename OUT>
317 {
auto unpacker = FEDZSChannelUnpacker::zeroSuppressedLiteModeUnpacker(chan);
318 while (unpacker.hasData()) { *out++ =
SiStripDigi(stripOffset+unpacker.sampleNumber(), unpacker.adc()); unpacker++; }
322 {
auto unpacker = FEDBSChannelUnpacker::zeroSuppressedLiteModeUnpacker(chan, 10);
323 while (unpacker.hasData()) { *out++ =
SiStripDigi(stripOffset+unpacker.sampleNumber(), unpacker.adc()); unpacker++; }
330 {
auto unpacker = FEDZSChannelUnpacker::zeroSuppressedModeUnpacker(chan);
331 while (unpacker.hasData()) { *out++ =
SiStripDigi(stripOffset+unpacker.sampleNumber(), unpacker.adc()); unpacker++; }
334 {
auto unpacker = FEDBSChannelUnpacker::zeroSuppressedModeUnpacker(chan, 10);
335 while (unpacker.hasData()) { *out++ =
SiStripDigi(stripOffset+unpacker.sampleNumber(), unpacker.adc()); unpacker++; }
338 {
auto unpacker = FEDBSChannelUnpacker::zeroSuppressedModeUnpacker(chan, 8);
339 while (unpacker.hasData()) { *out++ =
SiStripDigi(stripOffset+unpacker.sampleNumber(), unpacker.adc()<<2); unpacker++; }
342 {
auto unpacker = FEDBSChannelUnpacker::zeroSuppressedModeUnpacker(chan, 8);
343 while (unpacker.hasData()) { *out++ =
SiStripDigi(stripOffset+unpacker.sampleNumber(), unpacker.adc()<<1); unpacker++; }
347 <<
" invalid packet code " << chan.
packetCode() <<
" for zero-suppressed.";
352 {
auto unpacker = FEDZSChannelUnpacker::zeroSuppressedLiteModeUnpacker(chan);
353 while (unpacker.hasData()) { *out++ =
SiStripDigi(stripOffset+unpacker.sampleNumber(), unpacker.adc()<<1); unpacker++; }
357 {
auto unpacker = FEDZSChannelUnpacker::zeroSuppressedLiteModeUnpacker(chan);
358 while (unpacker.hasData()) { *out++ =
SiStripDigi(stripOffset+unpacker.sampleNumber(), unpacker.adc()<<2); unpacker++; }
365 class StripByStripAdder {
367 typedef std::output_iterator_tag iterator_category;
369 typedef void difference_type;
370 typedef void pointer;
376 : clusterizer_(clusterizer), state_(state), record_(record) {}
380 clusterizer_.stripByStripAdd(state_, digi.
strip(), digi.
adc(), record_);
384 StripByStripAdder&
operator* () {
return *
this; }
385 StripByStripAdder& operator++ () {
return *
this; }
386 StripByStripAdder& operator++ (
int) {
return *
this; }
398 auto idet= record.
id();
400 COUT <<
"filling " << idet << std::endl;
402 auto const & det =
clusterizer.stripByStripBegin(idet);
403 if (!det.valid())
return;
409 for (
auto const conn :
clusterizer.currentConnection(det)) {
412 const uint16_t
fedId = conn->fedId();
415 if UNLIKELY( !fedId || !conn->isConnected() ) {
continue; }
421 buffer = fillBuffer(fedId, rawColl).release();
422 if (!buffer) {
continue;}
424 if (done[fedId].compare_exchange_strong(exp, buffer)) buffers[
fedId].reset(buffer);
432 const uint8_t fedCh = conn->fedCh();
436 std::ostringstream ss;
437 ss <<
"Problem unpacking channel " << fedCh <<
" on FED " <<
fedId;
444 uint16_t ipair = conn->apvPairNumber();
453 auto perStripAdder = StripByStripAdder(
clusterizer, state, record);
454 if LIKELY( ! hybridZeroSuppressed_ ) {
455 unpackZS(buffer->
channel(fedCh),
mode, ipair*256, perStripAdder);
457 const uint32_t
id = conn->detId();
459 unpackZS(buffer->
channel(fedCh),
mode, ipair*256, std::back_inserter(unpDigis));
461 rawAlgos.convertHybridDigiToRawDigiVector(unpDigis, workRawDigis);
463 rawAlgos.suppressHybridData(
id, ipair*2, workRawDigis, suppDigis);
476 clusterizer.addFed(state, unpacker, ipair, record);
479 while (unpacker.hasData()) {
480 clusterizer.stripByStripAdd(state, ipair*256+unpacker.sampleNumber(), unpacker.adc(),
record);
489 while (unpacker.hasData()) { samples.push_back(unpacker.adc()); unpacker++; }
493 while (unpacker.hasData()) { samples.push_back(unpacker.adc()); unpacker++; }
497 while (unpacker.hasData()) { samples.push_back(unpacker.adc()<<2); unpacker++; }
501 while (unpacker.hasData()) { samples.push_back(unpacker.adc()<<1); unpacker++; }
505 <<
" invalid packet code " << buffer->
channel(fedCh).
packetCode() <<
" for virgin raw.";
508 std::vector<int16_t> digis;
509 for ( uint16_t
i = 0;
i != samples.size(); ++
i ) {
511 const auto readout = ((
i&0x7)<<5) + (
i&(0x3<<3)) + ((
i&(0x3<<5))>>4) + ((
i&(0
x1<<7))>>7);
512 digis.push_back(samples[readout]);
515 uint32_t
id = conn->detId();
520 uint16_t firstAPV = ipair*2;
521 rawAlgos.suppressVirginRawData(
id, firstAPV,digis, zsdigis);
522 for (
const auto digi : zsdigis ) {
532 std::vector<int16_t> digis;
534 digis.push_back(unpacker.
adc());
539 uint32_t
id = conn->detId();
543 uint16_t firstAPV = ipair*2;
544 rawAlgos.suppressProcessedRawData(
id, firstAPV,digis, zsdigis);
550 <<
"[ClustersFromRawProducer::" << __func__ <<
"]" 551 <<
" FEDRawData readout mode " << mode <<
" from FED id " << fedId <<
" not supported.";
566 if(!record.
empty()) incNoZ();
568 COUT <<
"filled " << record.
size() << std::endl;
569 for (
auto const &
cl : record )
COUT <<
cl.firstStrip() <<
','<<
cl.amplitudes().size() << std::endl;
570 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