CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends
sistrip::RawToDigiUnpacker Class Reference

#include <SiStripRawToDigiUnpacker.h>

Classes

class  Registry
 private class to register start and end index of digis in a collection More...
 
class  WarningSummary
 

Public Types

typedef edm::DetSetVector< SiStripDigiDigis
 
typedef edm::DetSetVector< SiStripRawDigiRawDigis
 

Public Member Functions

void createDigis (const SiStripFedCabling &, const FEDRawDataCollection &, SiStripEventSummary &, RawDigis &scope_mode, RawDigis &virgin_raw, RawDigis &proc_raw, Digis &zero_suppr, DetIdCollection &, RawDigis &common_mode)
 creates digis More...
 
void doAPVEmulatorCheck (bool)
 
void doFullCorruptBufferChecks (bool)
 
void extractCm (bool)
 
void legacy (bool)
 
void locateStartOfFedBuffer (const uint16_t &fed_id, const FEDRawData &input, FEDRawData &output)
 Removes any data appended prior to FED buffer and reorders 32-bit words if swapped. More...
 
void printWarningSummary () const
 
void quiet (bool)
 verbosity More...
 
 RawToDigiUnpacker (int16_t appended_bytes, int16_t fed_buffer_dump_freq, int16_t fed_event_dump_freq, int16_t trigger_fed_id, bool using_fed_key, bool unpack_bad_channels, bool mark_missing_feds, const uint32_t errorThreshold)
 constructor More...
 
void triggerFed (const FEDRawDataCollection &, SiStripEventSummary &, const uint32_t &event)
 trigger info More...
 
void useDaqRegister (bool)
 EventSummary update request -> not yet implemented for FEDBuffer class. More...
 
 ~RawToDigiUnpacker ()
 default constructor More...
 

Private Member Functions

void cleanupWorkVectors ()
 method to clear registries and digi collections More...
 
sistrip::FedBufferFormat fedBufferFormat (const uint16_t &register_value)
 returns buffer format More...
 
sistrip::FedReadoutMode fedReadoutMode (const uint16_t &register_value)
 returns buffer readout mode More...
 
void handleException (std::string method_name, std::string extra_info="")
 catches all possible exceptions and rethrows them as cms::Exceptions More...
 
void physicalOrder (uint16_t &readout_order, uint16_t &physical_order)
 order of strips More...
 
 RawToDigiUnpacker ()=delete
 private default constructor More...
 
void readoutOrder (uint16_t &physical_order, uint16_t &readout_order)
 order of strips More...
 
void update (RawDigis &scope_mode, RawDigis &virgin_raw, RawDigis &proc_raw, Digis &zero_suppr, RawDigis &common_mode)
 fill DetSetVectors using registries More...
 
void updateEventSummary (const sistrip::FEDBuffer &, SiStripEventSummary &)
 sets the SiStripEventSummary -> not yet implemented for FEDBuffer class More...
 

Static Private Member Functions

static void dumpRawData (uint16_t fed_id, const FEDRawData &, std::stringstream &)
 dumps raw data to stdout (NB: payload is byte-swapped,headers/trailer are not). More...
 

Private Attributes

std::vector< SiStripRawDigicm_work_digis_
 
std::vector< Registrycm_work_registry_
 
bool doAPVEmulatorCheck_
 
bool doFullCorruptBufferChecks_
 
uint32_t errorThreshold_
 
uint32_t event_
 other values More...
 
bool extractCm_
 
int16_t fedBufferDumpFreq_
 
int16_t fedEventDumpFreq_
 
bool first_
 
int16_t headerBytes_
 configurables More...
 
bool legacy_
 
bool markMissingFeds_
 
bool once_
 
std::vector< SiStripRawDigiproc_work_digis_
 
std::vector< Registryproc_work_registry_
 
bool quiet_
 
std::vector< SiStripRawDigiscope_work_digis_
 
std::vector< Registryscope_work_registry_
 
int16_t triggerFedId_
 
bool unpackBadChannels_
 
bool useDaqRegister_
 
bool useFedKey_
 
std::vector< SiStripRawDigivirgin_work_digis_
 
std::vector< Registryvirgin_work_registry_
 
WarningSummary warnings_
 
std::vector< SiStripDigizs_work_digis_
 digi collections More...
 
std::vector< Registryzs_work_registry_
 registries More...
 

Friends

class RawToClustersLazyUnpacker
 

Detailed Description

Definition at line 29 of file SiStripRawToDigiUnpacker.h.

Member Typedef Documentation

Definition at line 35 of file SiStripRawToDigiUnpacker.h.

Definition at line 36 of file SiStripRawToDigiUnpacker.h.

Constructor & Destructor Documentation

sistrip::RawToDigiUnpacker::RawToDigiUnpacker ( int16_t  appended_bytes,
int16_t  fed_buffer_dump_freq,
int16_t  fed_event_dump_freq,
int16_t  trigger_fed_id,
bool  using_fed_key,
bool  unpack_bad_channels,
bool  mark_missing_feds,
const uint32_t  errorThreshold 
)

constructor

Definition at line 24 of file SiStripRawToDigiUnpacker.cc.

References edm::isDebugEnabled(), LogTrace, and unpackBadChannels_.

25  :
26  headerBytes_( appended_bytes ),
27  fedBufferDumpFreq_( fed_buffer_dump_freq ),
28  fedEventDumpFreq_( fed_event_dump_freq ),
29  triggerFedId_( trigger_fed_id ),
30  useFedKey_( using_fed_key ),
31  unpackBadChannels_( unpack_bad_channels ),
32  markMissingFeds_( mark_missing_feds ),
33  event_(0),
34  once_(true),
35  first_(true),
36  useDaqRegister_(false),
37  quiet_(true),
38  extractCm_(false),
40  doAPVEmulatorCheck_(true),
41  errorThreshold_(errorThreshold),
42  warnings_(sistrip::mlRawToDigi_, "[sistrip::RawToDigiUnpacker::createDigis]", edm::isDebugEnabled())
43  {
44  if ( edm::isDebugEnabled() ) {
45  LogTrace("SiStripRawToDigi")
46  << "[sistrip::RawToDigiUnpacker::"<<__func__<<"]"
47  <<" Constructing object...";
48  }
49  if (unpackBadChannels_) {
50  edm::LogWarning("SiStripRawToDigi") << "Warning: Unpacking of bad channels enabled. Only enable this if you know what you are doing. " << std::endl;
51  }
52  }
bool isDebugEnabled()
static const char mlRawToDigi_[]
#define LogTrace(id)
sistrip::RawToDigiUnpacker::~RawToDigiUnpacker ( )

default constructor

Definition at line 54 of file SiStripRawToDigiUnpacker.cc.

References edm::isDebugEnabled(), and LogTrace.

54  {
55  if ( edm::isDebugEnabled() ) {
56  LogTrace("SiStripRawToDigi")
57  << "[sistrip::RawToDigiUnpacker::"<<__func__<<"]"
58  << " Destructing object...";
59  }
60  }
bool isDebugEnabled()
#define LogTrace(id)
sistrip::RawToDigiUnpacker::RawToDigiUnpacker ( )
privatedelete

private default constructor

Member Function Documentation

void sistrip::RawToDigiUnpacker::cleanupWorkVectors ( )
private

method to clear registries and digi collections

Definition at line 844 of file SiStripRawToDigiUnpacker.cc.

References cm_work_digis_, cm_work_registry_, proc_work_digis_, proc_work_registry_, scope_work_digis_, scope_work_registry_, virgin_work_digis_, virgin_work_registry_, zs_work_digis_, and zs_work_registry_.

Referenced by createDigis().

844  {
845  // Clear working areas and registries
846 
847  localRA.update(zs_work_digis_.size());
848  zs_work_registry_.clear(); zs_work_digis_.clear(); zs_work_digis_.shrink_to_fit(); assert(zs_work_digis_.capacity()==0);
849  virgin_work_registry_.clear(); virgin_work_digis_.clear();
850  proc_work_registry_.clear(); proc_work_digis_.clear();
851  scope_work_registry_.clear(); scope_work_digis_.clear();
852  cm_work_registry_.clear(); cm_work_digis_.clear();
853  }
std::vector< Registry > proc_work_registry_
std::vector< SiStripDigi > zs_work_digis_
digi collections
std::vector< Registry > scope_work_registry_
std::vector< Registry > zs_work_registry_
registries
std::vector< SiStripRawDigi > virgin_work_digis_
std::vector< SiStripRawDigi > scope_work_digis_
std::vector< SiStripRawDigi > proc_work_digis_
std::vector< SiStripRawDigi > cm_work_digis_
std::vector< Registry > cm_work_registry_
std::vector< Registry > virgin_work_registry_
void sistrip::RawToDigiUnpacker::createDigis ( const SiStripFedCabling cabling,
const FEDRawDataCollection buffers,
SiStripEventSummary summary,
RawDigis scope_mode,
RawDigis virgin_raw,
RawDigis proc_raw,
Digis zero_suppr,
DetIdCollection detids,
RawDigis common_mode 
)

creates digis

extract readout mode

FED channel

create unpacker

unpack -> add check to make sure strip < nstrips && strip > last strip......

create unpacker

unpack -> add check to make sure strip < nstrips && strip > last strip......

create unpacker

unpack -> add check to make sure strip < nstrips && strip > last strip......

create unpacker

unpack -> add check to make sure strip < nstrips && strip > last strip......

create unpacker and unpack -> add check to make sure strip < nstrips && strip > last strip......

create unpacker

unpack -> add check to make sure strip < nstrips && strip > last strip......

create unpacker

unpack -> add check to make sure strip < nstrips && strip > last strip......

create unpacker

unpack -> add check to make sure strip < nstrips && strip > last strip......

Definition at line 96 of file SiStripRawToDigiUnpacker.cc.

