44 if( outputFile.length() && (file = fopen(outputFile.c_str(),
"wt"))==
NULL )
45 throw cms::Exception(
"OutputFile ")<<
"CSCTFPacker: cannot open output file (errno="<<errno<<
"). Try outputFile=\"\"";
58 produces<FEDRawDataCollection>(
"CSCTFRawData");
70 bzero(&meDataRecord,
sizeof(meDataRecord));
72 bzero(&meDataHeader,
sizeof(meDataHeader));
78 int station = (*csc).first.station()-1;
79 int cscId = (*csc).first.triggerCscId()-1;
80 int sector = (*csc).first.triggerSector()-1 + ( (*csc).first.endcap()==1 ? 0 : 6 );
83 if( tbin>6 || tbin<0 ){
84 edm::LogError(
"CSCTFPacker|produce")<<
" LCT's BX="<<tbin<<
" is out of 0-6 window";
87 int fpga = ( subSector ? subSector-1 : station+1 );
91 if( sector<0 || sector>11 || station<0 || station>3 || cscId<0 || cscId>8 || lctId<0 || lctId>1){
92 edm::LogInfo(
"CSCTFPacker: CSC digi are out of range: ")<<
"sector="<<sector<<
", station="<<station<<
", cscId="<<cscId<<
", lctId="<<lctId;
97 meDataRecord[sector][tbin][fpga][cscId][lctId].
quality_ = lct->getQuality();
98 meDataRecord[sector][tbin][fpga][cscId][lctId].
wire_group_id = lct->getKeyWG();
100 meDataRecord[sector][tbin][fpga][cscId][lctId].
clct_pattern_id = (
swapME1strips && cscId<3 && station==0 && (*csc).first.endcap()==2 && lct->getStrip()<65 ? 65 - lct->getStrip() : lct->getStrip() );
101 meDataRecord[sector][tbin][fpga][cscId][lctId].
csc_id = (*csc).first.triggerCscId();
102 meDataRecord[sector][tbin][fpga][cscId][lctId].
left_right = lct->getBend();
103 meDataRecord[sector][tbin][fpga][cscId][lctId].
bx0_ = 0;
104 meDataRecord[sector][tbin][fpga][cscId][lctId].
bc0_ = 0;
106 meDataRecord[sector][tbin][fpga][cscId][lctId].
me_bxn = 0;
111 meDataRecord[sector][tbin][fpga][cscId][lctId].
link_id = lct->getMPCLink();
112 meDataRecord[sector][tbin][fpga][cscId][lctId].
mpc_id = 0;
113 meDataRecord[sector][tbin][fpga][cscId][lctId].
err_prop_cnt = 0;
118 if( lct->isValid() ){
119 switch( (meDataHeader[sector][tbin].vp_bits>>(fpga*3)) & 0x7 ){
120 case 0x0: meDataHeader[sector][tbin].
vp_bits |= (0x1 << (fpga*3));
break;
121 case 0x1: meDataHeader[sector][tbin].
vp_bits |= (0x3 << (fpga*3));
break;
122 case 0x3: meDataHeader[sector][tbin].
vp_bits |= (0x7 << (fpga*3));
break;
124 edm::LogInfo(
"CSCTFPacker: more than 3 LCTs from a single MPC in one BX!!!");
128 meDataRecord[sector][tbin][fpga][cscId][lctId].
valid_pattern = 1;
130 meDataHeader[sector][tbin].
vq_a = 0;
131 meDataHeader[sector][tbin].
vq_b = 0;
132 meDataHeader[sector][tbin].
se_bits = 0;
133 meDataHeader[sector][tbin].
sm_bits = 0;
134 meDataHeader[sector][tbin].
af_bits = 0;
135 meDataHeader[sector][tbin].
bx_bits = 0;
137 meDataHeader[sector][tbin].
spare_1 = 0;
142 bzero(&mbDataRecord,
sizeof(mbDataRecord));
147 std::vector<csctf::TrackStub> stubs = barrelStubs.
product()->get();
148 for(std::vector<csctf::TrackStub>::const_iterator
dt=stubs.begin();
dt!=stubs.end();
dt++){
149 int sector =
dt->sector()-1 + (
dt->endcap()==1 ? 0 : 6 );
150 int subSector =
dt->subsector()-1;
152 if( tbin<0 || tbin>6 || sector<0 || sector>11 || subSector<0 || subSector>11 ){
153 edm::LogInfo(
"CSCTFPacker: CSC DT digi are out of range: ")<<
" sector="<<sector<<
" subSector="<<subSector<<
" tbin="<<tbin;
156 mbDataRecord[sector][subSector][tbin].
quality_ =
dt->getQuality();
157 mbDataRecord[sector][subSector][tbin].
phi_bend_ =
dt->getBend();
158 mbDataRecord[sector][subSector][tbin].
flag_ =
dt->getStrip();
159 mbDataRecord[sector][subSector][tbin].
cal_ =
dt->getKeyWG();
160 mbDataRecord[sector][subSector][tbin].
phi_ =
dt->phiPacked();
161 mbDataRecord[sector][subSector][tbin].
bxn1_ =(
dt->getBX0()>>1)&0x1;
162 mbDataRecord[sector][subSector][tbin].
bxn0_ =
dt->getBX0()&0x1;
163 mbDataRecord[sector][subSector][tbin].
bc0_ =
dt->getPattern();
164 mbDataRecord[sector][subSector][tbin].
mb_bxn_ =
dt->getCSCID();
166 case 0: meDataHeader[sector][tbin].
vq_a = 1;
break;
167 case 1: meDataHeader[sector][tbin].
vq_b = 1;
break;
168 default:
edm::LogInfo(
"CSCTFPacker: subSector=")<<subSector;
break;
170 mbDataRecord[sector][subSector][tbin].
id_ =
dt->getMPCLink();
176 bzero(&spDataRecord,
sizeof(spDataRecord));
178 bzero(&nTrk,
sizeof(nTrk));
184 for(L1CSCTrackCollection::const_iterator trk=tracks->begin(); trk!=tracks->end(); trk++){
185 int sector = 6*(trk->first.endcap()-1)+trk->first.sector()-1;
188 if( tbin>6 || tbin<0 ){
189 edm::LogError(
"CSCTFPacker|analyze")<<
" Track's BX="<<tbin<<
" is out of 0-6 window";
192 if( sector<0 || sector>11 ){
193 edm::LogError(
"CSCTFPacker|analyze")<<
" Track's sector="<<sector<<
" is out of range";
196 spDataRecord[sector][tbin][nTrk[sector][tbin]].
phi_ = trk->first.localPhi();
197 spDataRecord[sector][tbin][nTrk[sector][tbin]].
sign_ =(trk->first.ptLUTAddress()>>20)&0x1;
198 spDataRecord[sector][tbin][nTrk[sector][tbin]].
front_rear = trk->first.front_rear();
199 spDataRecord[sector][tbin][nTrk[sector][tbin]].
charge_ = trk->first.charge_packed();
200 spDataRecord[sector][tbin][nTrk[sector][tbin]].
eta_ = trk->first.eta_packed();
202 spDataRecord[sector][tbin][nTrk[sector][tbin]].
halo_ = trk->first.finehalo_packed();
203 spDataRecord[sector][tbin][nTrk[sector][tbin]].
se = 0;
204 spDataRecord[sector][tbin][nTrk[sector][tbin]].
deltaPhi12_= trk->first.ptLUTAddress()&0xFF;
205 spDataRecord[sector][tbin][nTrk[sector][tbin]].
deltaPhi23_=(trk->first.ptLUTAddress()>>8)&0xF;
206 spDataRecord[sector][tbin][nTrk[sector][tbin]].
bxn0_ = 0;
207 spDataRecord[sector][tbin][nTrk[sector][tbin]].
bc0_ = 0;
209 spDataRecord[sector][tbin][nTrk[sector][tbin]].
me1_id = trk->first.me1ID();
210 spDataRecord[sector][tbin][nTrk[sector][tbin]].
me2_id = trk->first.me2ID();
211 spDataRecord[sector][tbin][nTrk[sector][tbin]].
me3_id = trk->first.me3ID();
212 spDataRecord[sector][tbin][nTrk[sector][tbin]].
me4_id = trk->first.me4ID();
213 spDataRecord[sector][tbin][nTrk[sector][tbin]].
mb_id = trk->first.mb1ID();
214 spDataRecord[sector][tbin][nTrk[sector][tbin]].
ms_id = 0;
217 spDataRecord[sector][tbin][nTrk[sector][tbin]].
me1_tbin = trk->first.me1Tbin();
218 spDataRecord[sector][tbin][nTrk[sector][tbin]].
me2_tbin = trk->first.me2Tbin();
219 spDataRecord[sector][tbin][nTrk[sector][tbin]].
me3_tbin = trk->first.me3Tbin();
220 spDataRecord[sector][tbin][nTrk[sector][tbin]].
me4_tbin = trk->first.me4Tbin();
221 spDataRecord[sector][tbin][nTrk[sector][tbin]].
mb_tbin = trk->first.mb1Tbin();
223 if( trk->first.mb1ID() ){
224 int subSector = (trk->first.mb1ID() - 1)%2;
225 int MBtbin = tbin - spDataRecord[sector][tbin][nTrk[sector][tbin]].
mb_tbin;
226 if( subSector<0 || subSector>1 || MBtbin<0 || MBtbin>7 || !mbDataRecord[sector][subSector][MBtbin].id_ )
227 spDataRecord[sector][tbin][nTrk[sector][tbin]].
mb_id = ( subSector ? 6 : 5 );
229 spDataRecord[sector][tbin][nTrk[sector][tbin]].
id_ = nTrk[sector][tbin]+1;
231 nTrk[sector][tbin]++;
232 switch(nTrk[sector][tbin]){
233 case 1: meDataHeader[sector][tbin].
mode1 = (trk->first.ptLUTAddress()>>16)&0xF;
break;
234 case 2: meDataHeader[sector][tbin].
mode2 = (trk->first.ptLUTAddress()>>16)&0xF;
break;
235 case 3: meDataHeader[sector][tbin].
mode3 = (trk->first.ptLUTAddress()>>16)&0xF;
break;
237 edm::LogInfo(
"More than 3 tracks from one SP in the BX");
245 bzero(&header,
sizeof(header));
264 bzero(&counters,
sizeof(counters));
267 bzero(&trailer,
sizeof(trailer));
280 unsigned short spDDUrecord[700*12], *
pos=spDDUrecord;
281 bzero(&spDDUrecord,
sizeof(spDDUrecord));
282 int eventNumber = e.
id().
event();
283 *pos++ = 0x0000; *pos++ = 0x0000; *pos++ = 0xFFFF&eventNumber; *pos++ = 0x5000|(eventNumber>>16);
284 *pos++ = 0x0000; *pos++ = 0x8000; *pos++ = 0x0001; *pos++ = 0x8000;
285 *pos++ = 0x0000; *pos++ = 0x0000; *pos++ = 0x0000; *pos++ = 0x0000;
287 for(
int sector=0; sector<12; sector++){
290 memcpy(pos,&header,16);
292 memcpy(pos,&counters,8);
295 for(
int tbin=0; tbin<
nTBINs; tbin++){
296 memcpy(pos,&meDataHeader[sector][tbin],16);
298 for(
int fpga=0; fpga<5; fpga++){
301 for(
int cscId=0; cscId<9; cscId++)
302 for(
int lctId=0; lctId<2; lctId++)
304 if( meDataRecord[sector][tbin][fpga][cscId][lctId].valid_pattern
305 && meDataRecord[sector][tbin][fpga][cscId][lctId].link_id==
link+1 ){
306 memcpy(pos,&meDataRecord[sector][tbin][fpga][cscId][lctId],8);
313 for(
int subSector=0; subSector<2; subSector++)
314 if( !
zeroSuppression || (subSector==0 && meDataHeader[sector][tbin].vq_a) || (subSector==1 && meDataHeader[sector][tbin].
vq_b) ){
315 memcpy(pos,&mbDataRecord[sector][subSector][tbin],8);
318 for(
int trk=0; trk<3; trk++){
320 memcpy(pos,&spDataRecord[sector][tbin][trk],8);
325 memcpy(pos,&trailer,16);
329 *pos++ = 0x8000; *pos++ = 0x8000; *pos++ = 0xFFFF; *pos++ = 0x8000;
330 *pos++ = 0x0000; *pos++ = 0x0000; *pos++ = 0x0000; *pos++ = 0x0000;
331 *pos++ = 0x0000; *pos++ = 0x0000; *pos++ = 0x0000; *pos++ = 0x0000;
336 fedRawData.
resize((pos-spDDUrecord)*
sizeof(
unsigned short));
337 std::copy((
unsigned char*)spDDUrecord,(
unsigned char*)pos,fedRawData.
data());
342 e.
put(data,
"CSCTFRawData");
345 if(
file) fwrite(spDDUrecord,2,pos-spDDUrecord,
file);
T getParameter(std::string const &) const
EventNumber_t event() const
unsigned aligment_fifo_empty
unsigned clct_pattern_number
unsigned aligment_fifo_full
virtual void produce(edm::Event &e, const edm::EventSetup &c)
CSCTFPacker(const edm::ParameterSet &conf)
static void set(unsigned char *trailer, int evt_lgth, int crc, int evt_stat, int tts, bool T=false)
Set all fields in the trailer.
size_t size() const
Lenght of the data buffer in bytes.
std::string link(std::string &nm, std::string &ns)
unsigned receiver_status_dv2
edm::InputTag trackProducer
unsigned receiver_status_dv1
void resize(size_t newsize)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
unsigned receiver_status_er2
unsigned receiver_status_er1
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
unsigned short activeSectors
edm::InputTag lctProducer
std::vector< DigiType >::const_iterator const_iterator
static int triggerSubSectorFromLabels(int station, int chamber)
T const * product() const
char data[epos_bytes_allocation]
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
std::pair< const_iterator, const_iterator > Range
unsigned int valid_pattern