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