9 #include "GaudiKernel/TypeNameString.h"
13 #include "eformat/Issue.h"
15 using eformat::helper::SourceIdentifier;
22 declareProperty(
"IsCosmics",
m_isCosmic =
false);
30 m_hid2re.set(&(*m_cabling), &m_idHelperSvc->cscIdHelper());
32 m_hid2re.set_isCosmic();
33 if (m_isOldCosmic) m_hid2re.set_isOldCosmic();
35 return StatusCode::SUCCESS;
54 ATH_MSG_DEBUG(
"Error in ROB status word: 0x" << std::hex << *
it << std::dec);
59 eformat::helper::Version
ver(robFrag.rod_version());
60 const uint16_t& rodMinorVersion =
ver.minor_version();
62 ATH_MSG_DEBUG(
"in CscROD_Decoder::fillCollection :ROD version " << MSG::hex << rodMinorVersion << MSG::dec);
64 if (rodMinorVersion == 0x0200)
65 this->rodVersion2(robFrag, rdoIDC);
66 else if ((rodMinorVersion >> 8) == 4) {
67 this->rodVersion2(robFrag, rdoIDC);
68 }
else if (rodMinorVersion == 0
x1 ||
70 this->rodVersion1(robFrag, rdoIDC);
71 else if (rodMinorVersion == 0x0)
74 this->rodVersion0(robFrag, rdoIDC);
83 rodReadOut.
set(&m_idHelperSvc->cscIdHelper());
96 rodReadOut.
set(&m_idHelperSvc->cscIdHelper());
108 rodReadOut.
set(&m_idHelperSvc->cscIdHelper());
111 for (
unsigned int j = 0; j <
words.size(); ++j) {
114 samples.push_back(amp1);
115 samples.push_back(amp2);
121 ATH_MSG_DEBUG(
"===================================================");
122 ATH_MSG_DEBUG(
"in CscROD_Decode::fillCollection() - ROD version 2");
124 const uint32_t& detev_type = robFrag.rod_detev_type();
128 rodReadOut.
set(&m_idHelperSvc->cscIdHelper());
132 SourceIdentifier sid(robFrag.rod_source_id());
133 uint16_t subDetectorId = sid.subdetector_id();
134 uint32_t onlineRodId = sid.module_id();
135 ATH_MSG_DEBUG(
"Online ROD id is 0x" << MSG::hex << onlineRodId << MSG::dec);
138 bool check = m_cabling->offlineId(onlineRodId, rodId);
140 ATH_MSG_ERROR(
"enable to convert online ROD Id to offline ROD Id - "
141 <<
"check the cabling service ");
142 uint16_t idColl = m_cabling->collectionId(subDetectorId, rodId);
144 ATH_MSG_DEBUG(
"Online ROD / ROD / collection / subDetector IDs are 0x" << MSG::hex << onlineRodId << MSG::dec <<
" " << rodId <<
" "
145 << idColl <<
" " << subDetectorId);
150 std::unique_ptr<CscRawDataCollection> rawCollection(
nullptr);
153 ATH_MSG_DEBUG(
"CSC RDO collection already exist with collection hash = " << idColl <<
" collection filling is skipped!");
156 ATH_MSG_DEBUG(
"CSC RDO collection does not exist - creating a new one with hash = " << idColl);
157 rawCollection = std::make_unique<CscRawDataCollection>(idColl);
162 rawCollection->
setRodId(onlineRodId);
169 bool isSparsified = rawCollection->
sparsified();
172 bool ne = rawCollection->
neutron();
190 uint16_t numSamples = detev_type & 0xFF;
192 ATH_MSG_DEBUG(
"Event Type: " << MSG::hex << detev_type << MSG::dec);
193 ATH_MSG_DEBUG(
"Sampling Time: " << samplingTime <<
" Number of Samples: " << numSamples);
194 ATH_MSG_DEBUG(
"Is Calibration Enabled?: " << cal <<
" Calibration Amplitude: " << calAmplitude);
195 ATH_MSG_DEBUG(
"Calibration Layer: " << calLayer <<
" Latency: " << latency);
196 ATH_MSG_DEBUG(
"Is neutron rejection ON?: " << ne <<
" Is sparsified data?: " << isSparsified);
203 const unsigned int size = robFrag.rod_ndata();
208 robFrag.rod_data(vint);
210 bool isHeaderWordNull =
false;
211 bool isClusterWordsUnrealistic =
false;
217 isHeaderWordNull =
true;
227 if (rpuID_raw == 13) {
235 rawCollection->
addRPU(rpuID);
258 ATH_MSG_DEBUG(
"Error condition encounted on RPU ID = " << rpuID <<
" continuing ...");
265 <<
" Continue to next RPU ...");
277 ATH_MSG_DEBUG(
"Number of Precision Cluster word 0x" << MSG::hex << precisionClusters << MSG::dec);
278 uint32_t precisionClusterCounts = 0;
280 uint16_t counts = (precisionClusters >> (24 -
k * 8)) & 0xFF;
281 precisionClusterCounts += counts;
283 <<
"Layer Index = " <<
k <<
" Cluster Counts = " << counts);
284 unsigned int index = 0;
287 else if (rpuID == 11)
297 ATH_MSG_DEBUG(
"Second cluster word 0x" << MSG::hex << secondClusterWord << MSG::dec);
301 uint16_t nonPrecisionClusterCounts = (secondClusterWord >> 24) & 0xFF;
302 ATH_MSG_DEBUG(
"Summed Number of Clusters for non-precision layers " << nonPrecisionClusterCounts);
303 if (rpuID == 5) rawCollection->
set_spuCount(4, nonPrecisionClusterCounts);
305 rawCollection->
set_spuCount(9, nonPrecisionClusterCounts);
312 bool samplingPhase = (secondClusterWord >> 20) & 0
x1;
316 uint8_t firstBitSummary = (secondClusterWord >> 16) & 0xF;
320 uint16_t clusterDataWords = secondClusterWord & 0xFFFF;
324 uint32_t totalClusterCounts = nonPrecisionClusterCounts + precisionClusterCounts;
325 ATH_MSG_DEBUG(
"Total summed Cluster Count for precision and non-precision layers = " << totalClusterCounts);
327 if (totalClusterCounts == 0) {
336 while (clusterCount < totalClusterCounts) {
345 int stationId = m_idHelperSvc->cscIdHelper().stationName(
channelId);
346 int currentLayer = m_idHelperSvc->cscIdHelper().wireLayer(
channelId);
347 int orientation = m_idHelperSvc->cscIdHelper().measuresPhi(
channelId);
348 int stripId = m_idHelperSvc->cscIdHelper().strip(
channelId);
354 ATH_MSG_DEBUG(
" cluster time size word : stripId (CscIdHelper) 0x" << MSG::hex << time_width << MSG::dec <<
" " << stripId);
356 uint16_t time = (time_width >> 16) & 0xFFF;
359 isClusterWordsUnrealistic =
true;
362 bool isTimeComputed = (time_width >> 28) & 0
x1;
367 std::vector<uint16_t> amplitude;
368 for (
int j = 0; j < totalSampleWords; ++j) {
371 amplitude.push_back(amp1);
372 amplitude.push_back(amp2);
379 if (orientation == 0)
380 spuID =
static_cast<uint16_t>((stationId - 50) * 5 + currentLayer - 1);
382 spuID =
static_cast<uint16_t>(((stationId - 50) + 1) * 5 - 1);
388 ATH_MSG_INFO(
"Location word is not available and CscRawData is discarded!!");
397 << idColl <<
" " << hashId <<
" " << spuID <<
" " << stationId <<
" :: measphi" << orientation <<
" L"
398 << currentLayer <<
" strId " << stripId <<
" nStr " <<
width <<
" T" << time <<
" nSampWords "
399 << totalSampleWords <<
" " << m_idHelperSvc->cscIdHelper().show_to_string(
channelId));
402 ATH_MSG_DEBUG(
"****Total Cluster count = " << clusterCount <<
" for RPU ID " << rpuID);
407 ATH_MSG_INFO(
"ROB Fragment with ID 0x" << std::hex << robFrag.rod_source_id() << std::dec <<
" has word Counter ="
408 <<
counter <<
" must not exceed summed RPU sizes =" << rpuSize <<
" Discarded!!");
410 rawCollection->
erase(rawCollection->
begin(), rawCollection->
end());
416 ATH_MSG_DEBUG(
"" << (rpuSize -
counter) <<
" ghost words at the end of this RPU - skipping ...");
423 if (isHeaderWordNull) {
424 ATH_MSG_INFO(
" ROB Fragment with ID " << std::hex << robFrag.rod_source_id() << std::dec <<
" has null rpuID. Discarded!!");
425 rawCollection->
erase(rawCollection->
begin(), rawCollection->
end());
427 if (isClusterWordsUnrealistic) {
428 ATH_MSG_INFO(
" ROB Fragment with ID 0x" << std::hex << robFrag.rod_source_id() << std::dec
429 <<
" has too many cluster words. Discarded!!");
430 rawCollection->
erase(rawCollection->
begin(), rawCollection->
end());
435 if (status_lock.isFailure()) {
436 ATH_MSG_ERROR(
"Could not insert CscRawDataCollection into CscRawDataContainer...");
445 ATH_MSG_DEBUG(
"in CscROD_Decode::fillCollection() - ROD version 1");
450 rodReadOut.
set(
nullptr);
453 SourceIdentifier sid(robFrag.rod_source_id());
455 uint16_t subDetectorId = sid.subdetector_id();
458 uint16_t idColl = m_cabling->collectionId(subDetectorId, rodId);
463 std::unique_ptr<CscRawDataCollection> rawCollection(
nullptr);
466 ATH_MSG_DEBUG(
"CSC RDO collection already exist with collection hash = " << idColl <<
" converting is skipped!");
469 ATH_MSG_DEBUG(
"CSC RDO collection does not exist - creating a new one with hash = " << idColl);
470 rawCollection = std::make_unique<CscRawDataCollection>(idColl);
478 const unsigned int size = robFrag.rod_ndata();
509 bool dpuFragment = rodReadOut.
isDPU(
p[rodHeader]);
517 while (dpuFragment &&
i < (
size - rodFooter)) {
540 if (!rodReadOut.
discard(numChannel)) {
541 for (
unsigned int j = 0; j < numChannel; j++) {
549 std::vector<uint16_t> amplitude;
550 for (
unsigned int j = 1; j <= numSamples; j++) {
553 amplitude.push_back(rodReadOut.
getAmp1());
554 if (amplitude.size() < numSamples) amplitude.push_back(rodReadOut.
getAmp2());
563 ATH_MSG_INFO(
"this is a discard::numChannel = " << MSG::hex << numChannel);
566 if (
i < (
size - rodFooter)) dpuFragment = rodReadOut.
isDPU(
p[
i]);
571 if (status_lock.isFailure()) {
572 ATH_MSG_ERROR(
"Could not insert CscRawDataCollection into CscRawDataContainer...");
580 ATH_MSG_DEBUG(
"in CscROD_Decode::fillCollection() - ROD version 0");
585 rodReadOut.
set(
nullptr);
587 const unsigned int size = robFrag.rod_ndata();
600 uint16_t subId = (subDetectorId == 0x0) ? 0x6A : 0x69;
602 uint16_t idColl = m_cabling->collectionId(subId, rodId);
605 std::unique_ptr<CscRawDataCollection> rawCollection(
nullptr);
608 ATH_MSG_DEBUG(
"CSC RDO collection already exist with collection hash = " << idColl <<
" converting is skipped!");
611 ATH_MSG_DEBUG(
"CSC RDO collection does not exist - creating a new one with hash = " << idColl);
612 rawCollection = std::make_unique<CscRawDataCollection>(idColl);
624 bool bodyFragment = rodReadOut.
isBody(
p[rodHeader]);
630 while (bodyFragment &&
i < (
size - rodFooter)) {
656 std::vector<uint16_t> amplitudes;
657 amplitudes.push_back(rodReadOut.
getAmp1());
658 amplitudes.push_back(rodReadOut.
getAmp2());
659 amplitudes.push_back(rodReadOut.
getAmp3());
660 amplitudes.push_back(rodReadOut.
getAmp4());
666 bodyFragment = rodReadOut.
isBody(
p[
i]);
671 if (status_lock.isFailure()) {
672 ATH_MSG_ERROR(
"Could not insert CscRawDataCollection into CscRawDataContainer...");