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), header2007(chamberType) { //constructor for digi->raw packing based on header2006
24  if (firmwareVersion == 2006) {
26  } else if (firmwareVersion == 2007) {
28  // assume no virtex or masks or registers
30  theALCTs.resize(header2007.lctBins * 2);
31  } else {
32  edm::LogError("CSCALCTHeader|CSCRawToDigi")
33  << "Cannot construct ALCT header: ALCT firmware version is bad/not defined!" << firmwareVersion;
34  }
35 }
36 
37 CSCALCTHeader::CSCALCTHeader(const unsigned short *buf) {
42  constexpr unsigned short int collisionMaskWordcount[7] = {8, 8, 12, 16, 16, 24, 28};
43  constexpr unsigned short int hotChannelMaskWordcount[7] = {18, 18, 24, 36, 36, 48, 60};
44 
46  if (buf[0] == 0xDB0A) {
47  firmwareVersion = 2007;
48  } else if ((buf[0] & 0xF800) == 0x6000) {
49  firmwareVersion = 2006;
50  } else {
51  edm::LogError("CSCALCTHeader|CSCRawToDigi") << "failed to determine ALCT firmware version!!";
52  }
53 
54  LogTrace("CSCALCTHeader|CSCRawToDigi") << "firmware version - " << firmwareVersion;
55 
57 #ifdef LOCAL_UNPACK
58  switch (firmwareVersion) {
59 #else
60  switch (firmwareVersion.load()) {
61 #endif
62  case 2006:
67  break;
68 
69  case 2007:
74  if (header2007.configPresent == 1) {
81 
82  collisionMasks.resize(collisionMaskWordcount[header2007.boardType]);
83  for (unsigned int i = 0; i < collisionMaskWordcount[header2007.boardType]; ++i) {
84  collisionMasks[i].setFromBuffer(buf);
85  buf += collisionMasks[i].sizeInWords();
86  sizeInWords2007_ += collisionMasks[i].sizeInWords();
87  }
88 
89  hotChannelMasks.resize(hotChannelMaskWordcount[header2007.boardType]);
90  for (unsigned int i = 0; i < hotChannelMaskWordcount[header2007.boardType]; ++i) {
91  hotChannelMasks[i].setFromBuffer(buf);
92  buf += hotChannelMasks[i].sizeInWords();
93  sizeInWords2007_ += hotChannelMasks[i].sizeInWords();
94  }
95  }
96 
97  theALCTs.resize(header2007.lctBins * 2);
98  for (int i = 0; i < header2007.lctBins * 2; ++i) {
99  theALCTs[i].setFromBuffer(buf);
100  buf += theALCTs[i].sizeInWords();
101  sizeInWords2007_ += theALCTs[i].sizeInWords();
102  }
103 
104  ALCTDigis();
105  break;
106 
107  default:
108  edm::LogError("CSCALCTHeader|CSCRawToDigi") << "couldn't construct: ALCT firmware version is bad/not defined!";
109  break;
110  }
111 
113  if ((firmwareVersion == 2006) || (firmwareVersion == 2007))
114  memcpy(theOriginalBuffer, buf - sizeInWords(), sizeInWords() * 2);
115 }
116 
118 
120 #ifdef LOCAL_UNPACK
121  switch (firmwareVersion) {
122 #else
123  switch (firmwareVersion.load()) {
124 #endif
125  case 2006: {
127  break;
128  }
129  case 2007: {
131  break;
132  }
133  default:
134  edm::LogError("CSCALCTHeader|CSCRawToDigi")
135  << "setEventInformation: ALCT firmware version is bad/not defined!" << firmwareVersion;
136  break;
137  }
138 }
139 
140 unsigned short CSCALCTHeader::nLCTChipRead() const {
141  if (firmwareVersion == 2006) {
142  return header2006.nLCTChipRead();
143  } else {
144  // nLCTChip obsolete in ALCT2007 format (email Andrey K. & Victor B., 20.10.2008)
145  // and we don't think anyone makes uses of this call.
146  // edm::LogError("CSCALCTHeader|CSCRawToDigi")
147  // <<"How is nLCTChipRead() supposed to work for ALCTHeader2007?";
148  }
149  return 0;
150 }
151 
152 std::vector<CSCALCTDigi> CSCALCTHeader::ALCTDigis() const {
153  std::vector<CSCALCTDigi> result;
154 
155 #ifdef LOCAL_UNPACK
156  switch (firmwareVersion) {
157 #else
158  switch (firmwareVersion.load()) {
159 #endif
160  case 2006: {
162  break;
163  }
164  case 2007: {
165  result.reserve(theALCTs.size());
166  for (unsigned int i = 0; i < theALCTs.size(); ++i) {
167  CSCALCTDigi digi(theALCTs[i].valid,
168  theALCTs[i].quality,
169  theALCTs[i].accel,
170  theALCTs[i].pattern,
171  theALCTs[i].keyWire,
172  (int)i / 2,
173  i % 2 + 1);
174  result.push_back(digi);
175  }
176  break;
177  }
178  default:
179  edm::LogError("CSCALCTHeader|CSCRawToDigi")
180  << "Empty Digis: ALCT firmware version is bad/not defined!" << firmwareVersion;
181  break;
182  }
183  for (unsigned i = 0; i < result.size(); ++i) {
184  result[i].setFullBX(BXNCount());
185  }
186  return result;
187 }
188 
189 void CSCALCTHeader::add(const std::vector<CSCALCTDigi> &digis) {
190  if (firmwareVersion == 2006) {
191  alcts2006.add(digis);
192  } else if (firmwareVersion == 2007) {
193  if (theALCTs.empty()) {
194  theALCTs.resize(header2007.lctBins * 2);
195  }
196  for (std::vector<CSCALCTDigi>::const_iterator digi = digis.begin(); digi != digis.end(); ++digi) {
197  int bx = digi->getBX();
198  if (bx < (int)header2007.lctBins) {
199  // 2 ALCTs per bx
200  int i = bx * 2;
201  int q1 = theALCTs[i].quality;
202  int q2 = theALCTs[i + 1].quality;
203  // see if it's non=blank
204  if (!theALCTs[i].valid) {
205  theALCTs[i] = CSCALCT(*digi);
206  }
207  // new best LCT
208  else if (digi->getQuality() > q1) {
209  theALCTs[i + 1] = theALCTs[i];
210  theALCTs[i] = CSCALCT(*digi);
211  }
212  // new second best
213  else if (!theALCTs[i + 1].valid || (digi->getQuality() > q2)) {
214  theALCTs[i + 1] = CSCALCT(*digi);
215  }
216  }
217  }
218  }
219 }
220 
221 boost::dynamic_bitset<> CSCALCTHeader::pack() {
222  boost::dynamic_bitset<> result;
223  if (firmwareVersion == 2006) {
224  boost::dynamic_bitset<> header =
226  boost::dynamic_bitset<> alcts =
229 
230  bitset_utilities::bitsetToChar(result, (unsigned char *)data());
231  }
232 
233  else if (firmwareVersion == 2007) {
235 
236  for (unsigned i = 0; i < theALCTs.size(); ++i) {
237  boost::dynamic_bitset<> alct =
238  bitset_utilities::ushortToBitset(theALCTs[i].sizeInWords() * 16, (unsigned short *)&theALCTs[i]);
240  }
241 
242  bitset_utilities::bitsetToChar(result, (unsigned char *)data());
243  }
244  return result;
245 }
246 
249  CSCALCTDigi alct0(true, 1, 1, 1, 10, 6, 1);
250  CSCALCTDigi alct1(true, 1, 1, 0, 11, 6, 2);
251 
252  // tests packing and unpacking
253  for (int station = 1; station <= 4; ++station) {
254  CSCDetId detId(1, station, 1, 1, 0);
255 
256  std::vector<CSCALCTDigi> oldAlcts;
257  oldAlcts.push_back(alct0);
258  oldAlcts.push_back(alct1);
259  CSCALCTHeader alctHeader(detId.iChamberType());
260 
261  alctHeader.add(oldAlcts);
262 
263  std::vector<CSCALCTDigi> alcts = alctHeader.ALCTDigis();
264  // pick out the valid ones
265  std::vector<CSCALCTDigi> validALCTs;
266  for (std::vector<CSCALCTDigi>::const_iterator alctItr = alcts.begin(); alctItr != alcts.end(); ++alctItr) {
267  if (alctItr->isValid()) {
268  validALCTs.push_back(*alctItr);
269  }
270  }
271  assert(validALCTs[0] == alct0);
272  assert(validALCTs[1] == alct1);
273  //cscClassPackerCompare(alctHeader);
274  }
275 }
276 
277 std::ostream &operator<<(std::ostream &os, const CSCALCTHeader &header) {
278  os << "ALCT HEADER CSCID " << header.CSCID() << " L1ACC " << header.L1Acc() << std::endl;
279  os << " time samples " << header.NTBins() << std::endl;
280  return os;
281 }
CSCVirtexID::sizeInWords
short unsigned int sizeInWords() const
Definition: CSCALCTHeader2007.h:89
CSCALCTHeader::header2007
CSCALCTHeader2007 header2007
Definition: CSCALCTHeader.h:190
CSCALCTs2006::ALCTDigis
std::vector< CSCALCTDigi > ALCTDigis() const
Definition: CSCALCTHeader2006.cc:44
CSCConfigurationRegister::setFromBuffer
void setFromBuffer(unsigned short const *buf)
Definition: CSCALCTHeader2007.h:108
mps_fire.i
i
Definition: mps_fire.py:428
CSCALCTHeader.h
CSCALCTHeader::data
unsigned short int * data()
Definition: CSCALCTHeader.h:146
CSCALCTHeader::theOriginalBuffer
unsigned short int theOriginalBuffer[116]
Definition: CSCALCTHeader.h:200
CSCALCTHeader::header2006
CSCALCTHeader2006 header2006
Definition: CSCALCTHeader.h:189
CSCALCTHeader::sizeInWords2007_
unsigned short int sizeInWords2007_
size of the 2007 header in words
Definition: CSCALCTHeader.h:211
CSCALCTs2006::sizeInWords
short unsigned int sizeInWords() const
Definition: CSCALCTHeader2006.h:82
CSCALCTStatusDigi::header
const uint16_t * header() const
Data Accessors.
Definition: CSCALCTStatusDigi.h:24
CSCALCTHeader::sizeInWords
int sizeInWords()
in 16-bit words
Definition: CSCALCTHeader.h:149
relativeConstraints.station
station
Definition: relativeConstraints.py:67
CSCALCTs2006::add
void add(const std::vector< CSCALCTDigi > &digis)
should try to sort, but doesn't for now
Definition: CSCALCTHeader2006.cc:57
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
cms::cuda::assert
assert(be >=bs)
CSCALCTHeader::add
void add(const std::vector< CSCALCTDigi > &digis)
Definition: CSCALCTHeader.cc:189
CSCALCTHeader2006::setEventInformation
void setEventInformation(const CSCDMBHeader &)
Definition: CSCALCTHeader2006.cc:28
cscPackerCompare.h
bitset_utilities::append
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
Definition: bitset_append.cc:10
CSCDetId::iChamberType
unsigned short iChamberType() const
Definition: CSCDetId.h:96
CSCDetId.h
CSCALCT
Definition: CSCALCTHeader2007.h:17
CSCALCTHeader
Definition: CSCALCTHeader.h:21
bitset_utilities::bitsetToChar
void bitsetToChar(const boost::dynamic_bitset<> &bs, unsigned char *result)
this method takes bitset obj and returns char * array
Definition: bitset_append.cc:32
CSCALCTHeader::BXNCount
unsigned short int BXNCount() const
Definition: CSCALCTHeader.h:61
CSCALCTHeader2007::setEventInformation
void setEventInformation(const CSCDMBHeader &)
Definition: CSCALCTHeader2007.cc:38
CSCDMBHeader.h
simCaloStage2Digis_cfi.firmware
firmware
Definition: simCaloStage2Digis_cfi.py:6
q2
double q2[4]
Definition: TauolaWrapper.h:88
CSCALCTHeader::nLCTChipRead
unsigned short int nLCTChipRead() const
for packing
Definition: CSCALCTHeader.cc:140
CSCALCTStatusDigi
Definition: CSCALCTStatusDigi.h:15
CSCConfigurationRegister::sizeInWords
short unsigned int sizeInWords() const
Definition: CSCALCTHeader2007.h:110
q1
double q1[4]
Definition: TauolaWrapper.h:87
CSCALCTHeader::theALCTs
std::vector< CSCALCT > theALCTs
Definition: CSCALCTHeader.h:191
CSCALCTs2006::setFromBuffer
void setFromBuffer(unsigned short const *buf)
Definition: CSCALCTHeader2006.h:80
CSCDetId
Definition: CSCDetId.h:26
CSCALCTHeader::selfTest
static void selfTest(int firmware)
tests that we unpack what we packed
Definition: CSCALCTHeader.cc:247
topSingleLeptonDQM_PU_cfi.pattern
pattern
Definition: topSingleLeptonDQM_PU_cfi.py:39
CSCALCTHeader::debug
static std::atomic< bool > debug
Definition: CSCALCTHeader.h:206
CSCALCTHeader::ALCTDigis
std::vector< CSCALCTDigi > ALCTDigis() const
Definition: CSCALCTHeader.cc:152
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
CSCALCTHeader2007::lctBins
unsigned lctBins
Definition: CSCALCTHeader2007.h:77
CSCALCTHeader2006::sizeInWords
short unsigned int sizeInWords() const
Definition: CSCALCTHeader2006.h:22
CSCDMBHeader
Definition: CSCDMBHeader.h:15
CSCALCTHeader::configRegister
CSCConfigurationRegister configRegister
Definition: CSCALCTHeader.h:194
CSCALCTHeader2007::boardType
unsigned boardType
Definition: CSCALCTHeader2007.h:65
qcdUeDQM_cfi.quality
quality
Definition: qcdUeDQM_cfi.py:31
CSCALCTHeader::alcts2006
CSCALCTs2006 alcts2006
Definition: CSCALCTHeader.h:192
bitset_utilities::ushortToBitset
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.
Definition: bitset_append.cc:23
CSCALCTHeader::setEventInformation
void setEventInformation(const CSCDMBHeader &)
Definition: CSCALCTHeader.cc:119
CSCALCTHeader::firmwareVersion
static std::atomic< unsigned short int > firmwareVersion
Definition: CSCALCTHeader.h:207
CSCALCTHeader::CSCALCTHeader
CSCALCTHeader(int chamberType)
Definition: CSCALCTHeader.cc:22
CSCALCTHeader::virtexID
CSCVirtexID virtexID
Definition: CSCALCTHeader.h:193
CSCALCTHeader::collisionMasks
std::vector< CSCCollisionMask > collisionMasks
Definition: CSCALCTHeader.h:195
CSCALCTDigi
Definition: CSCALCTDigi.h:17
CSCALCTHeader2006::setFromBuffer
void setFromBuffer(unsigned short const *buf)
Definition: CSCALCTHeader2006.h:16
CSCVirtexID::setFromBuffer
void setFromBuffer(unsigned short const *buf)
Definition: CSCALCTHeader2007.h:87
bitset_append.h
CSCALCTHeader2007::setFromBuffer
void setFromBuffer(unsigned short const *buf)
Definition: CSCALCTHeader2007.h:37
CSCALCTHeader::pack
boost::dynamic_bitset pack()
Definition: CSCALCTHeader.cc:221
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:292
CSCALCTHeader2006::nLCTChipRead
unsigned short nLCTChipRead() const
Definition: CSCALCTHeader2006.cc:35
mps_fire.result
result
Definition: mps_fire.py:311
RunInfoPI::valid
Definition: RunInfoPayloadInspectoHelper.h:16
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:224
CSCALCT::sizeInWords
static short unsigned int sizeInWords()
Definition: CSCALCTHeader2007.h:23
CSCALCTHeader::hotChannelMasks
std::vector< CSCHotChannelMask > hotChannelMasks
Definition: CSCALCTHeader.h:196
operator<<
std::ostream & operator<<(std::ostream &os, const CSCALCTHeader &header)
Definition: CSCALCTHeader.cc:277
CSCALCTHeader2007::configPresent
unsigned configPresent
Definition: CSCALCTHeader2007.h:59
CSCALCTHeader2007::sizeInWords
short unsigned int sizeInWords() const
for packing
Definition: CSCALCTHeader2007.h:41