References sistrip::FEDZSChannelUnpacker::adc(), sistrip::FEDRawChannelUnpacker::adc(), sistrip::FEDBSChannelUnpacker::adc(), sistrip::FEDZSChannelUnpacker::adcPreMix(), sistrip::RawToDigiUnpacker::WarningSummary::add(), sistrip::APV_LATENCY, edmScanValgrind::buffer, officialStyle::chan, cleanupWorkVectors(), cm_work_digis_, cm_work_registry_, FEDRawData::data(), TauDecayModes::dec, doAPVEmulatorCheck_, doFullCorruptBufferChecks_, dumpRawData(), MillePedeFileConverter_cfg::e, errorThreshold_, event_, Exception, extractCm_, sistrip::FED_CABLING, fedBufferDumpFreq_, sistrip::FEDCH_PER_FEUNIT, SiStripFedCabling::fedConnections(), FEDRawDataCollection::FEDData(), fedEventDumpFreq_, SiStripFedCabling::fedIds(), sistrip::FINE_DELAY, first_, cmsPerfStripChart::format, sistrip::FEDZSChannelUnpacker::hasData(), sistrip::FEDRawChannelUnpacker::hasData(), sistrip::FEDBSChannelUnpacker::hasData(), mps_fire::i, input, sistrip::invalid32_, sistrip::invalid_, edm::isDebugEnabled(), SiStripEventSummary::isSet(), crabWrapper::key, legacy_, LogTrace, FEDNumbering::MAXSiStripFEDID, FEDNumbering::MINSiStripFEDID, sistrip::mlRawToDigi_, ALCARECOPromptCalibProdSiPixelAli0T_cff::mode, gen::n, sistrip::PACKET_CODE_VIRGIN_RAW, sistrip::PACKET_CODE_VIRGIN_RAW10, sistrip::PACKET_CODE_VIRGIN_RAW8_BOTBOT, sistrip::PACKET_CODE_VIRGIN_RAW8_TOPBOT, sistrip::PACKET_CODE_ZERO_SUPPRESSED, sistrip::PACKET_CODE_ZERO_SUPPRESSED10, sistrip::PACKET_CODE_ZERO_SUPPRESSED8_BOTBOT, sistrip::PACKET_CODE_ZERO_SUPPRESSED8_TOPBOT, sistrip::FEDZSChannelUnpacker::preMixRawModeUnpacker(), proc_work_digis_, proc_work_registry_, sistrip::FEDRawChannelUnpacker::procRawModeUnpacker(), edm::EDCollection< T >::push_back(), quiet_, sistrip::READOUT_MODE_LEGACY_INVALID, sistrip::READOUT_MODE_LEGACY_PREMIX_RAW, sistrip::READOUT_MODE_LEGACY_PROC_RAW_FAKE, sistrip::READOUT_MODE_LEGACY_PROC_RAW_REAL, sistrip::READOUT_MODE_LEGACY_SCOPE, sistrip::READOUT_MODE_LEGACY_VIRGIN_RAW_FAKE, sistrip::READOUT_MODE_LEGACY_VIRGIN_RAW_REAL, sistrip::READOUT_MODE_LEGACY_ZERO_SUPPRESSED_FAKE, sistrip::READOUT_MODE_LEGACY_ZERO_SUPPRESSED_LITE_FAKE, sistrip::READOUT_MODE_LEGACY_ZERO_SUPPRESSED_LITE_REAL, sistrip::READOUT_MODE_LEGACY_ZERO_SUPPRESSED_REAL, sistrip::READOUT_MODE_PREMIX_RAW, sistrip::READOUT_MODE_PROC_RAW, sistrip::READOUT_MODE_SCOPE, sistrip::READOUT_MODE_VIRGIN_RAW, sistrip::READOUT_MODE_ZERO_SUPPRESSED, sistrip::READOUT_MODE_ZERO_SUPPRESSED_FAKE, sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE10, sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE10_CMOVERRIDE, sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE8, sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE8_BOTBOT, sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE8_BOTBOT_CMOVERRIDE, sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE8_CMOVERRIDE, sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE8_TOPBOT, sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE8_TOPBOT_CMOVERRIDE, readoutOrder(), edm::EDCollection< T >::reserve(), SiStripEventSummary::runType(), sistrip::FEDZSChannelUnpacker::sampleNumber(), sistrip::FEDBSChannelUnpacker::sampleNumber(), hcalTTPDigis_cfi::samples, scope_work_digis_, scope_work_registry_, sistrip::FEDRawChannelUnpacker::scopeModeUnpacker(), edm::EDCollection< T >::size(), FEDRawData::size(), harvestTrackValidationPlots::str, triggerFedId_, unpackBadChannels_, update(), updateEventSummary(), useDaqRegister_, useFedKey_, SiStripEventSummary::valid(), virgin_work_digis_, virgin_work_registry_, sistrip::FEDRawChannelUnpacker::virginRawModeUnpacker(), sistrip::FEDBSChannelUnpacker::virginRawModeUnpacker(), warnings_, cms::Exception::what(), sistrip::FEDZSChannelUnpacker::zeroSuppressedLiteModeUnpacker(), sistrip::FEDBSChannelUnpacker::zeroSuppressedLiteModeUnpacker(), sistrip::FEDZSChannelUnpacker::zeroSuppressedModeUnpacker(), sistrip::FEDBSChannelUnpacker::zeroSuppressedModeUnpacker(), zs_work_digis_, and zs_work_registry_.

Referenced by sistrip::RawToDigiModule::produce().

