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) {
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) m_ptr+=2;
18 
19  if (isHeader()) determineMode();
20  return *this;
21 }
22 
24  if (!isHeader()) return;
25  m_flavor=flavor();
26  m_stepclass=0;
27  if (m_flavor==5) { m_stepclass=1; m_microstep=0; }
28  else if ((m_flavor&0x6)==0x2) { m_stepclass=2; }
29 }
30 
32  if (m_flavor==0x5 && m_microstep==0) return ((*m_ptr)>>8)&0x7F;
33  else return (*m_ptr)&0xFF;
34 }
35 
37  if (m_flavor==0x5) return 0x80;
38  else if ((m_flavor&0x6)==0x2) return (m_ptr[1]&0x3F);
39  else return (((*m_ptr)&0x3F00)>>8);
40 }
41 
43  if (m_flavor==0x5) return false;
44  else if ((m_flavor&0x6)==0x2) return (m_ptr[0]&0x2000);
45  else return (((*m_ptr)&0x4000));
46 }
47 
49  if (m_flavor==0x5 || (m_flavor&0x6)==0x0) return 0x80;
50  else return ((m_ptr[1]>>6)&0xF);
51 }
52 
53 
56 }
57 
59  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));
60 }
61 
62 HcalUHTRData::packer::packer(uint16_t* baseptr) : m_baseptr(baseptr),m_ptr(0),m_flavor(0),m_ministep(0) {
63 }
64 
65 void HcalUHTRData::packer::addHeader(int flavor, int errf, int cap0, int channelid) {
66  m_baseptr[m_ptr]=0x8000 |
67  ((flavor&0x7)<<12) |
68  ((errf&0x3)<<10) |
69  ((cap0&0x3)<<8) |
70  (channelid&0xFF);
71  m_flavor=flavor;
72  m_ministep=0;
73  m_ptr++;
74 }
75 
76 void HcalUHTRData::packer::addSample(int adc, bool soi, int retdc, int fetdc, int tdcstat) {
77  if (m_flavor==0x5) {
78  if (m_ministep==0) m_baseptr[m_ptr]=adc&0x7F;
79  else m_baseptr[m_ptr]|=((adc&0x7f)<<8);
80  if (m_ministep==1) m_ptr++;
81  m_ministep=(m_ministep+1)%2;
82  } else if ((m_flavor&0x6)==0x0) {
83  m_baseptr[m_ptr]=(adc&0xFF) | ((retdc&0x3F)<<8);
84  if (soi) m_baseptr[m_ptr]|=0x4000;
85  m_ptr++;
86  } else if ((m_flavor&0x6)==0x1) {
87  m_baseptr[m_ptr]=(adc&0xFF);
88  m_baseptr[m_ptr+1]=0x4000| ((tdcstat&0x3)<<10) | ((fetdc&0xF)<<6) | ((retdc)<<8);
89  if (soi) m_baseptr[m_ptr]|=0x2000;
90  m_ptr+=2;
91  }
92 }
93 
94 void HcalUHTRData::packer::addTP(int tpword, bool soi) {
95  if (m_flavor==0x4) {
96  m_baseptr[m_ptr]=tpword&0xFFF;
97  if (soi) m_baseptr[m_ptr]|=0x4000;
98  m_ptr++;
99  }
100 }
101 
103 
104 HcalUHTRData::HcalUHTRData(const uint64_t* data, int length) : m_rawLength64(length),m_raw64(data),m_raw16((const uint16_t*)(data)),m_ownData(0) {
105  m_formatVersion=(m_raw16[6]>>12)&0xF;
106 }
107 
108 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) { }
109 
110 HcalUHTRData::HcalUHTRData(int version_to_create) : m_formatVersion(version_to_create) {
111 
112  // the needed space is for the biggest possible event...
113  // fibers*maxsamples/fiber
114  const int needed=(0x20+FIBERS_PER_UHTR*CHANNELS_PER_FIBER_MAX*(10+1))*sizeof(uint16_t)/sizeof(uint64_t);
115 
116  m_ownData=new uint64_t[needed];
117  memset(m_ownData,0,sizeof(uint64_t)*needed);
118  m_rawLength64=0;
120  m_raw16=(const uint16_t*)m_raw64;
121 }
122 
124  if (m_ownData==0) {
127  m_raw64=hd.m_raw64;
128  m_raw16=hd.m_raw16;
129  }
130  return (*this);
131 }
int adc(sample_type sample)
get the ADC sample (12 bits)
void addTP(int tpword, bool soi=false)
Definition: HcalUHTRData.cc:94
static const int CHANNELS_PER_FIBER_MAX
Definition: HcalUHTRData.h:21
void addHeader(int flavor, int errf, int cap0, int channelid)
Definition: HcalUHTRData.cc:65
packer(uint16_t *baseptr)
Definition: HcalUHTRData.cc:62
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:76
const_iterator begin() const
Definition: HcalUHTRData.cc:54
const uint16_t * m_raw16
Definition: HcalUHTRData.h:127
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:126
const_iterator end() const
Definition: HcalUHTRData.cc:58
uint64_t * m_ownData
Definition: HcalUHTRData.h:128