40 throw cms::Exception(
"OutputFile ") <<
"CSCTFPacker: cannot open output file (errno=" << errno
41 <<
"). Try outputFile=\"\"";
54 produces<FEDRawDataCollection>(
"CSCTFRawData");
72 bzero(&meDataRecord,
sizeof(meDataRecord));
74 bzero(&meDataHeader,
sizeof(meDataHeader));
82 int station = (*csc).first.station() - 1;
83 int cscId = (*csc).first.triggerCscId() - 1;
84 int sector = (*csc).first.triggerSector() - 1 + ((*csc).first.endcap() == 1 ? 0 : 6);
87 if (tbin > 6 || tbin < 0) {
88 edm::LogError(
"CSCTFPacker|produce") <<
" LCT's BX=" << tbin <<
" is out of 0-6 window";
91 int fpga = (subSector ? subSector - 1 :
station + 1);
95 if (sector < 0 || sector > 11 || station < 0 || station > 3 || cscId < 0 || cscId > 8 || lctId < 0 || lctId > 1) {
97 <<
"sector=" << sector <<
", station=" <<
station <<
", cscId=" << cscId <<
", lctId=" << lctId;
102 meDataRecord[sector][tbin][fpga][cscId][lctId].
quality_ = lct->getQuality();
103 meDataRecord[sector][tbin][fpga][cscId][lctId].
wire_group_id = lct->getKeyWG();
106 (
swapME1strips && cscId < 3 &&
station == 0 && (*csc).first.endcap() == 2 && lct->getStrip() < 65
107 ? 65 - lct->getStrip()
109 meDataRecord[sector][tbin][fpga][cscId][lctId].
csc_id = (*csc).first.triggerCscId();
110 meDataRecord[sector][tbin][fpga][cscId][lctId].
left_right = lct->getBend();
111 meDataRecord[sector][tbin][fpga][cscId][lctId].
bx0_ = 0;
112 meDataRecord[sector][tbin][fpga][cscId][lctId].
bc0_ = 0;
114 meDataRecord[sector][tbin][fpga][cscId][lctId].
me_bxn = 0;
119 meDataRecord[sector][tbin][fpga][cscId][lctId].
link_id = lct->getMPCLink();
120 meDataRecord[sector][tbin][fpga][cscId][lctId].
mpc_id = 0;
121 meDataRecord[sector][tbin][fpga][cscId][lctId].
err_prop_cnt = 0;
126 if (lct->isValid()) {
127 switch ((meDataHeader[sector][tbin].vp_bits >> (fpga * 3)) & 0x7) {
129 meDataHeader[sector][tbin].
vp_bits |= (0x1 << (fpga * 3));
132 meDataHeader[sector][tbin].
vp_bits |= (0x3 << (fpga * 3));
135 meDataHeader[sector][tbin].
vp_bits |= (0x7 << (fpga * 3));
138 edm::LogInfo(
"CSCTFPacker: more than 3 LCTs from a single MPC in one BX!!!");
142 meDataRecord[sector][tbin][fpga][cscId][lctId].
valid_pattern = 1;
144 meDataHeader[sector][tbin].
vq_a = 0;
145 meDataHeader[sector][tbin].
vq_b = 0;
146 meDataHeader[sector][tbin].
se_bits = 0;
147 meDataHeader[sector][tbin].
sm_bits = 0;
148 meDataHeader[sector][tbin].
af_bits = 0;
149 meDataHeader[sector][tbin].
bx_bits = 0;
151 meDataHeader[sector][tbin].
spare_1 = 0;
156 bzero(&mbDataRecord,
sizeof(mbDataRecord));
161 std::vector<csctf::TrackStub> stubs = barrelStubs.
product()->get();
162 for (std::vector<csctf::TrackStub>::const_iterator
dt = stubs.begin();
dt != stubs.end();
dt++) {
163 int sector =
dt->sector() - 1 + (
dt->endcap() == 1 ? 0 : 6);
164 int subSector =
dt->subsector() - 1;
166 if (tbin < 0 || tbin > 6 || sector < 0 || sector > 11 || subSector < 0 || subSector > 11) {
167 edm::LogInfo(
"CSCTFPacker: CSC DT digi are out of range: ")
168 <<
" sector=" << sector <<
" subSector=" << subSector <<
" tbin=" << tbin;
171 mbDataRecord[sector][subSector][tbin].
quality_ =
dt->getQuality();
172 mbDataRecord[sector][subSector][tbin].
phi_bend_ =
dt->getBend();
173 mbDataRecord[sector][subSector][tbin].
flag_ =
dt->getStrip();
174 mbDataRecord[sector][subSector][tbin].
cal_ =
dt->getKeyWG();
175 mbDataRecord[sector][subSector][tbin].
phi_ =
dt->phiPacked();
176 mbDataRecord[sector][subSector][tbin].
bxn1_ = (
dt->getBX0() >> 1) & 0
x1;
177 mbDataRecord[sector][subSector][tbin].
bxn0_ =
dt->getBX0() & 0x1;
178 mbDataRecord[sector][subSector][tbin].
bc0_ =
dt->getPattern();
179 mbDataRecord[sector][subSector][tbin].
mb_bxn_ =
dt->getCSCID();
182 meDataHeader[sector][tbin].
vq_a = 1;
185 meDataHeader[sector][tbin].
vq_b = 1;
191 mbDataRecord[sector][subSector][tbin].
id_ =
dt->getMPCLink();
197 bzero(&spDataRecord,
sizeof(spDataRecord));
199 bzero(&nTrk,
sizeof(nTrk));
205 for (L1CSCTrackCollection::const_iterator trk =
tracks->begin(); trk !=
tracks->end(); trk++) {
206 int sector = 6 * (trk->first.endcap() - 1) + trk->first.sector() - 1;
209 if (tbin > 6 || tbin < 0) {
210 edm::LogError(
"CSCTFPacker|analyze") <<
" Track's BX=" << tbin <<
" is out of 0-6 window";
213 if (sector < 0 || sector > 11) {
214 edm::LogError(
"CSCTFPacker|analyze") <<
" Track's sector=" << sector <<
" is out of range";
217 spDataRecord[sector][tbin][nTrk[sector][tbin]].
phi_ = trk->first.localPhi();
218 spDataRecord[sector][tbin][nTrk[sector][tbin]].
sign_ = (trk->first.ptLUTAddress() >> 20) & 0
x1;
219 spDataRecord[sector][tbin][nTrk[sector][tbin]].
front_rear = trk->first.front_rear();
220 spDataRecord[sector][tbin][nTrk[sector][tbin]].
charge_ = trk->first.charge_packed();
221 spDataRecord[sector][tbin][nTrk[sector][tbin]].
eta_ = trk->first.eta_packed();
223 spDataRecord[sector][tbin][nTrk[sector][tbin]].
halo_ = trk->first.finehalo_packed();
224 spDataRecord[sector][tbin][nTrk[sector][tbin]].
se = 0;
225 spDataRecord[sector][tbin][nTrk[sector][tbin]].
deltaPhi12_ = trk->first.ptLUTAddress() & 0xFF;
226 spDataRecord[sector][tbin][nTrk[sector][tbin]].
deltaPhi23_ = (trk->first.ptLUTAddress() >> 8) & 0xF;
227 spDataRecord[sector][tbin][nTrk[sector][tbin]].
bxn0_ = 0;
228 spDataRecord[sector][tbin][nTrk[sector][tbin]].
bc0_ = 0;
230 spDataRecord[sector][tbin][nTrk[sector][tbin]].
me1_id = trk->first.me1ID();
231 spDataRecord[sector][tbin][nTrk[sector][tbin]].
me2_id = trk->first.me2ID();
232 spDataRecord[sector][tbin][nTrk[sector][tbin]].
me3_id = trk->first.me3ID();
233 spDataRecord[sector][tbin][nTrk[sector][tbin]].
me4_id = trk->first.me4ID();
234 spDataRecord[sector][tbin][nTrk[sector][tbin]].
mb_id = trk->first.mb1ID();
235 spDataRecord[sector][tbin][nTrk[sector][tbin]].
ms_id = 0;
238 spDataRecord[sector][tbin][nTrk[sector][tbin]].
me1_tbin = trk->first.me1Tbin();
239 spDataRecord[sector][tbin][nTrk[sector][tbin]].
me2_tbin = trk->first.me2Tbin();
240 spDataRecord[sector][tbin][nTrk[sector][tbin]].
me3_tbin = trk->first.me3Tbin();
241 spDataRecord[sector][tbin][nTrk[sector][tbin]].
me4_tbin = trk->first.me4Tbin();
242 spDataRecord[sector][tbin][nTrk[sector][tbin]].
mb_tbin = trk->first.mb1Tbin();
244 if (trk->first.mb1ID()) {
245 int subSector = (trk->first.mb1ID() - 1) % 2;
246 int MBtbin = tbin - spDataRecord[sector][tbin][nTrk[sector][tbin]].
mb_tbin;
247 if (subSector < 0 || subSector > 1 || MBtbin < 0 || MBtbin > 7 || !mbDataRecord[sector][subSector][MBtbin].id_)
248 spDataRecord[sector][tbin][nTrk[sector][tbin]].
mb_id = (subSector ? 6 : 5);
250 spDataRecord[sector][tbin][nTrk[sector][tbin]].
id_ = nTrk[sector][tbin] + 1;
252 nTrk[sector][tbin]++;
253 switch (nTrk[sector][tbin]) {
255 meDataHeader[sector][tbin].
mode1 = (trk->first.ptLUTAddress() >> 16) & 0xF;
258 meDataHeader[sector][tbin].
mode2 = (trk->first.ptLUTAddress() >> 16) & 0xF;
261 meDataHeader[sector][tbin].
mode3 = (trk->first.ptLUTAddress() >> 16) & 0xF;
264 edm::LogInfo(
"More than 3 tracks from one SP in the BX");
274 header.header_mark_1 = 0x9;
275 header.header_mark_2 = 0x9;
276 header.header_mark_3 = 0x9;
277 header.header_mark_4 = 0x9;
279 header.header_mark_5 = 0xA;
280 header.header_mark_6 = 0xA;
281 header.header_mark_7 = 0xA;
282 header.header_mark_8 = 0xA;
294 bzero(&trailer,
sizeof(trailer));
307 unsigned short spDDUrecord[700 * 12], *
pos = spDDUrecord;
308 bzero(&spDDUrecord,
sizeof(spDDUrecord));
309 int eventNumber =
e.id().event();
312 *
pos++ = 0xFFFF & eventNumber;
313 *
pos++ = 0x5000 | (eventNumber >> 16);
323 for (
int sector = 0; sector < 12; sector++) {
326 header.sp_trigger_sector = sector + 1;
332 for (
int tbin = 0; tbin <
nTBINs; tbin++) {
333 memcpy(
pos, &meDataHeader[sector][tbin], 16);
335 for (
int fpga = 0; fpga < 5; fpga++) {
338 for (
int cscId = 0; cscId < 9; cscId++)
339 for (
int lctId = 0; lctId < 2; lctId++)
341 if (meDataRecord[sector][tbin][fpga][cscId][lctId].valid_pattern &&
342 meDataRecord[sector][tbin][fpga][cscId][lctId].link_id ==
link + 1) {
343 memcpy(
pos, &meDataRecord[sector][tbin][fpga][cscId][lctId], 8);
349 pos += 4 * (3 - nLCTs);
351 for (
int subSector = 0; subSector < 2; subSector++)
352 if (!
zeroSuppression || (subSector == 0 && meDataHeader[sector][tbin].vq_a) ||
353 (subSector == 1 && meDataHeader[sector][tbin].
vq_b)) {
354 memcpy(
pos, &mbDataRecord[sector][subSector][tbin], 8);
357 for (
int trk = 0; trk < 3; trk++) {
359 memcpy(
pos, &spDataRecord[sector][tbin][trk], 8);
364 memcpy(
pos, &trailer, 16);
382 auto data = std::make_unique<FEDRawDataCollection>();
384 fedRawData.resize((
pos - spDDUrecord) *
sizeof(
unsigned short));
398 fwrite(spDDUrecord, 2,
pos - spDDUrecord,
file);