Go to the documentation of this file.00001
00002
00003
00004 #include "FWCore/Utilities/interface/Exception.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006
00007 #include "DataFormats/Common/interface/DetSetVector.h"
00008 #include "DataFormats/Common/interface/DetSet.h"
00009
00010 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
00011 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
00012 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00013 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00014 #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
00015
00016 #include "EventFilter/SiStripRawToDigi/interface/SiStripDetSetVectorFiller.h"
00017
00018 #include "DQM/SiStripMonitorHardware/interface/SiStripFEDSpyBuffer.h"
00019 #include "DQM/SiStripMonitorHardware/interface/SiStripSpyUnpacker.h"
00020
00021 #include <algorithm>
00022 #include <vector>
00023 #include <ext/algorithm>
00024
00025 using namespace std;
00026
00027 namespace sistrip {
00028
00029 SpyUnpacker::SpyUnpacker(const bool allowIncompleteEvents) :
00030 allowIncompleteEvents_(allowIncompleteEvents)
00031 {
00032 if ( edm::isDebugEnabled() ) {
00033 LogTrace("SiStripSpyUnpacker")
00034 << "[sistrip::SpyUnpacker::"<<__func__<<"]"
00035 <<" Constructing object...";
00036 }
00037 }
00038
00039 SpyUnpacker::~SpyUnpacker() {
00040 if ( edm::isDebugEnabled() ) {
00041 LogTrace("SiStripSpyUnpacker")
00042 << "[sistrip::SpyUnpacker::"<<__func__<<"]"
00043 << " Destructing object...";
00044 }
00045 }
00046
00047 void SpyUnpacker::createDigis(const SiStripFedCabling& cabling,
00048 const FEDRawDataCollection& buffers,
00049 RawDigis* pDigis,
00050 const std::vector<uint32_t> & ids,
00051 Counters* pTotalEventCounts,
00052 Counters* pL1ACounts,
00053 uint32_t* aRunRef)
00054 {
00055
00056
00057
00058
00059
00060 uint16_t nFeds = static_cast<uint16_t>( FED_ID_MAX - FED_ID_MIN + 1);
00061
00062 RawDigiDetSetVectorFiller dsvFiller(nFeds*FEDCH_PER_FED,nFeds*FEDCH_PER_FED*SPY_SAMPLES_PER_CHANNEL);
00063
00064
00065 if ( edm::isDebugEnabled() ) {
00066 if ( cabling.feds().empty() ) {
00067 edm::LogWarning("SiStripSpyUnpacker")
00068 << "[sistrip::SpyUnpacker::" << __func__ << "]"
00069 << " No FEDs found in cabling map!";
00070 }
00071 }
00072
00073
00074 std::vector<uint32_t>::const_iterator ifed = ids.begin();
00075 std::vector<uint32_t>::const_iterator endfed = ids.end();
00076
00077
00078
00079 uint32_t lRef = 0;
00080
00081
00082 pTotalEventCounts->resize(FED_ID_MAX+1,0);
00083 pL1ACounts->resize(FED_ID_MAX+1,0);
00084
00085 for ( ; ifed != endfed; ++ifed ) {
00086
00087 uint32_t lFedId = (*ifed);
00088
00089
00090 if (lFedId < FED_ID_MIN || lFedId > FED_ID_MAX) {
00091 if ( edm::isDebugEnabled() ) {
00092 edm::LogWarning("SiStripSpyUnpacker")
00093 << "[sistrip::SpyUnpacker::" << __func__ << "]"
00094 << " Invalid FED id provided: "
00095 << lFedId;
00096 }
00097 continue;
00098 }
00099
00100
00101 const FEDRawData& input = buffers.FEDData( static_cast<int>(lFedId) );
00102
00103 if ( !input.data() ) {
00104 if ( edm::isDebugEnabled() ) {
00105 edm::LogWarning("SiStripSpyUnpacker")
00106 << "[sistrip::SpyUnpacker::" << __func__ << "]"
00107 << " NULL pointer to FEDRawData for FED id "
00108 << lFedId;
00109 }
00110 continue;
00111 }
00112
00113 if ( !input.size() ) {
00114 if ( edm::isDebugEnabled() ) {
00115 edm::LogWarning("SiStripSpyUnpacker")
00116 << "[sistrip::SpyUnpacker::" << __func__ << "]"
00117 << " FEDRawData has zero size for FED id "
00118 << lFedId;
00119 }
00120 continue;
00121 }
00122
00123
00124 const std::vector<FedChannelConnection>& conns = cabling.connections(lFedId);
00125
00126
00127 std::auto_ptr<sistrip::FEDSpyBuffer> buffer;
00128 try {
00129 buffer.reset(new sistrip::FEDSpyBuffer(input.data(),input.size()));
00130 if (!buffer->doChecks() && !allowIncompleteEvents_) {
00131 throw cms::Exception("FEDSpyBuffer") << "FED Buffer check fails for FED ID " << lFedId << ".";
00132 }
00133 } catch (const cms::Exception& e) {
00134 if ( edm::isDebugEnabled() ) {
00135 edm::LogWarning("SiStripSpyUnpacker")
00136 << "Exception caught when creating FEDSpyBuffer object for FED " << lFedId << ": " << e.what();
00137 }
00138 continue;
00139 }
00140
00141
00142 uint32_t totalEvCount = buffer->spyHeaderTotalEventCount();
00143 uint32_t l1ID = buffer->spyHeaderL1ID();
00144
00145 uint32_t lGRun = buffer->globalRunNumber();
00146
00147
00148 if (lRef == 0) lRef = lGRun;
00149 if (lGRun != lRef){
00150 edm::LogError("SiStripSpyUnpacker")
00151 << " -- Global run encoded in buffer for FED " << lFedId << ": "
00152 << lGRun << " is different from reference value " << lRef
00153 << std::endl;
00154 }
00155
00156
00157 (*pL1ACounts)[lFedId] = l1ID;
00158 (*pTotalEventCounts)[lFedId] = totalEvCount;
00159
00160
00161 std::vector<FedChannelConnection>::const_iterator iconn = conns.begin();
00162 std::vector<FedChannelConnection>::const_iterator endconn = conns.end();
00163 for ( ; iconn != endconn; ++iconn ) {
00164
00165
00166 if ( !iconn->isConnected()) { continue; }
00167
00168
00169 uint16_t chan = iconn->fedCh();
00170
00171
00172 if (chan > FEDCH_PER_FED || iconn->fedId() != lFedId){
00173 if (edm::isDebugEnabled()) {
00174 std::ostringstream ss;
00175 ss << "Channel connection values invalid: iconn->fedId() = " << iconn->fedId() << " for FED " << lFedId << ", iconn->fedCh() = " << chan << std::endl;
00176 edm::LogWarning("SiStripSpyUnpacker") << ss.str();
00177 }
00178 continue;
00179 }
00180
00181
00182 if (!buffer->channelGood(chan)) {
00183 if (edm::isDebugEnabled()) {
00184 std::ostringstream ss;
00185 ss << "Channel check failed for FED " << lFedId << " channel " << chan << std::endl;
00186 edm::LogWarning("SiStripSpyUnpacker") << ss.str();
00187 }
00188 continue;
00189 }
00190
00191 const uint32_t key = SiStripFedKey::fedIndex(lFedId,chan);
00192
00193
00194 dsvFiller.newChannel(key);
00195
00196 sistrip::FEDSpyChannelUnpacker unpacker = sistrip::FEDSpyChannelUnpacker(buffer->channel(chan));
00197
00198
00199 while (unpacker.hasData()) {
00200 dsvFiller.addItem(unpacker.adc());
00201 unpacker++;
00202 }
00203 }
00204
00205 }
00206
00207
00208 *aRunRef = lRef;
00209
00210
00211 std::auto_ptr<RawDigis> pResult = dsvFiller.createDetSetVector();
00212 pDigis->swap(*pResult);
00213
00214 }
00215
00216 }