CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCAnodeData2006.cc
Go to the documentation of this file.
4 #include <string.h> // for bzero
5 
6 bool debug = false;
7 #include <iostream>
8 
9 CSCAnodeDataFrame2006::CSCAnodeDataFrame2006(unsigned chip, unsigned tbin, unsigned data)
10 : theFrame(0)
11 {
12  // lowest bit, plus the OR of the next two.
13  unsigned packedChip = ( (chip&1) + 2*(chip>1) );
14  theFrame = data + ((tbin&0x1F) << 8) + (packedChip<<13);
15 }
16 
17 
19  : nAFEBs_(header.nLCTChipRead()), nTimeBins_(header.NTBins())
20 {
21  LogTrace ("CSCAnodeData|CSCRawToDigi") << "Making Anode data "
22  << sizeInWords() << " AFEB " << nAFEBs_
23  << " TBINS " << nTimeBins_;
24  bzero(theDataFrames, sizeInWords()*2);
25  for(int afeb = 0; afeb < nAFEBs_; ++afeb) {
26  for(int tbin = 0; tbin < nTimeBins_; ++tbin) {
27  for(int layer = 1; layer <= 6; ++layer) {
28  for(int halfLayer = 0; halfLayer < 2; ++halfLayer) {
29  theDataFrames[index(afeb, tbin, layer)+halfLayer] = CSCAnodeDataFrame2006(afeb, tbin, 0).frame();
30  }
31  }
32  }
33  }
35  alctBX_= header.BXNCount();
36 }
37 
38 // initialize
40  const unsigned short *buf)
41  : nAFEBs_(header.nLCTChipRead()),
42  nTimeBins_(header.NTBins())
43 {
44 
48  LogTrace ("CSCAnodeData|CSCRawToDigi") << "nAFEBs = " << nAFEBs_ << " nTimeBins = "
49  << nTimeBins_ << " nFrames = " << sizeInWords();
50  LogTrace ("CSCAnodeData|CSCRawToDigi") << header << " HEADER CHECK " << header.check();
51 
52  memcpy(theDataFrames, buf, sizeInWords()*2);
53 }
54 
55 
56 std::vector<CSCWireDigi> CSCAnodeData2006::wireDigis(int layer) const {
57  std::vector<CSCWireDigi> digis;
58  uint32_t tbinbits=0;
59  uint16_t wireGroup=0;
60  for(int afeb = 0; afeb < nAFEBs_; ++afeb) {
61  for(int halfLayer = 0; halfLayer <2; ++halfLayer) {
62  for (int j=0;j<8;++j) {
63  for(int tbin = 0; tbin < nTimeBins_; ++tbin) {
64  CSCAnodeDataFrame2006 frame(rawHit(afeb,tbin,layer, halfLayer));
65  // see if there's anything in 1st 8 bits. Usually zero
66  if(frame.data() != 0) {
67  if(frame.isHit(j)) {
68  tbinbits=tbinbits + (1<<tbin);
69  }
70  }
71  }//end of tbin loop
72  if (tbinbits !=0 ) {
73  wireGroup = (afeb*16+halfLayer*8+j)+1;
74  uint32_t wireGroupBX=alctBX_;
75  wireGroup = wireGroup | (wireGroupBX << 16);
76  CSCWireDigi digi(wireGroup, tbinbits);
77  if (debug)
78  LogTrace ("CSCAnodeData|CSCRawToDigi") << "Layer " << layer << " " << digi;
79  digis.push_back(digi);
80  tbinbits=0;
81  }
82  }
83  }
84  }
85 
86  return digis;
87 }
88 
89 
90 void CSCAnodeData2006::add(const CSCWireDigi & digi, int layer)
91 {
92 
93  int wireGroup = digi.getWireGroup();
94  int bxn=digi.getBeamCrossingTag();
95  int alctBoard = (wireGroup-1) / 16;
96  int localGroup = (wireGroup-1) % 16;
97 
98  // crash if there's a bad wire number, but don't freak out
99  // if a time bin is out of range
100  // assert(alctBoard < nAFEBs_);
101  if(alctBoard > nAFEBs_)
102  {
103  edm::LogError("CSCAnodeData|CSCRawToDigi") << "Bad Wire Number for this digi.";
104  return;
105  }
106  if(bxn >= 0 && bxn < nTimeBins_)
107  {
108  // 12 16-bit words per time bin, two per layer
109  // wiregroups 0-7 go on the first line, 8-15 go on the 2nd.
110  unsigned halfLayer = (localGroup > 7);
111  unsigned bitNumber = localGroup % 8;
112  // and pack it in the 8 bits allocated
113  addHit(alctBoard, bxn, layer, halfLayer, bitNumber);
114  }
115  else
116  {
117  LogTrace("CSCAnodeData|CSCRawToDigi")<< "warning: not saving anode data in bx " << bxn
118  << ": out of range ";
119  }
120 }
121 
122 
123 void CSCAnodeData2006::addHit(int afeb, int tbin, int layer, int halfLayer, unsigned wireBit)
124 {
125  int i = index(afeb,tbin,layer) + halfLayer;
127  frame.addHit(wireBit);
128  theDataFrames[i] = frame.frame();
129 }
130 
131 
132 CSCAnodeDataFrame2006 CSCAnodeData2006::rawHit(int afeb, int tbin, int layer, int halfLayer) const
133 {
134  return CSCAnodeDataFrame2006(theDataFrames[index(afeb, tbin, layer)+halfLayer]);
135 }
136 
137 
138 int CSCAnodeData2006::index(int afeb, int tbin, int layer) const {
139  int result = (layer-1)*2 + 12*tbin + afeb*12*nTimeBins_;
140  assert(result < sizeInWords());
141  return result;
142 }
143 
144 #include <iostream>
146 {
147  CSCAnodeDataFrame2006 frame(2, 15, 32);
148  assert(frame.chip() == 2);
149  assert(frame.tbin() == 15);
150  assert(frame.data() == 32);
151  assert(frame.isHit(5));
152  assert(!frame.isHit(7));
153  frame.addHit(7);
154  assert(frame.isHit(7));
155 
156  CSCWireDigi wireDigi(10, (1 << 4));
157  CSCALCTHeader header(7);
158  CSCAnodeData2006 anodeData(header);
159  anodeData.add(wireDigi, 1);
160  anodeData.add(wireDigi, 6);
161 
162  std::vector<CSCWireDigi> wires1 = anodeData.wireDigis(1);
163  std::vector<CSCWireDigi> wires6 = anodeData.wireDigis(6);
164 
165  assert(wires1.size() == 1);
166  assert(wires6.size() == 1);
167  assert(wires1[0].getWireGroup() == 10);
168  assert(wires6[0].getWireGroup() == 10);
169 }
170 
171 
int i
Definition: DBlmapReader.cc:9
void addHit(unsigned wireBit)
sets a bit, from 0 to 7
CSCAnodeDataFrame2006 rawHit(int afeb, int tbin, int layer, int halfLayer) const
unsigned int alctBX_
unsigned short theDataFrames[2700]
we don&#39;t know the size at first. Max should be 7 boards * 32 bins * 6 layers * 2
virtual std::vector< CSCWireDigi > wireDigis(int layer) const
input layer is from 1 to 6
virtual unsigned short int sizeInWords() const
the amount of the input binary buffer read, in 16-bit words
bool check() const
tuple result
Definition: query.py:137
int j
Definition: DBlmapReader.cc:9
int getBeamCrossingTag() const
return tbin number, (obsolete, use getTimeBin() instead)
Definition: CSCWireDigi.cc:33
unsigned short theFrame
static void selfTest()
#define LogTrace(id)
int index(int afeb, int tbin, int layer) const
the index into theDataFrames
unsigned tbin() const
time bin
CSCAnodeData2006(const CSCALCTHeader &)
a blank one, for Monte Carlo
#define debug
Definition: HDRShower.cc:19
virtual void add(const CSCWireDigi &, int layer)
int getWireGroup() const
default
Definition: CSCWireDigi.h:24
unsigned short data() const
int nAFEBs_
in 2007 format the max number of frames is 1860
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
bool isHit(unsigned wireGroup) const
given a wiregroup between 0 and 7, it tells whether this bit was on
void addHit(int afeb, int tbin, int layer, int halfLayer, unsigned wireBit)
unsigned short int BXNCount() const
Definition: CSCALCTHeader.h:55
unsigned short frame() const
unsigned chip() const