96  {
97 
98  // Clear done at the end
99  assert(zs_work_digis_.empty());
100  zs_work_digis_.reserve(localRA.upper());
101  // Reserve space in bad module list
102  detids.reserve(100);
103 
104  // Check if FEDs found in cabling map and event data
105  if ( cabling.fedIds().empty() ) {
106  warnings_.add("No FEDs found in cabling map!");
107  if ( edm::isDebugEnabled() ) {
108  // Check which FED ids have non-zero size buffers
109  std::vector<uint16_t> feds;
110  for ( uint16_t ifed = FEDNumbering::MINSiStripFEDID; ifed < FEDNumbering::MAXSiStripFEDID; ifed++ ) {
111  if ( ifed != triggerFedId_ &&
112  buffers.FEDData( static_cast<int>(ifed) ).size() ) {
113  feds.push_back(ifed);
114  }
115  }
116  LogTrace("SiStripRawToDigi")
117  << "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
118  << " Found "
119  << feds.size()
120  << " FED buffers with non-zero size!";
121  }
122  }
123 
124  // Flag for EventSummary update using DAQ register
125  bool first_fed = true;
126 
127  // Retrieve FED ids from cabling map and iterate through
128  std::vector<uint16_t>::const_iterator ifed = cabling.fedIds().begin();
129  for ( ; ifed != cabling.fedIds().end(); ifed++ ) {
130 
131  // ignore trigger FED
132  if ( *ifed == triggerFedId_ ) { continue; }
133 
134  // Retrieve FED raw data for given FED
135  const FEDRawData& input = buffers.FEDData( static_cast<int>(*ifed) );
136 
137  // Some debug on FED buffer size
138  if ( edm::isDebugEnabled() ) {
139  if ( first_ && input.data() ) {
140  std::stringstream ss;
141  ss << "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
142  << " Found FED id "
143  << std::setw(4) << std::setfill(' ') << *ifed
144  << " in FEDRawDataCollection"
145  << " with non-zero pointer 0x"
146  << std::hex
147  << std::setw(8) << std::setfill('0')
148  << reinterpret_cast<uint32_t*>( const_cast<uint8_t*>(input.data()))
149  << std::dec
150  << " and size "
151  << std::setw(5) << std::setfill(' ') << input.size()
152  << " chars";
153  LogTrace("SiStripRawToDigi") << ss.str();
154  }
155  }
156 
157  // Dump of FEDRawData to stdout
158  if ( edm::isDebugEnabled() ) {
160  std::stringstream ss;
161  dumpRawData( *ifed, input, ss );
163  }
164  }
165 
166  // get the cabling connections for this FED
167  auto conns = cabling.fedConnections(*ifed);
168 
169  // Check on FEDRawData pointer
170  if ( !input.data() ) {
171  warnings_.add("NULL pointer to FEDRawData for FED", (boost::format("id %1%") % *ifed).str());
172  // Mark FED modules as bad
173  detids.reserve(detids.size()+conns.size());
174  std::vector<FedChannelConnection>::const_iterator iconn = conns.begin();
175  for ( ; iconn != conns.end(); iconn++ ) {
176  if ( !iconn->detId() || iconn->detId() == sistrip::invalid32_ ) continue;
177  detids.push_back(iconn->detId()); //@@ Possible multiple entries (ok for Giovanni)
178  }
179  continue;
180  }
181 
182  // Check on FEDRawData size
183  if ( !input.size() ) {
184  warnings_.add("FEDRawData has zero size for FED", (boost::format("id %1%") % *ifed).str());
185  // Mark FED modules as bad
186  detids.reserve(detids.size()+conns.size());
187  std::vector<FedChannelConnection>::const_iterator iconn = conns.begin();
188  for ( ; iconn != conns.end(); iconn++ ) {
189  if ( !iconn->detId() || iconn->detId() == sistrip::invalid32_ ) continue;
190  detids.push_back(iconn->detId()); //@@ Possible multiple entries (ok for Giovanni)
191  }
192  continue;
193  }
194 
195  // construct FEDBuffer
196  std::auto_ptr<sistrip::FEDBuffer> buffer;
197  try {
198  buffer.reset(new sistrip::FEDBuffer(input.data(),input.size()));
199  buffer->setLegacyMode(legacy_);
200  if (!buffer->doChecks(true)) {
201  if (!unpackBadChannels_ || !buffer->checkNoFEOverflows() )
202  throw cms::Exception("FEDBuffer") << "FED Buffer check fails for FED ID " << *ifed << ".";
203  }
204  if (doFullCorruptBufferChecks_ && !buffer->doCorruptBufferChecks()) {
205  throw cms::Exception("FEDBuffer") << "FED corrupt buffer check fails for FED ID " << *ifed << ".";
206  }
207  }
208  catch (const cms::Exception& e) {
209  warnings_.add("Exception caught when creating FEDBuffer object for FED", (boost::format("id %1%: %2%") % *ifed % e.what()).str());
210  // FED buffer is bad and should not be unpacked. Skip this FED and mark all modules as bad.
211  std::vector<FedChannelConnection>::const_iterator iconn = conns.begin();
212  for ( ; iconn != conns.end(); iconn++ ) {
213  if ( !iconn->detId() || iconn->detId() == sistrip::invalid32_ ) continue;
214  detids.push_back(iconn->detId()); //@@ Possible multiple entries (ok for Giovanni)
215  }
216  continue;
217  }
218 
219  // Check if EventSummary ("trigger FED info") needs updating
220  if ( first_fed && useDaqRegister_ ) { updateEventSummary( *buffer, summary ); first_fed = false; }
221 
222  // Check to see if EventSummary info is set
223  if ( !quiet_ && !summary.isSet() ) {
224  warnings_.add("EventSummary is not set correctly! Missing information from both \"trigger FED\" and \"DAQ registers\"!");
225  }
226 
227  // Check to see if event is to be analyzed according to EventSummary
228  if ( !summary.valid() ) {
229  if ( edm::isDebugEnabled() ) {
230  LogTrace("SiStripRawToDigi")
231  << "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
232  << " EventSummary is not valid: skipping...";
233  }
234  continue;
235  }
236 
238  sistrip::FEDReadoutMode mode = buffer->readoutMode();
239  sistrip::FEDLegacyReadoutMode lmode = (legacy_) ? buffer->legacyReadoutMode() : sistrip::READOUT_MODE_LEGACY_INVALID;
240 
241  // Retrive run type
242  sistrip::RunType runType_ = summary.runType();
243  if( runType_ == sistrip::APV_LATENCY || runType_ == sistrip::FINE_DELAY ) { useFedKey_ = false; }
244 
245  // Dump of FED buffer
246  if ( edm::isDebugEnabled() ) {
248  std::stringstream ss;
249  buffer->dump( ss );
251  }
252  }
253 
254  // Iterate through FED channels, extract payload and create Digis
255  std::vector<FedChannelConnection>::const_iterator iconn = conns.begin();
256  for ( ; iconn != conns.end(); iconn++ ) {
257 
259  uint16_t chan = iconn->fedCh();
260 
261  // Check if fed connection is valid
262  if ( !iconn->isConnected() ) { continue; }
263 
264  // Check DetId is valid (if to be used as key)
265  if ( !useFedKey_ && ( !iconn->detId() || iconn->detId() == sistrip::invalid32_ ) ) { continue; }
266 
267  // Check FED channel
268  if (!buffer->channelGood(iconn->fedCh(),doAPVEmulatorCheck_)) {
269  if (!unpackBadChannels_ || !(buffer->fePresent(iconn->fedCh()/FEDCH_PER_FEUNIT) && buffer->feEnabled(iconn->fedCh()/FEDCH_PER_FEUNIT)) ) {
270  detids.push_back(iconn->detId()); //@@ Possible multiple entries (ok for Giovanni)
271  continue;
272  }
273  }
274 
275  // Determine whether FED key is inferred from cabling or channel loop
276  uint32_t fed_key = ( summary.runType() == sistrip::FED_CABLING ) ? ( ( *ifed & sistrip::invalid_ ) << 16 ) | ( chan & sistrip::invalid_ ) : ( ( iconn->fedId() & sistrip::invalid_ ) << 16 ) | ( iconn->fedCh() & sistrip::invalid_ );
277 
278  // Determine whether DetId or FED key should be used to index digi containers
279  uint32_t key = ( useFedKey_ || (!legacy_ && mode == sistrip::READOUT_MODE_SCOPE) || (legacy_ && lmode == sistrip::READOUT_MODE_LEGACY_SCOPE) ) ? fed_key : iconn->detId();
280 
281  // Determine APV std::pair number (needed only when using DetId)
282  uint16_t ipair = ( useFedKey_ || (!legacy_ && mode == sistrip::READOUT_MODE_SCOPE) || (legacy_ && lmode == sistrip::READOUT_MODE_LEGACY_SCOPE) ) ? 0 : iconn->apvPairNumber();
283 
286 
287  Registry regItem(key, 0, zs_work_digis_.size(), 0);
288 
289  try {
292  const uint8_t packet_code = buffer->packetCode(legacy_, iconn->fedCh());
293  switch (packet_code) {
296  while (unpacker.hasData()) {zs_work_digis_.push_back(SiStripDigi(unpacker.sampleNumber()+ipair*256,unpacker.adc())); unpacker++;}
297  break; }
300  while (unpacker.hasData()) {zs_work_digis_.push_back(SiStripDigi(unpacker.sampleNumber()+ipair*256,unpacker.adc())); unpacker++;}
301  break; }
304  while (unpacker.hasData()) {zs_work_digis_.push_back(SiStripDigi(unpacker.sampleNumber()+ipair*256,unpacker.adc()<<2)); unpacker++;}
305  break; }
308  while (unpacker.hasData()) {zs_work_digis_.push_back(SiStripDigi(unpacker.sampleNumber()+ipair*256,unpacker.adc()<<1)); unpacker++;}
309  break; }
310  default: {
311  warnings_.add((boost::format("Invalid packet code %1$#x for zero-suppressed data") % uint16_t(buffer->packetCode(legacy_, iconn->fedCh()))).str(), (boost::format("FED %1% channel %2%") % *ifed % iconn->fedCh()).str());
312  if ( packet_code == 0 ) {
313  // workaround for a pre-2015 bug in the packer: assume default ZS packing
315  while (unpacker.hasData()) {zs_work_digis_.push_back(SiStripDigi(unpacker.sampleNumber()+ipair*256,unpacker.adc())); unpacker++;}
316  }
317  }
318  }
319  } catch (const cms::Exception& e) {
320  warnings_.add("Clusters are not ordered", (boost::format("FED %1% channel %2% : %3%") % *ifed % iconn->fedCh() % e.what()).str());
321  detids.push_back(iconn->detId()); //@@ Possible multiple entries (ok for Giovanni)
322  continue;
323  }
324 
325  regItem.length = zs_work_digis_.size() - regItem.index;
326  if (regItem.length > 0) {
327  regItem.first = zs_work_digis_[regItem.index].strip();
328  zs_work_registry_.push_back(regItem);
329  }
330 
331 
332  // Common mode values
333  if ( extractCm_ ) {
334  try {
335  Registry regItem2( key, 2*ipair, cm_work_digis_.size(), 2 );
336  cm_work_digis_.push_back( SiStripRawDigi( buffer->channel(iconn->fedCh()).cmMedian(0) ) );
337  cm_work_digis_.push_back( SiStripRawDigi( buffer->channel(iconn->fedCh()).cmMedian(1) ) );
338  cm_work_registry_.push_back( regItem2 );
339  } catch (const cms::Exception& e) {
340  warnings_.add("Problem extracting common modes", (boost::format("FED %1% channel %2%:\n %3%") % *ifed % iconn->fedCh() % e.what()).str());
341  }
342  }
343 
344  }
345 
347 
348  Registry regItem(key, 0, zs_work_digis_.size(), 0);
349 
350  try {
353 
355  while (unpacker.hasData()) {zs_work_digis_.push_back(SiStripDigi(unpacker.sampleNumber()+ipair*256,unpacker.adc()));unpacker++;}
356  } catch (const cms::Exception& e) {
357  warnings_.add("Clusters are not ordered", (boost::format("FED %1% channel %2%: %3%") % *ifed % iconn->fedCh() % e.what()).str());
358  detids.push_back(iconn->detId()); //@@ Possible multiple entries (ok for Giovanni)
359  continue;
360  }
361 
362  regItem.length = zs_work_digis_.size() - regItem.index;
363  if (regItem.length > 0) {
364  regItem.first = zs_work_digis_[regItem.index].strip();
365  zs_work_registry_.push_back(regItem);
366  }
367 
368 
369  }
370 
371  else if ((!legacy_ &&
376 
377  Registry regItem(key, 0, zs_work_digis_.size(), 0);
378 
379  size_t bits_shift = 0;
382 
383  try {
386 
388  while (unpacker.hasData()) {zs_work_digis_.push_back(SiStripDigi(unpacker.sampleNumber()+ipair*256,unpacker.adc()<<bits_shift));unpacker++;}
389  } catch (const cms::Exception& e) {
390  warnings_.add("Clusters are not ordered", (boost::format("FED %1% channel %2%: %3%") % *ifed % iconn->fedCh() % e.what()).str());
391  detids.push_back(iconn->detId()); //@@ Possible multiple entries (ok for Giovanni)
392  continue;
393  }
394 
395  regItem.length = zs_work_digis_.size() - regItem.index;
396  if (regItem.length > 0) {
397  regItem.first = zs_work_digis_[regItem.index].strip();
398  zs_work_registry_.push_back(regItem);
399  }
400 
401  }
402 
403  else if ((!legacy_ && mode == sistrip::READOUT_MODE_PREMIX_RAW)
405  ) {
406 
407  Registry regItem(key, 0, zs_work_digis_.size(), 0);
408 
409  try {
410 
413 
415  while (unpacker.hasData()) {zs_work_digis_.push_back(SiStripDigi(unpacker.sampleNumber()+ipair*256,unpacker.adcPreMix()));unpacker++;}
416  } catch (const cms::Exception& e) {
417  warnings_.add("Clusters are not ordered", (boost::format("FED %1% channel %2%: %3%") % *ifed % iconn->fedCh() % e.what()).str());
418  detids.push_back(iconn->detId()); //@@ Possible multiple entries (ok for Giovanni)
419  continue;
420  }
421 
422  regItem.length = zs_work_digis_.size() - regItem.index;
423  if (regItem.length > 0) {
424  regItem.first = zs_work_digis_[regItem.index].strip();
425  zs_work_registry_.push_back(regItem);
426  }
427 
428 
429  }
430 
431  else if ((!legacy_ && mode == sistrip::READOUT_MODE_VIRGIN_RAW)
433  ) {
434 
435  std::vector<uint16_t> samples;
436 
439 
440  uint8_t packet_code = buffer->packetCode(legacy_);
441  if ( packet_code == PACKET_CODE_VIRGIN_RAW ) {
443  while (unpacker.hasData()) {samples.push_back(unpacker.adc());unpacker++;}
444  }
445  else {
446  if ( packet_code == PACKET_CODE_VIRGIN_RAW10 ) {
447  sistrip::FEDBSChannelUnpacker unpacker = sistrip::FEDBSChannelUnpacker::virginRawModeUnpacker(buffer->channel(iconn->fedCh()), 10);
448  while (unpacker.hasData()) {samples.push_back(unpacker.adc());unpacker.sampleNumber();unpacker++;}
449  }
450  else if ( packet_code == PACKET_CODE_VIRGIN_RAW8_BOTBOT ) {
451  sistrip::FEDBSChannelUnpacker unpacker = sistrip::FEDBSChannelUnpacker::virginRawModeUnpacker(buffer->channel(iconn->fedCh()), 8);
452  while (unpacker.hasData()) {samples.push_back(( unpacker.adc()<<2 ));unpacker++;}
453  }
454  else if ( packet_code == PACKET_CODE_VIRGIN_RAW8_TOPBOT ) {
455  sistrip::FEDBSChannelUnpacker unpacker = sistrip::FEDBSChannelUnpacker::virginRawModeUnpacker(buffer->channel(iconn->fedCh()), 8);
456  while (unpacker.hasData()) {samples.push_back(( unpacker.adc()<<1 ));unpacker++;}
457  }
458  }
459  if ( !samples.empty() ) {
460  Registry regItem(key, 256*ipair, virgin_work_digis_.size(), samples.size());
461  uint16_t physical;
462  uint16_t readout;
463  for ( uint16_t i = 0, n = samples.size(); i < n; i++ ) {
464  physical = i%128;
465  readoutOrder( physical, readout ); // convert index from physical to readout order
466  (i/128) ? readout=readout*2+1 : readout=readout*2; // un-multiplex data
467  virgin_work_digis_.push_back( SiStripRawDigi( samples[readout] ) );
468  }
469  virgin_work_registry_.push_back( regItem );
470  }
471  }
472 
473  else if ((!legacy_ && mode == sistrip::READOUT_MODE_PROC_RAW)
475  ) {
476 
477  std::vector<uint16_t> samples;
478 
481 
483  while (unpacker.hasData()) {samples.push_back(unpacker.adc());unpacker++;}
484 
485  if ( !samples.empty() ) {
486  Registry regItem(key, 256*ipair, proc_work_digis_.size(), samples.size());
487  for ( uint16_t i = 0, n = samples.size(); i < n; i++ ) {
488  proc_work_digis_.push_back( SiStripRawDigi( samples[i] ) );
489  }
490  proc_work_registry_.push_back( regItem );
491  }
492  }
493 
494  else if ((!legacy_ && mode == sistrip::READOUT_MODE_SCOPE)
496  ) {
497 
498  std::vector<uint16_t> samples;
499 
501  sistrip::FEDRawChannelUnpacker unpacker = sistrip::FEDRawChannelUnpacker::scopeModeUnpacker(buffer->channel(iconn->fedCh()));
502 
504  while (unpacker.hasData()) {samples.push_back(unpacker.adc());unpacker++;}
505 
506  if ( !samples.empty() ) {
507  Registry regItem(key, 0, scope_work_digis_.size(), samples.size());
508  for ( uint16_t i = 0, n = samples.size(); i < n; i++ ) {
509  scope_work_digis_.push_back( SiStripRawDigi( samples[i] ) );
510  }
511  scope_work_registry_.push_back( regItem );
512  }
513  }
514 
515  else { // Unknown readout mode! => assume scope mode
516 
517  warnings_.add((boost::format("Unknown FED readout mode (%1%)! Assuming SCOPE MODE...") % mode).str());
518 
519  std::vector<uint16_t> samples;
520 
522  sistrip::FEDRawChannelUnpacker unpacker = sistrip::FEDRawChannelUnpacker::scopeModeUnpacker(buffer->channel(iconn->fedCh()));
523 
525  while (unpacker.hasData()) {samples.push_back(unpacker.adc());unpacker++;}
526 
527  if ( !samples.empty() ) {
528  Registry regItem(key, 0, scope_work_digis_.size(), samples.size());
529  for ( uint16_t i = 0, n = samples.size(); i < n; i++ ) {
530  scope_work_digis_.push_back( SiStripRawDigi( samples[i] ) );
531  }
532  scope_work_registry_.push_back( regItem );
533 
534  if ( edm::isDebugEnabled() ) {
535  std::stringstream ss;
536  ss << "Extracted " << samples.size()
537  << " SCOPE MODE digis (samples[0] = "
538  << samples[0]
539  << ") from FED id/ch "
540  << iconn->fedId()
541  << "/"
542  << iconn->fedCh();
543  LogTrace("SiStripRawToDigi") << ss.str();
544  }
545  } else {
546  warnings_.add("No SM digis found!");
547  }
548  }
549  } // channel loop
550  } // fed loop
551 
552  // bad channels warning
553  unsigned int detIdsSize = detids.size();
554  if ( edm::isDebugEnabled() && detIdsSize ) {
555  std::ostringstream ss;
556  ss << "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
557  << " Problems were found in data and " << detIdsSize << " channels could not be unpacked. "
558  << "See output of FED Hardware monitoring for more information. ";
560  }
561  if( (errorThreshold_ != 0) && (detIdsSize > errorThreshold_) ) {
562  edm::LogError("TooManyErrors") << "Total number of errors = " << detIdsSize;
563  }
564 
565  // update DetSetVectors
566  update(scope_mode, virgin_raw, proc_raw, zero_suppr, cm_values);
567 
568  // increment event counter
569  event_++;
570 
571  // no longer first event!
572  if ( first_ ) { first_ = false; }
573 
574  // final cleanup, just in case
576  }
static FEDRawChannelUnpacker procRawModeUnpacker(const FEDChannel &channel)
size_type size() const
Definition: EDCollection.h:97
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED8_BOTBOT
bool isDebugEnabled()
void update(RawDigis &scope_mode, RawDigis &virgin_raw, RawDigis &proc_raw, Digis &zero_suppr, RawDigis &common_mode)
fill DetSetVectors using registries
std::vector< Registry > proc_work_registry_
void updateEventSummary(const sistrip::FEDBuffer &, SiStripEventSummary &)
sets the SiStripEventSummary -> not yet implemented for FEDBuffer class
static FEDZSChannelUnpacker zeroSuppressedModeUnpacker(const FEDChannel &channel)
std::vector< SiStripDigi > zs_work_digis_
digi collections
std::vector< Registry > scope_work_registry_
void cleanupWorkVectors()
method to clear registries and digi collections
std::vector< Registry > zs_work_registry_
registries
static FEDZSChannelUnpacker preMixRawModeUnpacker(const FEDChannel &channel)
static const uint32_t invalid32_
Definition: Constants.h:15
static FEDRawChannelUnpacker scopeModeUnpacker(const FEDChannel &channel)
static FEDRawChannelUnpacker virginRawModeUnpacker(const FEDChannel &channel)
static FEDBSChannelUnpacker zeroSuppressedModeUnpacker(const FEDChannel &channel, uint16_t num_bits)
static const char mlRawToDigi_[]
void push_back(T const &t)
Definition: EDCollection.h:67
char const * what() const override
Definition: Exception.cc:141
static FEDBSChannelUnpacker zeroSuppressedLiteModeUnpacker(const FEDChannel &channel, uint16_t num_bits)
static FEDBSChannelUnpacker virginRawModeUnpacker(const FEDChannel &channel, uint16_t num_bits)
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
static std::string const input
Definition: EdmProvDump.cc:44
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED8_TOPBOT
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED10
const sistrip::RunType & runType() const
std::vector< SiStripRawDigi > virgin_work_digis_
static const uint8_t PACKET_CODE_VIRGIN_RAW10
void readoutOrder(uint16_t &physical_order, uint16_t &readout_order)
order of strips
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
static void dumpRawData(uint16_t fed_id, const FEDRawData &, std::stringstream &)
dumps raw data to stdout (NB: payload is byte-swapped,headers/trailer are not).
void add(const std::string &message, const std::string &details="")
FedsConstIterRange fedIds() const
std::vector< SiStripRawDigi > scope_work_digis_
format
Some error handling for the usage.
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
Definition: SiStripDigi.h:12
static const uint8_t PACKET_CODE_VIRGIN_RAW8_TOPBOT
std::vector< SiStripRawDigi > proc_work_digis_
#define LogTrace(id)
void reserve(size_type n)
Definition: EDCollection.h:111
std::vector< SiStripRawDigi > cm_work_digis_
static const uint8_t PACKET_CODE_VIRGIN_RAW8_BOTBOT
static FEDZSChannelUnpacker zeroSuppressedLiteModeUnpacker(const FEDChannel &channel)
static const uint16_t FEDCH_PER_FEUNIT
static const uint16_t invalid_
Definition: Constants.h:16
ConnsConstIterRange fedConnections(uint16_t fed_id) const
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
std::vector< Registry > cm_work_registry_
A Digi for the silicon strip detector, containing only adc information, and suitable for storing raw ...
static const uint8_t PACKET_CODE_VIRGIN_RAW
std::vector< Registry > virgin_work_registry_
void sistrip::RawToDigiUnpacker::doAPVEmulatorCheck ( bool  do_APVEmulator_check)
inline

