CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
6 #include "boost/cstdint.hpp"
21 #include <memory>
22 #include <vector>
23 
24 using edm::LogError;
25 using edm::LogInfo;
26 
27 namespace sistrip {
28 
30  {
31  public:
33  virtual ~SpyEventMatcherModule();
34  virtual void beginJob();
35  virtual bool filter(edm::Event& event, const edm::EventSetup& eventSetup);
36  private:
37  void findL1IDandAPVAddress(const edm::Event& event, const SiStripFedCabling& cabling, uint32_t& l1ID, uint8_t& apvAddress) const;
38  void copyData(const uint32_t eventId, const uint8_t apvAddress, const SpyEventMatcher::SpyEventList* matches, edm::Event& event,
39  const SiStripFedCabling& cabling) const;
40 
41  static const char* messageLabel_;
43  const bool doMerge_;
45  std::auto_ptr<SpyEventMatcher> spyEventMatcher_;
46  std::auto_ptr<SpyUtilities> utils_;
47  };
48 
49 }
50 
51 namespace sistrip {
52 
53  const char* SpyEventMatcherModule::messageLabel_ = "SiStripSpyDataMergeModule";
54 
56  : filterNonMatchingEvents_( config.getParameter<bool>("FilterNonMatchingEvents") ),
57  doMerge_( config.getParameter<bool>("MergeData") ),
58  primaryStreamRawDataTag_( config.getParameter<edm::InputTag>("PrimaryEventRawDataTag") ),
59  spyEventMatcher_(new SpyEventMatcher(config)),
60  utils_(new SpyUtilities)
61  {
62  if (doMerge_) {
63  produces<FEDRawDataCollection>("RawSpyData");
64  produces< std::vector<uint32_t> >("SpyTotalEventCount");
65  produces< std::vector<uint32_t> >("SpyL1ACount");
66  produces< std::vector<uint32_t> >("SpyAPVAddress");
67  produces< edm::DetSetVector<SiStripRawDigi> >("SpyScope");
68  produces< edm::DetSetVector<SiStripRawDigi> >("SpyPayload");
69  produces< edm::DetSetVector<SiStripRawDigi> >("SpyReordered");
70  produces< edm::DetSetVector<SiStripRawDigi> >("SpyVirginRaw");
71  }
72  }
73 
75  {
76  }
77 
79  {
80  spyEventMatcher_->initialize();
81  }
82 
84  {
85  const SiStripFedCabling& cabling = *(utils_->getCabling(eventSetup));
86  uint8_t apvAddress = 0;
87  uint32_t eventId = 0;
88  try {
89  findL1IDandAPVAddress(event,cabling,eventId,apvAddress);
90  } catch (const cms::Exception& e) {
91  LogError(messageLabel_) << e.what();
92  return ( filterNonMatchingEvents_ ? false : true );
93  }
94  const SpyEventMatcher::SpyEventList* matches = spyEventMatcher_->matchesForEvent(eventId,apvAddress);
95  if (matches) {
96  if (doMerge_) {
97  copyData(eventId,apvAddress,matches,event,cabling);
98  }
99  return true;
100  } else {
101  return ( filterNonMatchingEvents_ ? false : true );
102  }
103  }
104 
105  void SpyEventMatcherModule::findL1IDandAPVAddress(const edm::Event& event, const SiStripFedCabling& cabling, uint32_t& l1ID, uint8_t& apvAddress) const
106  {
107  edm::Handle<FEDRawDataCollection> fedRawDataHandle;
108  event.getByLabel(primaryStreamRawDataTag_,fedRawDataHandle);
109  const FEDRawDataCollection& fedRawData = *fedRawDataHandle;
110  for (std::vector<uint16_t>::const_iterator iFedId = cabling.feds().begin(); iFedId != cabling.feds().end(); ++iFedId) {
111  const FEDRawData& data = fedRawData.FEDData(*iFedId);
112  if ( (!data.data()) || (!data.size()) ) {
113  LogDebug(messageLabel_) << "Failed to get FED data for FED ID " << *iFedId;
114  continue;
115  }
116  std::auto_ptr<FEDBuffer> buffer;
117  try {
118  buffer.reset(new FEDBuffer(data.data(),data.size()));
119  } catch (const cms::Exception& e) {
120  LogDebug(messageLabel_) << "Failed to build FED buffer for FED ID " << *iFedId << ". Exception was " << e.what();
121  continue;
122  }
123  if (!buffer->doChecks()) {
124  LogDebug(messageLabel_) << "Buffer check failed for FED ID " << *iFedId;
125  continue;
126  }
127  l1ID = buffer->daqLvl1ID();
128  apvAddress = buffer->trackerSpecialHeader().apveAddress();
129  if (apvAddress != 0) {
130  return;
131  } else {
132  if (buffer->trackerSpecialHeader().headerType() != HEADER_TYPE_FULL_DEBUG) {
133  continue;
134  }
135  const FEDFullDebugHeader* header = dynamic_cast<const FEDFullDebugHeader*>(buffer->feHeader());
136  const std::vector<FedChannelConnection>& connections = cabling.connections(*iFedId);
137  for (std::vector<FedChannelConnection>::const_iterator iConn = connections.begin(); iConn != connections.end(); ++iConn) {
138  if (!iConn->isConnected()) {
139  continue;
140  }
141  if ( !buffer->channelGood(iConn->fedCh()) ) {
142  continue;
143  } else {
144  apvAddress = header->feUnitMajorityAddress(iConn->fedCh()/FEDCH_PER_FEUNIT);
145  return;
146  }
147  }
148  }
149  }
150  //if we haven't already found an acceptable alternative, throw an exception
151  throw cms::Exception(messageLabel_) << "Failed to get L1ID/APV address from any FED";
152  }
153 
154  void SpyEventMatcherModule::copyData(const uint32_t eventId, const uint8_t apvAddress, const SpyEventMatcher::SpyEventList* matches, edm::Event& event,
155  const SiStripFedCabling& cabling) const
156  {
157  SpyEventMatcher::SpyDataCollections matchedCollections;
158  spyEventMatcher_->getMatchedCollections(eventId,apvAddress,matches,cabling,matchedCollections);
159  if (matchedCollections.rawData.get()) event.put(matchedCollections.rawData,"RawSpyData");
160  if (matchedCollections.totalEventCounters.get()) event.put(matchedCollections.totalEventCounters,"SpyTotalEventCount");
161  if (matchedCollections.l1aCounters.get()) event.put(matchedCollections.l1aCounters,"SpyL1ACount");
162  if (matchedCollections.apvAddresses.get()) event.put(matchedCollections.apvAddresses,"SpyAPVAddress");
163  if (matchedCollections.scopeDigis.get()) event.put(matchedCollections.scopeDigis,"SpyScope");
164  if (matchedCollections.payloadDigis.get()) event.put(matchedCollections.payloadDigis,"SpyPayload");
165  if (matchedCollections.reorderedDigis.get()) event.put(matchedCollections.reorderedDigis,"SpyReordered");
166  if (matchedCollections.virginRawDigis.get()) event.put(matchedCollections.virginRawDigis,"SpyVirginRaw");
167  }
168 
169 }
170 
174 
175 #endif //SiStripMonitorHardware_BuildEventMatchingCode
#define LogDebug(id)
virtual char const * what() const
Definition: Exception.cc:141
const std::vector< uint16_t > & feds() const
std::auto_ptr< std::vector< uint32_t > > apvAddresses
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:17
std::auto_ptr< std::vector< uint32_t > > l1aCounters
std::auto_ptr< std::vector< uint32_t > > totalEventCounters
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:49
std::auto_ptr< edm::DetSetVector< SiStripRawDigi > > reorderedDigis
std::auto_ptr< SpyUtilities > utils_
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
std::set< EventID > SpyEventList
std::auto_ptr< edm::DetSetVector< SiStripRawDigi > > payloadDigis
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
std::auto_ptr< SpyEventMatcher > spyEventMatcher_
std::auto_ptr< edm::DetSetVector< SiStripRawDigi > > scopeDigis
static const uint16_t FEDCH_PER_FEUNIT
std::auto_ptr< FEDRawDataCollection > rawData
virtual bool filter(edm::Event &event, const edm::EventSetup &eventSetup)
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
std::auto_ptr< edm::DetSetVector< SiStripRawDigi > > virginRawDigis
uint8_t feUnitMajorityAddress(const uint8_t internalFEUnitNum) const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
const std::vector< FedChannelConnection > & connections(uint16_t fed_id) const
sistrip::SpyEventMatcherModule SiStripSpyEventMatcherModule
void findL1IDandAPVAddress(const edm::Event &event, const SiStripFedCabling &cabling, uint32_t &l1ID, uint8_t &apvAddress) const