Go to the documentation of this file.00001 #include "EventFilter/SiStripRawToDigi/interface/SiStripRawToClustersLazyUnpacker.h"
00002 #include <sstream>
00003 #include <iostream>
00004
00005
00006 namespace sistrip {
00007
00008 RawToClustersLazyUnpacker::RawToClustersLazyUnpacker(const SiStripRegionCabling& regioncabling, StripClusterizerAlgorithm& clustalgo, SiStripRawProcessingAlgorithms& rpAlgos, const FEDRawDataCollection& data, bool dump) :
00009
00010 raw_(&data),
00011 regions_(&(regioncabling.getRegionCabling())),
00012 clusterizer_(&clustalgo),
00013 rawAlgos_(&rpAlgos),
00014 buffers_(),
00015 rawToDigi_(0,0,0,0,0,0,0,0),
00016 dump_(dump)
00017 {
00018 buffers_.assign(1024,static_cast<sistrip::FEDBuffer*>(0));
00019 }
00020
00021 RawToClustersLazyUnpacker::~RawToClustersLazyUnpacker() {
00022
00023 std::vector< sistrip::FEDBuffer*>::iterator ibuffer = buffers_.begin();
00024 for (; ibuffer!=buffers_.end(); ibuffer++) {
00025 if (*ibuffer) delete *ibuffer;
00026 }
00027 }
00028
00029 void RawToClustersLazyUnpacker::fill(const uint32_t& index, record_type& record) {
00030
00031
00032 uint32_t region = SiStripRegionCabling::region(index);
00033 uint32_t subdet = static_cast<uint32_t>(SiStripRegionCabling::subdet(index));
00034 uint32_t layer = SiStripRegionCabling::layer(index);
00035
00036
00037 const SiStripRegionCabling::ElementCabling& element = (*regions_)[region][subdet][layer];
00038
00039
00040 SiStripRegionCabling::ElementCabling::const_iterator idet = element.begin();
00041 for (;idet!=element.end();idet++) {
00042
00043
00044 if ( !(idet->first) || (idet->first == sistrip::invalid32_) || !clusterizer_->stripByStripBegin(idet->first)) { continue; }
00045
00046
00047 std::vector<FedChannelConnection>::const_iterator iconn = idet->second.begin();
00048 for (;iconn!=idet->second.end();iconn++) {
00049 const uint16_t fedId = iconn->fedId();
00050
00051
00052 if ( !fedId || !iconn->isConnected() ) { continue; }
00053
00054
00055 FEDBuffer* buffer = buffers_[fedId];
00056 if (!buffer) {
00057
00058
00059 const FEDRawData& rawData = raw_->FEDData( static_cast<int>(fedId) );
00060
00061
00062 if ( !rawData.data() ) {
00063 if (edm::isDebugEnabled()) {
00064 edm::LogWarning(sistrip::mlRawToCluster_)
00065 << "[sistrip::RawToClustersLazyGetter::"
00066 << __func__
00067 << "]"
00068 << " NULL pointer to FEDRawData for FED id "
00069 << fedId;
00070 }
00071 continue;
00072 }
00073
00074
00075 if ( !rawData.size() ) {
00076 if (edm::isDebugEnabled()) {
00077 edm::LogWarning(sistrip::mlRawToCluster_)
00078 << "[sistrip::RawToClustersLazyGetter::"
00079 << __func__ << "]"
00080 << " FEDRawData has zero size for FED id "
00081 << fedId;
00082 }
00083 continue;
00084 }
00085
00086
00087 try {
00088 buffers_[fedId] = buffer = new sistrip::FEDBuffer(rawData.data(),rawData.size());
00089 if (!buffer->doChecks()) throw cms::Exception("FEDBuffer") << "FED Buffer check fails for FED ID" << fedId << ".";
00090 }
00091 catch (const cms::Exception& e) {
00092 if (edm::isDebugEnabled()) {
00093 edm::LogWarning(sistrip::mlRawToCluster_)
00094 << "Exception caught when creating FEDBuffer object for FED " << fedId << ": " << e.what();
00095 }
00096 if ( buffer ) { delete buffer; }
00097 buffers_[fedId] = 0;
00098 continue;
00099 }
00100
00101
00102 if ( dump_ ) {
00103 std::stringstream ss;
00104 rawToDigi_.dumpRawData( fedId, rawData, ss );
00105 LogTrace(mlRawToDigi_)
00106 << ss.str();
00107 }
00108 }
00109
00110
00111 const uint8_t fedCh = iconn->fedCh();
00112 if (!buffer->channelGood(fedCh)) {
00113 if (edm::isDebugEnabled()) {
00114 std::ostringstream ss;
00115 ss << "Problem unpacking channel " << fedCh << " on FED " << fedId;
00116 edm::LogWarning(sistrip::mlRawToCluster_) << ss.str();
00117 }
00118 continue;
00119 }
00120
00121
00122 uint16_t ipair = iconn->apvPairNumber();
00123
00124 const sistrip::FEDReadoutMode mode = buffer->readoutMode();
00125 if (mode == sistrip::READOUT_MODE_ZERO_SUPPRESSED ) {
00126
00127 try {
00128
00129 sistrip::FEDZSChannelUnpacker unpacker = sistrip::FEDZSChannelUnpacker::zeroSuppressedModeUnpacker(buffer->channel(fedCh));
00130
00131
00132 while (unpacker.hasData()) {
00133 clusterizer_->stripByStripAdd(unpacker.sampleNumber()+ipair*256,unpacker.adc(),record);
00134 unpacker++;
00135 }
00136 } catch (const cms::Exception& e) {
00137 if (edm::isDebugEnabled()) {
00138 std::ostringstream ss;
00139 ss << "Unordered clusters for channel " << fedCh << " on FED " << fedId << ": " << e.what();
00140 edm::LogWarning(sistrip::mlRawToCluster_) << ss.str();
00141 }
00142 continue;
00143 }
00144 }
00145
00146 else if (mode == sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE ) {
00147
00148 try {
00149
00150 sistrip::FEDZSChannelUnpacker unpacker = sistrip::FEDZSChannelUnpacker::zeroSuppressedLiteModeUnpacker(buffer->channel(fedCh));
00151
00152
00153 while (unpacker.hasData()) {
00154 clusterizer_->stripByStripAdd(unpacker.sampleNumber()+ipair*256,unpacker.adc(),record);
00155 unpacker++;
00156 }
00157 } catch (const cms::Exception& e) {
00158 if (edm::isDebugEnabled()) {
00159 std::ostringstream ss;
00160 ss << "Unordered clusters for channel " << fedCh << " on FED " << fedId << ": " << e.what();
00161 edm::LogWarning(sistrip::mlRawToCluster_) << ss.str();
00162 }
00163 continue;
00164 }
00165 }
00166
00167 else if (mode == sistrip::READOUT_MODE_VIRGIN_RAW ) {
00168
00169
00170 sistrip::FEDRawChannelUnpacker unpacker = sistrip::FEDRawChannelUnpacker::virginRawModeUnpacker(buffer->channel(fedCh));
00171
00172
00173 std::vector<int16_t> digis;
00174 while (unpacker.hasData()) {
00175 digis.push_back(unpacker.adc());
00176 unpacker++;
00177 }
00178
00179
00180 uint32_t id = iconn->detId();
00181 edm::DetSet<SiStripDigi> zsdigis(id);
00182
00183
00184
00185 uint16_t firstAPV = ipair*2;
00186 rawAlgos_->SuppressVirginRawData(id, firstAPV,digis, zsdigis);
00187 for( edm::DetSet<SiStripDigi>::const_iterator it = zsdigis.begin(); it!=zsdigis.end(); it++) {
00188 clusterizer_->stripByStripAdd( it->strip(), it->adc(), record);
00189 }
00190 }
00191
00192 else if (mode == sistrip::READOUT_MODE_PROC_RAW ) {
00193
00194
00195 sistrip::FEDRawChannelUnpacker unpacker = sistrip::FEDRawChannelUnpacker::procRawModeUnpacker(buffer->channel(fedCh));
00196
00197
00198 std::vector<int16_t> digis;
00199 while (unpacker.hasData()) {
00200 digis.push_back(unpacker.adc());
00201 unpacker++;
00202 }
00203
00204
00205 uint32_t id = iconn->detId();
00206 edm::DetSet<SiStripDigi> zsdigis(id);
00207
00208
00209 uint16_t firstAPV = ipair*2;
00210 rawAlgos_->SuppressProcessedRawData(id, firstAPV,digis, zsdigis);
00211 for( edm::DetSet<SiStripDigi>::const_iterator it = zsdigis.begin(); it!=zsdigis.end(); it++) {
00212 clusterizer_->stripByStripAdd( it->strip(), it->adc(), record);
00213 }
00214 }
00215
00216 else {
00217 edm::LogWarning(sistrip::mlRawToCluster_)
00218 << "[sistrip::RawToClustersLazyGetter::"
00219 << __func__ << "]"
00220 << " FEDRawData readout mode "
00221 << mode
00222 << " from FED id "
00223 << fedId
00224 << " not supported.";
00225 continue;
00226 }
00227 }
00228 clusterizer_->stripByStripEnd(record);
00229 }
00230 }
00231
00232 }