Definition at line 204 of file SiStripRawToDigiUnpacker.h.

204 { doAPVEmulatorCheck_ = do_APVEmulator_check; }
void sistrip::RawToDigiUnpacker::doFullCorruptBufferChecks ( bool  do_full_corrupt_buffer_checks)
inline

Definition at line 202 of file SiStripRawToDigiUnpacker.h.

202 { doFullCorruptBufferChecks_ = do_full_corrupt_buffer_checks; }
void sistrip::RawToDigiUnpacker::dumpRawData ( uint16_t  fed_id,
const FEDRawData buffer,
std::stringstream &  ss 
)
staticprivate

dumps raw data to stdout (NB: payload is byte-swapped,headers/trailer are not).

Definition at line 1154 of file SiStripRawToDigiUnpacker.cc.

References FEDRawData::data(), TauDecayModes::dec, relativeConstraints::empty, mps_fire::i, sistrip::invalid32_, and FEDRawData::size().

Referenced by createDigis().

1154  {
1155 
1156  ss << "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
1157  << " Dump of buffer for FED id " << fed_id << std::endl
1158  << " Buffer contains " << buffer.size()
1159  << " bytes (NB: payload is byte-swapped)" << std::endl;
1160 
1161  if ( false ) {
1162  uint32_t* buffer_u32 = reinterpret_cast<uint32_t*>( const_cast<unsigned char*>( buffer.data() ) );
1163  unsigned int empty = 0;
1164 
1165  ss << "Byte-> 4 5 6 7 0 1 2 3\n";
1166  for ( uint32_t i = 0; i < buffer.size()/8; i++ ) {
1167  unsigned int temp0 = buffer_u32[i*2] & sistrip::invalid32_;
1168  unsigned int temp1 = buffer_u32[i*2+1] & sistrip::invalid32_;
1169  if ( !temp0 && !temp1 ) { empty++; }
1170  else {
1171  if ( empty ) {
1172  ss << " [ empty words ]" << std::endl;
1173  empty = 0;
1174  }
1175  ss << std::dec
1176  << std::setfill(' ') << std::setw(6) << i*8 << ": "
1177  << std::hex
1178  << std::setfill('0') << std::setw(8) << temp0
1179  << std::setfill('0') << std::setw(8) << temp1
1180  << std::dec
1181  << std::endl;
1182  }
1183  }
1184 
1185  } else {
1186 
1187  ss << " Byte | <---- Byte order ----< | Byte" << std::endl;
1188  ss << " cntr | 7 6 5 4 3 2 1 0 | cntr" << std::endl;
1189  for ( uint32_t i = 0; i < buffer.size()/8; i++ ) {
1190  //if ( i>=20 && ((i+4)<(buffer.size()/8)) ) { continue; }
1191  uint16_t tmp0 = buffer.data()[i*8+0] & 0xFF;
1192  uint16_t tmp1 = buffer.data()[i*8+1] & 0xFF;
1193  uint16_t tmp2 = buffer.data()[i*8+2] & 0xFF;
1194  uint16_t tmp3 = buffer.data()[i*8+3] & 0xFF;
1195  uint16_t tmp4 = buffer.data()[i*8+4] & 0xFF;
1196  uint16_t tmp5 = buffer.data()[i*8+5] & 0xFF;
1197  uint16_t tmp6 = buffer.data()[i*8+6] & 0xFF;
1198  uint16_t tmp7 = buffer.data()[i*8+7] & 0xFF;
1199 // if ( !tmp0 && !tmp1 && !tmp2 && !tmp3 &&
1200 // !tmp4 && !tmp5 && !tmp6 && !tmp7 ) { empty++; }
1201 // else {
1202 // if ( empty ) {
1203 // ss << " [.."
1204 // << std::dec << std::setfill('.') << std::setw(4) << empty
1205 // << " null words....]" << std::endl;
1206 // empty = 0;
1207 // }
1208  ss << std::dec
1209  << std::setfill(' ') << std::setw(6) << i*8+7 << " : "
1210  << std::hex
1211  << std::setfill('0') << std::setw(2) << tmp7 << " "
1212  << std::setfill('0') << std::setw(2) << tmp6 << " "
1213  << std::setfill('0') << std::setw(2) << tmp5 << " "
1214  << std::setfill('0') << std::setw(2) << tmp4 << " "
1215  << std::setfill('0') << std::setw(2) << tmp3 << " "
1216  << std::setfill('0') << std::setw(2) << tmp2 << " "
1217  << std::setfill('0') << std::setw(2) << tmp1 << " "
1218  << std::setfill('0') << std::setw(2) << tmp0
1219  << std::dec
1220  << " :" << std::setfill(' ') << std::setw(6) << i*8
1221  << std::endl;
1222 // }
1223  }
1224 
1225  }
1226  ss << "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
1227  << " End of FED buffer";
1228  }
static const uint32_t invalid32_
Definition: Constants.h:15
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
void sistrip::RawToDigiUnpacker::extractCm ( bool  extract_cm)
inline

