CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/SimGeneral/MixingModule/plugins/Adjuster.h

Go to the documentation of this file.
00001 #ifndef SimGeneral_MixingModule_Adjuster_h
00002 #define SimGeneral_MixingModule_Adjuster_h
00003 
00004 #include "DataFormats/Common/interface/Wrapper.h"
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "FWCore/Framework/interface/EventPrincipal.h"
00007 #include "FWCore/Utilities/interface/InputTag.h"
00008 #include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
00009 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00010 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00011 #include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
00012 
00013 #include "boost/shared_ptr.hpp"
00014 
00015 #include <vector>
00016 
00017 namespace edm {
00018   class AdjusterBase {
00019   public:
00020     virtual ~AdjusterBase() {}
00021     virtual void doOffset(int bunchspace, int bcr, const edm::EventPrincipal&, unsigned int EventNr, int vertexOffset) = 0;
00022     virtual bool checkSignal(edm::Event const& event) = 0;
00023   };
00024 
00025   template<typename T>
00026   class Adjuster : public AdjusterBase {
00027 
00028   public:
00029     Adjuster(InputTag const& tag);
00030 
00031     virtual ~Adjuster() {}
00032 
00033     virtual void doOffset(int bunchspace, int bcr, const edm::EventPrincipal&, unsigned int EventNr, int vertexOffset);
00034 
00035     virtual bool checkSignal(edm::Event const& event) {
00036       bool got = false;
00037       edm::Handle<std::vector<T> > result_t;
00038       got = event.getByLabel(tag_, result_t);
00039       return got;
00040     }
00041 
00042    private:
00043     InputTag tag_;
00044   };
00045 
00046   //==============================================================================
00047   //                              implementations
00048   //==============================================================================
00049 
00050   namespace detail {
00051     void doTheOffset(int bunchspace, int bcr, std::vector<SimTrack>& product, unsigned int eventNr, int vertexOffset);
00052     void doTheOffset(int bunchspace, int bcr, std::vector<SimVertex>& product, unsigned int eventNr, int vertexOffset);
00053     void doTheOffset(int bunchspace, int bcr, std::vector<PCaloHit>& product, unsigned int eventNr, int vertexOffset);
00054     void doTheOffset(int bunchspace, int bcr, std::vector<PSimHit>& product, unsigned int eventNr, int vertexOffset);
00055   }
00056 
00057   template<typename T>
00058   void  Adjuster<T>::doOffset(int bunchspace, int bcr, const EventPrincipal &ep, unsigned int eventNr, int vertexOffset) {
00059     boost::shared_ptr<Wrapper<std::vector<T> > const> shPtr = getProductByTag<std::vector<T> >(ep, tag_);
00060     if (shPtr) {
00061       std::vector<T>& product = const_cast<std::vector<T>&>(*shPtr->product());
00062       detail::doTheOffset(bunchspace, bcr, product, eventNr, vertexOffset);
00063     }
00064   }
00065 
00066   template<typename T>
00067   Adjuster<T>::Adjuster(InputTag const& tag) : tag_(tag) {
00068   }
00069 }
00070 
00071 #endif