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:
37  void findL1IDandAPVAddress(const edm::Event& event,
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,
44  edm::Event& event,
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  if ((!data.data()) || (!data.size())) {
116  LogDebug(messageLabel_) << "Failed to get FED data for FED ID " << *iFedId;
117  continue;
118  }
119  std::unique_ptr<FEDBuffer> buffer;
120  try {
121  buffer.reset(new FEDBuffer(data.data(), data.size()));
122  } catch (const cms::Exception& e) {
123  LogDebug(messageLabel_) << "Failed to build FED buffer for FED ID " << *iFedId << ". Exception was "
124  << e.what();
125  continue;
126  }
127  if (!buffer->doChecks(true)) {
128  LogDebug(messageLabel_) << "Buffer check failed for FED ID " << *iFedId;
129  continue;
130  }
131  l1ID = buffer->daqLvl1ID();
132  apvAddress = buffer->trackerSpecialHeader().apveAddress();
133  if (apvAddress != 0) {
134  return;
135  } else {
136  if (buffer->trackerSpecialHeader().headerType() != HEADER_TYPE_FULL_DEBUG) {
137  continue;
138  }
139  const FEDFullDebugHeader* header = dynamic_cast<const FEDFullDebugHeader*>(buffer->feHeader());
140  auto connections = cabling.fedConnections(*iFedId);
141  for (auto iConn = connections.begin(); iConn != connections.end(); ++iConn) {
142  if (!iConn->isConnected()) {
143  continue;
144  }
145  if (!buffer->channelGood(iConn->fedCh(), true)) {
146  continue;
147  } else {
148  apvAddress = header->feUnitMajorityAddress(iConn->fedCh() / FEDCH_PER_FEUNIT);
149  return;
150  }
151  }
152  }
153  }
154  //if we haven't already found an acceptable alternative, throw an exception
155  throw cms::Exception(messageLabel_) << "Failed to get L1ID/APV address from any FED";
156  }
157 
158  void SpyEventMatcherModule::copyData(const uint32_t eventId,
159  const uint8_t apvAddress,
161  edm::Event& event,
162  const SiStripFedCabling& cabling) const {
163  SpyEventMatcher::SpyDataCollections matchedCollections;
164  spyEventMatcher_->getMatchedCollections(eventId, apvAddress, matches, cabling, matchedCollections);
165  if (matchedCollections.rawData.get())
166  event.put(std::move(matchedCollections.rawData), "RawSpyData");
167  if (matchedCollections.totalEventCounters.get())
168  event.put(std::move(matchedCollections.totalEventCounters), "SpyTotalEventCount");
169  if (matchedCollections.l1aCounters.get())
170  event.put(std::move(matchedCollections.l1aCounters), "SpyL1ACount");
171  if (matchedCollections.apvAddresses.get())
172  event.put(std::move(matchedCollections.apvAddresses), "SpyAPVAddress");
173  if (matchedCollections.scopeDigis.get())
174  event.put(std::move(matchedCollections.scopeDigis), "SpyScope");
175  if (matchedCollections.payloadDigis.get())
176  event.put(std::move(matchedCollections.payloadDigis), "SpyPayload");
177  if (matchedCollections.reorderedDigis.get())
178  event.put(std::move(matchedCollections.reorderedDigis), "SpyReordered");
179  if (matchedCollections.virginRawDigis.get())
180  event.put(std::move(matchedCollections.virginRawDigis), "SpyVirginRaw");
181  }
182 
183 } // namespace sistrip
184 
186 #include <cstdint>
189 
190 #endif //SiStripMonitorHardware_BuildEventMatchingCode
#define LogDebug(id)
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > payloadDigis
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
void copyData(const uint32_t eventId, const uint8_t apvAddress, const SpyEventMatcher::SpyEventList *matches, edm::Event &event, const SiStripFedCabling &cabling) const
SpyEventMatcherModule(const edm::ParameterSet &config)
std::unique_ptr< SpyUtilities > utils_
char const * what() const override
Definition: Exception.cc:103
Definition: config.py:1
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
sistrip classes
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
edm::EDGetTokenT< FEDRawDataCollection > primaryStreamRawDataToken_
std::unique_ptr< FEDRawDataCollection > rawData
bool filter(edm::Event &event, const edm::EventSetup &eventSetup) override
FedsConstIterRange fedIds() const
std::unique_ptr< std::vector< uint32_t > > totalEventCounters
std::set< EventID > SpyEventList
std::unique_ptr< SpyEventMatcher > spyEventMatcher_
std::unique_ptr< std::vector< uint32_t > > apvAddresses
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > scopeDigis
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > reorderedDigis
static const uint16_t FEDCH_PER_FEUNIT
ConnsConstIterRange fedConnections(uint16_t fed_id) const
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
uint8_t feUnitMajorityAddress(const uint8_t internalFEUnitNum) const
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > virginRawDigis
std::unique_ptr< std::vector< uint32_t > > l1aCounters
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
sistrip::SpyEventMatcherModule SiStripSpyEventMatcherModule
void findL1IDandAPVAddress(const edm::Event &event, const SiStripFedCabling &cabling, uint32_t &l1ID, uint8_t &apvAddress) const