Definition at line 200 of file SiStripRawToDigiUnpacker.h.

200 { extractCm_ = extract_cm; }
sistrip::FedBufferFormat sistrip::RawToDigiUnpacker::fedBufferFormat ( const uint16_t &  register_value)
inlineprivate
sistrip::FedReadoutMode sistrip::RawToDigiUnpacker::fedReadoutMode ( const uint16_t &  register_value)
inlineprivate

returns buffer readout mode

Definition at line 191 of file SiStripRawToDigiUnpacker.h.

192 {
193  return static_cast<sistrip::FedReadoutMode>(register_value&0xF);
194 }
void sistrip::RawToDigiUnpacker::handleException ( std::string  method_name,
std::string  extra_info = "" 
)
private

catches all possible exceptions and rethrows them as cms::Exceptions

Definition at line 1230 of file SiStripRawToDigiUnpacker.cc.

References MillePedeFileConverter_cfg::e, cppFunctionSkipper::exception, edm::isDebugEnabled(), and sistrip::mlRawToDigi_.

1230  {
1231 
1232  method_name = "sistrip::RawToDigiUnpacker::" + method_name;
1233  try {
1234  throw; // rethrow caught exception to be dealt with below
1235  }
1236  catch ( const cms::Exception& e ) {
1237  //throw e; // rethrow cms::Exception to be caught by framework
1238  }
1239  catch ( const std::exception& e ) {
1240  if ( edm::isDebugEnabled() ) {
1241  std::stringstream ss;
1242  ss << "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
1243  << " Caught std::exception!" << std::endl;
1244  if ( !extra_info.empty() ) {
1245  ss << " Information: " << extra_info << std::endl;
1246  }
1247  ss << " Caught std::exception in ["
1248  << method_name << "] with message:" << std::endl
1249  << e.what();
1251  }
1252  //throw cms::Exception(sistrip::mlRawToDigi_) << ss.str();
1253  }
1254  catch (...) {
1255  if ( edm::isDebugEnabled() ) {
1256  std::stringstream ss;
1257  ss << "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
1258  << " Caught unknown exception!" << std::endl;
1259  if ( !extra_info.empty() ) {
1260  ss << " Information: " << extra_info << std::endl;
1261  }
1262  ss << "Caught unknown exception in ["
1263  << method_name << "]" << std::endl;
1265  }
1266  //throw cms::Exception(sistrip::mlRawToDigi_) << ss.str();
1267  }
1268  }
bool isDebugEnabled()
static const char mlRawToDigi_[]
void sistrip::RawToDigiUnpacker::legacy ( bool  legacy)
inline
void sistrip::RawToDigiUnpacker::locateStartOfFedBuffer ( const uint16_t &  fed_id,
const FEDRawData input,
FEDRawData output 
)

Removes any data appended prior to FED buffer and reorders 32-bit words if swapped.

Definition at line 973 of file SiStripRawToDigiUnpacker.cc.

References FEDRawData::data(), TauDecayModes::dec, runEdmFileComparison::found, headerBytes_, edm::isDebugEnabled(), LogTrace, sistrip::mlRawToDigi_, PFRecoTauDiscriminationByIsolation_cfi::offset, FEDRawData::resize(), and FEDRawData::size().

973  {
974 
975  // Check size of input buffer
976  if ( input.size() < 24 ) {
977  output.resize( input.size() ); // Return UNadjusted buffer start position and size
978  memcpy( output.data(), input.data(), input.size() );
979  if ( edm::isDebugEnabled() ) {
980  std::stringstream ss;
981  ss << "[sistrip::RawToDigiUnpacker::" << __func__ << "] "
982  << "Input FEDRawData with FED id " << fed_id
983  << " has size " << input.size();
985  }
986  return;
987  }
988 
989  // Iterator through buffer to find DAQ header
990  bool found = false;
991  uint16_t ichar = 0;
992  while ( ichar < input.size()-16 && !found ) {
993  uint16_t offset = headerBytes_ < 0 ? ichar : headerBytes_; // Negative value means use "search mode" to find DAQ header
994  uint32_t* input_u32 = reinterpret_cast<uint32_t*>( const_cast<unsigned char*>( input.data() ) + offset );
995  uint32_t* fed_trailer = reinterpret_cast<uint32_t*>( const_cast<unsigned char*>( input.data() ) + input.size() - 8 );
996 
997  // see info on FED 32-bit swapping at end-of-file
998 
999  bool old_vme_header = ( input_u32[0] & 0xF0000000 ) == 0x50000000 && ( fed_trailer[0] & 0xF0000000 ) == 0xA0000000 && ( (fed_trailer[0] & 0x00FFFFFF)*0x8 ) == (input.size() - offset);
1000 
1001  bool old_slink_header = ( input_u32[1] & 0xF0000000 ) == 0x50000000 && ( fed_trailer[1] & 0xF0000000 ) == 0xA0000000 && ( (fed_trailer[1] & 0x00FFFFFF)*0x8 ) == (input.size() - offset);
1002 
1003  bool old_slink_payload = ( input_u32[3] & 0xFF000000 ) == 0xED000000;
1004 
1005  bool new_buffer_format = ( input_u32[2] & 0xFF000000 ) == 0xC5000000;
1006 
1007  if ( old_vme_header ) {
1008 
1009  // Found DAQ header at byte position 'offset'
1010  found = true;
1011  output.resize( input.size()-offset );
1012  memcpy( output.data(), // target
1013  input.data()+offset, // source
1014  input.size()-offset ); // nbytes
1015  if ( headerBytes_ < 0 ) {
1016  if ( edm::isDebugEnabled() ) {
1017  std::stringstream ss;
1018  ss << "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
1019  << " Buffer for FED id " << fed_id
1020  << " has been found at byte position " << offset
1021  << " with a size of " << input.size()-offset << " bytes."
1022  << " Adjust the configurable 'AppendedBytes' to " << offset;
1023  LogTrace("SiStripRawToDigi") << ss.str();
1024  }
1025  }
1026 
1027  } else if ( old_slink_header ) {
1028 
1029  if ( old_slink_payload ) {
1030 
1031  // Found DAQ header (with MSB and LSB 32-bit words swapped) at byte position 'offset'
1032  found = true;
1033  output.resize( input.size()-offset );
1034  uint32_t* output_u32 = reinterpret_cast<uint32_t*>( const_cast<unsigned char*>( output.data() ) );
1035  uint16_t iter = offset;
1036  while ( iter < output.size() / sizeof(uint32_t) ) {
1037  output_u32[iter] = input_u32[iter+1];
1038  output_u32[iter+1] = input_u32[iter];
1039  iter+=2;
1040  }
1041  if ( headerBytes_ < 0 ) {
1042  if ( edm::isDebugEnabled() ) {
1043  std::stringstream ss;
1044  ss << "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
1045  << " Buffer (with MSB and LSB 32-bit words swapped) for FED id " << fed_id
1046  << " has been found at byte position " << offset
1047  << " with a size of " << output.size() << " bytes."
1048  << " Adjust the configurable 'AppendedBytes' to " << offset;
1049  LogTrace("SiStripRawToDigi") << ss.str();
1050  }
1051  }
1052 
1053  } else if ( new_buffer_format ) {
1054 
1055  // Found DAQ header at byte position 'offset'
1056  found = true;
1057  output.resize( input.size()-offset );
1058  memcpy( output.data(), // target
1059  input.data()+offset, // source
1060  input.size()-offset ); // nbytes
1061  if ( headerBytes_ < 0 ) {
1062  if ( edm::isDebugEnabled() ) {
1063  std::stringstream ss;
1064  ss << "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
1065  << " Buffer for FED id " << fed_id
1066  << " has been found at byte position " << offset
1067  << " with a size of " << input.size()-offset << " bytes."
1068  << " Adjust the configurable 'AppendedBytes' to " << offset;
1069  LogTrace("SiStripRawToDigi") << ss.str();
1070  }
1071  }
1072 
1073  } else { headerBytes_ < 0 ? found = false : found = true; }
1074  } else { headerBytes_ < 0 ? found = false : found = true; }
1075  ichar++;
1076  }
1077 
1078  // Check size of output buffer
1079  if ( output.size() == 0 ) {
1080 
1081  // Did not find DAQ header after search => return buffer with null size
1082  output.resize( 0 ); //@@ NULL SIZE
1083  memcpy( output.data(), input.data(), 0 ); //@@ NULL SIZE
1084  if ( edm::isDebugEnabled() ) {
1085  std::stringstream ss;
1086  if ( headerBytes_ < 0 ) {
1087  ss << "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
1088  << " DAQ header not found within buffer for FED id: " << fed_id;
1089  } else {
1090  uint32_t* input_u32 = reinterpret_cast<uint32_t*>( const_cast<unsigned char*>( input.data() ) );
1091  ss << "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
1092  << " DAQ header not found at expected location for FED id: " << fed_id << std::endl
1093  << " First 64-bit word of buffer is 0x"
1094  << std::hex
1095  << std::setfill('0') << std::setw(8) << input_u32[0]
1096  << std::setfill('0') << std::setw(8) << input_u32[1]
1097  << std::dec << std::endl
1098  << " Adjust 'AppendedBytes' configurable to '-1' to activate 'search mode'";
1099  }
1101  }
1102 
1103  } else if ( output.size() < 24 ) { // Found DAQ header after search, but too few words
1104 
1105  if ( edm::isDebugEnabled() ) {
1106  std::stringstream ss;
1107  ss << "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
1108  << " Unexpected buffer size! FEDRawData with FED id " << fed_id
1109  << " has size " << output.size();
1111  }
1112  }
1113  }
bool isDebugEnabled()
static const char mlRawToDigi_[]
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
void resize(size_t newsize)
Definition: FEDRawData.cc:32
#define LogTrace(id)
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
void sistrip::RawToDigiUnpacker::physicalOrder ( uint16_t &  readout_order,
uint16_t &  physical_order 
)
inlineprivate

