CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalUHTRData.cc
Go to the documentation of this file.
2 #include <string.h>
3 
4 static const int HEADER_LENGTH_16BIT=2*sizeof(uint64_t)/sizeof(uint16_t);
5 
6 HcalUHTRData::const_iterator::const_iterator(const uint16_t* ptr, const uint16_t* limit) : m_ptr(ptr), m_limit(limit), m_stepclass(0) {
7  if (isHeader()) determineMode();
8 }
9 
11  if (m_ptr==m_limit) return *this;
12  if (m_stepclass==0) m_ptr++;
13  else if (m_stepclass==1) {
14  if (m_microstep==0) { m_ptr++; m_microstep++; }
15  else { m_microstep--; }
16  }
17  else if (m_stepclass==2) {
18  if (isHeader()) { m_ptr++; }
19  else { m_ptr+=2; }
20  }
21 
22  if (isHeader()) {
23  determineMode();
24  m_header_ptr = m_ptr;
25  m_0th_data_ptr = m_header_ptr + 1;
26  }
27  return *this;
28 }
29 
31  if (!isHeader()) return;
32  m_flavor=flavor();
33  m_stepclass=0;
34  if (m_flavor==5) { m_stepclass=1; m_microstep=0; }
35  else if (m_flavor == 2) { m_stepclass=2; }
36 }
37 
39  if (m_flavor==0x5 && m_microstep==0) return ((*m_ptr)>>8)&0x7F;
40  else return (*m_ptr)&0xFF;
41 }
42 
44  if (m_flavor==0x5) return 0x80;
45  else if (m_flavor == 2) return (m_ptr[1]&0x3F);
46  else return (((*m_ptr)&0x3F00)>>8);
47 }
48 
50  if (m_flavor==0x5) return false;
51  else if (m_flavor == 2) return (m_ptr[0]&0x2000);
52  else return (((*m_ptr)&0x4000));
53 }
54 
56  if (m_flavor==2) return(m_ptr[1]>>6)&0x1F;
57  else return 0x80;
58 }
59 
61  if (m_flavor==2) return(m_ptr[1]>>12)&0x3;
62  else if (m_flavor == 1 || m_flavor == 0) {
63  // For flavor 0,1 we only get the first capid in the header, and so we need
64  // to count the number of data rows and figure out which cap we want,
65  // knowing that they go 0->1->2->3->0
66  return 0;
67  }
68  else { return 0; }
69 }
70 
72  if (m_flavor == 2) { return (m_ptr[0]>>12)&0x1; }
73  else if (m_flavor == 4) { return (m_ptr[0]>>13)&0x1; }
74  else { return false; }
75 }
76 
79 }
80 
82  return HcalUHTRData::const_iterator(m_raw16+(m_rawLength64-1)*sizeof(uint64_t)/sizeof(uint16_t),m_raw16+(m_rawLength64-1)*sizeof(uint64_t)/sizeof(uint16_t));
83 }
84 
85 HcalUHTRData::packer::packer(uint16_t* baseptr) : m_baseptr(baseptr),m_ptr(0),m_flavor(0),m_ministep(0) {
86 }
87 
88 void HcalUHTRData::packer::addHeader(int flavor, int errf, int cap0, int channelid) {
89  m_baseptr[m_ptr]=0x8000 |
90  ((flavor&0x7)<<12) |
91  ((errf&0x3)<<10) |
92  ((cap0&0x3)<<8) |
93  (channelid&0xFF);
94  m_flavor=flavor;
95  m_ministep=0;
96  m_ptr++;
97 }
98 
99 void HcalUHTRData::packer::addSample(int adc, bool soi, int retdc, int fetdc, int tdcstat) {
100  if (m_flavor==0x5) {
101  if (m_ministep==0) m_baseptr[m_ptr]=adc&0x7F;
102  else m_baseptr[m_ptr]|=((adc&0x7f)<<8);
103  if (m_ministep==1) m_ptr++;
104  m_ministep=(m_ministep+1)%2;
105  } else if ((m_flavor&0x6)==0x0) {
106  m_baseptr[m_ptr]=(adc&0xFF) | ((retdc&0x3F)<<8);
107  if (soi) m_baseptr[m_ptr]|=0x4000;
108  m_ptr++;
109  } else if ((m_flavor&0x6)==0x1) {
110  m_baseptr[m_ptr]=(adc&0xFF);
111  m_baseptr[m_ptr+1]=0x4000| ((tdcstat&0x3)<<10) | ((fetdc&0xF)<<6) | ((retdc)<<8);
112  if (soi) m_baseptr[m_ptr]|=0x2000;
113  m_ptr+=2;
114  }
115 }
116 
117 void HcalUHTRData::packer::addTP(int tpword, bool soi) {
118  if (m_flavor==0x4) {
119  m_baseptr[m_ptr]=tpword&0xFFF;
120  if (soi) m_baseptr[m_ptr]|=0x4000;
121  m_ptr++;
122  }
123 }
124 
126 
127 HcalUHTRData::HcalUHTRData(const uint64_t* data, int length) : m_rawLength64(length),m_raw64(data),m_raw16((const uint16_t*)(data)),m_ownData(0) {
128  m_formatVersion=(m_raw16[6]>>12)&0xF;
129 }
130 
131 HcalUHTRData::HcalUHTRData(const HcalUHTRData& hd) : m_formatVersion(hd.m_formatVersion), m_rawLength64(hd.m_rawLength64), m_raw64(hd.m_raw64), m_raw16(hd.m_raw16), m_ownData(0) { }
132 
133 HcalUHTRData::HcalUHTRData(int version_to_create) : m_formatVersion(version_to_create) {
134 
135  // the needed space is for the biggest possible event...
136  // fibers*maxsamples/fiber
137  const int needed=(0x20+FIBERS_PER_UHTR*CHANNELS_PER_FIBER_MAX*(10+1))*sizeof(uint16_t)/sizeof(uint64_t);
138 
139  m_ownData=new uint64_t[needed];
140  memset(m_ownData,0,sizeof(uint64_t)*needed);
141  m_rawLength64=0;
143  m_raw16=(const uint16_t*)m_raw64;
144 }
145 
147  if (m_ownData==0) {
150  m_raw64=hd.m_raw64;
151  m_raw16=hd.m_raw16;
152  }
153  return (*this);
154 }
int adc(sample_type sample)
get the ADC sample (12 bits)
void addTP(int tpword, bool soi=false)
static const int CHANNELS_PER_FIBER_MAX
Definition: HcalUHTRData.h:21
void addHeader(int flavor, int errf, int cap0, int channelid)
Definition: HcalUHTRData.cc:88
packer(uint16_t *baseptr)
Definition: HcalUHTRData.cc:85
const_iterator & operator++()
Definition: HcalUHTRData.cc:10
static const int HEADER_LENGTH_16BIT
Definition: HcalUHTRData.cc:4
void addSample(int adc, bool soi=false, int retdc=0, int fetdc=0, int tdcstat=0)
Definition: HcalUHTRData.cc:99
const_iterator begin() const
Definition: HcalUHTRData.cc:77
const uint16_t * m_raw16
Definition: HcalUHTRData.h:131
static const int FIBERS_PER_UHTR
Definition: HcalUHTRData.h:18
const_iterator(const uint16_t *ptr, const uint16_t *limit=0)
Definition: HcalUHTRData.cc:6
HcalUHTRData & operator=(const HcalUHTRData &)
unsigned long long uint64_t
Definition: Time.h:15
string const
Definition: compareJSON.py:14
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const uint64_t * m_raw64
Definition: HcalUHTRData.h:130
const_iterator end() const
Definition: HcalUHTRData.cc:81
uint64_t * m_ownData
Definition: HcalUHTRData.h:132