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 
23 #include <memory>
24 #include <vector>
25 
26 using edm::LogError;
27 using edm::LogInfo;
28 
29 namespace sistrip {
30 
32  public:
34  ~SpyEventMatcherModule() override;
35  void beginJob() override;
36  bool filter(edm::Event& event, const edm::EventSetup& eventSetup) override;
37 
38  private:
40  const SiStripFedCabling& cabling,
41  uint32_t& l1ID,
42  uint8_t& apvAddress) const;
43  void copyData(const uint32_t eventId,
44  const uint8_t apvAddress,
47  const SiStripFedCabling& cabling) const;
48 
49  static const char* messageLabel_;
51  const bool doMerge_;
54  std::unique_ptr<SpyEventMatcher> spyEventMatcher_;
58  void updateFedCabling(const SiStripFedCablingRcd& rcd);
59  };
60 
61 } // namespace sistrip
62 
63 namespace sistrip {
64 
65  const char* SpyEventMatcherModule::messageLabel_ = "SiStripSpyDataMergeModule";
66 
68  : filterNonMatchingEvents_(config.getParameter<bool>("FilterNonMatchingEvents")),
69  doMerge_(config.getParameter<bool>("MergeData")),
70  primaryStreamRawDataTag_(config.getParameter<edm::InputTag>("PrimaryEventRawDataTag")),
71  spyEventMatcher_(new SpyEventMatcher(config)),
72  fedCablingToken_(esConsumes<>()),
73  cablingWatcher_(this, &SpyEventMatcherModule::updateFedCabling) {
74  primaryStreamRawDataToken_ = consumes<FEDRawDataCollection>(primaryStreamRawDataTag_);
75  if (doMerge_) {
76  produces<FEDRawDataCollection>("RawSpyData");
77  produces<std::vector<uint32_t> >("SpyTotalEventCount");
78  produces<std::vector<uint32_t> >("SpyL1ACount");
79  produces<std::vector<uint32_t> >("SpyAPVAddress");
80  produces<edm::DetSetVector<SiStripRawDigi> >("SpyScope");
81  produces<edm::DetSetVector<SiStripRawDigi> >("SpyPayload");
82  produces<edm::DetSetVector<SiStripRawDigi> >("SpyReordered");
83  produces<edm::DetSetVector<SiStripRawDigi> >("SpyVirginRaw");
84  }
85  }
86 
88 
91  }
92 
94 
96  cablingWatcher_.check(eventSetup);
97  uint8_t apvAddress = 0;
98  uint32_t eventId = 0;
99  try {
100  findL1IDandAPVAddress(event, *fedCabling_, eventId, apvAddress);
101  } catch (const cms::Exception& e) {
102  LogError(messageLabel_) << e.what();
103  return (filterNonMatchingEvents_ ? false : true);
104  }
105  const SpyEventMatcher::SpyEventList* matches = spyEventMatcher_->matchesForEvent(eventId, apvAddress);
106  if (matches) {
107  if (doMerge_) {
108  copyData(eventId, apvAddress, matches, event, *fedCabling_);
109  }
110  return true;
111  } else {
112  return (filterNonMatchingEvents_ ? false : true);
113  }
114  }
115 
117  const SiStripFedCabling& cabling,
118  uint32_t& l1ID,
119  uint8_t& apvAddress) const {
120  edm::Handle<FEDRawDataCollection> fedRawDataHandle;
121  event.getByToken(primaryStreamRawDataToken_, fedRawDataHandle);
122  const FEDRawDataCollection& fedRawData = *fedRawDataHandle;
123  for (auto iFedId = cabling.fedIds().begin(); iFedId != cabling.fedIds().end(); ++iFedId) {
124  const FEDRawData& data = fedRawData.FEDData(*iFedId);
125  const auto st_buffer = preconstructCheckFEDBuffer(data);
126  if (FEDBufferStatusCode::SUCCESS != st_buffer) {
127  LogInfo(messageLabel_) << "Failed to build FED buffer for FED ID " << *iFedId
128  << ". Exception was: An exception of category 'FEDBuffer' occurred.\n"
129  << st_buffer << " (see debug output for details)";
130  continue;
131  }
133  const auto st_chan = buffer.findChannels();
134  if (FEDBufferStatusCode::SUCCESS != st_chan) {
135  LogDebug(messageLabel_) << "Failed to build FED buffer for FED ID " << *iFedId << ". Exception was " << st_chan
136  << " (see above for more details)";
137  continue;
138  }
139  if (!buffer.doChecks(true)) {
140  LogDebug(messageLabel_) << "Buffer check failed for FED ID " << *iFedId;
141  continue;
142  }
143  l1ID = buffer.daqLvl1ID();
144  apvAddress = buffer.trackerSpecialHeader().apveAddress();
145  if (apvAddress != 0) {
146  return;
147  } else {
148  if (buffer.trackerSpecialHeader().headerType() != HEADER_TYPE_FULL_DEBUG) {
149  continue;
150  }
151  const FEDFullDebugHeader* header = dynamic_cast<const FEDFullDebugHeader*>(buffer.feHeader());
152  auto connections = cabling.fedConnections(*iFedId);
153  for (auto iConn = connections.begin(); iConn != connections.end(); ++iConn) {
154  if (!iConn->isConnected()) {
155  continue;
156  }
157  if (!buffer.channelGood(iConn->fedCh(), true)) {
158  continue;
159  } else {
160  apvAddress = header->feUnitMajorityAddress(iConn->fedCh() / FEDCH_PER_FEUNIT);
161  return;
162  }
163  }
164  }
165  }
166  //if we haven't already found an acceptable alternative, throw an exception
167  throw cms::Exception(messageLabel_) << "Failed to get L1ID/APV address from any FED";
168  }
169 
170  void SpyEventMatcherModule::copyData(const uint32_t eventId,
171  const uint8_t apvAddress,
173  edm::Event& event,
174  const SiStripFedCabling& cabling) const {
175  SpyEventMatcher::SpyDataCollections matchedCollections;
176  spyEventMatcher_->getMatchedCollections(eventId, apvAddress, matches, cabling, matchedCollections);
177  if (matchedCollections.rawData.get())
178  event.put(std::move(matchedCollections.rawData), "RawSpyData");
179  if (matchedCollections.totalEventCounters.get())
180  event.put(std::move(matchedCollections.totalEventCounters), "SpyTotalEventCount");
181  if (matchedCollections.l1aCounters.get())
182  event.put(std::move(matchedCollections.l1aCounters), "SpyL1ACount");
183  if (matchedCollections.apvAddresses.get())
184  event.put(std::move(matchedCollections.apvAddresses), "SpyAPVAddress");
185  if (matchedCollections.scopeDigis.get())
186  event.put(std::move(matchedCollections.scopeDigis), "SpyScope");
187  if (matchedCollections.payloadDigis.get())
188  event.put(std::move(matchedCollections.payloadDigis), "SpyPayload");
189  if (matchedCollections.reorderedDigis.get())
190  event.put(std::move(matchedCollections.reorderedDigis), "SpyReordered");
191  if (matchedCollections.virginRawDigis.get())
192  event.put(std::move(matchedCollections.virginRawDigis), "SpyVirginRaw");
193  }
194 
195 } // namespace sistrip
196 
198 #include <cstdint>
201 
202 #endif //SiStripMonitorHardware_BuildEventMatchingCode
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
sistrip::SpyEventMatcherModule::primaryStreamRawDataToken_
edm::EDGetTokenT< FEDRawDataCollection > primaryStreamRawDataToken_
Definition: SiStripSpyEventMatcherModule.cc:53
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:116
sistrip::SpyEventMatcherModule::updateFedCabling
void updateFedCabling(const SiStripFedCablingRcd &rcd)
Definition: SiStripSpyEventMatcherModule.cc:89
edm::ESWatcher< SiStripFedCablingRcd >
edm::EDGetTokenT< FEDRawDataCollection >
FEDRawDataCollection
Definition: FEDRawDataCollection.h:18
edm
HLT enums.
Definition: AlignableModifier.h:19
SiStripRawDigi.h
oniaPATMuonsWithTrigger_cff.matches
matches
Definition: oniaPATMuonsWithTrigger_cff.py:77
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89281
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
FEDRawData.h
edm::Handle< FEDRawDataCollection >
sistrip::SpyEventMatcherModule::fedCabling_
const SiStripFedCabling * fedCabling_
Definition: SiStripSpyEventMatcherModule.cc:56
SiStripSpyUtilities.h
FEDRawData
Definition: FEDRawData.h:19
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
config
Definition: config.py:1
MakerMacros.h
SiStripFedCablingRcd
Definition: SiStripCondDataRecords.h:22
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:49
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
SiStripSpyEventMatcherModule
sistrip::SpyEventMatcherModule SiStripSpyEventMatcherModule
Definition: SiStripSpyEventMatcherModule.cc:199
sistrip::SpyEventMatcherModule::cablingWatcher_
edm::ESWatcher< SiStripFedCablingRcd > cablingWatcher_
Definition: SiStripSpyEventMatcherModule.cc:57
EDGetToken.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
sistrip::HEADER_TYPE_FULL_DEBUG
Definition: SiStripFEDBufferComponents.h:39
sistrip::SpyEventMatcherModule
Definition: SiStripSpyEventMatcherModule.cc:31
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:58
sistrip::SpyEventMatcherModule::fedCablingToken_
edm::ESGetToken< SiStripFedCabling, SiStripFedCablingRcd > fedCablingToken_
Definition: SiStripSpyEventMatcherModule.cc:55
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:50
edm::ESGetToken< SiStripFedCabling, SiStripFedCablingRcd >
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:67
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:95
ESWatcher.h
sistrip::SpyEventMatcher::SpyDataCollections::payloadDigis
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > payloadDigis
Definition: SiStripSpyEventMatcher.h:42
Exception
Definition: hltDiff.cc:245
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:170
sistrip::SpyEventMatcher
Definition: SiStripSpyEventMatcher.h:33
sistrip::SpyEventMatcherModule::~SpyEventMatcherModule
~SpyEventMatcherModule() override
Definition: SiStripSpyEventMatcherModule.cc:87
EventSetup.h
Exception.h
SiStripFedCablingRcd.h
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
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
edm::eventsetup::EventSetupRecordImplementation::get
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
Definition: EventSetupRecordImplementation.h:74
sistrip::SpyEventMatcherModule::doMerge_
const bool doMerge_
Definition: SiStripSpyEventMatcherModule.cc:51
cms::Exception
Definition: Exception.h:70
sistrip::SpyEventMatcherModule::spyEventMatcher_
std::unique_ptr< SpyEventMatcher > spyEventMatcher_
Definition: SiStripSpyEventMatcherModule.cc:54
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
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
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:52
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
sistrip::SpyEventMatcherModule::beginJob
void beginJob() override
Definition: SiStripSpyEventMatcherModule.cc:93