CMS 3D CMS Logo

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