5 #include <fmt/format.h>
26 packetCode_(packetCode),
27 useFedKey_(useFedKey),
29 warnings_(
"DigiToRaw",
"[sistrip::DigiToRaw::createFedBuffers_]",
edm::
isDebugEnabled()) {
31 LogDebug(
"DigiToRaw") <<
"[sistrip::DigiToRaw::DigiToRaw]"
32 <<
" Constructing object...";
41 LogDebug(
"DigiToRaw") <<
"[sistrip::DigiToRaw::~DigiToRaw]"
42 <<
" Destructing object...";
58 std::unique_ptr<FEDRawDataCollection>& buffers) {
65 std::unique_ptr<FEDRawDataCollection>& buffers) {
74 std::unique_ptr<FEDRawDataCollection>& buffers) {
82 std::unique_ptr<FEDRawDataCollection>& buffers) {
86 template <
class Digi_t>
90 std::unique_ptr<FEDRawDataCollection>& buffers,
97 template <
class Digi_t>
102 std::unique_ptr<FEDRawDataCollection>& buffers,
104 const bool dataIsAlready8BitTruncated =
116 auto fed_ids = cabling->
fedIds();
121 edm::LogWarning(
"DigiToRaw") <<
"[sistrip::DigiToRaw::createFedBuffers_]"
122 <<
" Valid raw buffers, getting headers from them..."
123 <<
" Number of feds: " << fed_ids.size() <<
" between " << *(fed_ids.begin())
124 <<
" and " << *(fed_ids.end());
129 for (
auto ifed = fed_ids.begin(); ifed != fed_ids.end(); ++ifed) {
133 edm::LogWarning(
"DigiToRaw") <<
"[sistrip::DigiToRaw::createFedBuffers_]"
134 <<
"Fed " << *ifed <<
" : size of buffer = " << rawfedData.
size();
138 if (rawfedData.
size() == 0)
142 edm::LogWarning(
"DigiToRaw") <<
"[sistrip::DigiToRaw::createFedBuffers_]"
143 <<
" Could not construct FEDBuffer for FED " << *ifed << std::endl;
147 const auto st_chan = fedbuffer.findChannels();
149 edm::LogWarning(
"DigiToRaw") <<
"[sistrip::DigiToRaw::createFedBuffers_]"
150 <<
" Could not construct FEDBuffer for FED " << *ifed << std::endl;
158 edm::LogWarning(
"DigiToRaw") <<
"[sistrip::DigiToRaw::createFedBuffers_]"
159 <<
" Original header type: " << fedbuffer.headerType();
171 std::ostringstream debugStream;
172 if (ifed == fed_ids.begin()) {
178 <<
"[sistrip::DigiToRaw::createFedBuffers_]"
179 <<
" Tracker special header apveAddress: "
187 <<
" - feenabledregister " << std::hex
189 <<
" - feoverflowregister " << std::hex
192 <<
" SpecialHeader: " << debugStream.str();
195 std::unique_ptr<FEDFEHeader> tempFEHeader(fedbuffer.feHeader()->clone());
196 FEDFullDebugHeader* fedFeHeader = dynamic_cast<FEDFullDebugHeader*>(tempFEHeader.get());
198 std::ostringstream debugStream;
199 if (ifed == fed_ids.begin()) {
200 std::cout <<
"FEHeader before transfer: " << std::endl;
204 fedFeHeader->print(debugStream);
205 edm::LogWarning(
"DigiToRaw") <<
"[sistrip::DigiToRaw::createFedBuffers_]"
206 <<
" length of original feHeader: " << fedFeHeader->lengthInBytes() <<
"\n"
207 << debugStream.str();
213 for (uint8_t iFE = 1; iFE < 6; iFE++) {
215 .set32BitReservedRegister(iFE, fedFeHeader->get32BitWordFrom(fedFeHeader->feWord(iFE) + 10));
218 std::vector<bool> feEnabledVec;
221 feEnabledVec[iFE] = fedbuffer.trackerSpecialHeader().feEnabled(iFE);
223 for (uint8_t iFEUnitChannel = 0; iFEUnitChannel <
FEDCH_PER_FEUNIT; iFEUnitChannel++) {
225 .setChannelStatus(iFE, iFEUnitChannel, fedFeHeader->getChannelStatus(iFE, iFEUnitChannel));
231 std::ostringstream debugStream;
232 if (ifed == fed_ids.begin()) {
233 std::cout <<
"\nFEHeader after transfer: " << std::endl;
238 edm::LogWarning(
"DigiToRaw") <<
"[sistrip::DigiToRaw::createFedBuffers_]"
241 << debugStream.str();
247 for (
auto iconn = conns.begin(); iconn != conns.end(); iconn++) {
268 <<
"digis collection is not valid...";
272 typename std::vector<edm::DetSet<Digi_t> >::const_iterator digis =
collection->find(
key);
278 for (idigi = digis_begin; idigi != digis->
data.end(); idigi++) {
279 if (
STRIP(idigi, digis_begin) < ipair * 256 ||
STRIP(idigi, digis_begin) > ipair * 256 + 255) {
282 const unsigned short strip =
STRIP(idigi, digis_begin) % 256;
286 std::stringstream
ss;
287 ss <<
"[sistrip::DigiToRaw::createFedBuffers]"
288 <<
" strip >= strips_per_fedCh";
296 const uint16_t
value = 0;
298 std::stringstream
ss;
299 ss <<
"[sistrip::DigiToRaw::createFedBuffers]"
300 <<
" Incompatible ADC values in buffer!"
301 <<
" FedId/FedCh: " << *ifed <<
"/" << iconn->fedCh()
302 <<
" DetStrip: " <<
STRIP(idigi, digis_begin) <<
" FedChStrip: " <<
strip
303 <<
" AdcValue: " << (*idigi).adc() <<
" RawData[" <<
strip <<
"]: " <<
value;
309 chanData[
strip] = (*idigi).adc();
316 <<
"Almost at the end...";
319 FEDRawData& fedrawdata = buffers->FEDData(*ifed);
323 std::ostringstream debugStream;
325 edm::LogWarning(
"DigiToRaw") <<
"[sistrip::DigiToRaw::createFedBuffers_]"
328 << debugStream.str();
332 edm::LogWarning(
"DigiToRaw") <<
"[sistrip::DigiToRaw::createFedBuffers_]"
333 <<
"end of first loop on feds";
339 edm::LogWarning(
"DigiToRaw") <<
"[sistrip::DigiToRaw::createFedBuffers_]"
340 <<
"Now getting the digis..."
341 <<
" Number of feds: " << fed_ids.size() <<
" between " << *(fed_ids.begin())
342 <<
" and " << *(fed_ids.end());
345 for (
auto ifed = fed_ids.begin(); ifed != fed_ids.end(); ++ifed) {
350 for (
auto iconn = conns.begin(); iconn != conns.end(); iconn++) {
371 <<
"digis collection is not valid...";
375 typename std::vector<edm::DetSet<Digi_t> >::const_iterator digis =
collection->find(
key);
381 for (idigi = digis_begin; idigi != digis->
data.end(); idigi++) {
382 if (
STRIP(idigi, digis_begin) < ipair * 256 ||
STRIP(idigi, digis_begin) > ipair * 256 + 255) {
385 const unsigned short strip =
STRIP(idigi, digis_begin) % 256;
389 std::stringstream
ss;
390 ss <<
"[sistrip::DigiToRaw::createFedBuffers]"
391 <<
" strip >= strips_per_fedCh";
399 const uint16_t
value = 0;
401 std::stringstream
ss;
402 ss <<
"[sistrip::DigiToRaw::createFedBuffers]"
403 <<
" Incompatible ADC values in buffer!"
404 <<
" FedId/FedCh: " << *ifed <<
"/" << iconn->fedCh()
405 <<
" DetStrip: " <<
STRIP(idigi, digis_begin) <<
" FedChStrip: " <<
strip
406 <<
" AdcValue: " << (*idigi).adc() <<
" RawData[" <<
strip <<
"]: " <<
value;
412 chanData[
strip] = (*idigi).adc();
419 <<
"Almost at the end...";
422 FEDRawData& fedrawdata = buffers->FEDData(*ifed);
426 std::ostringstream debugStream;
428 edm::LogWarning(
"DigiToRaw") <<
"[sistrip::DigiToRaw::createFedBuffers_]"
431 << debugStream.str();
439 <<
"Exception caught : " <<
e.what();