CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQM/SiStripMonitorHardware/interface/SiStripSpyEventMatcher.h

Go to the documentation of this file.
00001 #define SiStripMonitorHardware_BuildEventMatchingCode
00002 #ifdef SiStripMonitorHardware_BuildEventMatchingCode
00003 
00004 #ifndef DQM_SiStripMonitorHardware_SiStripSpyEventMatcher_H
00005 #define DQM_SiStripMonitorHardware_SiStripSpyEventMatcher_H
00006 
00007 #include "FWCore/Utilities/interface/InputTag.h"
00008 #include "FWCore/Sources/interface/VectorInputSource.h"
00009 #include "FWCore/Framework/interface/EventPrincipal.h"
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011 #include "boost/cstdint.hpp"
00012 #include <set>
00013 #include <map>
00014 #include <memory>
00015 #include <vector>
00016 
00017 //forward declarations
00018 class FEDRawDataCollection;
00019 class SiStripRawDigi;
00020 namespace edm {
00021   template<class T> class DetSetVector;
00022   template<class T> class DetSet;
00023   class EventID;
00024   class ParameterSet;
00025 }
00026 class SiStripFedCabling;
00027 
00028 namespace sistrip {
00029   
00030   class SpyEventMatcher
00031   {
00032     public:
00033       class SpyDataCollections
00034       {
00035         public:
00036         std::auto_ptr< FEDRawDataCollection > rawData;
00037         std::auto_ptr< std::vector<uint32_t> > totalEventCounters;
00038         std::auto_ptr< std::vector<uint32_t> > l1aCounters;
00039         std::auto_ptr< std::vector<uint32_t> > apvAddresses;
00040         std::auto_ptr< edm::DetSetVector<SiStripRawDigi> > scopeDigis;
00041         std::auto_ptr< edm::DetSetVector<SiStripRawDigi> > payloadDigis;
00042         std::auto_ptr< edm::DetSetVector<SiStripRawDigi> > reorderedDigis;
00043         std::auto_ptr< edm::DetSetVector<SiStripRawDigi> > virginRawDigis;
00044         SpyDataCollections();
00045         //NB. This will remove all elements in the containers pasted in. It does not copy the data. 
00046         SpyDataCollections(FEDRawDataCollection& theRawData,
00047                            std::vector<uint32_t>& theTotalEventCounters,
00048                            std::vector<uint32_t>& theL1ACounters,
00049                            std::vector<uint32_t>& theAPVAddresses,
00050                            std::vector< edm::DetSet<SiStripRawDigi> >* theScopeDigisVector,
00051                            std::vector< edm::DetSet<SiStripRawDigi> >* thePayloadDigisVector,
00052                            std::vector< edm::DetSet<SiStripRawDigi> >* theReorderedDigisVector,
00053                            std::vector< edm::DetSet<SiStripRawDigi> >* theVirginRawDigisVector);
00054         //does not copy, orginal object looses ownership of collections
00055         SpyDataCollections& operator = (SpyDataCollections original);
00056       };
00057       typedef edm::EventID EventID;
00058       typedef std::set<EventID> SpyEventList;
00059       
00060       SpyEventMatcher(const edm::ParameterSet& config);
00061       virtual ~SpyEventMatcher();
00062       //set up the internal map of eventID, to apvAddress
00063       void initialize();
00064       //check if there is any data for an event. Returns NULL if not or a pointer to a list of matches if they exist
00065       const SpyEventList* matchesForEvent(const uint32_t eventId, const uint8_t apvAddress) const;
00066       //get data for matching FEDs (non-const because reading events from the source modifies it)
00067       void getMatchedCollections(const uint32_t eventId, const uint8_t apvAddress, const SpyEventList* matchingEvents,
00068                                  const SiStripFedCabling& cabling, SpyDataCollections& collectionsToCreate);
00069     private:
00070       class EventKey
00071       {
00072         public:
00073           EventKey(const uint32_t eventId, const uint8_t apvAddress);
00074           uint32_t eventId() const { return eventId_; }
00075           uint8_t apvAddress() const { return apvAddress_; }
00076           bool operator < (const EventKey& rhs) const;
00077         private:
00078           uint32_t eventId_;
00079           uint8_t  apvAddress_;
00080       };
00081       typedef std::vector<uint32_t> Counters;
00082       //class to wrap counters that can take ownership of them or not.
00083       //It behaves like the counters themself but, it actualy holds a pointer to them and dletes them if necessary
00084       class CountersWrapper
00085       {
00086         public:
00087           CountersWrapper(const Counters* theCounters);
00088           CountersWrapper(Counters* theCounters, const bool takeOwnership);
00089           ~CountersWrapper();
00090           const Counters::value_type operator [] (const size_t i) const { return (*pConst)[i]; };
00091           const Counters::value_type at(const size_t i) const { return pConst->at(i); };
00092           Counters::const_iterator begin() const { return pConst->begin(); }
00093           Counters::const_iterator end() const { return pConst->end(); }
00094         private:
00095           const Counters* pConst;
00096           Counters* p;
00097           bool deleteP;
00098       };
00099       typedef boost::shared_ptr<CountersWrapper> CountersPtr;
00100       
00101       //source for spy events
00102       typedef edm::VectorInputSource Source;
00103       //reference counted pointer to an event
00104       typedef Source::EventPrincipalVectorElement SpyEventPtr;
00105             
00106       static std::auto_ptr<Source> constructSource(const edm::ParameterSet& sourceConfig);
00107       bool addNextEventToMap();
00108       template <class T> static const T* getProduct(const SpyEventPtr event, const edm::InputTag& tag);
00109       static CountersPtr getCounters(const SpyEventPtr event, const edm::InputTag& tag, const bool mapKeyIsByFedID = true);
00110       SpyEventPtr readNextEvent();
00111       SpyEventPtr readSpecificEvent(const edm::EventID& id);
00112       static void findMatchingFeds(const uint32_t eventId, const uint8_t apvAddress,
00113                                    CountersPtr totalEventCounters,
00114                                    CountersPtr l1aCounters,
00115                                    CountersPtr apvAddresses,
00116                                    std::set<uint16_t>& matchingFeds);
00117       static void mergeMatchingData(const std::set<uint16_t>& matchingFeds,
00118                                     const FEDRawDataCollection& inputRawData,
00119                                     CountersPtr inputTotalEventCounters,
00120                                     CountersPtr inputL1ACounters,
00121                                     CountersPtr inputAPVAddresses,
00122                                     const edm::DetSetVector<SiStripRawDigi>* inputScopeDigis,
00123                                     const edm::DetSetVector<SiStripRawDigi>* inputPayloadDigis,
00124                                     const edm::DetSetVector<SiStripRawDigi>* inputReorderedDigis,
00125                                     const edm::DetSetVector<SiStripRawDigi>* inputVirginRawDigis,
00126                                     FEDRawDataCollection& outputRawData,
00127                                     std::vector<uint32_t>& outputTotalEventCounters,
00128                                     std::vector<uint32_t>& outputL1ACounters,
00129                                     std::vector<uint32_t>& outputAPVAddresses,
00130                                     std::vector< edm::DetSet<SiStripRawDigi> >* outputScopeDigisVector,
00131                                     std::vector< edm::DetSet<SiStripRawDigi> >* outputPayloadDigisVector,
00132                                     std::vector< edm::DetSet<SiStripRawDigi> >* outputReorderedDigisVector,
00133                                     std::vector< edm::DetSet<SiStripRawDigi> >* outputVirginRawDigisVector,
00134                                     const SiStripFedCabling& cabling);
00135       
00136       std::map<EventKey,SpyEventList> eventMatches_;
00137       edm::InputTag rawDataTag_;
00138       edm::InputTag totalEventCountersTag_;
00139       edm::InputTag l1aCountersTag_;
00140       edm::InputTag apvAddressesTag_;
00141       edm::InputTag scopeDigisTag_;
00142       edm::InputTag payloadDigisTag_;
00143       edm::InputTag reorderedDigisTag_;
00144       edm::InputTag virginRawDigisTag_;
00145       std::auto_ptr<Source> source_;
00146       uint32_t counterDiffMax_;
00147       static const char* mlLabel_;
00148   };
00149   
00150   template <class T> const T* SpyEventMatcher::getProduct(const SpyEventPtr event, const edm::InputTag& tag)
00151   {
00152     LogDebug(mlLabel_) << "Retrieving product " << tag;
00153     const boost::shared_ptr< const edm::Wrapper<T> > productWrapper = edm::getProductByTag<T>(*event,tag);
00154     if (productWrapper) {
00155       return productWrapper->product();
00156     } else {
00157       return NULL;
00158     }
00159   }
00160   
00161   inline bool SpyEventMatcher::EventKey::operator < (const SpyEventMatcher::EventKey& rhs) const
00162   {
00163     return ( (this->eventId_<rhs.eventId_) ? true : ( ((this->eventId_==rhs.eventId_) && (this->apvAddress_<rhs.apvAddress_)) ? true : false) );
00164   }
00165   
00166 }
00167 
00168 #endif //ndef DQM_SiStripMonitorHardware_SiStripSpyEventMatcher_H
00169 
00170 #endif //SiStripMonitorHardware_BuildEventMatchingCode