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