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
162 <<
"[sistrip::DigiToRaw::createFedBuffers_]" 163 <<
" Original header type: " << fedbuffer->headerType();
175 std::ostringstream debugStream;
179 <<
"[sistrip::DigiToRaw::createFedBuffers_]" 190 <<
" SpecialHeader: " << debugStream.str();
193 std::unique_ptr<FEDFEHeader> tempFEHeader(fedbuffer->feHeader()->clone());
196 std::ostringstream debugStream;
197 if(ifed==fed_ids.begin()){
std::cout <<
"FEHeader before transfer: " << std::endl;fedFeHeader->print(
std::cout);
std::cout <<std::endl;}
198 fedFeHeader->print(debugStream);
200 <<
"[sistrip::DigiToRaw::createFedBuffers_]" 201 <<
" length of original feHeader: " << fedFeHeader->lengthInBytes() <<
"\n" 202 << debugStream.str();
208 for(uint8_t iFE=1; iFE<6; iFE++) {
209 (
bufferGenerator_.
feHeader()).set32BitReservedRegister(iFE,fedFeHeader->get32BitWordFrom(fedFeHeader->feWord(iFE)+10));
212 std::vector<bool> feEnabledVec;
215 feEnabledVec[iFE]=fedbuffer->trackerSpecialHeader().feEnabled(iFE);
217 for (uint8_t iFEUnitChannel = 0; iFEUnitChannel <
FEDCH_PER_FEUNIT; iFEUnitChannel++) {
218 (
bufferGenerator_.
feHeader()).setChannelStatus(iFE,iFEUnitChannel,fedFeHeader->getChannelStatus(iFE,iFEUnitChannel));
224 std::ostringstream debugStream;
228 <<
"[sistrip::DigiToRaw::createFedBuffers_]" 230 << debugStream.str();
237 for (
auto iconn = conns.begin() ; iconn != conns.end(); iconn++ ) {
257 <<
"[DigiToRaw::createFedBuffers] " 258 <<
"digis collection is not valid...";
262 typename std::vector< edm::DetSet<Digi_t> >::const_iterator digis =
collection->find( key );
266 for ( idigi = digis_begin; idigi != digis->
data.end(); idigi++ ) {
268 if (
STRIP(idigi, digis_begin) < ipair*256 ||
269 STRIP(idigi, digis_begin) > ipair*256+255 ) {
continue; }
270 const unsigned short strip =
STRIP(idigi, digis_begin) % 256;
274 std::stringstream ss;
275 ss <<
"[sistrip::DigiToRaw::createFedBuffers]" 276 <<
" strip >= strips_per_fedCh";
284 const uint16_t
value = 0;
285 if ( value && value != (*idigi).adc() ) {
286 std::stringstream ss;
287 ss <<
"[sistrip::DigiToRaw::createFedBuffers]" 288 <<
" Incompatible ADC values in buffer!" 289 <<
" FedId/FedCh: " << *ifed <<
"/" << iconn->fedCh()
290 <<
" DetStrip: " <<
STRIP(idigi, digis_begin)
291 <<
" FedChStrip: " << strip
292 <<
" AdcValue: " << (*idigi).adc()
293 <<
" RawData[" << strip <<
"]: " <<
value;
299 chanData[
strip] = (*idigi).adc();
306 <<
"DigiToRaw::createFedBuffers] " 307 <<
"Almost at the end...";
310 FEDRawData& fedrawdata = buffers->FEDData( *ifed );
314 std::ostringstream debugStream;
317 <<
"[sistrip::DigiToRaw::createFedBuffers_]" 319 << debugStream.str();
325 <<
"[sistrip::DigiToRaw::createFedBuffers_]" 326 <<
"end of first loop on feds";
333 <<
"[sistrip::DigiToRaw::createFedBuffers_]" 334 <<
"Now getting the digis..." 335 <<
" Number of feds: " << fed_ids.size() <<
" between " 336 << *(fed_ids.begin()) <<
" and " << *(fed_ids.end());
339 for (
auto ifed = fed_ids.begin(); ifed != fed_ids.end(); ++ifed ) {
346 for (
auto iconn = conns.begin() ; iconn != conns.end(); iconn++ ) {
366 <<
"[DigiToRaw::createFedBuffers] " 367 <<
"digis collection is not valid...";
371 typename std::vector< edm::DetSet<Digi_t> >::const_iterator digis =
collection->find( key );
375 for ( idigi = digis_begin; idigi != digis->
data.end(); idigi++ ) {
377 if (
STRIP(idigi, digis_begin) < ipair*256 ||
378 STRIP(idigi, digis_begin) > ipair*256+255 ) {
continue; }
379 const unsigned short strip =
STRIP(idigi, digis_begin) % 256;
383 std::stringstream ss;
384 ss <<
"[sistrip::DigiToRaw::createFedBuffers]" 385 <<
" strip >= strips_per_fedCh";
393 const uint16_t
value = 0;
394 if ( value && value != (*idigi).adc() ) {
395 std::stringstream ss;
396 ss <<
"[sistrip::DigiToRaw::createFedBuffers]" 397 <<
" Incompatible ADC values in buffer!" 398 <<
" FedId/FedCh: " << *ifed <<
"/" << iconn->fedCh()
399 <<
" DetStrip: " <<
STRIP(idigi, digis_begin)
400 <<
" FedChStrip: " << strip
401 <<
" AdcValue: " << (*idigi).adc()
402 <<
" RawData[" << strip <<
"]: " <<
value;
408 chanData[
strip] = (*idigi).adc();
415 <<
"DigiToRaw::createFedBuffers] " 416 <<
"Almost at the end...";
419 FEDRawData& fedrawdata = buffers->FEDData( *ifed );
423 std::ostringstream debugStream;
426 <<
"[sistrip::DigiToRaw::createFedBuffers_]" 428 << debugStream.str();
436 <<
"DigiToRaw::createFedBuffers] " 437 <<
"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)