CMS 3D CMS Logo

SiStripSpyEventMatcherModule.cc
Go to the documentation of this file.
1 // Module to import spy channel data into matching events
2 
4 #ifdef SiStripMonitorHardware_BuildEventMatchingCode
5 
21 #include <memory>
22 #include <vector>
23 
24 using edm::LogError;
25 using edm::LogInfo;
26 
27 namespace sistrip {
28 
30  public:
32  ~SpyEventMatcherModule() override;
33  void beginJob() override;
34  bool filter(edm::Event& event, const edm::EventSetup& eventSetup) override;
35 
36  private:
38  const SiStripFedCabling& cabling,
39  uint32_t& l1ID,
40  uint8_t& apvAddress) const;
41  void copyData(const uint32_t eventId,
42  const uint8_t apvAddress,
45  const SiStripFedCabling& cabling) const;
46 
47  static const char* messageLabel_;
49  const bool doMerge_;
52  std::unique_ptr<SpyEventMatcher> spyEventMatcher_;
53  std::unique_ptr<SpyUtilities> utils_;
54  };
55 
56 } // namespace sistrip
57 
58 namespace sistrip {
59 
60  const char* SpyEventMatcherModule::messageLabel_ = "SiStripSpyDataMergeModule";
61 
63  : filterNonMatchingEvents_(config.getParameter<bool>("FilterNonMatchingEvents")),
64  doMerge_(config.getParameter<bool>("MergeData")),
65  primaryStreamRawDataTag_(config.getParameter<edm::InputTag>("PrimaryEventRawDataTag")),
66  spyEventMatcher_(new SpyEventMatcher(config)),
67  utils_(new SpyUtilities) {
68  primaryStreamRawDataToken_ = consumes<FEDRawDataCollection>(primaryStreamRawDataTag_);
69  if (doMerge_) {
70  produces<FEDRawDataCollection>("RawSpyData");
71  produces<std::vector<uint32_t> >("SpyTotalEventCount");
72  produces<std::vector<uint32_t> >("SpyL1ACount");
73  produces<std::vector<uint32_t> >("SpyAPVAddress");
74  produces<edm::DetSetVector<SiStripRawDigi> >("SpyScope");
75  produces<edm::DetSetVector<SiStripRawDigi> >("SpyPayload");
76  produces<edm::DetSetVector<SiStripRawDigi> >("SpyReordered");
77  produces<edm::DetSetVector<SiStripRawDigi> >("SpyVirginRaw");
78  }
79  }
80 
82 
84 
86  const SiStripFedCabling& cabling = *(utils_->getCabling(eventSetup));
87  uint8_t apvAddress = 0;
88  uint32_t eventId = 0;
89  try {
90  findL1IDandAPVAddress(event, cabling, eventId, apvAddress);
91  } catch (const cms::Exception& e) {
92  LogError(messageLabel_) << e.what();
93  return (filterNonMatchingEvents_ ? false : true);
94  }
95  const SpyEventMatcher::SpyEventList* matches = spyEventMatcher_->matchesForEvent(eventId, apvAddress);
96  if (matches) {
97  if (doMerge_) {
98  copyData(eventId, apvAddress, matches, event, cabling);
99  }
100  return true;
101  } else {
102  return (filterNonMatchingEvents_ ? false : true);
103  }
104  }
105 
107  const SiStripFedCabling& cabling,
108  uint32_t& l1ID,
109  uint8_t& apvAddress) const {
110  edm::Handle<FEDRawDataCollection> fedRawDataHandle;
111  event.getByToken(primaryStreamRawDataToken_, fedRawDataHandle);
112  const FEDRawDataCollection& fedRawData = *fedRawDataHandle;
113  for (auto iFedId = cabling.fedIds().begin(); iFedId != cabling.fedIds().end(); ++iFedId) {
114  const FEDRawData& data = fedRawData.FEDData(*iFedId);
115  const auto st_buffer = preconstructCheckFEDBuffer(data);
116  if (FEDBufferStatusCode::SUCCESS != st_buffer) {
117  LogInfo(messageLabel_) << "Failed to build FED buffer for FED ID " << *iFedId
118  << ". Exception was: An exception of category 'FEDBuffer' occurred.\n"
119  << st_buffer << " (see debug output for details)";
120  continue;
121  }
123  const auto st_chan = buffer.findChannels();
124  if (FEDBufferStatusCode::SUCCESS != st_chan) {
125  LogDebug(messageLabel_) << "Failed to build FED buffer for FED ID " << *iFedId << ". Exception was " << st_chan
126  << " (see above for more details)";
127  continue;
128  }
129  if (!buffer.doChecks(true)) {
130  LogDebug(messageLabel_) << "Buffer check failed for FED ID " << *iFedId;
131  continue;
132  }
133  l1ID = buffer.daqLvl1ID();
134  apvAddress = buffer.trackerSpecialHeader().apveAddress();
135  if (apvAddress != 0) {
136  return;
137  } else {
138  if (buffer.trackerSpecialHeader().headerType() != HEADER_TYPE_FULL_DEBUG) {
139  continue;
140  }
141  const FEDFullDebugHeader* header = dynamic_cast<const FEDFullDebugHeader*>(buffer.feHeader());
142  auto connections = cabling.fedConnections(*iFedId);
143  for (auto iConn = connections.begin(); iConn != connections.end(); ++iConn) {
144  if (!iConn->isConnected()) {
145  continue;
146  }
147  if (!buffer.channelGood(iConn->fedCh(), true)) {
148  continue;
149  } else {
150  apvAddress = header->feUnitMajorityAddress(iConn->fedCh() / FEDCH_PER_FEUNIT);
151  return;
152  }
153  }
154  }
155  }
156  //if we haven't already found an acceptable alternative, throw an exception
157  throw cms::Exception(messageLabel_) << "Failed to get L1ID/APV address from any FED";
158  }
159 
160  void SpyEventMatcherModule::copyData(const uint32_t eventId,
161  const uint8_t apvAddress,
163  edm::Event& event,
164  const SiStripFedCabling& cabling) const {
165  SpyEventMatcher::SpyDataCollections matchedCollections;
166  spyEventMatcher_->getMatchedCollections(eventId, apvAddress, matches, cabling, matchedCollections);
167  if (matchedCollections.rawData.get())
168  event.put(std::move(matchedCollections.rawData), "RawSpyData");
169  if (matchedCollections.totalEventCounters.get())
170  event.put(std::move(matchedCollections.totalEventCounters), "SpyTotalEventCount");
171  if (matchedCollections.l1aCounters.get())
172  event.put(std::move(matchedCollections.l1aCounters), "SpyL1ACount");
173  if (matchedCollections.apvAddresses.get())
174  event.put(std::move(matchedCollections.apvAddresses), "SpyAPVAddress");
175  if (matchedCollections.scopeDigis.get())
176  event.put(std::move(matchedCollections.scopeDigis), "SpyScope");
177  if (matchedCollections.payloadDigis.get())
178  event.put(std::move(matchedCollections.payloadDigis), "SpyPayload");
179  if (matchedCollections.reorderedDigis.get())
180  event.put(std::move(matchedCollections.reorderedDigis), "SpyReordered");
181  if (matchedCollections.virginRawDigis.get())
182  event.put(std::move(matchedCollections.virginRawDigis), "SpyVirginRaw");
183  }
184 
185 } // namespace sistrip
186 
188 #include <cstdint>
191 
192 #endif //SiStripMonitorHardware_BuildEventMatchingCode
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:393
sistrip::SpyEventMatcherModule::primaryStreamRawDataToken_
edm::EDGetTokenT< FEDRawDataCollection > primaryStreamRawDataToken_
Definition: SiStripSpyEventMatcherModule.cc:51
sistrip::SpyEventMatcher::SpyDataCollections::apvAddresses
std::unique_ptr< std::vector< uint32_t > > apvAddresses
Definition: SiStripSpyEventMatcher.h:40
MessageLogger.h
sistrip::SpyEventMatcherModule::findL1IDandAPVAddress
void findL1IDandAPVAddress(const edm::Event &event, const SiStripFedCabling &cabling, uint32_t &l1ID, uint8_t &apvAddress) const
Definition: SiStripSpyEventMatcherModule.cc:106
edm::EDGetTokenT< FEDRawDataCollection >
FEDRawDataCollection
Definition: FEDRawDataCollection.h:18
edm
HLT enums.
Definition: AlignableModifier.h:19
SiStripRawDigi.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
SiStripFedCabling.h
EDFilter.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
SiStripFedCabling
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses,...
Definition: SiStripFedCabling.h:25
sistrip::SpyEventMatcherModule::utils_
std::unique_ptr< SpyUtilities > utils_
Definition: SiStripSpyEventMatcherModule.cc:53
FEDRawData.h
edm::Handle
Definition: AssociativeIterator.h:50
SiStripSpyUtilities.h
FEDRawData
Definition: FEDRawData.h:19
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
config
Definition: config.py:1
MakerMacros.h
sistrip::SpyEventMatcher::SpyDataCollections::reorderedDigis
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > reorderedDigis
Definition: SiStripSpyEventMatcher.h:43
sistrip::SpyEventMatcherModule::messageLabel_
static const char * messageLabel_
Definition: SiStripSpyEventMatcherModule.cc:47
l1t_dqm_sourceclient-live_cfg.fedRawData
fedRawData
Definition: l1t_dqm_sourceclient-live_cfg.py:188
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
SiStripFEDBuffer.h
sistrip::SpyUtilities
Definition: SiStripSpyUtilities.h:24
SiStripSpyEventMatcherModule
sistrip::SpyEventMatcherModule SiStripSpyEventMatcherModule
Definition: SiStripSpyEventMatcherModule.cc:189
EDGetToken.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
sistrip::HEADER_TYPE_FULL_DEBUG
Definition: SiStripFEDBufferComponents.h:39
sistrip::SpyEventMatcherModule
Definition: SiStripSpyEventMatcherModule.cc:29
sistrip::SpyEventMatcher::SpyEventList
std::set< EventID > SpyEventList
Definition: SiStripSpyEventMatcher.h:70
sistrip::FEDBufferStatusCode::SUCCESS
FEDRawDataCollection.h
sistrip::SpyEventMatcher::SpyDataCollections::l1aCounters
std::unique_ptr< std::vector< uint32_t > > l1aCounters
Definition: SiStripSpyEventMatcher.h:39
edm::EDFilter
Definition: EDFilter.h:38
sistrip::FEDFullDebugHeader
Definition: SiStripFEDBufferComponents.h:535
edm::EventSetup
Definition: EventSetup.h:57
DetSetVector.h
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
SiStripSpyEventMatcher.h
sistrip::FEDBuffer
Definition: SiStripFEDBuffer.h:24
sistrip::SpyEventMatcherModule::filterNonMatchingEvents_
const bool filterNonMatchingEvents_
Definition: SiStripSpyEventMatcherModule.cc:48
sistrip::SpyEventMatcher::SpyDataCollections::rawData
std::unique_ptr< FEDRawDataCollection > rawData
Definition: SiStripSpyEventMatcher.h:37
sistrip::preconstructCheckFEDBuffer
FEDBufferStatusCode preconstructCheckFEDBuffer(const FEDRawData &fedBuffer, bool allowBadBuffer=false)
Definition: SiStripFEDBuffer.h:131
sistrip::SpyEventMatcherModule::SpyEventMatcherModule
SpyEventMatcherModule(const edm::ParameterSet &config)
Definition: SiStripSpyEventMatcherModule.cc:62
sistrip::SpyEventMatcher::SpyDataCollections::scopeDigis
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > scopeDigis
Definition: SiStripSpyEventMatcher.h:41
sistrip::SpyEventMatcher::SpyDataCollections::virginRawDigis
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > virginRawDigis
Definition: SiStripSpyEventMatcher.h:44
sistrip::SpyEventMatcher::SpyDataCollections
Definition: SiStripSpyEventMatcher.h:35
eostools.move
def move(src, dest)
Definition: eostools.py:511
sistrip::SpyEventMatcherModule::filter
bool filter(edm::Event &event, const edm::EventSetup &eventSetup) override
Definition: SiStripSpyEventMatcherModule.cc:85
sistrip::SpyEventMatcher::SpyDataCollections::payloadDigis
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > payloadDigis
Definition: SiStripSpyEventMatcher.h:42
Exception
Definition: hltDiff.cc:246
sistrip::SpyEventMatcherModule::copyData
void copyData(const uint32_t eventId, const uint8_t apvAddress, const SpyEventMatcher::SpyEventList *matches, edm::Event &event, const SiStripFedCabling &cabling) const
Definition: SiStripSpyEventMatcherModule.cc:160
sistrip::SpyEventMatcher
Definition: SiStripSpyEventMatcher.h:33
sistrip::SpyEventMatcherModule::~SpyEventMatcherModule
~SpyEventMatcherModule() override
Definition: SiStripSpyEventMatcherModule.cc:81
EventSetup.h
Exception.h
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
patCandidatesForDimuonsSequences_cff.matches
matches
Definition: patCandidatesForDimuonsSequences_cff.py:131
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:292
SiStripFedCabling::fedIds
FedsConstIterRange fedIds() const
Definition: SiStripFedCabling.h:154
sistrip::FEDCH_PER_FEUNIT
static const uint16_t FEDCH_PER_FEUNIT
Definition: ConstantsForHardwareSystems.h:28
sistrip::SpyEventMatcherModule::doMerge_
const bool doMerge_
Definition: SiStripSpyEventMatcherModule.cc:49
cms::Exception
Definition: Exception.h:70
sistrip::SpyEventMatcherModule::spyEventMatcher_
std::unique_ptr< SpyEventMatcher > spyEventMatcher_
Definition: SiStripSpyEventMatcherModule.cc:52
ParameterSet.h
sistrip
sistrip classes
Definition: SiStripQualityHelpers.h:14
event
Definition: event.py:1
SiStripFedCabling::fedConnections
ConnsConstIterRange fedConnections(uint16_t fed_id) const
Definition: SiStripFedCabling.cc:160
edm::Event
Definition: Event.h:73
sistrip::SpyEventMatcher::SpyDataCollections::totalEventCounters
std::unique_ptr< std::vector< uint32_t > > totalEventCounters
Definition: SiStripSpyEventMatcher.h:38
edm::InputTag
Definition: InputTag.h:15
sistrip::SpyEventMatcherModule::primaryStreamRawDataTag_
const edm::InputTag primaryStreamRawDataTag_
Definition: SiStripSpyEventMatcherModule.cc:50
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
sistrip::SpyEventMatcherModule::beginJob
void beginJob() override
Definition: SiStripSpyEventMatcherModule.cc:83