16 #include <boost/format.hpp> 24 packetCode_(packetCode),
25 useFedKey_(useFedKey),
27 warnings_(
"DigiToRaw",
"[sistrip::DigiToRaw::createFedBuffers_]",
edm::
isDebugEnabled()) {
29 LogDebug(
"DigiToRaw") <<
"[sistrip::DigiToRaw::DigiToRaw]" 30 <<
" Constructing object...";
39 LogDebug(
"DigiToRaw") <<
"[sistrip::DigiToRaw::~DigiToRaw]" 40 <<
" Destructing object...";
56 std::unique_ptr<FEDRawDataCollection>& buffers) {
63 std::unique_ptr<FEDRawDataCollection>& buffers) {
72 std::unique_ptr<FEDRawDataCollection>& buffers) {
80 std::unique_ptr<FEDRawDataCollection>& buffers) {
84 template <
class Digi_t>
88 std::unique_ptr<FEDRawDataCollection>& buffers,
95 template <
class Digi_t>
100 std::unique_ptr<FEDRawDataCollection>& buffers,
102 const bool dataIsAlready8BitTruncated =
114 auto fed_ids = cabling->
fedIds();
119 edm::LogWarning(
"DigiToRaw") <<
"[sistrip::DigiToRaw::createFedBuffers_]" 120 <<
" Valid raw buffers, getting headers from them..." 121 <<
" Number of feds: " << fed_ids.size() <<
" between " << *(fed_ids.begin())
122 <<
" and " << *(fed_ids.end());
127 for (
auto ifed = fed_ids.begin(); ifed != fed_ids.end(); ++ifed) {
131 edm::LogWarning(
"DigiToRaw") <<
"[sistrip::DigiToRaw::createFedBuffers_]" 132 <<
"Fed " << *ifed <<
" : size of buffer = " << rawfedData.
size();
136 std::unique_ptr<const sistrip::FEDBuffer> fedbuffer;
137 if (rawfedData.
size() == 0) {
143 edm::LogWarning(
"DigiToRaw") <<
"[sistrip::DigiToRaw::createFedBuffers_]" 144 <<
" Could not construct FEDBuffer for FED " << *ifed << std::endl;
153 edm::LogWarning(
"DigiToRaw") <<
"[sistrip::DigiToRaw::createFedBuffers_]" 154 <<
" Original header type: " << fedbuffer->headerType();
166 std::ostringstream debugStream;
167 if (ifed == fed_ids.begin()) {
173 <<
"[sistrip::DigiToRaw::createFedBuffers_]" 174 <<
" Tracker special header apveAddress: " 182 <<
" - feenabledregister " << std::hex
184 <<
" - feoverflowregister " << std::hex
187 <<
" SpecialHeader: " << debugStream.str();
190 std::unique_ptr<FEDFEHeader> tempFEHeader(fedbuffer->feHeader()->clone());
193 std::ostringstream debugStream;
194 if (ifed == fed_ids.begin()) {
195 std::cout <<
"FEHeader before transfer: " << std::endl;
199 fedFeHeader->print(debugStream);
200 edm::LogWarning(
"DigiToRaw") <<
"[sistrip::DigiToRaw::createFedBuffers_]" 201 <<
" length of original feHeader: " << fedFeHeader->lengthInBytes() <<
"\n" 202 << debugStream.str();
208 for (uint8_t iFE = 1; iFE < 6; iFE++) {
210 .set32BitReservedRegister(iFE, fedFeHeader->get32BitWordFrom(fedFeHeader->feWord(iFE) + 10));
213 std::vector<bool> feEnabledVec;
216 feEnabledVec[iFE] = fedbuffer->trackerSpecialHeader().feEnabled(iFE);
218 for (uint8_t iFEUnitChannel = 0; iFEUnitChannel <
FEDCH_PER_FEUNIT; iFEUnitChannel++) {
220 .setChannelStatus(iFE, iFEUnitChannel, fedFeHeader->getChannelStatus(iFE, iFEUnitChannel));
226 std::ostringstream debugStream;
227 if (ifed == fed_ids.begin()) {
228 std::cout <<
"\nFEHeader after transfer: " << std::endl;
234 <<
"[sistrip::DigiToRaw::createFedBuffers_]" 236 << debugStream.str();
242 for (
auto iconn = conns.begin(); iconn != conns.end(); iconn++) {
263 <<
"digis collection is not valid...";
267 typename std::vector<edm::DetSet<Digi_t> >::const_iterator digis =
collection->find(key);
273 for (idigi = digis_begin; idigi != digis->
data.end(); idigi++) {
274 if (
STRIP(idigi, digis_begin) < ipair * 256 ||
STRIP(idigi, digis_begin) > ipair * 256 + 255) {
277 const unsigned short strip =
STRIP(idigi, digis_begin) % 256;
281 std::stringstream
ss;
282 ss <<
"[sistrip::DigiToRaw::createFedBuffers]" 283 <<
" strip >= strips_per_fedCh";
291 const uint16_t
value = 0;
292 if (value && value != (*idigi).adc()) {
293 std::stringstream
ss;
294 ss <<
"[sistrip::DigiToRaw::createFedBuffers]" 295 <<
" Incompatible ADC values in buffer!" 296 <<
" FedId/FedCh: " << *ifed <<
"/" << iconn->fedCh()
297 <<
" DetStrip: " <<
STRIP(idigi, digis_begin) <<
" FedChStrip: " << strip
298 <<
" AdcValue: " << (*idigi).adc() <<
" RawData[" << strip <<
"]: " <<
value;
304 chanData[
strip] = (*idigi).adc();
311 <<
"Almost at the end...";
314 FEDRawData& fedrawdata = buffers->FEDData(*ifed);
318 std::ostringstream debugStream;
321 <<
"[sistrip::DigiToRaw::createFedBuffers_]" 323 << debugStream.str();
328 edm::LogWarning(
"DigiToRaw") <<
"[sistrip::DigiToRaw::createFedBuffers_]" 329 <<
"end of first loop on feds";
335 edm::LogWarning(
"DigiToRaw") <<
"[sistrip::DigiToRaw::createFedBuffers_]" 336 <<
"Now getting the digis..." 337 <<
" Number of feds: " << fed_ids.size() <<
" between " << *(fed_ids.begin())
338 <<
" and " << *(fed_ids.end());
341 for (
auto ifed = fed_ids.begin(); ifed != fed_ids.end(); ++ifed) {
346 for (
auto iconn = conns.begin(); iconn != conns.end(); iconn++) {
367 <<
"digis collection is not valid...";
371 typename std::vector<edm::DetSet<Digi_t> >::const_iterator digis =
collection->find(key);
377 for (idigi = digis_begin; idigi != digis->
data.end(); idigi++) {
378 if (
STRIP(idigi, digis_begin) < ipair * 256 ||
STRIP(idigi, digis_begin) > ipair * 256 + 255) {
381 const unsigned short strip =
STRIP(idigi, digis_begin) % 256;
385 std::stringstream
ss;
386 ss <<
"[sistrip::DigiToRaw::createFedBuffers]" 387 <<
" strip >= strips_per_fedCh";
395 const uint16_t
value = 0;
396 if (value && value != (*idigi).adc()) {
397 std::stringstream
ss;
398 ss <<
"[sistrip::DigiToRaw::createFedBuffers]" 399 <<
" Incompatible ADC values in buffer!" 400 <<
" FedId/FedCh: " << *ifed <<
"/" << iconn->fedCh()
401 <<
" DetStrip: " <<
STRIP(idigi, digis_begin) <<
" FedChStrip: " << strip
402 <<
" AdcValue: " << (*idigi).adc() <<
" RawData[" << strip <<
"]: " <<
value;
408 chanData[
strip] = (*idigi).adc();
415 <<
"Almost at the end...";
418 FEDRawData& fedrawdata = buffers->FEDData(*ifed);
422 std::ostringstream debugStream;
424 edm::LogWarning(
"DigiToRaw") <<
"[sistrip::DigiToRaw::createFedBuffers_]" 427 << debugStream.str();
435 <<
"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
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)