CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
sistrip::DigiToRaw Class Reference

Input: edm::DetSetVector<SiStripDigi>. Output: FEDRawDataCollection. More...

#include <SiStripDigiToRaw.h>

Public Member Functions

void createFedBuffers (edm::Event &, edm::ESHandle< SiStripFedCabling > &cabling, edm::Handle< edm::DetSetVector< SiStripDigi > > &digis, std::unique_ptr< FEDRawDataCollection > &buffers)
 
void createFedBuffers (edm::Event &, edm::ESHandle< SiStripFedCabling > &cabling, edm::Handle< edm::DetSetVector< SiStripRawDigi > > &digis, std::unique_ptr< FEDRawDataCollection > &buffers)
 
void createFedBuffers (edm::Event &, edm::ESHandle< SiStripFedCabling > &cabling, edm::Handle< FEDRawDataCollection > &rawbuffers, edm::Handle< edm::DetSetVector< SiStripDigi > > &digis, std::unique_ptr< FEDRawDataCollection > &buffers)
 
void createFedBuffers (edm::Event &, edm::ESHandle< SiStripFedCabling > &cabling, edm::Handle< FEDRawDataCollection > &rawbuffers, edm::Handle< edm::DetSetVector< SiStripRawDigi > > &digis, std::unique_ptr< FEDRawDataCollection > &buffers)
 
 DigiToRaw (FEDReadoutMode mode, uint8_t packetCode, bool use_fed_key)
 
void fedReadoutMode (FEDReadoutMode mode)
 
void printWarningSummary () const
 
 ~DigiToRaw ()
 

Private Member Functions

template<class Digi_t >
void createFedBuffers_ (edm::Event &, edm::ESHandle< SiStripFedCabling > &cabling, edm::Handle< edm::DetSetVector< Digi_t > > &digis, std::unique_ptr< FEDRawDataCollection > &buffers, bool zeroSuppressed)
 
template<class Digi_t >
void createFedBuffers_ (edm::Event &, edm::ESHandle< SiStripFedCabling > &cabling, edm::Handle< FEDRawDataCollection > &rawbuffers, edm::Handle< edm::DetSetVector< Digi_t > > &digis, std::unique_ptr< FEDRawDataCollection > &buffers, bool zeroSuppressed)
 
uint16_t STRIP (const edm::DetSet< SiStripDigi >::const_iterator &it, const edm::DetSet< SiStripDigi >::const_iterator &begin) const
 
uint16_t STRIP (const edm::DetSet< SiStripRawDigi >::const_iterator &it, const edm::DetSet< SiStripRawDigi >::const_iterator &begin) const
 

Private Attributes

FEDBufferGenerator bufferGenerator_
 
FEDReadoutMode mode_
 
uint8_t packetCode_
 
bool useFedKey_
 
WarningSummary warnings_
 

Detailed Description

Input: edm::DetSetVector<SiStripDigi>. Output: FEDRawDataCollection.

Definition at line 29 of file SiStripDigiToRaw.h.

Constructor & Destructor Documentation

sistrip::DigiToRaw::DigiToRaw ( FEDReadoutMode  mode,
uint8_t  packetCode,
bool  use_fed_key 
)

Definition at line 22 of file SiStripDigiToRaw.cc.

References bufferGenerator_, edm::isDebugEnabled(), LogDebug, mode_, and sistrip::FEDBufferGenerator::setReadoutMode().

24  :
25  mode_(mode),
26  packetCode_(packetCode),
27  useFedKey_(useFedKey),
29  warnings_("DigiToRaw", "[sistrip::DigiToRaw::createFedBuffers_]", edm::isDebugEnabled())
30  {
31  if ( edm::isDebugEnabled() ) {
32  LogDebug("DigiToRaw")
33  << "[sistrip::DigiToRaw::DigiToRaw]"
34  << " Constructing object...";
35  }
37  }
#define LogDebug(id)
bool isDebugEnabled()
FEDBufferGenerator & setReadoutMode(const FEDReadoutMode newReadoutMode)
WarningSummary warnings_
FEDReadoutMode mode_
FEDBufferGenerator bufferGenerator_
sistrip::DigiToRaw::~DigiToRaw ( )

