CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/SimGeneral/MixingModule/interface/PileUpEventPrincipal.h

Go to the documentation of this file.
00001 #ifndef SimGeneral_MixingModule_PileUpEventPrincipal_h
00002 #define SimGeneral_MixingModule_PileUpEventPrincipal_h
00003 
00004 #include <set>
00005 #include <string>
00006 
00007 #include "FWCore/Framework/interface/EventPrincipal.h"
00008 #include "FWCore/Utilities/interface/InputTag.h"
00009 #include "FWCore/Utilities/interface/TypeID.h"
00010 #include "DataFormats/Common/interface/BasicHandle.h"
00011 #include "DataFormats/Common/interface/ConvertHandle.h"
00012 #include "SimDataFormats/EncodedEventId/interface/EncodedEventId.h"
00013 class PCaloHit;
00014 class PSimHit;
00015 class SimTrack;
00016 class SimVertex;
00017 
00018 class PileUpEventPrincipal {
00019 public:
00020 
00021   PileUpEventPrincipal(edm::EventPrincipal const& ep, int bcr, int bsp, int eventId, int vtxOffset) :
00022     principal_(ep), bunchCrossing_(bcr), bunchCrossingXbunchSpace_(bcr*bsp), id_(bcr, eventId), vertexOffset_(vtxOffset), labels_() {}
00023 
00024   bool
00025   addLabel(edm::TypeID const& type, std::string const& label) const {
00026     return true;
00027     //return labels_.insert(std::make_pair(type, label)).second;
00028   }
00029 
00030   edm::EventPrincipal const& principal() {
00031     return principal_;
00032   }
00033 
00034   edm::EventPrincipal const& principal() const {
00035     return principal_;
00036   }
00037 
00038   int bunchCrossing() const {
00039     return bunchCrossing_;
00040   }
00041 
00042   template<typename T>
00043   void
00044   adjust(T& item) const {
00045   }
00046 
00047   template<typename T>
00048   bool
00049   getByLabel(edm::InputTag const& tag, edm::Handle<T>& result) const {
00050     typedef typename T::value_type ItemType;
00051     typedef typename T::iterator iterator;
00052     edm::BasicHandle bh = principal_.getByLabel(edm::TypeID(typeid(T)), tag.label(), tag.instance(), tag.process(), tag.cachedOffset(), tag.fillCount());
00053     convert_handle(bh, result);
00054     if(result.isValid() && addLabel(edm::TypeID(typeid(T)), tag.label())) {
00055       T& product = const_cast<T&>(*result.product());
00056       for(iterator i = product.begin(), iEnd = product.end(); i != iEnd; ++i) {
00057         adjust<ItemType>(*i);
00058       }
00059     }
00060     return result.isValid();
00061   }
00062 
00063 private: 
00064   edm::EventPrincipal const& principal_;
00065   int bunchCrossing_;
00066   int bunchCrossingXbunchSpace_;
00067   EncodedEventId id_;
00068   int vertexOffset_;
00069   mutable std::set<std::pair<edm::TypeID, std::string> > labels_;
00070 };
00071 
00072 template<>
00073 void PileUpEventPrincipal::adjust<PCaloHit>(PCaloHit& item) const;
00074 
00075 template<>
00076 void PileUpEventPrincipal::adjust<PSimHit>(PSimHit& item) const;
00077 
00078 template<>
00079 void PileUpEventPrincipal::adjust<SimTrack>(SimTrack& item) const;
00080 
00081 template<>
00082 void PileUpEventPrincipal::adjust<SimVertex>(SimVertex& item) const;
00083 #endif