10 #include "GaudiKernel/Bootstrap.h"
11 #include "GaudiKernel/IMessageSvc.h"
12 #include "GaudiKernel/ISvcLocator.h"
13 #include "GaudiKernel/MsgStream.h"
14 #include "GaudiKernel/StatusCode.h"
33 typedef std::vector<const CscRawData*> rpu;
34 std::map<uint16_t, rpu> mapRPU;
40 for (;
it != it_end; ++
it) {
45 else if (spuID > 4 && spuID <= 9)
48 mLog << MSG::ERROR <<
"CscROD_Encoder : RPU ID out of range for Initial Layout:: SPU ID = " << spuID <<
endmsg;
49 return StatusCode::FAILURE;
51 mLog <<
MSG::DEBUG <<
"CscROD_Encoder : SPU ID is " << spuID <<
" for RPU ID= " << rpuID <<
endmsg;
52 mapRPU[rpuID].push_back(rawData);
59 if (rpus.size() == 1) {
61 mLog <<
MSG::DEBUG <<
"CscROD_Encoder : Only one RPU with data in this ROD - RPU ID = " << rId <<
endmsg;
63 if (rId == emptyRPU) emptyRPU = 11;
64 mapRPU.insert(std::make_pair(emptyRPU, emptyVect));
73 mLog <<
MSG::DEBUG <<
"Number of RPU in this ROD = " << mapRPU.size() <<
endmsg;
75 unsigned int rpuIndex = 0;
76 for (std::pair<const uint16_t, rpu>& rpuPair : mapRPU) {
91 uint32_t spuSize[] = {0, 0, 0, 0, 0};
94 for (
const CscRawData* rawData : rpuPair.second) {
97 unsigned int i = 0x800;
100 else if (spuID > 4 && spuID < 9)
102 else if (spuID == 4 || spuID == 9)
105 mLog << MSG::ERROR <<
"CscROD_Encoder : SPU ID out of range - " << spuID <<
" Stop and fix it " <<
endmsg;
107 mLog <<
MSG::DEBUG <<
"CscROD_Encoder : SPU ID and Index = " << spuID <<
" " <<
i <<
endmsg;
111 numberOfDataWords += 2 + unitSize;
112 sampleDataWords += unitSize;
115 mLog <<
MSG::DEBUG <<
"CscROD_Encoder : Total Sample size = " << sampleDataWords <<
endmsg;
120 uint16_t rpuSize = numberOfDataWords + 4;
122 mLog <<
MSG::DEBUG <<
"CscRDO_Encoder : RPU ID and size (in words) = " << rpuID <<
" " << rpuSize <<
endmsg;
128 if (typeSize > rpuIndex)
130 else if (typeSize == 1)
139 uint32_t rpuHeader = (0xFFFF & rpuSize) | (0x000F &
type) << 16 | (0x000F & rpuID) << 24;
142 v.push_back(rpuHeader);
144 mLog <<
MSG::DEBUG <<
"CscROD_Encoder : this rpuHeader = " << MSG::hex << rpuHeader << MSG::dec <<
endmsg;
150 uint32_t precisionClusterWord = 0x0;
151 for (
unsigned int i = 0;
i < 4; ++
i) {
152 precisionClusterWord = precisionClusterWord | (spuSize[
i] << (24 -
i * 8));
153 mLog <<
MSG::DEBUG <<
"CscROD_Encoder : SPU ID = " << (
i + 1) <<
" cluster Counts " << spuSize[
i] <<
endmsg;
155 v.push_back(precisionClusterWord);
157 mLog <<
MSG::DEBUG <<
"CscROD_Encoder : Non-precision "
158 <<
" cluster Counts " << spuSize[4] <<
endmsg;
160 mLog <<
MSG::DEBUG <<
"CscROD_Encoder:: number of Cluster Data Words " << numberOfDataWords <<
endmsg;
163 uint32_t secondClusterWord = (0xFFFF & numberOfDataWords) | (0xF & firstBitSummary) << 16 | (0x1 & samplingPhase) << 17 |
165 v.push_back(secondClusterWord);
169 unsigned int check = 0;
170 for (
const CscRawData* rawData : rpuPair.second) {
179 uint32_t secondWord = (0xFFF &
width) | (0xFFFF &
time) << 16 | (0x1 & isTimeComputed) << 28;
181 v.push_back(secondWord);
184 const std::vector<uint16_t> amplitude = rawData->
samples();
185 std::vector<uint32_t> v32;
187 unsigned int n = v32.size();
188 for (
unsigned int i = 0;
i <
n;
i++) {
v.push_back(v32[
i]); }
190 mLog <<
MSG::DEBUG <<
"CscROD_Encoder : The with and the 32-bit sample words " <<
width <<
" " <<
n <<
endmsg;
195 mLog <<
MSG::DEBUG <<
"CScROD_Encoder : Check and number of data words " <<
check <<
" " << numberOfDataWords <<
endmsg;
200 return StatusCode::SUCCESS;