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 
12 #include <set>
13 #include <map>
14 #include <memory>
15 #include <vector>
16 #include <cstdint>
17 
18 //forward declarations
20 class SiStripRawDigi;
21 namespace edm {
22  template <class T>
23  class DetSetVector;
24  template <class T>
25  struct DetSet;
26  class EventID;
27  class ParameterSet;
28 } // namespace edm
29 class SiStripFedCabling;
30 
31 namespace sistrip {
32 
34  public:
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  };
56  struct MatchingOutput {
57  explicit MatchingOutput(FEDRawDataCollection& outputRawData);
59  std::vector<uint32_t> outputTotalEventCounters_;
60  std::vector<uint32_t> outputL1ACounters_;
61  std::vector<uint32_t> outputAPVAddresses_;
62  std::shared_ptr<std::vector<edm::DetSet<SiStripRawDigi> > > outputScopeDigisVector_;
63  std::shared_ptr<std::vector<edm::DetSet<SiStripRawDigi> > > outputPayloadDigisVector_;
64  std::shared_ptr<std::vector<edm::DetSet<SiStripRawDigi> > > outputReorderedDigisVector_;
65  std::shared_ptr<std::vector<edm::DetSet<SiStripRawDigi> > > outputVirginRawDigisVector_;
66  std::set<uint16_t> alreadyMergedFeds_;
67  };
68 
70  typedef std::set<EventID> SpyEventList;
71 
73  virtual ~SpyEventMatcher();
74  //set up the internal map of eventID, to apvAddress
75  void initialize();
76  //check if there is any data for an event. Returns NULL if not or a pointer to a list of matches if they exist
77  const SpyEventList* matchesForEvent(const uint32_t eventId, const uint8_t apvAddress) const;
78  //get data for matching FEDs (non-const because reading events from the source modifies it)
79  void getMatchedCollections(const uint32_t eventId,
80  const uint8_t apvAddress,
81  const SpyEventList* matchingEvents,
82  const SiStripFedCabling& cabling,
83  SpyDataCollections& collectionsToCreate);
84  //helper for getMatchedCollections()
86  const uint32_t eventId,
87  const uint8_t apvAddress,
88  const SiStripFedCabling& cabling,
89  MatchingOutput& matchingOutput);
90 
91  private:
92  class EventKey {
93  public:
94  EventKey(const uint32_t eventId, const uint8_t apvAddress);
95  uint32_t eventId() const { return eventId_; }
96  uint8_t apvAddress() const { return apvAddress_; }
97  bool operator<(const EventKey& rhs) const;
98 
99  private:
100  uint32_t eventId_;
101  uint8_t apvAddress_;
102  };
103  typedef std::vector<uint32_t> Counters;
104  //class to wrap counters that can take ownership of them or not.
105  //It behaves like the counters themself but, it actualy holds a pointer to them and dletes them if necessary
107  public:
108  CountersWrapper(const Counters* theCounters);
109  CountersWrapper(Counters* theCounters, const bool takeOwnership);
111  const Counters::value_type operator[](const size_t i) const { return (*pConst)[i]; };
112  const Counters::value_type at(const size_t i) const { return pConst->at(i); };
113  Counters::const_iterator begin() const { return pConst->begin(); }
114  Counters::const_iterator end() const { return pConst->end(); }
115 
116  private:
117  const Counters* pConst;
119  bool deleteP;
120  };
121  typedef std::shared_ptr<CountersWrapper> CountersPtr;
122 
123  //source for spy events
125  //reference counted pointer to an event
126 
127  std::unique_ptr<Source> constructSource(const edm::ParameterSet& sourceConfig);
128  void addNextEventToMap(const edm::EventPrincipal& nextSpyEvent);
129  template <class T>
130  static const T* getProduct(const edm::EventPrincipal& event, const edm::InputTag& tag);
132  const edm::InputTag& tag,
133  const bool mapKeyIsByFedID = true);
134  void operator()(const edm::EventPrincipal& event);
135  static void findMatchingFeds(const uint32_t eventId,
136  const uint8_t apvAddress,
137  CountersPtr totalEventCounters,
138  CountersPtr l1aCounters,
139  CountersPtr apvAddresses,
140  std::set<uint16_t>& matchingFeds);
141  static void mergeMatchingData(const std::set<uint16_t>& matchingFeds,
142  const FEDRawDataCollection& inputRawData,
143  CountersPtr inputTotalEventCounters,
144  CountersPtr inputL1ACounters,
145  CountersPtr inputAPVAddresses,
146  const edm::DetSetVector<SiStripRawDigi>* inputScopeDigis,
147  const edm::DetSetVector<SiStripRawDigi>* inputPayloadDigis,
148  const edm::DetSetVector<SiStripRawDigi>* inputReorderedDigis,
149  const edm::DetSetVector<SiStripRawDigi>* inputVirginRawDigis,
150  FEDRawDataCollection& outputRawData,
151  std::vector<uint32_t>& outputTotalEventCounters,
152  std::vector<uint32_t>& outputL1ACounters,
153  std::vector<uint32_t>& outputAPVAddresses,
154  std::vector<edm::DetSet<SiStripRawDigi> >* outputScopeDigisVector,
155  std::vector<edm::DetSet<SiStripRawDigi> >* outputPayloadDigisVector,
156  std::vector<edm::DetSet<SiStripRawDigi> >* outputReorderedDigisVector,
157  std::vector<edm::DetSet<SiStripRawDigi> >* outputVirginRawDigisVector,
158  const SiStripFedCabling& cabling);
159 
160  std::map<EventKey, SpyEventList> eventMatches_;
169  uint32_t counterDiffMax_;
170  std::shared_ptr<edm::ProductRegistry> productRegistry_;
171  std::unique_ptr<edm::VectorInputSource> const source_;
172  std::unique_ptr<edm::ProcessConfiguration> processConfiguration_;
173  std::unique_ptr<edm::EventPrincipal> eventPrincipal_;
174  static const char* const mlLabel_;
175  };
176 
177  template <class T>
179  LogDebug(mlLabel_) << "Retrieving product " << tag;
180  // Note: The third argument to getProductByTag can be a nullptr
181  // as long as unscheduled execution of an EDProducer cannot occur
182  // as a result of this function call (and with the current implementation
183  // of SpyEventMatcher unscheduled execution never happens).
184  const std::shared_ptr<const edm::Wrapper<T> > productWrapper = edm::getProductByTag<T>(event, tag, nullptr);
185  if (productWrapper) {
186  return productWrapper->product();
187  } else {
188  return nullptr;
189  }
190  }
191 
193  return ((this->eventId_ < rhs.eventId_)
194  ? true
195  : (((this->eventId_ == rhs.eventId_) && (this->apvAddress_ < rhs.apvAddress_)) ? true : false));
196  }
197 
198 } // namespace sistrip
199 
200 #endif //ndef DQM_SiStripMonitorHardware_SiStripSpyEventMatcher_H
201 
202 #endif //SiStripMonitorHardware_BuildEventMatchingCode
edm::VectorInputSource Source
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > payloadDigis
std::map< EventKey, SpyEventList > eventMatches_
static void findMatchingFeds(const uint32_t eventId, const uint8_t apvAddress, CountersPtr totalEventCounters, CountersPtr l1aCounters, CountersPtr apvAddresses, std::set< uint16_t > &matchingFeds)
void operator()(const edm::EventPrincipal &event)
static const T * getProduct(const edm::EventPrincipal &event, const edm::InputTag &tag)
std::shared_ptr< std::vector< edm::DetSet< SiStripRawDigi > > > outputVirginRawDigisVector_
std::vector< uint32_t > Counters
std::unique_ptr< edm::EventPrincipal > eventPrincipal_
bool operator<(const EventKey &rhs) const
void getCollections(const edm::EventPrincipal &event, const uint32_t eventId, const uint8_t apvAddress, const SiStripFedCabling &cabling, MatchingOutput &matchingOutput)
static CountersPtr getCounters(const edm::EventPrincipal &event, const edm::InputTag &tag, const bool mapKeyIsByFedID=true)
std::unique_ptr< edm::ProcessConfiguration > processConfiguration_
const SpyEventList * matchesForEvent(const uint32_t eventId, const uint8_t apvAddress) const
void getMatchedCollections(const uint32_t eventId, const uint8_t apvAddress, const SpyEventList *matchingEvents, const SiStripFedCabling &cabling, SpyDataCollections &collectionsToCreate)
Definition: config.py:1
std::shared_ptr< std::vector< edm::DetSet< SiStripRawDigi > > > outputScopeDigisVector_
sistrip classes
std::shared_ptr< std::vector< edm::DetSet< SiStripRawDigi > > > outputReorderedDigisVector_
std::unique_ptr< FEDRawDataCollection > rawData
std::unique_ptr< Source > constructSource(const edm::ParameterSet &sourceConfig)
std::shared_ptr< CountersWrapper > CountersPtr
edmNew::DetSet< TTStub< Ref_Phase2TrackerDigi_ > > DetSet
Definition: Stub.h:28
std::unique_ptr< std::vector< uint32_t > > totalEventCounters
std::set< EventID > SpyEventList
std::shared_ptr< edm::ProductRegistry > productRegistry_
std::unique_ptr< std::vector< uint32_t > > apvAddresses
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > scopeDigis
const Counters::value_type operator[](const size_t i) const
MatchingOutput(FEDRawDataCollection &outputRawData)
std::unique_ptr< edm::VectorInputSource > const source_
static const char *const mlLabel_
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > reorderedDigis
EventKey(const uint32_t eventId, const uint8_t apvAddress)
const Counters::value_type at(const size_t i) const
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
void addNextEventToMap(const edm::EventPrincipal &nextSpyEvent)
HLT enums.
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > virginRawDigis
std::unique_ptr< std::vector< uint32_t > > l1aCounters
static void mergeMatchingData(const std::set< uint16_t > &matchingFeds, const FEDRawDataCollection &inputRawData, CountersPtr inputTotalEventCounters, CountersPtr inputL1ACounters, CountersPtr inputAPVAddresses, const edm::DetSetVector< SiStripRawDigi > *inputScopeDigis, const edm::DetSetVector< SiStripRawDigi > *inputPayloadDigis, const edm::DetSetVector< SiStripRawDigi > *inputReorderedDigis, const edm::DetSetVector< SiStripRawDigi > *inputVirginRawDigis, FEDRawDataCollection &outputRawData, std::vector< uint32_t > &outputTotalEventCounters, std::vector< uint32_t > &outputL1ACounters, std::vector< uint32_t > &outputAPVAddresses, std::vector< edm::DetSet< SiStripRawDigi > > *outputScopeDigisVector, std::vector< edm::DetSet< SiStripRawDigi > > *outputPayloadDigisVector, std::vector< edm::DetSet< SiStripRawDigi > > *outputReorderedDigisVector, std::vector< edm::DetSet< SiStripRawDigi > > *outputVirginRawDigisVector, const SiStripFedCabling &cabling)
SpyEventMatcher(const edm::ParameterSet &config)
std::shared_ptr< std::vector< edm::DetSet< SiStripRawDigi > > > outputPayloadDigisVector_
A Digi for the silicon strip detector, containing only adc information, and suitable for storing raw ...
long double T
Definition: event.py:1
#define LogDebug(id)