order of strips

Definition at line 178 of file SiStripRawToDigiUnpacker.h.

179 {
180  physical_order = ( (32 * (readout_order%4)) + (8 * static_cast<uint16_t>(static_cast<float>(readout_order)/4.0)) - (31 * static_cast<uint16_t>(static_cast<float>(readout_order)/16.0)) );
181 }
void sistrip::RawToDigiUnpacker::printWarningSummary ( ) const
inline
void sistrip::RawToDigiUnpacker::quiet ( bool  quiet)
inline

verbosity

Definition at line 196 of file SiStripRawToDigiUnpacker.h.

void sistrip::RawToDigiUnpacker::readoutOrder ( uint16_t &  physical_order,
uint16_t &  readout_order 
)
inlineprivate

order of strips

Definition at line 173 of file SiStripRawToDigiUnpacker.h.

Referenced by createDigis().

174 {
175  readout_order = ( 4*((static_cast<uint16_t>((static_cast<float>(physical_order)/8.0)))%4) + static_cast<uint16_t>(static_cast<float>(physical_order)/32.0) + 16*(physical_order%8) );
176 }
void sistrip::RawToDigiUnpacker::triggerFed ( const FEDRawDataCollection buffers,
SiStripEventSummary summary,
const uint32_t &  event 
)

trigger info

Definition at line 855 of file SiStripRawToDigiUnpacker.cc.

References SiStripEventSummary::bx(), SiStripEventSummary::commissioningInfo(), FEDRawData::data(), SiStripEventSummary::event(), FEDRawDataCollection::FEDData(), TFHeaderDescription::getBunchCrossing(), TFHeaderDescription::getFedEventNumber(), RecoTauValidation_cfi::header, edm::isDebugEnabled(), SiStripEventSummary::isSet(), FEDNumbering::lastFEDId(), FEDHeader::length, FEDTrailer::length, LogTrace, sistrip::mlRawToDigi_, once_, FEDRawData::size(), heppy_report::summary, groupFilesInBlocks::temp, SiStripEventSummary::triggerFed(), and triggerFedId_.

Referenced by sistrip::RawToDigiModule::produce().

855  {
856 
857  // Pointer to data (recast as 32-bit words) and number of 32-bit words
858  uint32_t* data_u32 = nullptr;
859  uint32_t size_u32 = 0;
860 
861  // Search mode
862  if ( triggerFedId_ < 0 ) {
863 
864  uint16_t ifed = 0;
865  while ( triggerFedId_ < 0 &&
866  ifed < 1 + FEDNumbering::lastFEDId() ) {
867  const FEDRawData& trigger_fed = buffers.FEDData( ifed );
868  if ( trigger_fed.data() && trigger_fed.size() ) {
869  uint8_t* temp = const_cast<uint8_t*>( trigger_fed.data() );
870  data_u32 = reinterpret_cast<uint32_t*>( temp ) + FEDHeader::length/sizeof(uint32_t) + 1;
871  size_u32 = trigger_fed.size()/sizeof(uint32_t) - FEDHeader::length/sizeof(uint32_t) - 1;
872  const FEDTrailer fedTrailer( temp + trigger_fed.size() - FEDTrailer::length );
873  if ( fedTrailer.conscheck() == 0xDEADFACE ) {
874  triggerFedId_ = ifed;
875  if ( edm::isDebugEnabled() ) {
876  std::stringstream ss;
877  ss << "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
878  << " Search mode for 'trigger FED' activated!"
879  << " Found 'trigger FED' info with id " << triggerFedId_;
880  LogTrace("SiStripRawToDigi") << ss.str();
881  }
882  }
883  }
884  ifed++;
885  }
886  if ( triggerFedId_ < 0 ) {
887  triggerFedId_ = 0;
888  if ( edm::isDebugEnabled() ) {
889  std::stringstream ss;
890  ss << "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
891  << " Search mode for 'trigger FED' activated!"
892  << " 'Trigger FED' info not found!";
894  }
895  }
896  }
897 
898  // "Trigger FED" id given in .cfg file
899  else if ( triggerFedId_ > 0 ) {
900 
901  const FEDRawData& trigger_fed = buffers.FEDData( triggerFedId_ );
902  if ( trigger_fed.data() && trigger_fed.size() ) {
903  uint8_t* temp = const_cast<uint8_t*>( trigger_fed.data() );
904  data_u32 = reinterpret_cast<uint32_t*>( temp ) + FEDHeader::length/sizeof(uint32_t) + 1;
905  size_u32 = trigger_fed.size()/sizeof(uint32_t) - FEDHeader::length/sizeof(uint32_t) - 1;
906  const FEDTrailer fedTrailer( temp + trigger_fed.size() - FEDTrailer::length );
907  if ( fedTrailer.conscheck() != 0xDEADFACE ) {
908  if ( edm::isDebugEnabled() ) {
910  << "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
911  << " Unexpected stamp found in DAQ trailer (ie, not 0xDEADFACE)!"
912  << " Buffer appears not to contain 'trigger FED' data!";
913  }
914  triggerFedId_ = 0;
915  }
916  }
917 
918  } else {
919  triggerFedId_ = 0;
920  data_u32 = nullptr;
921  size_u32 = 0;
922  }
923 
924  // Populate summary object with commissioning information
925  if ( triggerFedId_ > 0 ) {
926 
927  // Some checks
928  if ( !data_u32 ) {
929  if ( edm::isDebugEnabled() ) {
930  std::stringstream ss;
931  ss << "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
932  << " NULL pointer to 'trigger FED' data";
934  }
935  return;
936  }
937  if ( size_u32 < sizeof(TFHeaderDescription)/sizeof(uint32_t) ) {
938  if ( edm::isDebugEnabled() ) {
939  std::stringstream ss;
940  ss << "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
941  << " Unexpected 'Trigger FED' data size [32-bit words]: " << size_u32;
943  }
944  return;
945  }
946 
947  // Write event-specific data to event
949  summary.event( static_cast<uint32_t>( header->getFedEventNumber()) );
950  summary.bx( static_cast<uint32_t>( header->getBunchCrossing()) );
951 
952  // Write commissioning information to event
953  uint32_t hsize = sizeof(TFHeaderDescription)/sizeof(uint32_t);
954  uint32_t* head = &data_u32[hsize];
955  summary.commissioningInfo( head, event );
956  summary.triggerFed( triggerFedId_ );
957 
958  }
959 
960  // Some debug
961  if ( summary.isSet() && once_ ) {
962  if ( edm::isDebugEnabled() ) {
963  std::stringstream ss;
964  ss << "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
965  << " EventSummary built from \"trigger FED\":"
966  << std::endl << summary;
967  LogTrace("SiStripRawToDigi") << ss.str();
968  }
969  once_ = false;
970  }
971  }
bool isDebugEnabled()
static const uint32_t length
Definition: FEDTrailer.h:61
static const uint32_t length
Definition: FEDHeader.h:54
static const char mlRawToDigi_[]
unsigned long getBunchCrossing()
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
unsigned long getFedEventNumber()
const uint32_t & bx() const
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void commissioningInfo(const uint32_t *const buffer, const uint32_t &event)
const uint32_t & event() const
#define LogTrace(id)
static int lastFEDId()
Definition: FEDNumbering.cc:17
uint16_t triggerFed() const
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
Definition: event.py:1
void sistrip::RawToDigiUnpacker::update ( RawDigis scope_mode,
RawDigis virgin_raw,
RawDigis proc_raw,
Digis zero_suppr,
RawDigis common_mode 
)
private

fill DetSetVectors using registries

Definition at line 578 of file SiStripRawToDigiUnpacker.cc.