Definition at line 41 of file SiStripDigiToRaw.cc.

References edm::isDebugEnabled(), and LogDebug.

41  {
42  if ( edm::isDebugEnabled() ) {
43  LogDebug("DigiToRaw")
44  << "[sistrip::DigiToRaw::~DigiToRaw]"
45  << " Destructing object...";
46  }
47  }
#define LogDebug(id)
bool isDebugEnabled()

Member Function Documentation

void sistrip::DigiToRaw::createFedBuffers ( edm::Event event,
edm::ESHandle< SiStripFedCabling > &  cabling,
edm::Handle< edm::DetSetVector< SiStripDigi > > &  collection,
std::unique_ptr< FEDRawDataCollection > &  buffers 
)

Input: DetSetVector of SiStripDigis. Output: FEDRawDataCollection. Retrieves and iterates through FED buffers, extract FEDRawData from collection and (optionally) dumps raw data to stdout, locates start of FED buffer by identifying DAQ header, creates new Fed9UEvent object using current FEDRawData buffer, dumps FED buffer to stdout, retrieves data from various header fields

Definition at line 58 of file SiStripDigiToRaw.cc.

References universalConfigTemplate::collection, and createFedBuffers_().

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

61  {
62  createFedBuffers_(event, cabling, collection, buffers, true);
63  }
void createFedBuffers_(edm::Event &, edm::ESHandle< SiStripFedCabling > &cabling, edm::Handle< edm::DetSetVector< Digi_t > > &digis, std::unique_ptr< FEDRawDataCollection > &buffers, bool zeroSuppressed)
void sistrip::DigiToRaw::createFedBuffers ( edm::Event event,
edm::ESHandle< SiStripFedCabling > &  cabling,
edm::Handle< edm::DetSetVector< SiStripRawDigi > > &  digis,
std::unique_ptr< FEDRawDataCollection > &  buffers 
)

Definition at line 65 of file SiStripDigiToRaw.cc.

References universalConfigTemplate::collection, and createFedBuffers_().

68  {
69  createFedBuffers_(event, cabling, collection, buffers, false);
70  }
void createFedBuffers_(edm::Event &, edm::ESHandle< SiStripFedCabling > &cabling, edm::Handle< edm::DetSetVector< Digi_t > > &digis, std::unique_ptr< FEDRawDataCollection > &buffers, bool zeroSuppressed)
void sistrip::DigiToRaw::createFedBuffers ( edm::Event event,
edm::ESHandle< SiStripFedCabling > &  cabling,
edm::Handle< FEDRawDataCollection > &  rawbuffers,
edm::Handle< edm::DetSetVector< SiStripDigi > > &  digis,
std::unique_ptr< FEDRawDataCollection > &  buffers 
)

Definition at line 73 of file SiStripDigiToRaw.cc.

References universalConfigTemplate::collection, and createFedBuffers_().

77  {
78  createFedBuffers_(event, cabling, rawbuffers, collection, buffers, true);
79  }
void createFedBuffers_(edm::Event &, edm::ESHandle< SiStripFedCabling > &cabling, edm::Handle< edm::DetSetVector< Digi_t > > &digis, std::unique_ptr< FEDRawDataCollection > &buffers, bool zeroSuppressed)
void sistrip::DigiToRaw::createFedBuffers ( edm::Event event,
edm::ESHandle< SiStripFedCabling > &  cabling,
edm::Handle< FEDRawDataCollection > &  rawbuffers,
edm::Handle< edm::DetSetVector< SiStripRawDigi > > &  digis,
std::unique_ptr< FEDRawDataCollection > &  buffers 
)

Definition at line 81 of file SiStripDigiToRaw.cc.

References universalConfigTemplate::collection, and createFedBuffers_().

85  {
86  createFedBuffers_(event, cabling, rawbuffers, collection, buffers, false);
87  }
void createFedBuffers_(edm::Event &, edm::ESHandle< SiStripFedCabling > &cabling, edm::Handle< edm::DetSetVector< Digi_t > > &digis, std::unique_ptr< FEDRawDataCollection > &buffers, bool zeroSuppressed)
template<class Digi_t >
void sistrip::DigiToRaw::createFedBuffers_ ( edm::Event event,
edm::ESHandle< SiStripFedCabling > &  cabling,
edm::Handle< edm::DetSetVector< Digi_t > > &  digis,
std::unique_ptr< FEDRawDataCollection > &  buffers,
bool  zeroSuppressed 
)
private

