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 namespace sistrip {
6 
8 
9  raw_(&data),
10  regions_(&(regioncabling.getRegionCabling())),
11  clusterizer_(&clustalgo),
12  rawAlgos_(&rpAlgos),
13  buffers_(),
14  rawToDigi_(0,0,0,0,0,0,0,0),
15  dump_(dump)
16  {
17  buffers_.assign(1024,static_cast<sistrip::FEDBuffer*>(0));
18  }
19 
21 
22  std::vector< sistrip::FEDBuffer*>::iterator ibuffer = buffers_.begin();
23  for (; ibuffer!=buffers_.end(); ibuffer++) {
24  if (*ibuffer) delete *ibuffer;
25  }
26  }
27 
29 
30  // Get region, subdet and layer from element-index
31  uint32_t region = SiStripRegionCabling::region(index);
32  uint32_t subdet = static_cast<uint32_t>(SiStripRegionCabling::subdet(index));
33  uint32_t layer = SiStripRegionCabling::layer(index);
34 
35  // Retrieve cabling for element
36  const SiStripRegionCabling::ElementCabling& element = (*regions_)[region][subdet][layer];
37 
38  // Loop dets
39  SiStripRegionCabling::ElementCabling::const_iterator idet = element.begin();
40  for (;idet!=element.end();idet++) {
41 
42  // If det id is null or invalid continue.
43  if ( !(idet->first) || (idet->first == sistrip::invalid32_) || !clusterizer_->stripByStripBegin(idet->first)) { continue; }
44 
45  // Loop over apv-pairs of det
46  std::vector<FedChannelConnection>::const_iterator iconn = idet->second.begin();
47  for (;iconn!=idet->second.end();iconn++) {
48  const uint16_t fedId = iconn->fedId();
49 
50  // If fed id is null or connection is invalid continue
51  if ( !fedId || !iconn->isConnected() ) { continue; }
52 
53  // If Fed hasnt already been initialised, extract data and initialise
54  FEDBuffer* buffer = buffers_[fedId];
55  if (!buffer) {
56 
57  // Retrieve FED raw data for given FED
58  const FEDRawData& rawData = raw_->FEDData( static_cast<int>(fedId) );
59 
60  // Check on FEDRawData pointer
61  if ( !rawData.data() ) {
62  if (edm::isDebugEnabled()) {
64  << "[sistrip::RawToClustersLazyGetter::"
65  << __func__
66  << "]"
67  << " NULL pointer to FEDRawData for FED id "
68  << fedId;
69  }
70  continue;
71  }
72 
73  // Check on FEDRawData size
74  if ( !rawData.size() ) {
75  if (edm::isDebugEnabled()) {
77  << "[sistrip::RawToClustersLazyGetter::"
78  << __func__ << "]"
79  << " FEDRawData has zero size for FED id "
80  << fedId;
81  }
82  continue;
83  }
84 
85  // construct FEDBuffer
86  try {
87  buffers_[fedId] = buffer = new sistrip::FEDBuffer(rawData.data(),rawData.size());
88  if (!buffer->doChecks()) throw cms::Exception("FEDBuffer") << "FED Buffer check fails for FED ID" << fedId << ".";
89  }
90  catch (const cms::Exception& e) {
91  if (edm::isDebugEnabled()) {
93  << "Exception caught when creating FEDBuffer object for FED " << fedId << ": " << e.what();
94  }
95  if ( buffer ) { delete buffer; }
96  buffers_[fedId] = 0;
97  continue;
98  }
99 
100  // dump of FEDRawData to stdout
101  if ( dump_ ) {
102  std::stringstream ss;
103  rawToDigi_.dumpRawData( fedId, rawData, ss );
105  << ss.str();
106  }
107  }
108 
109  // check channel
110  const uint8_t fedCh = iconn->fedCh();
111  if (!buffer->channelGood(fedCh)) {
112  if (edm::isDebugEnabled()) {
113  std::ostringstream ss;
114  ss << "Problem unpacking channel " << fedCh << " on FED " << fedId;
116  }
117  continue;
118  }
119 
120  // Determine APV std::pair number
121  uint16_t ipair = iconn->apvPairNumber();
122 
123  const sistrip::FEDReadoutMode mode = buffer->readoutMode();
125 
126  try {
127  // create unpacker
129 
130  // unpack
131  while (unpacker.hasData()) {
132  clusterizer_->stripByStripAdd(unpacker.sampleNumber()+ipair*256,unpacker.adc(),record);
133  unpacker++;
134  }
135  } catch (const cms::Exception& e) {
136  if (edm::isDebugEnabled()) {
137  std::ostringstream ss;
138  ss << "Unordered clusters for channel " << fedCh << " on FED " << fedId << ": " << e.what();
140  }
141  continue;
142  }
143  }
144 
145  else if (mode == sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE ) {
146 
147  try {
148  // create unpacker
150 
151  // unpack
152  while (unpacker.hasData()) {
153  clusterizer_->stripByStripAdd(unpacker.sampleNumber()+ipair*256,unpacker.adc(),record);
154  unpacker++;
155  }
156  } catch (const cms::Exception& e) {
157  if (edm::isDebugEnabled()) {
158  std::ostringstream ss;
159  ss << "Unordered clusters for channel " << fedCh << " on FED " << fedId << ": " << e.what();
161  }
162  continue;
163  }
164  }
165 
166  else if (mode == sistrip::READOUT_MODE_VIRGIN_RAW ) {
167 
168  // create unpacker
170 
171  // unpack
172  std::vector<int16_t> digis;
173  while (unpacker.hasData()) {
174  digis.push_back(unpacker.adc());
175  unpacker++;
176  }
177 
178  //process raw
179  uint32_t id = iconn->detId();
180  rawAlgos_->subtractorPed->subtract( id, ipair*256, digis);
181  rawAlgos_->subtractorCMN->subtract( id, digis);
182  edm::DetSet<SiStripDigi> zsdigis(id);
183  rawAlgos_->suppressor->suppress( digis, zsdigis);
184  for( edm::DetSet<SiStripDigi>::const_iterator it = zsdigis.begin(); it!=zsdigis.end(); it++) {
185  clusterizer_->stripByStripAdd( it->strip(), it->adc(), record);
186  }
187  }
188 
189  else if (mode == sistrip::READOUT_MODE_PROC_RAW ) {
190 
191  // create unpacker
193 
194  // unpack
195  std::vector<int16_t> digis;
196  while (unpacker.hasData()) {
197  digis.push_back(unpacker.adc());
198  unpacker++;
199  }
200 
201  //process raw
202  uint32_t id = iconn->detId();
203  rawAlgos_->subtractorCMN->subtract( id, digis);
204  edm::DetSet<SiStripDigi> zsdigis(id);
205  rawAlgos_->suppressor->suppress( digis, zsdigis);
206  for( edm::DetSet<SiStripDigi>::const_iterator it = zsdigis.begin(); it!=zsdigis.end(); it++) {
207  clusterizer_->stripByStripAdd( it->strip(), it->adc(), record);
208  }
209  }
210 
211  else {
213  << "[sistrip::RawToClustersLazyGetter::"
214  << __func__ << "]"
215  << " FEDRawData readout mode "
216  << mode
217  << " from FED id "
218  << fedId
219  << " not supported.";
220  continue;
221  }
222  }
223  clusterizer_->stripByStripEnd(record);
224  }
225  }
226 
227 }
iterator end()
Definition: DetSet.h:50
static FEDRawChannelUnpacker procRawModeUnpacker(const FEDChannel &channel)
virtual char const * what() const
Definition: Exception.cc:97
bool isDebugEnabled()
static FEDZSChannelUnpacker zeroSuppressedModeUnpacker(const FEDChannel &channel)
SiStripRawProcessingAlgorithms *const rawAlgos_
raw processing algorithms
const std::auto_ptr< SiStripPedestalsSubtractor > subtractorPed
static const char mlRawToCluster_[]
JetCorrectorParameters::Record record
Definition: classes.h:11
static const uint32_t invalid32_
Definition: Constants.h:16
static FEDRawChannelUnpacker virginRawModeUnpacker(const FEDChannel &channel)
FEDReadoutMode readoutMode() const
static const char mlRawToDigi_[]
virtual bool doChecks() const
const std::auto_ptr< SiStripFedZeroSuppression > suppressor
virtual void stripByStripEnd(std::vector< SiStripCluster > &out)=0
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:213
static const SubDet subdet(const ElementIndex)
virtual bool channelGood(const uint8_t internalFEDannelNum) const
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:49
static FEDZSChannelUnpacker zeroSuppressedLiteModeUnpacker(const FEDChannel &channel)
int mode
Definition: AMPTWrapper.h:139
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
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
const std::auto_ptr< SiStripCommonModeNoiseSubtractor > subtractorCMN
collection_type::const_iterator const_iterator
Definition: DetSet.h:31
RawToClustersLazyUnpacker()
private default constructor
static const uint32_t layer(const ElementIndex)
std::map< uint32_t, std::vector< FedChannelConnection > > ElementCabling