16 #include <boost/format.hpp> 26 packetCode_(packetCode),
27 useFedKey_(useFedKey),
29 warnings_(
"DigiToRaw",
"[sistrip::DigiToRaw::createFedBuffers_]",
edm::
isDebugEnabled())
33 <<
"[sistrip::DigiToRaw::DigiToRaw]" 34 <<
" Constructing object...";
44 <<
"[sistrip::DigiToRaw::~DigiToRaw]" 45 <<
" Destructing object...";
61 std::unique_ptr<FEDRawDataCollection>& buffers ) {
68 std::unique_ptr<FEDRawDataCollection>& buffers ) {
77 std::unique_ptr<FEDRawDataCollection>& buffers ) {
85 std::unique_ptr<FEDRawDataCollection>& buffers ) {
92 template<
class Digi_t>
96 std::unique_ptr<FEDRawDataCollection>& buffers,
97 bool zeroSuppressed) {
105 template<
class Digi_t>
110 std::unique_ptr<FEDRawDataCollection>& buffers,
111 bool zeroSuppressed) {
112 const bool dataIsAlready8BitTruncated = zeroSuppressed && ( ! (
124 auto fed_ids = cabling->
fedIds();
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());
138 for (
auto ifed = fed_ids.begin(); ifed != fed_ids.end(); ++ifed ) {
143 <<
"[sistrip::DigiToRaw::createFedBuffers_]" 144 <<
"Fed " << *ifed <<
" : size of buffer = " << rawfedData.
size();
148 std::unique_ptr<const sistrip::FEDBuffer> fedbuffer;
149 if ( rawfedData.
size() == 0 ) {
155 edm::LogWarning(
"DigiToRaw") <<
"[sistrip::DigiToRaw::createFedBuffers_]" 156 <<
" Could not construct FEDBuffer for FED " << *ifed
167 <<
"[sistrip::DigiToRaw::createFedBuffers_]" 168 <<
" Original header type: " << fedbuffer->headerType();
180 std::ostringstream debugStream;
184 <<
"[sistrip::DigiToRaw::createFedBuffers_]" 195 <<
" SpecialHeader: " << debugStream.str();
198 std::unique_ptr<FEDFEHeader> tempFEHeader(fedbuffer->feHeader()->clone());
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);
205 <<
"[sistrip::DigiToRaw::createFedBuffers_]" 206 <<
" length of original feHeader: " << fedFeHeader->lengthInBytes() <<
"\n" 207 << debugStream.str();
213 for(uint8_t iFE=1; iFE<6; iFE++) {
214 (
bufferGenerator_.
feHeader()).set32BitReservedRegister(iFE,fedFeHeader->get32BitWordFrom(fedFeHeader->feWord(iFE)+10));
217 std::vector<bool> feEnabledVec;
220 feEnabledVec[iFE]=fedbuffer->trackerSpecialHeader().feEnabled(iFE);
222 for (uint8_t iFEUnitChannel = 0; iFEUnitChannel <
FEDCH_PER_FEUNIT; iFEUnitChannel++) {
223 (
bufferGenerator_.
feHeader()).setChannelStatus(iFE,iFEUnitChannel,fedFeHeader->getChannelStatus(iFE,iFEUnitChannel));
229 std::ostringstream debugStream;
233 <<
"[sistrip::DigiToRaw::createFedBuffers_]" 235 << debugStream.str();
242 for (
auto iconn = conns.begin() ; iconn != conns.end(); iconn++ ) {
262 <<
"[DigiToRaw::createFedBuffers] " 263 <<
"digis collection is not valid...";
267 typename std::vector< edm::DetSet<Digi_t> >::const_iterator digis =
collection->find( key );
271 for ( idigi = digis_begin; idigi != digis->
data.end(); idigi++ ) {
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;
279 std::stringstream ss;
280 ss <<
"[sistrip::DigiToRaw::createFedBuffers]" 281 <<
" strip >= strips_per_fedCh";
289 const uint16_t
value = 0;
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;
304 chanData[
strip] = (*idigi).adc();
311 <<
"DigiToRaw::createFedBuffers] " 312 <<
"Almost at the end...";
315 FEDRawData& fedrawdata = buffers->FEDData( *ifed );
319 std::ostringstream debugStream;
322 <<
"[sistrip::DigiToRaw::createFedBuffers_]" 324 << debugStream.str();
330 <<
"[sistrip::DigiToRaw::createFedBuffers_]" 331 <<
"end of first loop on feds";
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());
344 for (
auto ifed = fed_ids.begin(); ifed != fed_ids.end(); ++ifed ) {
351 for (
auto iconn = conns.begin() ; iconn != conns.end(); iconn++ ) {
371 <<
"[DigiToRaw::createFedBuffers] " 372 <<
"digis collection is not valid...";
376 typename std::vector< edm::DetSet<Digi_t> >::const_iterator digis =
collection->find( key );
380 for ( idigi = digis_begin; idigi != digis->
data.end(); idigi++ ) {
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;
388 std::stringstream ss;
389 ss <<
"[sistrip::DigiToRaw::createFedBuffers]" 390 <<
" strip >= strips_per_fedCh";
398 const uint16_t
value = 0;
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;
413 chanData[
strip] = (*idigi).adc();
420 <<
"DigiToRaw::createFedBuffers] " 421 <<
"Almost at the end...";
424 FEDRawData& fedrawdata = buffers->FEDData( *ifed );
428 std::ostringstream debugStream;
431 <<
"[sistrip::DigiToRaw::createFedBuffers_]" 433 << debugStream.str();
441 <<
"DigiToRaw::createFedBuffers] " 442 <<
"Exception caught : " << e.what();
EventNumber_t event() const
DigiToRaw(FEDReadoutMode mode, uint8_t packetCode, bool use_fed_key)
FEDBufferGenerator & setReadoutMode(const FEDReadoutMode newReadoutMode)
static const uint32_t invalid32_
TrackerSpecialHeader & trackerSpecialHeader()
FEDBufferFormat getBufferFormat() const
size_t size() const
Lenght of the data buffer in bytes.
FEDDAQTrailer & daqTrailer()
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.
void createFedBuffers(edm::Event &, edm::ESHandle< SiStripFedCabling > &cabling, edm::Handle< edm::DetSetVector< SiStripDigi > > &digis, std::unique_ptr< FEDRawDataCollection > &buffers)
void add(const std::string &message, const std::string &details="")
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_
ConnsConstIterRange fedConnections(uint16_t fed_id) const
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
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
FEDBufferGenerator bufferGenerator_
FEDDAQHeader & daqHeader()
void createFedBuffers_(edm::Event &, edm::ESHandle< SiStripFedCabling > &cabling, edm::Handle< edm::DetSetVector< Digi_t > > &digis, std::unique_ptr< FEDRawDataCollection > &buffers, bool zeroSuppressed)