Definition at line 93 of file SiStripDigiToRaw.cc.

References universalConfigTemplate::collection.

Referenced by createFedBuffers().

97  {
98 
100  //CAMM initialise to some dummy empty buffers??? Or OK like this ?
101  createFedBuffers_(event,cabling,rawbuffers,collection,buffers,zeroSuppressed);
102 
103  }
void createFedBuffers_(edm::Event &, edm::ESHandle< SiStripFedCabling > &cabling, edm::Handle< edm::DetSetVector< Digi_t > > &digis, std::unique_ptr< FEDRawDataCollection > &buffers, bool zeroSuppressed)
template<class Digi_t >
void sistrip::DigiToRaw::createFedBuffers_ ( edm::Event event,
edm::ESHandle< SiStripFedCabling > &  cabling,
edm::Handle< FEDRawDataCollection > &  rawbuffers,
edm::Handle< edm::DetSetVector< Digi_t > > &  digis,
std::unique_ptr< FEDRawDataCollection > &  buffers,
bool  zeroSuppressed 
)
private

Definition at line 106 of file SiStripDigiToRaw.cc.

References sistrip::WarningSummary::add(), sistrip::TrackerSpecialHeader::apvAddressErrorRegister(), sistrip::TrackerSpecialHeader::apveAddress(), sistrip::TrackerSpecialHeader::bufferFormat(), bufferGenerator_, universalConfigTemplate::collection, gather_cfg::cout, sistrip::FEDBufferGenerator::daqHeader(), sistrip::FEDBufferGenerator::daqTrailer(), FEDRawData::data(), edm::DetSet< T >::data, MillePedeFileConverter_cfg::e, edm::EventID::event(), cppFunctionSkipper::exception, sistrip::FEDCH_PER_FEUNIT, SiStripFedCabling::fedConnections(), FEDRawDataCollection::FEDData(), SiStripFedCabling::fedIds(), sistrip::TrackerSpecialHeader::fedStatusRegister(), sistrip::TrackerSpecialHeader::feEnableRegister(), sistrip::FEDBufferGenerator::feHeader(), sistrip::TrackerSpecialHeader::feOverflowRegister(), sistrip::FEUNITS_PER_FED, cmsPerfStripChart::format, sistrip::FEDBufferGenerator::generateBuffer(), sistrip::FEDBufferGenerator::getBufferFormat(), sistrip::FEDBufferGenerator::getDAQEventType(), sistrip::HEADER_TYPE_FULL_DEBUG, sistrip::HEADER_TYPE_INVALID, sistrip::TrackerSpecialHeader::headerType(), edm::EventBase::id(), sistrip::invalid32_, sistrip::invalid_, edm::isDebugEnabled(), edm::HandleBase::isValid(), crabWrapper::key, sistrip::FEDFEHeader::lengthInBytes(), mode_, sistrip::PACKET_CODE_ZERO_SUPPRESSED10, packetCode_, sistrip::TrackerSpecialHeader::print(), sistrip::FEDFEHeader::print(), sistrip::READOUT_MODE_PREMIX_RAW, sistrip::READOUT_MODE_SCOPE, sistrip::READOUT_MODE_ZERO_SUPPRESSED, sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE10, sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE10_CMOVERRIDE, sistrip::TrackerSpecialHeader::readoutMode(), sistrip::FEDBufferGenerator::setFEUnitEnables(), sistrip::FEDBufferGenerator::setHeaderType(), sistrip::FEDBufferGenerator::setL1ID(), sistrip::FEDBufferGenerator::setReadoutMode(), FEDRawData::size(), str, digitizers_cfi::strip, STRIP(), sistrip::STRIPS_PER_FEDCH, sistrip::FEDBufferGenerator::trackerSpecialHeader(), useFedKey_, relativeConstraints::value, and warnings_.

