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 "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::auto_ptr< FEDRawDataCollection > rawData;
38  std::auto_ptr< std::vector<uint32_t> > totalEventCounters;
39  std::auto_ptr< std::vector<uint32_t> > l1aCounters;
40  std::auto_ptr< std::vector<uint32_t> > apvAddresses;
41  std::auto_ptr< edm::DetSetVector<SiStripRawDigi> > scopeDigis;
42  std::auto_ptr< edm::DetSetVector<SiStripRawDigi> > payloadDigis;
43  std::auto_ptr< edm::DetSetVector<SiStripRawDigi> > reorderedDigis;
44  std::auto_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  //does not copy, orginal object looses ownership of collections
57  };
59  {
60  explicit MatchingOutput(FEDRawDataCollection& outputRawData);
62  std::vector<uint32_t> outputTotalEventCounters_;
63  std::vector<uint32_t> outputL1ACounters_;
64  std::vector<uint32_t> outputAPVAddresses_;
65  boost::shared_ptr< std::vector< edm::DetSet<SiStripRawDigi> > > outputScopeDigisVector_;
66  boost::shared_ptr< std::vector< edm::DetSet<SiStripRawDigi> > > outputPayloadDigisVector_;
67  boost::shared_ptr< std::vector< edm::DetSet<SiStripRawDigi> > > outputReorderedDigisVector_;
68  boost::shared_ptr< std::vector< edm::DetSet<SiStripRawDigi> > > outputVirginRawDigisVector_;
69  std::set<uint16_t> alreadyMergedFeds_;
70  };
71 
73  typedef std::set<EventID> SpyEventList;
74 
76  virtual ~SpyEventMatcher();
77  //set up the internal map of eventID, to apvAddress
78  void initialize();
79  //check if there is any data for an event. Returns NULL if not or a pointer to a list of matches if they exist
80  const SpyEventList* matchesForEvent(const uint32_t eventId, const uint8_t apvAddress) const;
81  //get data for matching FEDs (non-const because reading events from the source modifies it)
82  void getMatchedCollections(const uint32_t eventId, const uint8_t apvAddress, const SpyEventList* matchingEvents,
83  const SiStripFedCabling& cabling, SpyDataCollections& collectionsToCreate);
84  //helper for getMatchedCollections()
85  void getCollections(const edm::EventPrincipal& event, const uint32_t eventId,
86  const uint8_t apvAddress, const SiStripFedCabling& cabling,
87  MatchingOutput& matchingOutput);
88 
89  private:
90  class EventKey
91  {
92  public:
93  EventKey(const uint32_t eventId, const uint8_t apvAddress);
94  uint32_t eventId() const { return eventId_; }
95  uint8_t apvAddress() const { return apvAddress_; }
96  bool operator < (const EventKey& rhs) const;
97  private:
98  uint32_t eventId_;
99  uint8_t apvAddress_;
100  };
101  typedef std::vector<uint32_t> Counters;
102  //class to wrap counters that can take ownership of them or not.
103  //It behaves like the counters themself but, it actualy holds a pointer to them and dletes them if necessary
105  {
106  public:
107  CountersWrapper(const Counters* theCounters);
108  CountersWrapper(Counters* theCounters, const bool takeOwnership);
110  const Counters::value_type operator [] (const size_t i) const { return (*pConst)[i]; };
111  const Counters::value_type at(const size_t i) const { return pConst->at(i); };
112  Counters::const_iterator begin() const { return pConst->begin(); }
113  Counters::const_iterator end() const { return pConst->end(); }
114  private:
115  const Counters* pConst;
117  bool deleteP;
118  };
119  typedef boost::shared_ptr<CountersWrapper> CountersPtr;
120 
121  //source for spy events
123  //reference counted pointer to an event
124 
125  std::unique_ptr<Source> constructSource(const edm::ParameterSet& sourceConfig);
126  void addNextEventToMap(const edm::EventPrincipal& nextSpyEvent);
127  template <class T> static const T* getProduct(const edm::EventPrincipal& event, const edm::InputTag& tag);
128  static CountersPtr getCounters(const edm::EventPrincipal& event, const edm::InputTag& tag, const bool mapKeyIsByFedID = true);
129  void operator()(const edm::EventPrincipal& event);
130  static void findMatchingFeds(const uint32_t eventId, const uint8_t apvAddress,
131  CountersPtr totalEventCounters,
132  CountersPtr l1aCounters,
133  CountersPtr apvAddresses,
134  std::set<uint16_t>& matchingFeds);
135  static void mergeMatchingData(const std::set<uint16_t>& matchingFeds,
136  const FEDRawDataCollection& inputRawData,
137  CountersPtr inputTotalEventCounters,
138  CountersPtr inputL1ACounters,
139  CountersPtr inputAPVAddresses,
140  const edm::DetSetVector<SiStripRawDigi>* inputScopeDigis,
141  const edm::DetSetVector<SiStripRawDigi>* inputPayloadDigis,
142  const edm::DetSetVector<SiStripRawDigi>* inputReorderedDigis,
143  const edm::DetSetVector<SiStripRawDigi>* inputVirginRawDigis,
144  FEDRawDataCollection& outputRawData,
145  std::vector<uint32_t>& outputTotalEventCounters,
146  std::vector<uint32_t>& outputL1ACounters,
147  std::vector<uint32_t>& outputAPVAddresses,
148  std::vector< edm::DetSet<SiStripRawDigi> >* outputScopeDigisVector,
149  std::vector< edm::DetSet<SiStripRawDigi> >* outputPayloadDigisVector,
150  std::vector< edm::DetSet<SiStripRawDigi> >* outputReorderedDigisVector,
151  std::vector< edm::DetSet<SiStripRawDigi> >* outputVirginRawDigisVector,
152  const SiStripFedCabling& cabling);
153 
154  std::map<EventKey,SpyEventList> eventMatches_;
163  uint32_t counterDiffMax_;
164  std::shared_ptr<edm::ProductRegistry> productRegistry_;
165  std::unique_ptr<edm::VectorInputSource> const source_;
166  std::unique_ptr<edm::ProcessConfiguration> processConfiguration_;
167  std::unique_ptr<edm::EventPrincipal> eventPrincipal_;
168  static const char* mlLabel_;
169  };
170 
171  template <class T> const T* SpyEventMatcher::getProduct(const edm::EventPrincipal& event, const edm::InputTag& tag)
172  {
173  LogDebug(mlLabel_) << "Retrieving product " << tag;
174  // Note: The third argument to getProductByTag can be a nullptr
175  // as long as unscheduled execution of an EDProducer cannot occur
176  // as a result of this function call (and with the current implementation
177  // of SpyEventMatcher unscheduled execution never happens).
178  const std::shared_ptr< const edm::Wrapper<T> > productWrapper = edm::getProductByTag<T>(event,tag,nullptr);
179  if (productWrapper) {
180  return productWrapper->product();
181  } else {
182  return NULL;
183  }
184  }
185 
187  {
188  return ( (this->eventId_<rhs.eventId_) ? true : ( ((this->eventId_==rhs.eventId_) && (this->apvAddress_<rhs.apvAddress_)) ? true : false) );
189  }
190 
191 }
192 
193 #endif //ndef DQM_SiStripMonitorHardware_SiStripSpyEventMatcher_H
194 
195 #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
std::shared_ptr< edm::ProductRegistry > productRegistry_
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
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)
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_