CMS 3D CMS Logo

CSCALCTHeader.cc
Go to the documentation of this file.
6 #include <iomanip>
7 
8 #ifdef LOCAL_UNPACK
9 
10 bool CSCALCTHeader::debug=false;
11 short unsigned int CSCALCTHeader::firmwareVersion=2007;
12 
13 #else
14 
15 #include <atomic>
16 
17 std::atomic<bool> CSCALCTHeader::debug{false};
18 std::atomic<short unsigned int> CSCALCTHeader::firmwareVersion{2007};
19 
20 #endif
21 
23 : header2006(chamberType),
24  header2007(chamberType)
25 { //constructor for digi->raw packing based on header2006
26  if (firmwareVersion==2006)
27  {
29  }
30  else if(firmwareVersion==2007)
31  {
33  // assume no virtex or masks or registers
35  theALCTs.resize(header2007.lctBins*2);
36  }
37  else
38  {
39  edm::LogError("CSCALCTHeader|CSCRawToDigi")
40  <<"Cannot construct ALCT header: ALCT firmware version is bad/not defined!" << firmwareVersion;
41  }
42 
43 }
44 
45 CSCALCTHeader::CSCALCTHeader(const unsigned short * buf) {
50  constexpr unsigned short int collisionMaskWordcount[7] = { 8, 8,12,16,16,24,28};
51  constexpr unsigned short int hotChannelMaskWordcount[7] = {18,18,24,36,36,48,60};
52 
54  if (buf[0]==0xDB0A) {
55  firmwareVersion=2007;
56  }
57  else if ( (buf[0]&0xF800)==0x6000 ) {
58  firmwareVersion=2006;
59  }
60  else {
61  edm::LogError("CSCALCTHeader|CSCRawToDigi") << "failed to determine ALCT firmware version!!";
62  }
63 
64  LogTrace("CSCALCTHeader|CSCRawToDigi") << "firmware version - " << firmwareVersion;
65 
67 #ifdef LOCAL_UNPACK
68  switch (firmwareVersion) {
69 #else
70  switch (firmwareVersion.load()) {
71 #endif
72  case 2006:
74  buf +=header2006.sizeInWords();
76  buf +=alcts2006.sizeInWords();
77  break;
78 
79  case 2007:
81  buf +=header2007.sizeInWords();
84  if (header2007.configPresent==1) {
86  buf +=virtexID.sizeInWords();
91 
92  collisionMasks.resize(collisionMaskWordcount[header2007.boardType]);
93  for (unsigned int i=0; i<collisionMaskWordcount[header2007.boardType]; ++i){
94  collisionMasks[i].setFromBuffer(buf);
95  buf += collisionMasks[i].sizeInWords();
96  sizeInWords2007_ += collisionMasks[i].sizeInWords();
97  }
98 
99  hotChannelMasks.resize(hotChannelMaskWordcount[header2007.boardType]);
100  for (unsigned int i=0; i<hotChannelMaskWordcount[header2007.boardType]; ++i) {
101  hotChannelMasks[i].setFromBuffer(buf);
102  buf += hotChannelMasks[i].sizeInWords();
103  sizeInWords2007_ += hotChannelMasks[i].sizeInWords();
104  }
105  }
106 
107  theALCTs.resize(header2007.lctBins*2);
108  for (int i=0; i<header2007.lctBins*2; ++i) {
109  theALCTs[i].setFromBuffer(buf);
110  buf += theALCTs[i].sizeInWords();
111  sizeInWords2007_ += theALCTs[i].sizeInWords();
112  }
113 
114  ALCTDigis();
115  break;
116 
117  default:
118  edm::LogError("CSCALCTHeader|CSCRawToDigi")
119  <<"couldn't construct: ALCT firmware version is bad/not defined!";
120  break;
121  }
122 
124  if ((firmwareVersion==2006)||(firmwareVersion==2007))
125  memcpy(theOriginalBuffer, buf-sizeInWords(), sizeInWords()*2);
126 
127 }
128 
129 
131  CSCALCTHeader(digi.header());
132 }
133 
135 #ifdef LOCAL_UNPACK
136  switch (firmwareVersion) {
137 #else
138  switch (firmwareVersion.load()) {
139 #endif
140  case 2006:
141  {
143  break;
144  }
145  case 2007:
146  {
148  break;
149  }
150  default:
151  edm::LogError("CSCALCTHeader|CSCRawToDigi")
152  <<"setEventInformation: ALCT firmware version is bad/not defined!" << firmwareVersion;
153  break;
154  }
155 }
156 
157 
158 unsigned short CSCALCTHeader::nLCTChipRead() const {
159  if(firmwareVersion == 2006) {
160  return header2006.nLCTChipRead();
161  }
162  else {
163  // nLCTChip obsolete in ALCT2007 format (email Andrey K. & Victor B., 20.10.2008)
164  // and we don't think anyone makes uses of this call.
165  // edm::LogError("CSCALCTHeader|CSCRawToDigi")
166  // <<"How is nLCTChipRead() supposed to work for ALCTHeader2007?";
167  }
168  return 0;
169 }
170 
171 
172 std::vector<CSCALCTDigi> CSCALCTHeader::ALCTDigis() const
173 {
174  std::vector<CSCALCTDigi> result;
175 
176 #ifdef LOCAL_UNPACK
177  switch (firmwareVersion) {
178 #else
179  switch (firmwareVersion.load()) {
180 #endif
181  case 2006:
182  {
183  result = alcts2006.ALCTDigis();
184  break;
185  }
186  case 2007:
187  {
188  result.reserve(theALCTs.size());
189  for (unsigned int i=0; i<theALCTs.size(); ++i) {
190  CSCALCTDigi digi(theALCTs[i].valid, theALCTs[i].quality, theALCTs[i].accel, theALCTs[i].pattern,
191  theALCTs[i].keyWire, (int)i/2, i%2+1);
192  result.push_back(digi);
193  }
194  break;
195  }
196  default:
197  edm::LogError("CSCALCTHeader|CSCRawToDigi")
198  <<"Empty Digis: ALCT firmware version is bad/not defined!" << firmwareVersion;
199  break;
200  }
201  for(unsigned i = 0; i < result.size(); ++i) {result[i].setFullBX(BXNCount());}
202  return result;
203 
204 }
205 
206 
207 void CSCALCTHeader::add(const std::vector<CSCALCTDigi> & digis)
208 {
209  if(firmwareVersion == 2006) {
210  alcts2006.add(digis);
211  }
212  else if(firmwareVersion == 2007) {
213  if(theALCTs.empty())
214  {
215  theALCTs.resize(header2007.lctBins*2);
216  }
217  for(std::vector<CSCALCTDigi>::const_iterator digi = digis.begin();
218  digi != digis.end(); ++digi)
219  {
220  int bx = digi->getBX();
221  if(bx < (int)header2007.lctBins)
222  {
223  // 2 ALCTs per bx
224  int i = bx*2;
225  int q1 = theALCTs[i].quality;
226  int q2 = theALCTs[i+1].quality;
227  // see if it's non=blank
228  if(!theALCTs[i].valid)
229  {
230  theALCTs[i] = CSCALCT(*digi);
231  }
232  // new best LCT
233  else if(digi->getQuality() > q1)
234  {
235  theALCTs[i+1] = theALCTs[i];
236  theALCTs[i] = CSCALCT(*digi);
237  }
238  // new second best
239  else if(!theALCTs[i+1].valid || (digi->getQuality() > q2))
240  {
241  theALCTs[i+1] = CSCALCT(*digi);
242  }
243  }
244  }
245  }
246 }
247 
248 
249 boost::dynamic_bitset<> CSCALCTHeader::pack()
250 {
251  boost::dynamic_bitset<> result;
252  if(firmwareVersion == 2006)
253  {
254  boost::dynamic_bitset<> header
256  (unsigned short *) &header2006);
257  boost::dynamic_bitset<> alcts
259  (unsigned short *) &alcts2006);
260  result = bitset_utilities::append(header, alcts);
261 
262  bitset_utilities::bitsetToChar(result, (unsigned char *) data());
263  }
264 
265  else if(firmwareVersion == 2007)
266  {
268  (unsigned short *) &header2007);
269 
270  for (unsigned i = 0; i < theALCTs.size(); ++i)
271  {
272  boost::dynamic_bitset<> alct
274  (unsigned short *) &theALCTs[i]);
275  result = bitset_utilities::append(result, alct);
276  }
277 
278  bitset_utilities::bitsetToChar(result, (unsigned char *) data());
279 
280  }
281  return result;
282 }
283 
284 
285 
286 void CSCALCTHeader::selfTest(int firmware)
287 {
288  firmwareVersion = firmware;
289  CSCALCTDigi alct0(true, 1, 1, 1, 10, 6, 1);
290  CSCALCTDigi alct1(true, 1, 1, 0, 11, 6, 2);
291 
292  // tests packing and unpacking
293  for(int station = 1; station <= 4; ++station)
294  {
295  CSCDetId detId(1, station, 1, 1, 0);
296 
297  std::vector<CSCALCTDigi> oldAlcts;
298  oldAlcts.push_back(alct0);
299  oldAlcts.push_back(alct1);
300  CSCALCTHeader alctHeader(detId.iChamberType());
301 
302  alctHeader.add(oldAlcts);
303 
304  std::vector<CSCALCTDigi> alcts = alctHeader.ALCTDigis();
305  // pick out the valid ones
306  std::vector<CSCALCTDigi> validALCTs;
307  for(std::vector<CSCALCTDigi>::const_iterator alctItr = alcts.begin();
308  alctItr != alcts.end(); ++ alctItr)
309  {
310  if(alctItr->isValid())
311  {
312  validALCTs.push_back(*alctItr);
313  }
314  }
315  assert(validALCTs[0] == alct0);
316  assert(validALCTs[1] == alct1);
317  //cscClassPackerCompare(alctHeader);
318  }
319 }
320 
321 std::ostream & operator<<(std::ostream & os, const CSCALCTHeader & header)
322 {
323  os << "ALCT HEADER CSCID " << header.CSCID()
324  << " L1ACC " << header.L1Acc() << std::endl;
325  os << " time samples " << header.NTBins() << std::endl;
326  return os;
327 }
328 
329 
std::vector< CSCHotChannelMask > hotChannelMasks
std::vector< CSCCollisionMask > collisionMasks
CSCVirtexID virtexID
short unsigned int sizeInWords() const
short unsigned int sizeInWords() const
unsigned short int nLCTChipRead() const
for packing
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...
short unsigned int sizeInWords() const
CSCConfigurationRegister configRegister
CSCALCTHeader(int chamberType)
CSCALCTs2006 alcts2006
void setEventInformation(const CSCDMBHeader &)
void setFromBuffer(unsigned short const *buf)
static std::atomic< unsigned short int > firmwareVersion
static void selfTest(int firmware)
tests that we unpack what we packed
double q2[4]
Definition: TauolaWrapper.h:88
void setEventInformation(const CSCDMBHeader &)
unsigned short int CSCID() const
Definition: CSCALCTHeader.h:60
short unsigned int sizeInWords() const
unsigned short int theOriginalBuffer[116]
CSCALCTHeader2006 header2006
void setFromBuffer(unsigned short const *buf)
static short unsigned int sizeInWords()
std::ostream & operator<<(std::ostream &os, const CSCALCTHeader &header)
std::vector< CSCALCT > theALCTs
void add(const std::vector< CSCALCTDigi > &digis)
CSCALCTHeader2007 header2007
void setFromBuffer(unsigned short const *buf)
boost::dynamic_bitset pack()
unsigned short iChamberType() const
Definition: CSCDetId.h:107
void setEventInformation(const CSCDMBHeader &)
#define LogTrace(id)
unsigned short int sizeInWords2007_
size of the 2007 header in words
int sizeInWords()
in 16-bit words
std::vector< CSCALCTDigi > ALCTDigis() const
void setFromBuffer(unsigned short const *buf)
double q1[4]
Definition: TauolaWrapper.h:87
void bitsetToChar(const boost::dynamic_bitset<> &bs, unsigned char *result)
this method takes bitset obj and returns char * array
std::vector< CSCALCTDigi > ALCTDigis() const
unsigned short int L1Acc() const
Definition: CSCALCTHeader.h:98
void add(const std::vector< CSCALCTDigi > &digis)
should try to sort, but doesn&#39;t for now
unsigned short int NTBins() const
Definition: CSCALCTHeader.h:42
const uint16_t * header() const
Data Accessors.
boost::dynamic_bitset ushortToBitset(const unsigned int numberOfBits, unsigned short *buf)
this method takes numberOfBits bits from unsigned short * array and returns them in the bitset obj...
short unsigned int sizeInWords() const
for packing
void setFromBuffer(unsigned short const *buf)
unsigned short int BXNCount() const
Definition: CSCALCTHeader.h:61
static std::atomic< bool > debug
#define constexpr
unsigned short int * data()
unsigned short nLCTChipRead() const