CMS 3D CMS Logo

SiStripSpyEventMatcher.h
Go to the documentation of this file.
1 #define SiStripMonitorHardware_BuildEventMatchingCode
2 #ifdef SiStripMonitorHardware_BuildEventMatchingCode
3 
4 #ifndef DQM_SiStripMonitorHardware_SiStripSpyEventMatcher_H
5 #define DQM_SiStripMonitorHardware_SiStripSpyEventMatcher_H
6 
11 #include "boost/cstdint.hpp"
12 #include "boost/shared_ptr.hpp"
13 #include <set>
14 #include <map>
15 #include <memory>
16 #include <vector>
17 
18 //forward declarations
20 class SiStripRawDigi;
21 namespace edm {
22  template<class T> class DetSetVector;
23  template<class T> class DetSet;
24  class EventID;
25  class ParameterSet;
26 }
27 class SiStripFedCabling;
28 
29 namespace sistrip {
30 
32  {
33  public:
35  {
36  public:
37  std::unique_ptr< FEDRawDataCollection > rawData;
38  std::unique_ptr< std::vector<uint32_t> > totalEventCounters;
39  std::unique_ptr< std::vector<uint32_t> > l1aCounters;
40  std::unique_ptr< std::vector<uint32_t> > apvAddresses;
41  std::unique_ptr< edm::DetSetVector<SiStripRawDigi> > scopeDigis;
42  std::unique_ptr< edm::DetSetVector<SiStripRawDigi> > payloadDigis;
43  std::unique_ptr< edm::DetSetVector<SiStripRawDigi> > reorderedDigis;
44  std::unique_ptr< edm::DetSetVector<SiStripRawDigi> > virginRawDigis;
46  //NB. This will remove all elements in the containers pasted in. It does not copy the data.
48  std::vector<uint32_t>& theTotalEventCounters,
49  std::vector<uint32_t>& theL1ACounters,
50  std::vector<uint32_t>& theAPVAddresses,
51  std::vector< edm::DetSet<SiStripRawDigi> >* theScopeDigisVector,
52  std::vector< edm::DetSet<SiStripRawDigi> >* thePayloadDigisVector,
53  std::vector< edm::DetSet<SiStripRawDigi> >* theReorderedDigisVector,
54  std::vector< edm::DetSet<SiStripRawDigi> >* theVirginRawDigisVector);
55  };
57  {
58  explicit MatchingOutput(FEDRawDataCollection& outputRawData);
60  std::vector<uint32_t> outputTotalEventCounters_;
61  std::vector<uint32_t> outputL1ACounters_;
62  std::vector<uint32_t> outputAPVAddresses_;
63  boost::shared_ptr< std::vector< edm::DetSet<SiStripRawDigi> > > outputScopeDigisVector_;
64  boost::shared_ptr< std::vector< edm::DetSet<SiStripRawDigi> > > outputPayloadDigisVector_;
65  boost::shared_ptr< std::vector< edm::DetSet<SiStripRawDigi> > > outputReorderedDigisVector_;
66  boost::shared_ptr< std::vector< edm::DetSet<SiStripRawDigi> > > outputVirginRawDigisVector_;
67  std::set<uint16_t> alreadyMergedFeds_;
68  };
69 
71  typedef std::set<EventID> SpyEventList;
72 
74  virtual ~SpyEventMatcher();
75  //set up the internal map of eventID, to apvAddress
76  void initialize();
77  //check if there is any data for an event. Returns NULL if not or a pointer to a list of matches if they exist
78  const SpyEventList* matchesForEvent(const uint32_t eventId, const uint8_t apvAddress) const;
79  //get data for matching FEDs (non-const because reading events from the source modifies it)
80  void getMatchedCollections(const uint32_t eventId, const uint8_t apvAddress, const SpyEventList* matchingEvents,
81  const SiStripFedCabling& cabling, SpyDataCollections& collectionsToCreate);
82  //helper for getMatchedCollections()
83  void getCollections(const edm::EventPrincipal& event, const uint32_t eventId,
84  const uint8_t apvAddress, const SiStripFedCabling& cabling,
85  MatchingOutput& matchingOutput);
86 
87  private:
88  class EventKey
89  {
90  public:
91  EventKey(const uint32_t eventId, const uint8_t apvAddress);
92  uint32_t eventId() const { return eventId_; }
93  uint8_t apvAddress() const { return apvAddress_; }
94  bool operator < (const EventKey& rhs) const;
95  private:
96  uint32_t eventId_;
97  uint8_t apvAddress_;
98  };
99  typedef std::vector<uint32_t> Counters;
100  //class to wrap counters that can take ownership of them or not.
101  //It behaves like the counters themself but, it actualy holds a pointer to them and dletes them if necessary
103  {
104  public:
105  CountersWrapper(const Counters* theCounters);
106  CountersWrapper(Counters* theCounters, const bool takeOwnership);
107  ~CountersWrapper();
108  const Counters::value_type operator [] (const size_t i) const { return (*pConst)[i]; };
109  const Counters::value_type at(const size_t i) const { return pConst->at(i); };
110  Counters::const_iterator begin() const { return pConst->begin(); }
111  Counters::const_iterator end() const { return pConst->end(); }
112  private:
113  const Counters* pConst;
114  Counters* p;
115  bool deleteP;
116  };
117  typedef boost::shared_ptr<CountersWrapper> CountersPtr;
118 
119  //source for spy events
121  //reference counted pointer to an event
122 
123  std::unique_ptr<Source> constructSource(const edm::ParameterSet& sourceConfig);
124  void addNextEventToMap(const edm::EventPrincipal& nextSpyEvent);
125  template <class T> static const T* getProduct(const edm::EventPrincipal& event, const edm::InputTag& tag);
126  static CountersPtr getCounters(const edm::EventPrincipal& event, const edm::InputTag& tag, const bool mapKeyIsByFedID = true);
127  void operator()(const edm::EventPrincipal& event);
128  static void findMatchingFeds(const uint32_t eventId, const uint8_t apvAddress,
129  CountersPtr totalEventCounters,
130  CountersPtr l1aCounters,
131  CountersPtr apvAddresses,
132  std::set<uint16_t>& matchingFeds);
133  static void mergeMatchingData(const std::set<uint16_t>& matchingFeds,
134  const FEDRawDataCollection& inputRawData,
135  CountersPtr inputTotalEventCounters,
136  CountersPtr inputL1ACounters,
137  CountersPtr inputAPVAddresses,
138  const edm::DetSetVector<SiStripRawDigi>* inputScopeDigis,
139  const edm::DetSetVector<SiStripRawDigi>* inputPayloadDigis,
140  const edm::DetSetVector<SiStripRawDigi>* inputReorderedDigis,
141  const edm::DetSetVector<SiStripRawDigi>* inputVirginRawDigis,
142  FEDRawDataCollection& outputRawData,
143  std::vector<uint32_t>& outputTotalEventCounters,
144  std::vector<uint32_t>& outputL1ACounters,
145  std::vector<uint32_t>& outputAPVAddresses,
146  std::vector< edm::DetSet<SiStripRawDigi> >* outputScopeDigisVector,
147  std::vector< edm::DetSet<SiStripRawDigi> >* outputPayloadDigisVector,
148  std::vector< edm::DetSet<SiStripRawDigi> >* outputReorderedDigisVector,
149  std::vector< edm::DetSet<SiStripRawDigi> >* outputVirginRawDigisVector,
150  const SiStripFedCabling& cabling);
151 
152  std::map<EventKey,SpyEventList> eventMatches_;
161  uint32_t counterDiffMax_;
162  std::shared_ptr<edm::ProductRegistry> productRegistry_;
163  std::unique_ptr<edm::VectorInputSource> const source_;
164  std::unique_ptr<edm::ProcessConfiguration> processConfiguration_;
165  std::unique_ptr<edm::EventPrincipal> eventPrincipal_;
166  static const char* mlLabel_;
167  };
168 
169  template <class T> const T* SpyEventMatcher::getProduct(const edm::EventPrincipal& event, const edm::InputTag& tag)
170  {
171  LogDebug(mlLabel_) << "Retrieving product " << tag;
172  // Note: The third argument to getProductByTag can be a nullptr
173  // as long as unscheduled execution of an EDProducer cannot occur
174  // as a result of this function call (and with the current implementation
175  // of SpyEventMatcher unscheduled execution never happens).
176  const std::shared_ptr< const edm::Wrapper<T> > productWrapper = edm::getProductByTag<T>(event,tag,nullptr);
177  if (productWrapper) {
178  return productWrapper->product();
179  } else {
180  return NULL;
181  }
182  }
183 
185  {
186  return ( (this->eventId_<rhs.eventId_) ? true : ( ((this->eventId_==rhs.eventId_) && (this->apvAddress_<rhs.apvAddress_)) ? true : false) );
187  }
188 
189 }
190 
191 #endif //ndef DQM_SiStripMonitorHardware_SiStripSpyEventMatcher_H
192 
193 #endif //SiStripMonitorHardware_BuildEventMatchingCode
#define LogDebug(id)
bool operator<(DetSet< T > const &x, DetSet< T > const &y)
Definition: DetSet.h:90
static AlgebraicMatrix initialize()
edm::VectorInputSource Source
std::vector< uint32_t > Counters
std::unique_ptr< std::vector< uint32_t > > l1aCounters
boost::shared_ptr< CountersWrapper > CountersPtr
std::unique_ptr< std::vector< uint32_t > > totalEventCounters
std::unique_ptr< edm::EventPrincipal > eventPrincipal_
T const * getProduct(RefCore const &ref)
Definition: RefCoreGet.h:41
std::unique_ptr< edm::ProcessConfiguration > processConfiguration_
#define NULL
Definition: scimark2.h:8
Definition: config.py:1
boost::shared_ptr< std::vector< edm::DetSet< SiStripRawDigi > > > outputReorderedDigisVector_
sistrip classes
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > virginRawDigis
boost::shared_ptr< std::vector< edm::DetSet< SiStripRawDigi > > > outputScopeDigisVector_
bool operator<(const FedChannelConnection &, const FedChannelConnection &)
boost::shared_ptr< std::vector< edm::DetSet< SiStripRawDigi > > > outputPayloadDigisVector_
std::set< EventID > SpyEventList
T operator[](int i) const
std::shared_ptr< edm::ProductRegistry > productRegistry_
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::unique_ptr< edm::VectorInputSource > const source_
std::unique_ptr< FEDRawDataCollection > rawData
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > scopeDigis
Counters::const_iterator begin() const
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
boost::shared_ptr< std::vector< edm::DetSet< SiStripRawDigi > > > outputVirginRawDigisVector_
HLT enums.
const Counters::value_type at(const size_t i) const
std::unique_ptr< std::vector< uint32_t > > apvAddresses
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > reorderedDigis
A Digi for the silicon strip detector, containing only adc information, and suitable for storing raw ...
long double T
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > payloadDigis
std::map< EventKey, SpyEventList > eventMatches_
Definition: event.py:1