References cm_work_digis_, cm_work_registry_, popcon2dropbox::copy(), end, Exception, extractCm_, min(), proc_work_digis_, proc_work_registry_, scope_work_digis_, scope_work_registry_, edm::DetSetVector< T >::swap(), virgin_work_digis_, virgin_work_registry_, zs_work_digis_, and zs_work_registry_.

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), Vispa.Gui.VispaWidget.VispaWidget::autosize(), createDigis(), Vispa.Views.LineDecayView.LineDecayContainer::createObject(), Vispa.Views.LineDecayView.LineDecayContainer::deselectAllObjects(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::deselectAllWidgets(), Vispa.Gui.VispaWidget.VispaWidget::enableAutosizing(), progressbar.ProgressBar::finish(), Vispa.Gui.MenuWidget.MenuWidget::leaveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseMoveEvent(), Vispa.Gui.MenuWidget.MenuWidget::mouseMoveEvent(), Vispa.Views.LineDecayView.LineDecayContainer::mouseMoveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner::mouseReleaseEvent(), Vispa.Views.LineDecayView.LineDecayContainer::objectMoved(), MatrixUtil.Steps::overwrite(), Vispa.Views.LineDecayView.LineDecayContainer::removeObject(), Vispa.Gui.ConnectableWidget.ConnectableWidget::removePorts(), Vispa.Gui.FindDialog.FindDialog::reset(), Vispa.Gui.PortConnection.PointToPointConnection::select(), Vispa.Gui.VispaWidget.VispaWidget::select(), Vispa.Views.LineDecayView.LineDecayContainer::select(), Vispa.Gui.VispaWidget.VispaWidget::setText(), Vispa.Gui.VispaWidget.VispaWidget::setTitle(), Vispa.Gui.ZoomableWidget.ZoomableWidget::setZoom(), Vispa.Views.LineDecayView.LineDecayContainer::setZoom(), and Vispa.Gui.PortConnection.PointToPointConnection::updateConnection().

578  {
579 
580  if ( ! zs_work_registry_.empty() ) {
581  std::sort( zs_work_registry_.begin(), zs_work_registry_.end() );
582  std::vector< edm::DetSet<SiStripDigi> > sorted_and_merged;
583  sorted_and_merged.reserve( std::min(zs_work_registry_.size(), size_t(17000)) );
584 
585  bool errorInData = false;
586  std::vector<Registry>::iterator it = zs_work_registry_.begin(), it2 = it+1, end = zs_work_registry_.end();
587  while (it < end) {
588  sorted_and_merged.push_back( edm::DetSet<SiStripDigi>(it->detid) );
589  std::vector<SiStripDigi> & digis = sorted_and_merged.back().data;
590  // first count how many digis we have
591  size_t len = it->length;
592  for (it2 = it+1; (it2 != end) && (it2->detid == it->detid); ++it2) { len += it2->length; }
593  // reserve memory
594  digis.reserve(len);
595  // push them in
596  for (it2 = it+0; (it2 != end) && (it2->detid == it->detid); ++it2) {
597  digis.insert( digis.end(), & zs_work_digis_[it2->index], & zs_work_digis_[it2->index + it2->length] );
598  }
599  it = it2;
600  }
601 
602  // check sorting
603  if (!__gnu_cxx::is_sorted( sorted_and_merged.begin(), sorted_and_merged.end() )) {
604  // this is an error in the code: i DID sort it already!
605  throw cms::Exception("Bug Found")
606  << "Container must be already sorted!\nat "
607  << __FILE__
608  << ", line "
609  << __LINE__
610  <<"\n";
611  }
612 
613  std::vector< edm::DetSet<SiStripDigi> >::iterator iii = sorted_and_merged.begin();
614  std::vector< edm::DetSet<SiStripDigi> >::iterator jjj = sorted_and_merged.end();
615  for ( ; iii != jjj; ++iii ) {
616  if ( ! __gnu_cxx::is_sorted( iii->begin(), iii->end() ) ) {
617  // this might be an error in the data, if the raws from one FED are not sorted
618  iii->clear();
619  errorInData = true;
620  }
621  }
622 
623  // output error
624  if (errorInData) edm::LogWarning("CorruptData") << "Some modules contained corrupted ZS raw data, and have been skipped in unpacking\n";
625 
626  // make output DetSetVector
627  edm::DetSetVector<SiStripDigi> zero_suppr_dsv( sorted_and_merged, true );
628  zero_suppr.swap( zero_suppr_dsv );
629  }
630 
631  // Populate final DetSetVector container with VR data
632  if ( !virgin_work_registry_.empty() ) {
633 
634  std::sort( virgin_work_registry_.begin(), virgin_work_registry_.end() );
635 
636  std::vector< edm::DetSet<SiStripRawDigi> > sorted_and_merged;
637  sorted_and_merged.reserve( std::min(virgin_work_registry_.size(), size_t(17000)) );
638 
639  bool errorInData = false;
640  std::vector<Registry>::iterator it = virgin_work_registry_.begin(), it2, end = virgin_work_registry_.end();
641  while (it < end) {
642  sorted_and_merged.push_back( edm::DetSet<SiStripRawDigi>(it->detid) );
643  std::vector<SiStripRawDigi> & digis = sorted_and_merged.back().data;
644 
645  bool isDetOk = true;
646  // first count how many digis we have
647  int maxFirstStrip = it->first;
648  for (it2 = it+1; (it2 != end) && (it2->detid == it->detid); ++it2) {
649  // duplicated APV or data corruption. DO NOT 'break' here!
650  if (it2->first <= maxFirstStrip) { isDetOk = false; continue; }
651  maxFirstStrip = it2->first;
652  }
653  if (!isDetOk) { errorInData = true; it = it2; continue; } // skip whole det
654 
655  // make room for 256 * (max_apv_pair + 1) Raw Digis
656  digis.resize(maxFirstStrip + 256);
657  // push them in
658  for (it2 = it+0; (it2 != end) && (it2->detid == it->detid); ++it2) {
659  // data corruption. DO NOT 'break' here
660  if (it->length != 256) { isDetOk = false; continue; }
661  std::copy( & virgin_work_digis_[it2->index], & virgin_work_digis_[it2->index + it2->length], & digis[it2->first] );
662  }
663  if (!isDetOk) { errorInData = true; digis.clear(); it = it2; continue; } // skip whole det
664  it = it2;
665  }
666 
667  // output error
668  if (errorInData) edm::LogWarning("CorruptData") << "Some modules contained corrupted virgin raw data, and have been skipped in unpacking\n";
669 
670  // check sorting
671  if ( !__gnu_cxx::is_sorted( sorted_and_merged.begin(), sorted_and_merged.end() ) ) {
672  // this is an error in the code: i DID sort it already!
673  throw cms::Exception("Bug Found")
674  << "Container must be already sorted!\nat "
675  << __FILE__
676  << ", line "
677  << __LINE__
678  <<"\n";
679  }
680 
681  // make output DetSetVector
682  edm::DetSetVector<SiStripRawDigi> virgin_raw_dsv( sorted_and_merged, true );
683  virgin_raw.swap( virgin_raw_dsv );
684  }
685 
686  // Populate final DetSetVector container with VR data
687  if ( !proc_work_registry_.empty() ) {
688  std::sort( proc_work_registry_.begin(), proc_work_registry_.end() );
689 
690  std::vector< edm::DetSet<SiStripRawDigi> > sorted_and_merged;
691  sorted_and_merged.reserve( std::min(proc_work_registry_.size(), size_t(17000)) );
692 
693  bool errorInData = false;
694  std::vector<Registry>::iterator it = proc_work_registry_.begin(), it2, end = proc_work_registry_.end();
695  while (it < end) {
696  sorted_and_merged.push_back( edm::DetSet<SiStripRawDigi>(it->detid) );
697  std::vector<SiStripRawDigi> & digis = sorted_and_merged.back().data;
698 
699  bool isDetOk = true;
700  // first count how many digis we have
701  int maxFirstStrip = it->first;
702  for (it2 = it+1; (it2 != end) && (it2->detid == it->detid); ++it2) {
703  // duplicated APV or data corruption. DO NOT 'break' here!
704  if (it2->first <= maxFirstStrip) { isDetOk = false; continue; }
705  maxFirstStrip = it2->first;
706  }
707  // skip whole det
708  if (!isDetOk) { errorInData = true; it = it2; continue; }
709 
710  // make room for 256 * (max_apv_pair + 1) Raw Digis
711  digis.resize(maxFirstStrip + 256);
712  // push them in
713  for (it2 = it+0; (it2 != end) && (it2->detid == it->detid); ++it2) {
714  // data corruption. DO NOT 'break' here
715  if (it->length != 256) { isDetOk = false; continue; }
716  std::copy( & proc_work_digis_[it2->index], & proc_work_digis_[it2->index + it2->length], & digis[it2->first] );
717  }
718  // skip whole det
719  if (!isDetOk) { errorInData = true; digis.clear(); it = it2; continue; }
720  it = it2;
721  }
722 
723  // output error
724  if (errorInData) edm::LogWarning("CorruptData") << "Some modules contained corrupted proc raw data, and have been skipped in unpacking\n";
725 
726  // check sorting
727  if ( !__gnu_cxx::is_sorted( sorted_and_merged.begin(), sorted_and_merged.end() ) ) {
728  // this is an error in the code: i DID sort it already!
729  throw cms::Exception("Bug Found")
730  << "Container must be already sorted!\nat "
731  << __FILE__
732  << ", line "
733  << __LINE__
734  <<"\n";
735  }
736 
737  // make output DetSetVector
738  edm::DetSetVector<SiStripRawDigi> proc_raw_dsv( sorted_and_merged, true );
739  proc_raw.swap( proc_raw_dsv );
740  }
741 
742  // Populate final DetSetVector container with SM data
743  if ( !scope_work_registry_.empty() ) {
744  std::sort( scope_work_registry_.begin(), scope_work_registry_.end() );
745 
746  std::vector< edm::DetSet<SiStripRawDigi> > sorted_and_merged;
747  sorted_and_merged.reserve( scope_work_registry_.size() );
748 
749  bool errorInData = false;
750  std::vector<Registry>::iterator it, end;
751  for (it = scope_work_registry_.begin(), end = scope_work_registry_.end() ; it != end; ++it) {
752  sorted_and_merged.push_back( edm::DetSet<SiStripRawDigi>(it->detid) );
753  std::vector<SiStripRawDigi> & digis = sorted_and_merged.back().data;
754  digis.insert( digis.end(), & scope_work_digis_[it->index], & scope_work_digis_[it->index + it->length] );
755 
756  if ( (it +1 != end) && (it->detid == (it+1)->detid) ) {
757  errorInData = true;
758  // let's skip *all* the detsets for that key, as we don't know which is the correct one!
759  do { ++it; } while ( ( it+1 != end) && (it->detid == (it+1)->detid) );
760  }
761  }
762 
763  // output error
764  if (errorInData) edm::LogWarning("CorruptData") << "Some fed keys contained corrupted scope mode data, and have been skipped in unpacking\n";
765 
766  // check sorting
767  if ( !__gnu_cxx::is_sorted( sorted_and_merged.begin(), sorted_and_merged.end() ) ) {
768  // this is an error in the code: i DID sort it already!
769  throw cms::Exception("Bug Found")
770  << "Container must be already sorted!\nat "
771  << __FILE__
772  << ", line "
773  << __LINE__
774  <<"\n";
775  }
776 
777  // make output DetSetVector
778  edm::DetSetVector<SiStripRawDigi> scope_mode_dsv( sorted_and_merged, true );
779  scope_mode.swap( scope_mode_dsv );
780  }
781 
782  // Populate DetSetVector with Common Mode values
783  if ( extractCm_ ) {
784 
785  // Populate final DetSetVector container with VR data
786  if ( !cm_work_registry_.empty() ) {
787 
788  std::sort( cm_work_registry_.begin(), cm_work_registry_.end() );
789 
790  std::vector< edm::DetSet<SiStripRawDigi> > sorted_and_merged;
791  sorted_and_merged.reserve( std::min(cm_work_registry_.size(), size_t(17000)) );
792 
793  bool errorInData = false;
794  std::vector<Registry>::iterator it = cm_work_registry_.begin(), it2, end = cm_work_registry_.end();
795  while (it < end) {
796  sorted_and_merged.push_back( edm::DetSet<SiStripRawDigi>(it->detid) );
797  std::vector<SiStripRawDigi> & digis = sorted_and_merged.back().data;
798 
799  bool isDetOk = true;
800  // first count how many digis we have
801  int maxFirstStrip = it->first;
802  for (it2 = it+1; (it2 != end) && (it2->detid == it->detid); ++it2) {
803  // duplicated APV or data corruption. DO NOT 'break' here!
804  if (it2->first <= maxFirstStrip) { isDetOk = false; continue; }
805  maxFirstStrip = it2->first;
806  }
807  if (!isDetOk) { errorInData = true; it = it2; continue; } // skip whole det
808 
809  // make room for 2 * (max_apv_pair + 1) Common mode values
810  digis.resize(maxFirstStrip + 2);
811  // push them in
812  for (it2 = it+0; (it2 != end) && (it2->detid == it->detid); ++it2) {
813  // data corruption. DO NOT 'break' here
814  if (it->length != 2) { isDetOk = false; continue; }
815  std::copy( & cm_work_digis_[it2->index], & cm_work_digis_[it2->index + it2->length], & digis[it2->first] );
816  }
817  if (!isDetOk) { errorInData = true; digis.clear(); it = it2; continue; } // skip whole det
818  it = it2;
819  }
820 
821  // output error
822  if (errorInData) edm::LogWarning("CorruptData") << "Some modules contained corrupted common mode data, and have been skipped in unpacking\n";
823 
824  // check sorting
825  if ( !__gnu_cxx::is_sorted( sorted_and_merged.begin(), sorted_and_merged.end() ) ) {
826  // this is an error in the code: i DID sort it already!
827  throw cms::Exception("Bug Found")
828  << "Container must be already sorted!\nat "
829  << __FILE__
830  << ", line "
831  << __LINE__
832  <<"\n";
833  }
834 
835  // make output DetSetVector
836  edm::DetSetVector<SiStripRawDigi> common_mode_dsv( sorted_and_merged, true );
837  common_mode.swap( common_mode_dsv );
838  }
839 
840  }
841 
842  }
std::vector< Registry > proc_work_registry_
std::vector< SiStripDigi > zs_work_digis_
digi collections
std::vector< Registry > scope_work_registry_
def copy(args, dbName)
std::vector< Registry > zs_work_registry_
registries
std::vector< SiStripRawDigi > virgin_work_digis_
std::vector< SiStripRawDigi > scope_work_digis_
#define end
Definition: vmac.h:39
T min(T a, T b)
Definition: MathUtil.h:58
std::vector< SiStripRawDigi > proc_work_digis_
std::vector< SiStripRawDigi > cm_work_digis_
std::vector< Registry > cm_work_registry_
std::vector< Registry > virgin_work_registry_
void sistrip::RawToDigiUnpacker::updateEventSummary ( const sistrip::FEDBuffer fed,
SiStripEventSummary summary 
)
private

sets the SiStripEventSummary -> not yet implemented for FEDBuffer class

Definition at line 1115 of file SiStripRawToDigiUnpacker.cc.

References SiStripEventSummary::bx(), sistrip::FEDDAQHeader::bxID(), SiStripEventSummary::commissioningInfo(), sistrip::FEDBufferBase::daqEventType(), sistrip::FEDBufferBase::daqHeader(), sistrip::FEDFullDebugHeader::daqRegister(), sistrip::FEDFullDebugHeader::daqRegister2(), SiStripEventSummary::event(), SiStripEventSummary::fedReadoutMode(), sistrip::FEDBuffer::feHeader(), RecoTauValidation_cfi::header, sistrip::HEADER_TYPE_FULL_DEBUG, sistrip::FEDBufferBase::headerType(), sistrip::invalid32_, edm::isDebugEnabled(), SiStripEventSummary::isSet(), sistrip::FEDDAQHeader::l1ID(), LogTrace, once_, heppy_report::summary, SiStripEventSummary::triggerFed(), and triggerFedId_.

Referenced by createDigis().

1115  {
1116 
1117  summary.event(fed.daqHeader().l1ID());
1118  summary.bx(fed.daqHeader().bxID());
1119 
1120  // Retrieve contents of DAQ registers
1121 
1122  sistrip::FEDDAQEventType readout_mode = fed.daqEventType();
1123  uint32_t daq1 = sistrip::invalid32_;
1124  uint32_t daq2 = sistrip::invalid32_;
1125 
1127  const sistrip::FEDFullDebugHeader* header = nullptr;
1128  header = dynamic_cast<const sistrip::FEDFullDebugHeader*>(fed.feHeader());
1129  daq1 = static_cast<uint32_t>( header->daqRegister() );
1130  daq2 = static_cast<uint32_t>( header->daqRegister2() );
1131  }
1132 
1133 
1134  // If FED DAQ registers contain info, update (and possibly overwrite) EventSummary
1135  if ( daq1 != 0 && daq1 != sistrip::invalid32_ ) {
1136 
1137  summary.triggerFed( triggerFedId_ );
1138  summary.fedReadoutMode( readout_mode );
1139  summary.commissioningInfo( daq1, daq2 );
1140 
1141  if ( summary.isSet() && once_ ) {
1142  if ( edm::isDebugEnabled() ) {
1143  std::stringstream ss;
1144  ss << "[sistrip::RawToDigiUnpacker::" << __func__ << "]"
1145  << " EventSummary built from FED DAQ registers:"
1146  << std::endl << summary;
1147  LogTrace("SiStripRawToDigi") << ss.str();
1148  }
1149  once_ = false;
1150  }
1151  }
1152  }
bool isDebugEnabled()
static const uint32_t invalid32_
Definition: Constants.h:15
const FEDFEHeader * feHeader() const
FEDDAQEventType daqEventType() const
const uint32_t & bx() const
void commissioningInfo(const uint32_t *const buffer, const uint32_t &event)
const uint32_t & event() const
FEDHeaderType headerType() const
#define LogTrace(id)
uint16_t triggerFed() const
const sistrip::FedReadoutMode & fedReadoutMode() const
void sistrip::RawToDigiUnpacker::useDaqRegister ( bool  use)
inline

