11 : pset_(ps), fedId_(0), run_number_(0), orbit_number_(0), bx_(0), lv1_(0), trgtype_(0)
28 int nLines, iz, ip, ix, iy, fed, kchip, pace, bundle, fiber, optorx;
30 file.open(lookup_.fullPath().c_str());
31 if( file.is_open() ) {
35 for (
int i=0;
i<nLines; ++
i) {
36 file>> iz >> ip >> ix >> iy >> fed >> kchip >> pace >> bundle >> fiber >> optorx;
38 zside_[kchip-1][pace-1] = iz;
39 pl_[kchip-1][pace-1] = ip;
40 x_[kchip-1][pace-1] = ix;
41 y_[kchip-1][pace-1] = iy;
45 edm::LogWarning(
"Invalid Data")<<
"ESUnpacker::ESUnpacker : Look up table file can not be found in "<<lookup_.fullPath().c_str();
56 if (nWords==0)
return;
58 int head, kPACE[4], kFlag1, kFlag2, kBC, kEC, optoBC, optoEC;
66 bool moreHeaders =
true;
69 FEDHeader ESHeader( reinterpret_cast<const unsigned char*>(header) );
70 if ( !ESHeader.
check() ) {
80 LogDebug(
"ESUnpacker") <<
"[ESUnpacker]: FED Header candidate. Is header? "<< ESHeader.
check();
83 else LogDebug(
"ESUnpacker")<<
" WARNING!, this is not a ES Header";
99 const Word64* trailer =
reinterpret_cast<const Word64*
>(rawData.
data())+(nWords-1); ++trailer;
100 bool moreTrailers =
true;
101 while (moreTrailers) {
103 FEDTrailer ESTrailer(reinterpret_cast<const unsigned char*>(trailer));
104 if ( !ESTrailer.
check()) {
109 if ( ESTrailer.
lenght() != nWords) {
115 if ( ESTrailer.
lenght() < 8) {
121 slinkCRC = (*trailer >> 2 ) & 0x1;
123 LogDebug(
"ESUnpacker")<<
"[ESUnpacker]: FED Trailer candidate. Is trailer? "<<ESTrailer.
check();
124 if (ESTrailer.
check())
125 LogDebug(
"ESUnpacker")<<
". Length of the ES event: "<<ESTrailer.
lenght();
126 else LogDebug(
"ESUnpacker")<<
" WARNING!, this is not a ES Trailer";
139 std::vector<int> FEch_status;
140 int dccHeaderCount = 0;
141 int dccLineCount = 0;
142 int dccHead, dccLine;
146 for (
const Word64* word=(header+1); word!=(header+dccWords+1); ++word) {
148 dccHead = (*word >> 60) &
m4;
149 if (dccHead == 3) dccHeaderCount++;
150 dccLine = (*word >> 56) &
m4;
152 if (dccLine != dccLineCount) {
158 if (dccLineCount == 1) {
159 dccCRC1_ = (*word >> 24) &
m1;
160 dccCRC2_ = (*word >> 25) &
m1;
161 dccCRC3_ = (*word >> 26) &
m1;
162 }
else if (dccLineCount == 2) {
177 if (dccLineCount == 3) {
186 if (dccLineCount == 4)
optoRX0_ = (*word >> 48) &
m8;
187 if (dccLineCount == 5)
optoRX1_ = (*word >> 48) &
m8;
188 if (dccLineCount == 6)
optoRX2_ = (*word >> 48) &
m8;
189 if (dccLineCount >=4) {
190 for (
unsigned int j=0;
j<12; ++
j) {
191 FEch_[(dccLineCount-4)*12+
j] = (*word >> (
j*4)) &
m4;
192 FEch_status.push_back(
FEch_[(dccLineCount-4)*12+
j]);
201 if (dccHeaderCount != 6) {
202 edm::LogWarning(
"Invalid Data")<<
"Invalid ES data : DCC header lines are "<<dccHeaderCount;
211 int enableOptoRX[3] = {-1, -1, -1};
212 int NenableOptoRX = 0;
214 enableOptoRX[NenableOptoRX] = 0;
218 enableOptoRX[NenableOptoRX] = 1;
222 enableOptoRX[NenableOptoRX] = 2;
228 for (
const Word64* word=(header+dccWords+1); word!=trailer; ++word) {
231 head = (*word >> 60) &
m4;
236 }
else if (head == 9) {
237 kid = (*word >> 2) & 0x07ff;
238 kPACE[0] = (*word >> 16) &
m1;
239 kPACE[1] = (*word >> 17) &
m1;
240 kPACE[2] = (*word >> 18) &
m1;
241 kPACE[3] = (*word >> 19) &
m1;
242 kFlag2 = (*word >> 20) &
m4;
243 kFlag1 = (*word >> 24) &
m8;
244 kBC = (*word >> 32) &
m16;
245 kEC = (*word >> 48) &
m8;
256 }
else if (head == 6) {
257 optoBC = (*word >> 32) &
m16;
258 optoEC = (*word >> 48) &
m8;
260 opto = enableOptoRX[iopto];
262 else if (opto==1) ESDCCHeader.
setOptoBC1(optoBC);
263 else if (opto==2) ESDCCHeader.
setOptoBC2(optoBC);
264 if (iopto < 2) ++iopto;
274 int pace = (word >> 53) &
m2;
275 if (kPACE[pace]==0)
return;
276 if (kid > 1511 || kid < 1)
return;
279 adc[0] = (word >> 0) &
m16;
280 adc[1] = (word >> 16) &
m16;
281 adc[2] = (word >> 32) &
m16;
284 if (
debug_)
LogDebug(
"ESUnpacker")<<kid<<
" "<<strip<<
" "<<pace<<
" "<<adc[0]<<
" "<<adc[1]<<
" "<<adc[2];
286 int zside, plane, ix, iy;
287 zside =
zside_[kid-1][pace];
288 plane =
pl_[kid-1][pace];
289 ix =
x_[kid-1][pace];
290 iy =
y_[kid-1][pace];
294 if (zside == 1 && plane == 1 && iy <= 20) strip = 31 -
strip;
295 if (zside == 1 && plane == 2 && ix > 20) strip = 31 -
strip;
296 if (zside == -1 && plane == 1 && iy > 20) strip = 31 -
strip;
297 if (zside == -1 && plane == 2 && ix <= 20) strip = 31 -
strip;
300 if (
debug_)
LogDebug(
"ESUnpacker")<<
"DetId : "<<zside<<
" "<<plane<<
" "<<ix<<
" "<<iy<<
" "<<strip+1;
304 ESDetId detId(strip+1, ix, iy, plane, zside);
320 std::ostringstream
str;
321 str <<
"Word64: " <<
reinterpret_cast<const std::bitset<64>&
> (word);
int adc(sample_type sample)
get the ADC sample (12 bits)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void setOptoBC(const int &OptoBC)
void setId(const int &kId)
void push_back(T const &t)
size_t size() const
Lenght of the data buffer in bytes.
ESUnpacker(const edm::ParameterSet &ps)
void setEC(const int &EC)
void setFlag1(const int &flag1)
const ESSample & sample(int i) const
void setSample(int i, const ESSample &sam)
void interpretRawData(int fedId, const FEDRawData &rawData, ESRawDataCollection &dccs, ESLocalRawDataCollection &kchips, ESDigiCollection &digis)
void setOptoEC(const int &OptoEC)
void word2digi(int kchip, int kPACE[4], const Word64 &word, ESDigiCollection &digis)
std::string print(const Word64 &word) const
void setFlag2(const int &flag2)
int lenght()
The length of the event fragment counted in 64-bit words including header and trailer.
static bool validDetId(int istrip, int ixs, int iys, int iplane, int iz)
check if a valid index combination
void push_back(unsigned int i)
void setBC(const int &BC)
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
int adc() const
get the ADC sample (singed 16 bits)
const edm::ParameterSet pset_
unsigned long long Word64