111  {
112  const bool dataIsAlready8BitTruncated = zeroSuppressed && ( ! (
113  //for special mode premix raw, data is zero-suppressed but not converted to 8 bit
115  // the same goes for 10bit ZS modes
119  ) );
120  try {
121 
122  //set the L1ID to use in the buffers
123  bufferGenerator_.setL1ID(0xFFFFFF & event.id().event());
124  auto fed_ids = cabling->fedIds();
125 
126  //copy header if valid rawbuffers handle
127  if (rawbuffers.isValid()){
128  if ( edm::isDebugEnabled() ) {
129  edm::LogWarning("DigiToRaw")
130  << "[sistrip::DigiToRaw::createFedBuffers_]"
131  << " Valid raw buffers, getting headers from them..."
132  << " Number of feds: " << fed_ids.size() << " between "
133  << *(fed_ids.begin()) << " and " << *(fed_ids.end());
134  }
135 
136  const FEDRawDataCollection& rawDataCollection = *rawbuffers;
137 
138  for ( auto ifed = fed_ids.begin(); ifed != fed_ids.end(); ++ifed ) {
139  const FEDRawData& rawfedData = rawDataCollection.FEDData(*ifed);
140 
141  if ( edm::isDebugEnabled() ) {
142  edm::LogWarning("DigiToRaw")
143  << "[sistrip::DigiToRaw::createFedBuffers_]"
144  << "Fed " << *ifed << " : size of buffer = " << rawfedData.size();
145  }
146 
147  //need to construct full object to copy full header
148  std::unique_ptr<const sistrip::FEDBuffer> fedbuffer;
149  if ( rawfedData.size() == 0 ) {
150  warnings_.add("Invalid raw data for FED, skipping", (boost::format("id %1%") % *ifed).str());
151  } else {
152  try {
153  fedbuffer.reset(new sistrip::FEDBuffer(rawfedData.data(),rawfedData.size(),true));
154  } catch (const cms::Exception& e) {
155  edm::LogWarning("DigiToRaw") << "[sistrip::DigiToRaw::createFedBuffers_]"
156  << " Could not construct FEDBuffer for FED " << *ifed
157  << std::endl;
158  }
159 
160  if ( fedbuffer->headerType() == sistrip::HEADER_TYPE_INVALID ) {
161  warnings_.add("Invalid header type for FED, skipping", (boost::format("id %1%") % *ifed).str());
162  continue;
163  }
164 
165  if ( edm::isDebugEnabled() ) {
166  edm::LogWarning("DigiToRaw")
167  << "[sistrip::DigiToRaw::createFedBuffers_]"
168  << " Original header type: " << fedbuffer->headerType();
169  }
170 
172  //fedbuffer->headerType());
173  bufferGenerator_.daqHeader() = fedbuffer->daqHeader();
174  bufferGenerator_.daqTrailer() = fedbuffer->daqTrailer();
175 
176  bufferGenerator_.trackerSpecialHeader() = fedbuffer->trackerSpecialHeader();
178 
179  if ( edm::isDebugEnabled() ) {
180  std::ostringstream debugStream;
181  if(ifed==fed_ids.begin()){ bufferGenerator_.trackerSpecialHeader().print(std::cout); std::cout << std::endl;}
183  edm::LogWarning("DigiToRaw")
184  << "[sistrip::DigiToRaw::createFedBuffers_]"
185  << " Tracker special header apveAddress: " << static_cast<int>(bufferGenerator_.trackerSpecialHeader().apveAddress())
186  << " - event type = " << bufferGenerator_.getDAQEventType()
187  << " - buffer format = " << bufferGenerator_.getBufferFormat() << "\n"
188  << " - SpecialHeader bufferformat " << bufferGenerator_.trackerSpecialHeader().bufferFormat()
189  << " - headertype " << bufferGenerator_.trackerSpecialHeader().headerType()
190  << " - readoutmode " << bufferGenerator_.trackerSpecialHeader().readoutMode()
191  << " - apvaddrregister " << std::hex << static_cast<int>(bufferGenerator_.trackerSpecialHeader().apvAddressErrorRegister())
192  << " - feenabledregister " << std::hex << static_cast<int>(bufferGenerator_.trackerSpecialHeader().feEnableRegister())
193  << " - feoverflowregister " << std::hex << static_cast<int>(bufferGenerator_.trackerSpecialHeader().feOverflowRegister())
194  << " - statusregister " << bufferGenerator_.trackerSpecialHeader().fedStatusRegister() << "\n"
195  << " SpecialHeader: " << debugStream.str();
196  }
197 
198  std::unique_ptr<FEDFEHeader> tempFEHeader(fedbuffer->feHeader()->clone());
199  FEDFullDebugHeader* fedFeHeader = dynamic_cast<FEDFullDebugHeader*>(tempFEHeader.get());
200  if ( edm::isDebugEnabled() ) {
201  std::ostringstream debugStream;
202  if(ifed==fed_ids.begin()){ std::cout << "FEHeader before transfer: " << std::endl;fedFeHeader->print(std::cout);std::cout <<std::endl;}
203  fedFeHeader->print(debugStream);
204  edm::LogWarning("DigiToRaw")
205  << "[sistrip::DigiToRaw::createFedBuffers_]"
206  << " length of original feHeader: " << fedFeHeader->lengthInBytes() << "\n"
207  << debugStream.str();
208  }
209  //status registers
210  (bufferGenerator_.feHeader()).setBEStatusRegister(fedFeHeader->beStatusRegister());
211  (bufferGenerator_.feHeader()).setDAQRegister2(fedFeHeader->daqRegister2());
212  (bufferGenerator_.feHeader()).setDAQRegister(fedFeHeader->daqRegister());
213  for(uint8_t iFE=1; iFE<6; iFE++) {
214  (bufferGenerator_.feHeader()).set32BitReservedRegister(iFE,fedFeHeader->get32BitWordFrom(fedFeHeader->feWord(iFE)+10));
215  }
216 
217  std::vector<bool> feEnabledVec;
218  feEnabledVec.resize(FEUNITS_PER_FED,true);
219  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
220  feEnabledVec[iFE]=fedbuffer->trackerSpecialHeader().feEnabled(iFE);
221  (bufferGenerator_.feHeader()).setFEUnitMajorityAddress(iFE,fedFeHeader->feUnitMajorityAddress(iFE));
222  for (uint8_t iFEUnitChannel = 0; iFEUnitChannel < FEDCH_PER_FEUNIT; iFEUnitChannel++) {
223  (bufferGenerator_.feHeader()).setChannelStatus(iFE,iFEUnitChannel,fedFeHeader->getChannelStatus(iFE,iFEUnitChannel));
224  }//loop on channels
225  }//loop on fe units
226  bufferGenerator_.setFEUnitEnables(feEnabledVec);
227 
228  if ( edm::isDebugEnabled() ) {
229  std::ostringstream debugStream;
230  if(ifed==fed_ids.begin()){ std::cout << "\nFEHeader after transfer: " << std::endl;bufferGenerator_.feHeader().print(std::cout); std::cout << std::endl;}
231  bufferGenerator_.feHeader().print(debugStream);
232  edm::LogWarning("DigiToRaw")
233  << "[sistrip::DigiToRaw::createFedBuffers_]"
234  << " length of feHeader: " << bufferGenerator_.feHeader().lengthInBytes() << "\n"
235  << debugStream.str();
236  }
237  auto conns = cabling->fedConnections(*ifed);
238 
239  FEDStripData fedData(dataIsAlready8BitTruncated);
240 
241 
242  for (auto iconn = conns.begin() ; iconn != conns.end(); iconn++ ) {
243 
244  // Determine FED key from cabling
245  uint32_t fed_key = ( ( iconn->fedId() & sistrip::invalid_ ) << 16 ) | ( iconn->fedCh() & sistrip::invalid_ );
246 
247  // Determine whether DetId or FED key should be used to index digi containers
248  uint32_t key = ( useFedKey_ || mode_ == READOUT_MODE_SCOPE ) ? fed_key : iconn->detId();
249 
250  // Check key is non-zero and valid
251  if ( !key || ( key == sistrip::invalid32_ ) ) { continue; }
252 
253  // Determine APV pair number (needed only when using DetId)
254  uint16_t ipair = ( useFedKey_ || mode_ == READOUT_MODE_SCOPE ) ? 0 : iconn->apvPairNumber();
255 
256  FEDStripData::ChannelData& chanData = fedData[iconn->fedCh()];
257 
258  // Find digis for DetID in collection
259  if (!collection.isValid()){
260  if ( edm::isDebugEnabled() ) {
261  edm::LogWarning("DigiToRaw")
262  << "[DigiToRaw::createFedBuffers] "
263  << "digis collection is not valid...";
264  }
265  break;
266  }
267  typename std::vector< edm::DetSet<Digi_t> >::const_iterator digis = collection->find( key );
268  if (digis == collection->end()) { continue; }
269 
270  typename edm::DetSet<Digi_t>::const_iterator idigi, digis_begin(digis->data.begin());
271  for ( idigi = digis_begin; idigi != digis->data.end(); idigi++ ) {
272 
273  if ( STRIP(idigi, digis_begin) < ipair*256 ||
274  STRIP(idigi, digis_begin) > ipair*256+255 ) { continue; }
275  const unsigned short strip = STRIP(idigi, digis_begin) % 256;
276 
277  if ( strip >= STRIPS_PER_FEDCH ) {
278  if ( edm::isDebugEnabled() ) {
279  std::stringstream ss;
280  ss << "[sistrip::DigiToRaw::createFedBuffers]"
281  << " strip >= strips_per_fedCh";
282  edm::LogWarning("DigiToRaw") << ss.str();
283  }
284  continue;
285  }
286 
287  // check if value already exists
288  if ( edm::isDebugEnabled() ) {
289  const uint16_t value = 0;//chanData[strip];
290  if ( value && value != (*idigi).adc() ) {
291  std::stringstream ss;
292  ss << "[sistrip::DigiToRaw::createFedBuffers]"
293  << " Incompatible ADC values in buffer!"
294  << " FedId/FedCh: " << *ifed << "/" << iconn->fedCh()
295  << " DetStrip: " << STRIP(idigi, digis_begin)
296  << " FedChStrip: " << strip
297  << " AdcValue: " << (*idigi).adc()
298  << " RawData[" << strip << "]: " << value;
299  edm::LogWarning("DigiToRaw") << ss.str();
300  }
301  }
302 
303  // Add digi to buffer
304  chanData[strip] = (*idigi).adc();
305  }
306  }
307  // if ((*idigi).strip() >= (ipair+1)*256) break;
308 
309  if ( edm::isDebugEnabled() ) {
310  edm::LogWarning("DigiToRaw")
311  << "DigiToRaw::createFedBuffers] "
312  << "Almost at the end...";
313  }
314  //create the buffer
315  FEDRawData& fedrawdata = buffers->FEDData( *ifed );
316  bufferGenerator_.generateBuffer(&fedrawdata, fedData, *ifed, packetCode_);
317 
318  if ( edm::isDebugEnabled() ) {
319  std::ostringstream debugStream;
320  bufferGenerator_.feHeader().print(debugStream);
321  edm::LogWarning("DigiToRaw")
322  << "[sistrip::DigiToRaw::createFedBuffers_]"
323  << " length of final feHeader: " << bufferGenerator_.feHeader().lengthInBytes() << "\n"
324  << debugStream.str();
325  }
326  }
327  }//loop on fedids
328  if ( edm::isDebugEnabled() ) {
329  edm::LogWarning("DigiToRaw")
330  << "[sistrip::DigiToRaw::createFedBuffers_]"
331  << "end of first loop on feds";
332  }
333 
334  }//end of workflow for copying header, below is workflow without copying header
335  else{
336  if ( edm::isDebugEnabled() ) {
337  edm::LogWarning("DigiToRaw")
338  << "[sistrip::DigiToRaw::createFedBuffers_]"
339  << "Now getting the digis..."
340  << " Number of feds: " << fed_ids.size() << " between "
341  << *(fed_ids.begin()) << " and " << *(fed_ids.end());
342  }
343 
344  for ( auto ifed = fed_ids.begin(); ifed != fed_ids.end(); ++ifed ) {
345 
346  auto conns = cabling->fedConnections(*ifed);
347 
348  FEDStripData fedData(dataIsAlready8BitTruncated);
349 
350 
351  for (auto iconn = conns.begin() ; iconn != conns.end(); iconn++ ) {
352 
353  // Determine FED key from cabling
354  uint32_t fed_key = ( ( iconn->fedId() & sistrip::invalid_ ) << 16 ) | ( iconn->fedCh() & sistrip::invalid_ );
355 
356  // Determine whether DetId or FED key should be used to index digi containers
357  uint32_t key = ( useFedKey_ || mode_ == READOUT_MODE_SCOPE ) ? fed_key : iconn->detId();
358 
359  // Check key is non-zero and valid
360  if ( !key || ( key == sistrip::invalid32_ ) ) { continue; }
361 
362  // Determine APV pair number (needed only when using DetId)
363  uint16_t ipair = ( useFedKey_ || mode_ == READOUT_MODE_SCOPE ) ? 0 : iconn->apvPairNumber();
364 
365  FEDStripData::ChannelData& chanData = fedData[iconn->fedCh()];
366 
367  // Find digis for DetID in collection
368  if (!collection.isValid()){
369  if ( edm::isDebugEnabled() ) {
370  edm::LogWarning("DigiToRaw")
371  << "[DigiToRaw::createFedBuffers] "
372  << "digis collection is not valid...";
373  }
374  break;
375  }
376  typename std::vector< edm::DetSet<Digi_t> >::const_iterator digis = collection->find( key );
377  if (digis == collection->end()) { continue; }
378 
379  typename edm::DetSet<Digi_t>::const_iterator idigi, digis_begin(digis->data.begin());
380  for ( idigi = digis_begin; idigi != digis->data.end(); idigi++ ) {
381 
382  if ( STRIP(idigi, digis_begin) < ipair*256 ||
383  STRIP(idigi, digis_begin) > ipair*256+255 ) { continue; }
384  const unsigned short strip = STRIP(idigi, digis_begin) % 256;
385 
386  if ( strip >= STRIPS_PER_FEDCH ) {
387  if ( edm::isDebugEnabled() ) {
388  std::stringstream ss;
389  ss << "[sistrip::DigiToRaw::createFedBuffers]"
390  << " strip >= strips_per_fedCh";
391  edm::LogWarning("DigiToRaw") << ss.str();
392  }
393  continue;
394  }
395 
396  // check if value already exists
397  if ( edm::isDebugEnabled() ) {
398  const uint16_t value = 0;//chanData[strip];
399  if ( value && value != (*idigi).adc() ) {
400  std::stringstream ss;
401  ss << "[sistrip::DigiToRaw::createFedBuffers]"
402  << " Incompatible ADC values in buffer!"
403  << " FedId/FedCh: " << *ifed << "/" << iconn->fedCh()
404  << " DetStrip: " << STRIP(idigi, digis_begin)
405  << " FedChStrip: " << strip
406  << " AdcValue: " << (*idigi).adc()
407  << " RawData[" << strip << "]: " << value;
408  edm::LogWarning("DigiToRaw") << ss.str();
409  }
410  }
411 
412  // Add digi to buffer
413  chanData[strip] = (*idigi).adc();
414  }
415  }
416  // if ((*idigi).strip() >= (ipair+1)*256) break;
417 
418  if ( edm::isDebugEnabled() ) {
419  edm::LogWarning("DigiToRaw")
420  << "DigiToRaw::createFedBuffers] "
421  << "Almost at the end...";
422  }
423  //create the buffer
424  FEDRawData& fedrawdata = buffers->FEDData( *ifed );
425  bufferGenerator_.generateBuffer(&fedrawdata, fedData, *ifed, packetCode_);
426 
427  if ( edm::isDebugEnabled() ) {
428  std::ostringstream debugStream;
429  bufferGenerator_.feHeader().print(debugStream);
430  edm::LogWarning("DigiToRaw")
431  << "[sistrip::DigiToRaw::createFedBuffers_]"
432  << " length of final feHeader: " << bufferGenerator_.feHeader().lengthInBytes() << "\n"
433  << debugStream.str();
434  }
435  }//loop on feds
436  }//end if-else for copying header
437  }//try
438  catch (const std::exception& e) {
439  if ( edm::isDebugEnabled() ) {
440  edm::LogWarning("DigiToRaw")
441  << "DigiToRaw::createFedBuffers] "
442  << "Exception caught : " << e.what();
443  }
444  }
445 
446  }
EventNumber_t event() const
Definition: EventID.h:41
bool isDebugEnabled()
FEDBufferGenerator & setReadoutMode(const FEDReadoutMode newReadoutMode)
static const uint32_t invalid32_
Definition: Constants.h:15
FEDStatusRegister fedStatusRegister() const
virtual void print(std::ostream &os) const =0
WarningSummary warnings_
TrackerSpecialHeader & trackerSpecialHeader()
FEDBufferFormat getBufferFormat() const
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED10
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
FEDBufferGenerator & setFEUnitEnables(const std::vector< bool > &feUnitsEnabled)
static const uint16_t FEUNITS_PER_FED
FedsConstIterRange fedIds() const
void generateBuffer(FEDRawData *rawDataObject, const FEDStripData &data, uint16_t sourceID, uint8_t packetCode) const
format
Some error handling for the usage.
Definition: value.py:1
bool isValid() const
Definition: HandleBase.h:74
void add(const std::string &message, const std::string &details="")
FEDReadoutMode mode_
void print(std::ostream &os) const
static const uint16_t STRIPS_PER_FEDCH
FEDBufferGenerator & setHeaderType(const FEDHeaderType newHeaderType)
FEDBufferGenerator & setL1ID(const uint32_t newL1ID)
static const uint16_t FEDCH_PER_FEUNIT
static const uint16_t invalid_
Definition: Constants.h:16
ConnsConstIterRange fedConnections(uint16_t fed_id) const
virtual size_t lengthInBytes() const =0
edm::EventID id() const
Definition: EventBase.h:59
collection_type data
Definition: DetSet.h:80
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
uint16_t STRIP(const edm::DetSet< SiStripDigi >::const_iterator &it, const edm::DetSet< SiStripDigi >::const_iterator &begin) const
FEDDAQEventType getDAQEventType() const
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
#define str(s)
FEDBufferGenerator bufferGenerator_
void sistrip::DigiToRaw::fedReadoutMode ( FEDReadoutMode  mode)
inline
void sistrip::DigiToRaw::printWarningSummary ( ) const
inline