EventSummary update request -> not yet implemented for FEDBuffer class.

Definition at line 198 of file SiStripRawToDigiUnpacker.h.

Friends And Related Function Documentation

friend class RawToClustersLazyUnpacker
friend

Definition at line 31 of file SiStripRawToDigiUnpacker.h.

Member Data Documentation

std::vector<SiStripRawDigi> sistrip::RawToDigiUnpacker::cm_work_digis_
private

Definition at line 150 of file SiStripRawToDigiUnpacker.h.

Referenced by cleanupWorkVectors(), createDigis(), and update().

std::vector<Registry> sistrip::RawToDigiUnpacker::cm_work_registry_
private

Definition at line 143 of file SiStripRawToDigiUnpacker.h.

Referenced by cleanupWorkVectors(), createDigis(), and update().

bool sistrip::RawToDigiUnpacker::doAPVEmulatorCheck_
private

Definition at line 134 of file SiStripRawToDigiUnpacker.h.

Referenced by createDigis().

bool sistrip::RawToDigiUnpacker::doFullCorruptBufferChecks_
private

Definition at line 133 of file SiStripRawToDigiUnpacker.h.

Referenced by createDigis().

uint32_t sistrip::RawToDigiUnpacker::errorThreshold_
private

Definition at line 136 of file SiStripRawToDigiUnpacker.h.

Referenced by createDigis().

uint32_t sistrip::RawToDigiUnpacker::event_
private

other values

Definition at line 127 of file SiStripRawToDigiUnpacker.h.

Referenced by createDigis().

bool sistrip::RawToDigiUnpacker::extractCm_
private

Definition at line 132 of file SiStripRawToDigiUnpacker.h.

Referenced by createDigis(), and update().

int16_t sistrip::RawToDigiUnpacker::fedBufferDumpFreq_
private

Definition at line 119 of file SiStripRawToDigiUnpacker.h.

Referenced by createDigis().

int16_t sistrip::RawToDigiUnpacker::fedEventDumpFreq_
private

Definition at line 120 of file SiStripRawToDigiUnpacker.h.

Referenced by createDigis().

bool sistrip::RawToDigiUnpacker::first_
private

Definition at line 129 of file SiStripRawToDigiUnpacker.h.

Referenced by createDigis().

int16_t sistrip::RawToDigiUnpacker::headerBytes_
private

configurables

Definition at line 118 of file SiStripRawToDigiUnpacker.h.

Referenced by locateStartOfFedBuffer().

bool sistrip::RawToDigiUnpacker::legacy_
private

Definition at line 135 of file SiStripRawToDigiUnpacker.h.

Referenced by createDigis().

bool sistrip::RawToDigiUnpacker::markMissingFeds_
private

Definition at line 124 of file SiStripRawToDigiUnpacker.h.

bool sistrip::RawToDigiUnpacker::once_
private

Definition at line 128 of file SiStripRawToDigiUnpacker.h.

Referenced by triggerFed(), and updateEventSummary().

std::vector<SiStripRawDigi> sistrip::RawToDigiUnpacker::proc_work_digis_
private

Definition at line 149 of file SiStripRawToDigiUnpacker.h.

Referenced by cleanupWorkVectors(), createDigis(), and update().

std::vector<Registry> sistrip::RawToDigiUnpacker::proc_work_registry_
private

Definition at line 142 of file SiStripRawToDigiUnpacker.h.

Referenced by cleanupWorkVectors(), createDigis(), and update().

bool sistrip::RawToDigiUnpacker::quiet_
private

Definition at line 131 of file SiStripRawToDigiUnpacker.h.

Referenced by createDigis().

std::vector<SiStripRawDigi> sistrip::RawToDigiUnpacker::scope_work_digis_
private

Definition at line 148 of file SiStripRawToDigiUnpacker.h.

Referenced by cleanupWorkVectors(), createDigis(), and update().

std::vector<Registry> sistrip::RawToDigiUnpacker::scope_work_registry_
private

Definition at line 141 of file SiStripRawToDigiUnpacker.h.

Referenced by cleanupWorkVectors(), createDigis(), and update().

int16_t sistrip::RawToDigiUnpacker::triggerFedId_
private

Definition at line 121 of file SiStripRawToDigiUnpacker.h.

Referenced by createDigis(), triggerFed(), and updateEventSummary().

bool sistrip::RawToDigiUnpacker::unpackBadChannels_
private

Definition at line 123 of file SiStripRawToDigiUnpacker.h.

Referenced by createDigis(), and RawToDigiUnpacker().

bool sistrip::RawToDigiUnpacker::useDaqRegister_
private

Definition at line 130 of file SiStripRawToDigiUnpacker.h.

Referenced by createDigis().

bool sistrip::RawToDigiUnpacker::useFedKey_
private

Definition at line 122 of file SiStripRawToDigiUnpacker.h.

Referenced by createDigis().

std::vector<SiStripRawDigi> sistrip::RawToDigiUnpacker::virgin_work_digis_
private

Definition at line 147 of file SiStripRawToDigiUnpacker.h.

Referenced by cleanupWorkVectors(), createDigis(), and update().

std::vector<Registry> sistrip::RawToDigiUnpacker::virgin_work_registry_
private

Definition at line 140 of file SiStripRawToDigiUnpacker.h.

Referenced by cleanupWorkVectors(), createDigis(), and update().

WarningSummary sistrip::RawToDigiUnpacker::warnings_
private

Definition at line 169 of file SiStripRawToDigiUnpacker.h.

Referenced by createDigis().

std::vector<SiStripDigi> sistrip::RawToDigiUnpacker::zs_work_digis_
private

digi collections

Definition at line 146 of file SiStripRawToDigiUnpacker.h.

Referenced by cleanupWorkVectors(), createDigis(), and update().

std::vector<Registry> sistrip::RawToDigiUnpacker::zs_work_registry_
private

registries

Definition at line 139 of file SiStripRawToDigiUnpacker.h.

Referenced by cleanupWorkVectors(), createDigis(), and update().