CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
39  void findL1IDandAPVAddress(const edm::Event& event,
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,
45  const SpyEventMatcher::SpyEventList* matches,
46  edm::Event& event,
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  }
132  FEDBuffer buffer{data};
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,
172  const SpyEventMatcher::SpyEventList* matches,
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
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > payloadDigis
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
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)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Log< level::Error, false > LogError
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
list connections
Definition: shell.py:10
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
def move
Definition: eostools.py:511
char const * what() const noexceptoverride
Definition: Exception.cc:103
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
Log< level::Info, false > LogInfo
static const uint16_t FEDCH_PER_FEUNIT
edm::ESWatcher< SiStripFedCablingRcd > cablingWatcher_
ConnsConstIterRange fedConnections(uint16_t fed_id) const
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
tuple config
parse the configuration file
uint8_t feUnitMajorityAddress(const uint8_t internalFEUnitNum) const
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
void updateFedCabling(const SiStripFedCablingRcd &rcd)
FEDBufferStatusCode preconstructCheckFEDBuffer(const FEDRawData &fedBuffer, bool allowBadBuffer=false)
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
#define LogDebug(id)
sistrip::SpyEventMatcherModule SiStripSpyEventMatcherModule
edm::ESGetToken< SiStripFedCabling, SiStripFedCablingRcd > fedCablingToken_
void findL1IDandAPVAddress(const edm::Event &event, const SiStripFedCabling &cabling, uint32_t &l1ID, uint8_t &apvAddress) const