CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCALCTHeader.cc
Go to the documentation of this file.
6 #include <iomanip>
7 #include <atomic>
8 
9 std::atomic<bool> CSCALCTHeader::debug{false};
10 std::atomic<short unsigned int> CSCALCTHeader::firmwareVersion{2007};
11 
13 : header2006(chamberType),
14  header2007(chamberType)
15 { //constructor for digi->raw packing based on header2006
16  if (firmwareVersion==2006)
17  {
19  }
20  else if(firmwareVersion==2007)
21  {
23  // assume no virtex or masks or registers
25  theALCTs.resize(header2007.lctBins*2);
26  }
27  else
28  {
29  edm::LogError("CSCALCTHeader|CSCRawToDigi")
30  <<"Cannot construct ALCT header: ALCT firmware version is bad/not defined!" << firmwareVersion;
31  }
32 
33 }
34 
35 CSCALCTHeader::CSCALCTHeader(const unsigned short * buf) {
40  constexpr unsigned short int collisionMaskWordcount[7] = { 8, 8,12,16,16,24,28};
41  constexpr unsigned short int hotChannelMaskWordcount[7] = {18,18,24,36,36,48,60};
42 
44  if (buf[0]==0xDB0A) {
45  firmwareVersion=2007;
46  }
47  else if ( (buf[0]&0xF800)==0x6000 ) {
48  firmwareVersion=2006;
49  }
50  else {
51  edm::LogError("CSCALCTHeader|CSCRawToDigi") << "failed to determine ALCT firmware version!!";
52  }
53 
54  LogTrace("CSCALCTHeader|CSCRawToDigi") << "firmware version - " << firmwareVersion;
55 
57  switch (firmwareVersion.load()) {
58  case 2006:
59  memcpy(&header2006, buf, header2006.sizeInWords()*2);
60  buf +=header2006.sizeInWords();
61  memcpy(&alcts2006, buf, alcts2006.sizeInWords()*2);
62  buf +=alcts2006.sizeInWords();
63  break;
64 
65  case 2007:
66  memcpy(&header2007, buf, header2007.sizeInWords()*2);
67  buf +=header2007.sizeInWords();
70  if (header2007.configPresent==1) {
71  memcpy(&virtexID, buf, virtexID.sizeInWords()*2);
72  buf +=virtexID.sizeInWords();
74  memcpy(&configRegister, buf, configRegister.sizeInWords()*2);
77 
78  collisionMasks.resize(collisionMaskWordcount[header2007.boardType]);
79  for (unsigned int i=0; i<collisionMaskWordcount[header2007.boardType]; ++i){
80  memcpy(&collisionMasks[i], buf, collisionMasks[i].sizeInWords()*2);
81  buf += collisionMasks[i].sizeInWords();
82  sizeInWords2007_ += collisionMasks[i].sizeInWords();
83  }
84 
85  hotChannelMasks.resize(hotChannelMaskWordcount[header2007.boardType]);
86  for (unsigned int i=0; i<hotChannelMaskWordcount[header2007.boardType]; ++i) {
87  memcpy(&hotChannelMasks[i], buf, hotChannelMasks[i].sizeInWords()*2);
88  buf += hotChannelMasks[i].sizeInWords();
89  sizeInWords2007_ += hotChannelMasks[i].sizeInWords();
90  }
91  }
92 
93  theALCTs.resize(header2007.lctBins*2);
94  for (int i=0; i<header2007.lctBins*2; ++i) {
95  memcpy(&theALCTs[i], buf, theALCTs[i].sizeInWords()*2);
96  buf += theALCTs[i].sizeInWords();
97  sizeInWords2007_ += theALCTs[i].sizeInWords();
98  }
99 
100  ALCTDigis();
101  break;
102 
103  default:
104  edm::LogError("CSCALCTHeader|CSCRawToDigi")
105  <<"couldn't construct: ALCT firmware version is bad/not defined!";
106  break;
107  }
108 
110  if ((firmwareVersion==2006)||(firmwareVersion==2007))
111  memcpy(theOriginalBuffer, buf-sizeInWords(), sizeInWords()*2);
112 
113 }
114 
115 
117  CSCALCTHeader(digi.header());
118 }
119 
122 }
123 
124 
125 unsigned short CSCALCTHeader::nLCTChipRead() const {
126  if(firmwareVersion == 2006) {
127  return header2006.nLCTChipRead();
128  }
129  else {
130  // nLCTChip obsolete in ALCT2007 format (email Andrey K. & Victor B., 20.10.2008)
131  // and we don't think anyone makes uses of this call.
132  // edm::LogError("CSCALCTHeader|CSCRawToDigi")
133  // <<"How is nLCTChipRead() supposed to work for ALCTHeader2007?";
134  }
135  return 0;
136 }
137 
138 
139 std::vector<CSCALCTDigi> CSCALCTHeader::ALCTDigis() const
140 {
141  std::vector<CSCALCTDigi> result;
142 
143  switch (firmwareVersion.load()) {
144  case 2006:
145  {
146  result = alcts2006.ALCTDigis();
147  break;
148  }
149  case 2007:
150  {
151  result.reserve(theALCTs.size());
152  for (unsigned int i=0; i<theALCTs.size(); ++i) {
153  CSCALCTDigi digi(theALCTs[i].valid, theALCTs[i].quality, theALCTs[i].accel, theALCTs[i].pattern,
154  theALCTs[i].keyWire, (int)i/2, i%2+1);
155  result.push_back(digi);
156  }
157  break;
158  }
159  default:
160  edm::LogError("CSCALCTHeader|CSCRawToDigi")
161  <<"Empty Digis: ALCT firmware version is bad/not defined!" << firmwareVersion;
162  break;
163  }
164  for(unsigned i = 0; i < result.size(); ++i) {result[i].setFullBX(BXNCount());}
165  return result;
166 
167 }
168 
169 
170 void CSCALCTHeader::add(const std::vector<CSCALCTDigi> & digis)
171 {
172  if(firmwareVersion == 2006) {
173  alcts2006.add(digis);
174  }
175  else if(firmwareVersion == 2007) {
176  if(theALCTs.empty())
177  {
178  theALCTs.resize(header2007.lctBins*2);
179  }
180  for(std::vector<CSCALCTDigi>::const_iterator digi = digis.begin();
181  digi != digis.end(); ++digi)
182  {
183  int bx = digi->getBX();
184  if(bx < (int)header2007.lctBins)
185  {
186  // 2 ALCTs per bx
187  int i = bx*2;
188  int q1 = theALCTs[i].quality;
189  int q2 = theALCTs[i+1].quality;
190  // see if it's non=blank
191  if(!theALCTs[i].valid)
192  {
193  theALCTs[i] = CSCALCT(*digi);
194  }
195  // new best LCT
196  else if(digi->getQuality() > q1)
197  {
198  theALCTs[i+1] = theALCTs[i];
199  theALCTs[i] = CSCALCT(*digi);
200  }
201  // new second best
202  else if(!theALCTs[i+1].valid || (digi->getQuality() > q2))
203  {
204  theALCTs[i+1] = CSCALCT(*digi);
205  }
206  }
207  }
208  }
209 }
210 
211 
212 boost::dynamic_bitset<> CSCALCTHeader::pack()
213 {
214  boost::dynamic_bitset<> result;
215  if(firmwareVersion == 2006)
216  {
217  boost::dynamic_bitset<> header
219  (unsigned short *) &header2006);
220  boost::dynamic_bitset<> alcts
222  (unsigned short *) &alcts2006);
223  result = bitset_utilities::append(header, alcts);
224  }
225 
226  else if(firmwareVersion == 2007)
227  {
229  (unsigned short *) &header2007);
230 
231  for (unsigned i = 0; i < theALCTs.size(); ++i)
232  {
233  boost::dynamic_bitset<> alct
235  (unsigned short *) &theALCTs[i]);
236  result = bitset_utilities::append(result, alct);
237  }
238  }
239  return result;
240 }
241 
242 
243 
244 void CSCALCTHeader::selfTest(int firmware)
245 {
246  firmwareVersion = firmware;
247  CSCALCTDigi alct0(true, 1, 1, 1, 10, 6, 1);
248  CSCALCTDigi alct1(true, 1, 1, 0, 11, 6, 2);
249 
250  // tests packing and unpacking
251  for(int station = 1; station <= 4; ++station)
252  {
253  CSCDetId detId(1, station, 1, 1, 0);
254 
255  std::vector<CSCALCTDigi> oldAlcts;
256  oldAlcts.push_back(alct0);
257  oldAlcts.push_back(alct1);
258  CSCALCTHeader alctHeader(detId.iChamberType());
259 
260  alctHeader.add(oldAlcts);
261 
262  std::vector<CSCALCTDigi> alcts = alctHeader.ALCTDigis();
263  // pick out the valid ones
264  std::vector<CSCALCTDigi> validALCTs;
265  for(std::vector<CSCALCTDigi>::const_iterator alctItr = alcts.begin();
266  alctItr != alcts.end(); ++ alctItr)
267  {
268  if(alctItr->isValid())
269  {
270  validALCTs.push_back(*alctItr);
271  }
272  }
273  assert(validALCTs[0] == alct0);
274  assert(validALCTs[1] == alct1);
275  //cscClassPackerCompare(alctHeader);
276  }
277 }
278 
279 std::ostream & operator<<(std::ostream & os, const CSCALCTHeader & header)
280 {
281  os << "ALCT HEADER CSCID " << header.CSCID()
282  << " L1ACC " << header.L1Acc() << std::endl;
283  os << " time samples " << header.NTBins() << std::endl;
284  return os;
285 }
286 
287 
int i
Definition: DBlmapReader.cc:9
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
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
void setEventInformation(const CSCDMBHeader &)
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:55
short unsigned int sizeInWords() const
unsigned short int theOriginalBuffer[116]
CSCALCTHeader2006 header2006
static short unsigned int sizeInWords()
tuple result
Definition: query.py:137
std::vector< CSCALCT > theALCTs
void add(const std::vector< CSCALCTDigi > &digis)
CSCALCTHeader2007 header2007
boost::dynamic_bitset pack()
#define LogTrace(id)
unsigned short int sizeInWords2007_
size of the 2007 header in words
unsigned short iChamberType()
Definition: CSCDetId.h:120
int sizeInWords()
in 16-bit words
Definition: CSCALCTHeader.h:99
std::vector< CSCALCTDigi > ALCTDigis() const
double q1[4]
Definition: TauolaWrapper.h:87
std::vector< CSCALCTDigi > ALCTDigis() const
unsigned short int L1Acc() const
Definition: CSCALCTHeader.h:69
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:40
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
unsigned short int BXNCount() const
Definition: CSCALCTHeader.h:56
static std::atomic< bool > debug
#define constexpr
unsigned short nLCTChipRead() const