CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripRawToClustersLazyUnpacker.cc
Go to the documentation of this file.
2 #include <sstream>
3 #include <iostream>
4 
5 
6 namespace sistrip {
7 
9 
10  raw_(&data),
11  regions_(&(regioncabling.getRegionCabling())),
12  clusterizer_(&clustalgo),
13  rawAlgos_(&rpAlgos),
14  buffers_(),
15  rawToDigi_(0,0,0,0,0,0,0,0),
16  dump_(dump),
17  doAPVEmulatorCheck_(true)
18  {
19  buffers_.assign(1024,static_cast<sistrip::FEDBuffer*>(0));
20  }
21 
23 
24  std::vector< sistrip::FEDBuffer*>::iterator ibuffer = buffers_.begin();
25  for (; ibuffer!=buffers_.end(); ibuffer++) {
26  if (*ibuffer) delete *ibuffer;
27  }
28  }
29 
31 
32  // Get region, subdet and layer from element-index
33  uint32_t region = SiStripRegionCabling::region(index);
34  uint32_t subdet = static_cast<uint32_t>(SiStripRegionCabling::subdet(index));
35  uint32_t layer = SiStripRegionCabling::layer(index);
36 
37  // Retrieve cabling for element
38  const SiStripRegionCabling::ElementCabling& element = (*regions_)[region][subdet][layer];
39 
40  // Loop dets
41  SiStripRegionCabling::ElementCabling::const_iterator idet = element.begin();
42  for (;idet!=element.end();idet++) {
43 
44  // If det id is null or invalid continue.
45  if ( !(idet->first) || (idet->first == sistrip::invalid32_) || !clusterizer_->stripByStripBegin(idet->first)) { continue; }
46 
47  // Loop over apv-pairs of det
48  std::vector<FedChannelConnection>::const_iterator iconn = idet->second.begin();
49  for (;iconn!=idet->second.end();iconn++) {
50  const uint16_t fedId = iconn->fedId();
51 
52  // If fed id is null or connection is invalid continue
53  if ( !fedId || !iconn->isConnected() ) { continue; }
54 
55  // If Fed hasnt already been initialised, extract data and initialise
56  FEDBuffer* buffer = buffers_[fedId];
57  if (!buffer) {
58 
59  // Retrieve FED raw data for given FED
60  const FEDRawData& rawData = raw_->FEDData( static_cast<int>(fedId) );
61 
62  // Check on FEDRawData pointer
63  if ( !rawData.data() ) {
64  if (edm::isDebugEnabled()) {
66  << "[sistrip::RawToClustersLazyGetter::"
67  << __func__
68  << "]"
69  << " NULL pointer to FEDRawData for FED id "
70  << fedId;
71  }
72  continue;
73  }
74 
75  // Check on FEDRawData size
76  if ( !rawData.size() ) {
77  if (edm::isDebugEnabled()) {
79  << "[sistrip::RawToClustersLazyGetter::"
80  << __func__ << "]"
81  << " FEDRawData has zero size for FED id "
82  << fedId;
83  }
84  continue;
85  }
86 
87  // construct FEDBuffer
88  try {
89  buffers_[fedId] = buffer = new sistrip::FEDBuffer(rawData.data(),rawData.size());
90  if (!buffer->doChecks()) throw cms::Exception("FEDBuffer") << "FED Buffer check fails for FED ID" << fedId << ".";
91  }
92  catch (const cms::Exception& e) {
93  if (edm::isDebugEnabled()) {
95  << "Exception caught when creating FEDBuffer object for FED " << fedId << ": " << e.what();
96  }
97  if ( buffer ) { delete buffer; }
98  buffers_[fedId] = 0;
99  continue;
100  }
101 
102  // dump of FEDRawData to stdout
103  if ( dump_ ) {
104  std::stringstream ss;
105  rawToDigi_.dumpRawData( fedId, rawData, ss );
107  << ss.str();
108  }
109  }
110 
111  // check channel
112  const uint8_t fedCh = iconn->fedCh();
113 
114  if (!buffer->channelGood(fedCh,doAPVEmulatorCheck_)) {
115  if (edm::isDebugEnabled()) {
116  std::ostringstream ss;
117  ss << "Problem unpacking channel " << fedCh << " on FED " << fedId;
119  }
120  continue;
121  }
122 
123  // Determine APV std::pair number
124  uint16_t ipair = iconn->apvPairNumber();
125 
126  const sistrip::FEDReadoutMode mode = buffer->readoutMode();
128 
129  try {
130  // create unpacker
132 
133  // unpack
134  while (unpacker.hasData()) {
135  clusterizer_->stripByStripAdd(unpacker.sampleNumber()+ipair*256,unpacker.adc(),record);
136  unpacker++;
137  }
138  } catch (const cms::Exception& e) {
139  if (edm::isDebugEnabled()) {
140  std::ostringstream ss;
141  ss << "Unordered clusters for channel " << fedCh << " on FED " << fedId << ": " << e.what();
143  }
144  continue;
145  }
146  }
147 
148  else if (mode == sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE ) {
149 
150  try {
151  // create unpacker
153 
154  // unpack
155  while (unpacker.hasData()) {
156  clusterizer_->stripByStripAdd(unpacker.sampleNumber()+ipair*256,unpacker.adc(),record);
157  unpacker++;
158  }
159  } catch (const cms::Exception& e) {
160  if (edm::isDebugEnabled()) {
161  std::ostringstream ss;
162  ss << "Unordered clusters for channel " << fedCh << " on FED " << fedId << ": " << e.what();
164  }
165  continue;
166  }
167  }
168 
169  else if (mode == sistrip::READOUT_MODE_VIRGIN_RAW ) {
170 
171  // create unpacker
173 
174  // unpack
175  std::vector<int16_t> digis;
176  while (unpacker.hasData()) {
177  digis.push_back(unpacker.adc());
178  unpacker++;
179  }
180 
181  //process raw
182  uint32_t id = iconn->detId();
183  edm::DetSet<SiStripDigi> zsdigis(id);
184  //rawAlgos_->subtractorPed->subtract( id, ipair*256, digis);
185  //rawAlgos_->subtractorCMN->subtract( id, digis);
186  //rawAlgos_->suppressor->suppress( digis, zsdigis);
187  uint16_t firstAPV = ipair*2;
188  rawAlgos_->SuppressVirginRawData(id, firstAPV,digis, zsdigis);
189  for( edm::DetSet<SiStripDigi>::const_iterator it = zsdigis.begin(); it!=zsdigis.end(); it++) {
190  clusterizer_->stripByStripAdd( it->strip(), it->adc(), record);
191  }
192  }
193 
194  else if (mode == sistrip::READOUT_MODE_PROC_RAW ) {
195 
196  // create unpacker
198 
199  // unpack
200  std::vector<int16_t> digis;
201  while (unpacker.hasData()) {
202  digis.push_back(unpacker.adc());
203  unpacker++;
204  }
205 
206  //process raw
207  uint32_t id = iconn->detId();
208  edm::DetSet<SiStripDigi> zsdigis(id);
209  //rawAlgos_->subtractorCMN->subtract( id, digis);
210  //rawAlgos_->suppressor->suppress( digis, zsdigis);
211  uint16_t firstAPV = ipair*2;
212  rawAlgos_->SuppressProcessedRawData(id, firstAPV,digis, zsdigis);
213  for( edm::DetSet<SiStripDigi>::const_iterator it = zsdigis.begin(); it!=zsdigis.end(); it++) {
214  clusterizer_->stripByStripAdd( it->strip(), it->adc(), record);
215  }
216  }
217 
218  else {
220  << "[sistrip::RawToClustersLazyGetter::"
221  << __func__ << "]"
222  << " FEDRawData readout mode "
223  << mode
224  << " from FED id "
225  << fedId
226  << " not supported.";
227  continue;
228  }
229  }
230  clusterizer_->stripByStripEnd(record);
231  }
232  }
233 
234 
235 }
iterator end()
Definition: DetSet.h:60
static FEDRawChannelUnpacker procRawModeUnpacker(const FEDChannel &channel)
virtual char const * what() const
Definition: Exception.cc:141
bool isDebugEnabled()
static FEDZSChannelUnpacker zeroSuppressedModeUnpacker(const FEDChannel &channel)
SiStripRawProcessingAlgorithms *const rawAlgos_
raw processing algorithms
static const char mlRawToCluster_[]
static const uint32_t invalid32_
Definition: Constants.h:15
int16_t SuppressVirginRawData(const uint32_t &, const uint16_t &, std::vector< int16_t > &, edm::DetSet< SiStripDigi > &)
static FEDRawChannelUnpacker virginRawModeUnpacker(const FEDChannel &channel)
FEDReadoutMode readoutMode() const
static const char mlRawToDigi_[]
virtual bool doChecks() const
virtual void stripByStripEnd(std::vector< SiStripCluster > &out)=0
virtual bool channelGood(const uint8_t internalFEDannelNum, const bool doAPVeCheck=true) const
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
virtual void fill(const uint32_t &, record_type &)
virtual bool stripByStripBegin(uint32_t id)=0
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void dumpRawData(uint16_t fed_id, const FEDRawData &, std::stringstream &)
dumps raw data to stdout (NB: payload is byte-swapped,headers/trailer are not).
std::vector< SiStripCluster > record_type
Definition: LazyGetter.h:219
static const SubDet subdet(const ElementIndex)
const FEDChannel & channel(const uint8_t internalFEDChannelNum) const
#define LogTrace(id)
StripClusterizerAlgorithm *const clusterizer_
clusterizer algorithm
std::vector< sistrip::FEDBuffer * > buffers_
FED event cache.
iterator begin()
Definition: DetSet.h:59
static FEDZSChannelUnpacker zeroSuppressedLiteModeUnpacker(const FEDChannel &channel)
virtual void stripByStripAdd(uint16_t strip, uint16_t adc, std::vector< SiStripCluster > &out)=0
const FEDRawDataCollection * raw_
raw data
const uint32_t region(const Position) const
int16_t SuppressProcessedRawData(const uint32_t &, const uint16_t &, std::vector< int16_t > &, edm::DetSet< SiStripDigi > &)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
RawToClustersLazyUnpacker()
private default constructor
static const uint32_t layer(const ElementIndex)
std::map< uint32_t, std::vector< FedChannelConnection > > ElementCabling