Definition at line 60 of file SiStripDigiToRaw.h.

References begin.

Referenced by sistrip::DigiToRawModule::endStream().

void printSummary() const
WarningSummary warnings_
uint16_t sistrip::DigiToRaw::STRIP ( const edm::DetSet< SiStripDigi >::const_iterator &  it,
const edm::DetSet< SiStripDigi >::const_iterator &  begin 
) const
inlineprivate

Definition at line 448 of file SiStripDigiToRaw.cc.

Referenced by createFedBuffers_().

448 {return it->strip();}
uint16_t sistrip::DigiToRaw::STRIP ( const edm::DetSet< SiStripRawDigi >::const_iterator &  it,
const edm::DetSet< SiStripRawDigi >::const_iterator &  begin 
) const
inlineprivate

Definition at line 449 of file SiStripDigiToRaw.cc.

References begin.

449 {return it-begin;}
#define begin
Definition: vmac.h:32

Member Data Documentation

FEDBufferGenerator sistrip::DigiToRaw::bufferGenerator_
private

Definition at line 87 of file SiStripDigiToRaw.h.

Referenced by createFedBuffers_(), and DigiToRaw().

FEDReadoutMode sistrip::DigiToRaw::mode_
private

Definition at line 84 of file SiStripDigiToRaw.h.

Referenced by createFedBuffers_(), and DigiToRaw().

uint8_t sistrip::DigiToRaw::packetCode_
private

Definition at line 85 of file SiStripDigiToRaw.h.

Referenced by createFedBuffers_().

bool sistrip::DigiToRaw::useFedKey_
private

Definition at line 86 of file SiStripDigiToRaw.h.

Referenced by createFedBuffers_().

WarningSummary sistrip::DigiToRaw::warnings_
private

Definition at line 89 of file SiStripDigiToRaw.h.

Referenced by createFedBuffers_().