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() ) {
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 std::cout<<
"ESUnpacker::ESUnpacker : Look up table file can not be found in "<<lookup_.fullPath().c_str()<<std::endl;
56 if (nWords==0)
return;
58 int head, kPACE[4], kFlag1, kFlag2, kBC, kEC, optoBC, optoEC, ttcEC;
65 const Word64* header =
reinterpret_cast<const Word64*
>(rawData.
data()); --header;
66 bool moreHeaders =
true;
69 FEDHeader ESHeader( reinterpret_cast<const unsigned char*>(header) );
70 if ( !ESHeader.
check() ) {
80 std::cout<<
"[ESUnpacker]: FED Header candidate. Is header? "<< ESHeader.
check();
83 else std::cout<<
" WARNING!, this is not a ES Header"<<std::endl;
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 std::cout<<
"[ESUnpacker]: FED Trailer candidate. Is trailer? "<<ESTrailer.
check();
124 if (ESTrailer.
check())
125 std::cout<<
". Length of the ES event: "<<ESTrailer.
lenght()<<std::endl;
126 else std::cout<<
" WARNING!, this is not a ES Trailer"<<std::endl;
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;
214 for (
const Word64* word=(header+dccWords+1); word!=trailer; ++word) {
217 head = (*word >> 60) &
m4;
222 }
else if (head == 9) {
223 kid = (*word >> 2) & 0x07ff;
224 kPACE[0] = (*word >> 16) &
m1;
225 kPACE[1] = (*word >> 17) &
m1;
226 kPACE[2] = (*word >> 18) &
m1;
227 kPACE[3] = (*word >> 19) &
m1;
228 kFlag2 = (*word >> 20) &
m4;
229 kFlag1 = (*word >> 24) &
m8;
230 kBC = (*word >> 32) &
m16;
231 kEC = (*word >> 48) &
m8;
242 }
else if (head == 6) {
243 ttcEC = (*word >> 0) &
m32;
244 optoBC = (*word >> 32) &
m16;
245 optoEC = (*word >> 48) &
m8;
247 else if (opto==1) ESDCCHeader.
setOptoBC1(optoBC);
248 else if (opto==2) ESDCCHeader.
setOptoBC2(optoBC);
259 int pace = (word >> 53) &
m2;
260 if (kPACE[pace]==0)
return;
261 if (kid > 1511 || kid < 1)
return;
264 adc[0] = (word >> 0) &
m16;
265 adc[1] = (word >> 16) &
m16;
266 adc[2] = (word >> 32) &
m16;
269 if (
debug_)
std::cout<<kid<<
" "<<strip<<
" "<<pace<<
" "<<adc[0]<<
" "<<adc[1]<<
" "<<adc[2]<<std::endl;
271 int zside, plane, ix, iy;
272 zside =
zside_[kid-1][pace];
273 plane =
pl_[kid-1][pace];
274 ix =
x_[kid-1][pace];
275 iy =
y_[kid-1][pace];
279 if (zside == 1 && plane == 1 && iy <= 20) strip = 31 -
strip;
280 if (zside == 1 && plane == 2 && ix > 20) strip = 31 -
strip;
281 if (zside == -1 && plane == 1 && iy > 20) strip = 31 -
strip;
282 if (zside == -1 && plane == 2 && ix <= 20) strip = 31 -
strip;
285 if (
debug_)
std::cout<<
"DetId : "<<zside<<
" "<<plane<<
" "<<ix<<
" "<<iy<<
" "<<strip+1<<std::endl;
289 ESDetId detId(strip+1, ix, iy, plane, zside);
305 std::ostringstream str;
306 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 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_