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 
3 
5 
6 #include <sstream>
7 #include <iostream>
8 
9 
10 namespace sistrip {
11 
13 
14  raw_(&data),
15  regions_(&(regioncabling.getRegionCabling())),
16  clusterizer_(&clustalgo),
17  rawAlgos_(&rpAlgos),
18  buffers_(),
19  dump_(dump),
20  doAPVEmulatorCheck_(true)
21  {
22  buffers_.assign(1024,static_cast<sistrip::FEDBuffer*>(0));
23  }
24 
26 
27  std::vector< sistrip::FEDBuffer*>::iterator ibuffer = buffers_.begin();
28  for (; ibuffer!=buffers_.end(); ibuffer++) {
29  if (*ibuffer) delete *ibuffer;
30  }
31  }
32 
34 
35  // Get region, subdet and layer from element-index
36  uint32_t region = SiStripRegionCabling::region(index);
37  uint32_t subdet = static_cast<uint32_t>(SiStripRegionCabling::subdet(index));
38  uint32_t layer = SiStripRegionCabling::layer(index);
39 
40  // Retrieve cabling for element
41  const SiStripRegionCabling::ElementCabling& element = (*regions_)[region][subdet][layer];
42 
43  // Loop dets
44  SiStripRegionCabling::ElementCabling::const_iterator idet = element.begin();
45  for (;idet!=element.end();idet++) {
46 
47  // If det id is null or invalid continue.
48  if ( ( (!(idet->first)) | (idet->first == sistrip::invalid32_)) || !clusterizer_->stripByStripBegin(idet->first)) { continue; }
49 
50  // Loop over apv-pairs of det
51  std::vector<FedChannelConnection>::const_iterator iconn = idet->second.begin();
52  for (;iconn!=idet->second.end();iconn++) {
53  const uint16_t fedId = iconn->fedId();
54 
55  // If fed id is null or connection is invalid continue
56  if ( !fedId || !iconn->isConnected() ) { continue; }
57 
58  // If Fed hasnt already been initialised, extract data and initialise
59  FEDBuffer* buffer = buffers_[fedId];
60  if (!buffer) {
61 
62  // Retrieve FED raw data for given FED
63  const FEDRawData& rawData = raw_->FEDData( static_cast<int>(fedId) );
64 
65  // Check on FEDRawData pointer
66  if ( !rawData.data() ) {
67  if (edm::isDebugEnabled()) {
69  << "[sistrip::RawToClustersLazyGetter::"
70  << __func__
71  << "]"
72  << " NULL pointer to FEDRawData for FED id "
73  << fedId;
74  }
75  continue;
76  }
77 
78  // Check on FEDRawData size
79  if ( !rawData.size() ) {
80  if (edm::isDebugEnabled()) {
82  << "[sistrip::RawToClustersLazyGetter::"
83  << __func__ << "]"
84  << " FEDRawData has zero size for FED id "
85  << fedId;
86  }
87  continue;
88  }
89 
90  // construct FEDBuffer
91  try {
92  buffers_[fedId] = buffer = new sistrip::FEDBuffer(rawData.data(),rawData.size());
93  if (!buffer->doChecks(false)) throw cms::Exception("FEDBuffer") << "FED Buffer check fails for FED ID" << fedId << ".";
94  }
95  catch (const cms::Exception& e) {
96  if (edm::isDebugEnabled()) {
98  << "Exception caught when creating FEDBuffer object for FED " << fedId << ": " << e.what();
99  }
100  if ( buffer ) { delete buffer; }
101  buffers_[fedId] = 0;
102  continue;
103  }
104 
105  // dump of FEDRawData to stdout
106  if ( dump_ ) {
107  std::stringstream ss;
108  RawToDigiUnpacker::dumpRawData( fedId, rawData, ss );
110  << ss.str();
111  }
112  }
113 
114  // check channel
115  const uint8_t fedCh = iconn->fedCh();
116 
117  if (!buffer->channelGood(fedCh,doAPVEmulatorCheck_)) {
118  if (edm::isDebugEnabled()) {
119  std::ostringstream ss;
120  ss << "Problem unpacking channel " << fedCh << " on FED " << fedId;
122  }
123  continue;
124  }
125 
126  // Determine APV std::pair number
127  uint16_t ipair = iconn->apvPairNumber();
128 
129  const sistrip::FEDReadoutMode mode = buffer->readoutMode();
131 
132  try {
133  // create unpacker
135 
136  // unpack
137  clusterizer_->addFed(unpacker,ipair,record);
138  /*
139  while (unpacker.hasData()) {
140  clusterizer_->stripByStripAdd(unpacker.sampleNumber()+ipair*256,unpacker.adc(),record);
141  unpacker++;
142  }
143  */
144  } catch (const cms::Exception& e) {
145  if (edm::isDebugEnabled()) {
146  std::ostringstream ss;
147  ss << "Unordered clusters for channel " << fedCh << " on FED " << fedId << ": " << e.what();
149  }
150  continue;
151  }
152  }
153 
154  else if (mode == sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE ) {
155 
156  try {
157  // create unpacker
159 
160  // unpack
161  clusterizer_->addFed(unpacker,ipair,record);
162  /*
163  while (unpacker.hasData()) {
164  clusterizer_->stripByStripAdd(unpacker.sampleNumber()+ipair*256,unpacker.adc(),record);
165  unpacker++;
166  }
167  */
168  } catch (const cms::Exception& e) {
169  if (edm::isDebugEnabled()) {
170  std::ostringstream ss;
171  ss << "Unordered clusters for channel " << fedCh << " on FED " << fedId << ": " << e.what();
173  }
174  continue;
175  }
176  }
177 
178  else if (mode == sistrip::READOUT_MODE_VIRGIN_RAW ) {
179 
180  // create unpacker
182 
183  // unpack
184  std::vector<int16_t> digis;
185  while (unpacker.hasData()) {
186  digis.push_back(unpacker.adc());
187  unpacker++;
188  }
189 
190  //process raw
191  uint32_t id = iconn->detId();
192  edm::DetSet<SiStripDigi> zsdigis(id);
193  //rawAlgos_->subtractorPed->subtract( id, ipair*256, digis);
194  //rawAlgos_->subtractorCMN->subtract( id, digis);
195  //rawAlgos_->suppressor->suppress( digis, zsdigis);
196  uint16_t firstAPV = ipair*2;
197  rawAlgos_->SuppressVirginRawData(id, firstAPV,digis, zsdigis);
198  for( edm::DetSet<SiStripDigi>::const_iterator it = zsdigis.begin(); it!=zsdigis.end(); it++) {
199  clusterizer_->stripByStripAdd( it->strip(), it->adc(), record);
200  }
201  }
202 
203  else if (mode == sistrip::READOUT_MODE_PROC_RAW ) {
204 
205  // create unpacker
207 
208  // unpack
209  std::vector<int16_t> digis;
210  while (unpacker.hasData()) {
211  digis.push_back(unpacker.adc());
212  unpacker++;
213  }
214 
215  //process raw
216  uint32_t id = iconn->detId();
217  edm::DetSet<SiStripDigi> zsdigis(id);
218  //rawAlgos_->subtractorCMN->subtract( id, digis);
219  //rawAlgos_->suppressor->suppress( digis, zsdigis);
220  uint16_t firstAPV = ipair*2;
221  rawAlgos_->SuppressProcessedRawData(id, firstAPV,digis, zsdigis);
222  for( edm::DetSet<SiStripDigi>::const_iterator it = zsdigis.begin(); it!=zsdigis.end(); it++) {
223  clusterizer_->stripByStripAdd( it->strip(), it->adc(), record);
224  }
225  }
226 
227  else {
229  << "[sistrip::RawToClustersLazyGetter::"
230  << __func__ << "]"
231  << " FEDRawData readout mode "
232  << mode
233  << " from FED id "
234  << fedId
235  << " not supported.";
236  continue;
237  }
238  }
239  clusterizer_->stripByStripEnd(record);
240  }
241  }
242 
243 
244 }
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
virtual void addFed(sistrip::FEDZSChannelUnpacker &unpacker, uint16_t ipair, std::vector< SiStripCluster > &out)
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_[]
std::vector< Element > ElementCabling
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 void stripByStripEnd(std::vector< SiStripCluster > &out)
virtual bool stripByStripBegin(uint32_t id)=0
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
static 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
virtual bool doChecks(bool doCRC=true) const
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)
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
virtual void stripByStripAdd(uint16_t strip, uint8_t adc, std::vector< SiStripCluster > &out)
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)