39 if (outputFile.length() && (file = fopen(outputFile.c_str(),
"wt")) ==
nullptr)
40 throw cms::Exception(
"OutputFile ") <<
"CSCTFPacker: cannot open output file (errno=" << errno
41 <<
"). Try outputFile=\"\"";
54 produces<FEDRawDataCollection>(
"CSCTFRawData");
58 CSCCDC_Tok = consumes<CSCCorrelatedLCTDigiCollection>(
edm::InputTag(lctProducer.label(), lctProducer.instance()));
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");
272 bzero(&header,
sizeof(header));
291 bzero(&counters,
sizeof(counters));
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++) {
327 memcpy(pos, &header, 16);
329 memcpy(pos, &counters, 8);
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));
385 std::copy((
unsigned char*)spDDUrecord, (
unsigned char*)pos, fedRawData.data());
386 FEDHeader csctfFEDHeader(fedRawData.data());
388 FEDTrailer csctfFEDTrailer(fedRawData.data() + (fedRawData.size() - 8));
389 csctfFEDTrailer.
set(fedRawData.data() + (fedRawData.size() - 8),
390 fedRawData.size() / 8,
398 fwrite(spDDUrecord, 2, pos - spDDUrecord,
file);
T getParameter(std::string const &) const
EventNumber_t event() const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
unsigned aligment_fifo_empty
bool getByToken(EDGetToken token, Handle< PROD > &result) const
unsigned clct_pattern_number
unsigned aligment_fifo_full
CSCTFPacker(const edm::ParameterSet &conf)
edm::EDGetTokenT< CSCTriggerContainer< csctf::TrackStub > > CSCTC_Tok
~CSCTFPacker(void) override
static void set(unsigned char *trailer, uint32_t lenght, uint16_t crc, uint8_t evt_stat, uint8_t tts, bool moreTrailers=false)
Set all fields in the trailer.
unsigned receiver_status_dv2
edm::InputTag trackProducer
unsigned receiver_status_dv1
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
void produce(edm::Event &e, const edm::EventSetup &c) override
unsigned receiver_status_er2
unsigned receiver_status_er1
unsigned short activeSectors
T const * product() const
std::pair< const_iterator, const_iterator > Range
edm::InputTag lctProducer
std::vector< DigiType >::const_iterator const_iterator
static int triggerSubSectorFromLabels(int station, int chamber)
edm::EDGetTokenT< CSCCorrelatedLCTDigiCollection > CSCCDC_Tok
char data[epos_bytes_allocation]
unsigned int valid_pattern
edm::EDGetTokenT< L1CSCTrackCollection > L1CSCTr_Tok