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* 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::DetSetVector< SiStripRawDigi >
sistrip::SpyEventMatcher::matchesForEvent
const SpyEventList * matchesForEvent(const uint32_t eventId, const uint8_t apvAddress) const
Definition: SiStripSpyEventMatcher.cc:151
sistrip::SpyEventMatcher::CountersWrapper::end
Counters::const_iterator end() const
Definition: SiStripSpyEventMatcher.h:114
sistrip::SpyEventMatcher::MatchingOutput::outputL1ACounters_
std::vector< uint32_t > outputL1ACounters_
Definition: SiStripSpyEventMatcher.h:60
sistrip::SpyEventMatcher::EventKey::EventKey
EventKey(const uint32_t eventId, const uint8_t apvAddress)
Definition: SiStripSpyEventMatcher.cc:36
mps_fire.i
i
Definition: mps_fire.py:428
sistrip::SpyEventMatcher::SpyDataCollections::apvAddresses
std::unique_ptr< std::vector< uint32_t > > apvAddresses
Definition: SiStripSpyEventMatcher.h:40
sistrip::SpyEventMatcher::MatchingOutput::outputRawData_
FEDRawDataCollection & outputRawData_
Definition: SiStripSpyEventMatcher.h:58
sistrip::SpyEventMatcher::payloadDigisTag_
edm::InputTag payloadDigisTag_
Definition: SiStripSpyEventMatcher.h:166
MessageLogger.h
sistrip::SpyEventMatcher::counterDiffMax_
uint32_t counterDiffMax_
Definition: SiStripSpyEventMatcher.h:169
sistrip::SpyEventMatcher::CountersWrapper
Definition: SiStripSpyEventMatcher.h:106
sistrip::SpyEventMatcher::MatchingOutput::outputTotalEventCounters_
std::vector< uint32_t > outputTotalEventCounters_
Definition: SiStripSpyEventMatcher.h:59
edm::DetSet
Definition: DetSet.h:23
sistrip::SpyEventMatcher::getCounters
static CountersPtr getCounters(const edm::EventPrincipal &event, const edm::InputTag &tag, const bool mapKeyIsByFedID=true)
Definition: SiStripSpyEventMatcher.cc:391
sistrip::SpyEventMatcher::virginRawDigisTag_
edm::InputTag virginRawDigisTag_
Definition: SiStripSpyEventMatcher.h:168
FEDRawDataCollection
Definition: FEDRawDataCollection.h:18
edm
HLT enums.
Definition: AlignableModifier.h:19
sistrip::SpyEventMatcher::CountersWrapper::at
const Counters::value_type at(const size_t i) const
Definition: SiStripSpyEventMatcher.h:112
sistrip::SpyEventMatcher::EventKey::eventId_
uint32_t eventId_
Definition: SiStripSpyEventMatcher.h:100
sistrip::SpyEventMatcher::CountersWrapper::operator[]
const Counters::value_type operator[](const size_t i) const
Definition: SiStripSpyEventMatcher.h:111
sistrip::SpyEventMatcher::l1aCountersTag_
edm::InputTag l1aCountersTag_
Definition: SiStripSpyEventMatcher.h:163
sistrip::SpyEventMatcher::MatchingOutput::MatchingOutput
MatchingOutput(FEDRawDataCollection &outputRawData)
Definition: SiStripSpyEventMatcher.cc:39
sistrip::SpyEventMatcher::SpyDataCollections::SpyDataCollections
SpyDataCollections()
Definition: SiStripSpyEventMatcher.cc:451
edm::VectorInputSource
Definition: VectorInputSource.h:27
sistrip::SpyEventMatcher::MatchingOutput::alreadyMergedFeds_
std::set< uint16_t > alreadyMergedFeds_
Definition: SiStripSpyEventMatcher.h:66
sistrip::SpyEventMatcher::constructSource
std::unique_ptr< Source > constructSource(const edm::ParameterSet &sourceConfig)
Definition: SiStripSpyEventMatcher.cc:73
SiStripFedCabling
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses,...
Definition: SiStripFedCabling.h:25
sistrip::SpyEventMatcher::mergeMatchingData
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)
Definition: SiStripSpyEventMatcher.cc:299
sistrip::SpyEventMatcher::CountersWrapper::begin
Counters::const_iterator begin() const
Definition: SiStripSpyEventMatcher.h:113
config
Definition: config.py:1
SiStripRawDigi
A Digi for the silicon strip detector, containing only adc information, and suitable for storing raw ...
Definition: SiStripRawDigi.h:15
sistrip::SpyEventMatcher::SpyDataCollections::reorderedDigis
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > reorderedDigis
Definition: SiStripSpyEventMatcher.h:43
edm::EventPrincipal
Definition: EventPrincipal.h:46
sistrip::SpyEventMatcher::scopeDigisTag_
edm::InputTag scopeDigisTag_
Definition: SiStripSpyEventMatcher.h:165
sistrip::SpyEventMatcher::SpyEventMatcher
SpyEventMatcher(const edm::ParameterSet &config)
Definition: SiStripSpyEventMatcher.cc:47
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
sistrip::SpyEventMatcher::Source
edm::VectorInputSource Source
Definition: SiStripSpyEventMatcher.h:124
sistrip::SpyEventMatcher::MatchingOutput::outputAPVAddresses_
std::vector< uint32_t > outputAPVAddresses_
Definition: SiStripSpyEventMatcher.h:61
EventPrincipal.h
sistrip::SpyEventMatcher::getCollections
void getCollections(const edm::EventPrincipal &event, const uint32_t eventId, const uint8_t apvAddress, const SiStripFedCabling &cabling, MatchingOutput &matchingOutput)
Definition: SiStripSpyEventMatcher.cc:171
sistrip::SpyEventMatcher::processConfiguration_
std::unique_ptr< edm::ProcessConfiguration > processConfiguration_
Definition: SiStripSpyEventMatcher.h:172
sistrip::SpyEventMatcher::productRegistry_
std::shared_ptr< edm::ProductRegistry > productRegistry_
Definition: SiStripSpyEventMatcher.h:170
sistrip::SpyEventMatcher::MatchingOutput::outputScopeDigisVector_
std::shared_ptr< std::vector< edm::DetSet< SiStripRawDigi > > > outputScopeDigisVector_
Definition: SiStripSpyEventMatcher.h:62
sistrip::SpyEventMatcher::~SpyEventMatcher
virtual ~SpyEventMatcher()
Definition: SiStripSpyEventMatcher.cc:45
sistrip::SpyEventMatcher::EventKey
Definition: SiStripSpyEventMatcher.h:92
sistrip::SpyEventMatcher::totalEventCountersTag_
edm::InputTag totalEventCountersTag_
Definition: SiStripSpyEventMatcher.h:162
sistrip::SpyEventMatcher::eventMatches_
std::map< EventKey, SpyEventList > eventMatches_
Definition: SiStripSpyEventMatcher.h:160
sistrip::SpyEventMatcher::MatchingOutput::outputVirginRawDigisVector_
std::shared_ptr< std::vector< edm::DetSet< SiStripRawDigi > > > outputVirginRawDigisVector_
Definition: SiStripSpyEventMatcher.h:65
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
ParameterSet
Definition: Functions.h:16
sistrip::SpyEventMatcher::operator()
void operator()(const edm::EventPrincipal &event)
sistrip::SpyEventMatcher::MatchingOutput
Definition: SiStripSpyEventMatcher.h:56
sistrip::SpyEventMatcher::getProduct
static const T * getProduct(const edm::EventPrincipal &event, const edm::InputTag &tag)
Definition: SiStripSpyEventMatcher.h:178
sistrip::SpyEventMatcher::findMatchingFeds
static void findMatchingFeds(const uint32_t eventId, const uint8_t apvAddress, CountersPtr totalEventCounters, CountersPtr l1aCounters, CountersPtr apvAddresses, std::set< uint16_t > &matchingFeds)
Definition: SiStripSpyEventMatcher.cc:277
sistrip::SpyEventMatcher::SpyEventList
std::set< EventID > SpyEventList
Definition: SiStripSpyEventMatcher.h:70
sistrip::SpyEventMatcher::rawDataTag_
edm::InputTag rawDataTag_
Definition: SiStripSpyEventMatcher.h:161
sistrip::SpyEventMatcher::SpyDataCollections::l1aCounters
std::unique_ptr< std::vector< uint32_t > > l1aCounters
Definition: SiStripSpyEventMatcher.h:39
sistrip::SpyEventMatcher::mlLabel_
static const char * mlLabel_
Definition: SiStripSpyEventMatcher.h:174
sistrip::SpyEventMatcher::EventKey::apvAddress
uint8_t apvAddress() const
Definition: SiStripSpyEventMatcher.h:96
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
sistrip::SpyEventMatcher::apvAddressesTag_
edm::InputTag apvAddressesTag_
Definition: SiStripSpyEventMatcher.h:164
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
sistrip::SpyEventMatcher::initialize
void initialize()
Definition: SiStripSpyEventMatcher.cc:79
sistrip::SpyEventMatcher::addNextEventToMap
void addNextEventToMap(const edm::EventPrincipal &nextSpyEvent)
Definition: SiStripSpyEventMatcher.cc:104
sistrip::SpyEventMatcher::EventKey::apvAddress_
uint8_t apvAddress_
Definition: SiStripSpyEventMatcher.h:101
InputTag.h
sistrip::SpyEventMatcher::SpyDataCollections::rawData
std::unique_ptr< FEDRawDataCollection > rawData
Definition: SiStripSpyEventMatcher.h:37
sistrip::SpyEventMatcher::EventKey::eventId
uint32_t eventId() const
Definition: SiStripSpyEventMatcher.h:95
sistrip::SpyEventMatcher::SpyDataCollections::scopeDigis
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > scopeDigis
Definition: SiStripSpyEventMatcher.h:41
sistrip::SpyEventMatcher::SpyDataCollections::virginRawDigis
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > virginRawDigis
Definition: SiStripSpyEventMatcher.h:44
sistrip::SpyEventMatcher::SpyDataCollections
Definition: SiStripSpyEventMatcher.h:35
sistrip::SpyEventMatcher::CountersWrapper::~CountersWrapper
~CountersWrapper()
Definition: SiStripSpyEventMatcher.cc:467
T
long double T
Definition: Basic3DVectorLD.h:48
sistrip::SpyEventMatcher::SpyDataCollections::payloadDigis
std::unique_ptr< edm::DetSetVector< SiStripRawDigi > > payloadDigis
Definition: SiStripSpyEventMatcher.h:42
sistrip::SpyEventMatcher::MatchingOutput::outputReorderedDigisVector_
std::shared_ptr< std::vector< edm::DetSet< SiStripRawDigi > > > outputReorderedDigisVector_
Definition: SiStripSpyEventMatcher.h:64
sistrip::SpyEventMatcher::eventPrincipal_
std::unique_ptr< edm::EventPrincipal > eventPrincipal_
Definition: SiStripSpyEventMatcher.h:173
sistrip::SpyEventMatcher::CountersPtr
std::shared_ptr< CountersWrapper > CountersPtr
Definition: SiStripSpyEventMatcher.h:121
sistrip::SpyEventMatcher::EventKey::operator<
bool operator<(const EventKey &rhs) const
Definition: SiStripSpyEventMatcher.h:192
sistrip::SpyEventMatcher
Definition: SiStripSpyEventMatcher.h:33
sistrip::SpyEventMatcher::CountersWrapper::p
Counters * p
Definition: SiStripSpyEventMatcher.h:118
sistrip::SpyEventMatcher::MatchingOutput::outputPayloadDigisVector_
std::shared_ptr< std::vector< edm::DetSet< SiStripRawDigi > > > outputPayloadDigisVector_
Definition: SiStripSpyEventMatcher.h:63
sistrip::SpyEventMatcher::CountersWrapper::CountersWrapper
CountersWrapper(const Counters *theCounters)
Definition: SiStripSpyEventMatcher.cc:461
sistrip::SpyEventMatcher::source_
const std::unique_ptr< edm::VectorInputSource > source_
Definition: SiStripSpyEventMatcher.h:171
sistrip::SpyEventMatcher::CountersWrapper::pConst
const Counters * pConst
Definition: SiStripSpyEventMatcher.h:117
sistrip::SpyEventMatcher::getMatchedCollections
void getMatchedCollections(const uint32_t eventId, const uint8_t apvAddress, const SpyEventList *matchingEvents, const SiStripFedCabling &cabling, SpyDataCollections &collectionsToCreate)
Definition: SiStripSpyEventMatcher.cc:251
sistrip::SpyEventMatcher::EventID
edm::EventID EventID
Definition: SiStripSpyEventMatcher.h:69
sistrip
sistrip classes
Definition: SiStripQualityHelpers.h:14
event
Definition: event.py:1
edm::EventID
Definition: EventID.h:31
sistrip::SpyEventMatcher::CountersWrapper::deleteP
bool deleteP
Definition: SiStripSpyEventMatcher.h:119
sistrip::SpyEventMatcher::reorderedDigisTag_
edm::InputTag reorderedDigisTag_
Definition: SiStripSpyEventMatcher.h:167
sistrip::SpyEventMatcher::SpyDataCollections::totalEventCounters
std::unique_ptr< std::vector< uint32_t > > totalEventCounters
Definition: SiStripSpyEventMatcher.h:38
sistrip::SpyEventMatcher::Counters
std::vector< uint32_t > Counters
Definition: SiStripSpyEventMatcher.h:103
VectorInputSource.h
edm::InputTag
Definition: InputTag.h:15