CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/SLHCUpgradeSimulations/L1CaloTrigger/interface/L1CaloAlgoBase.h

Go to the documentation of this file.
00001 #ifndef L1CaloAlgoBase_h
00002 #define L1CaloAlgoBase_h
00003 
00004 // system include files
00005 #include <memory>
00006 
00007 // user include files
00008 #include "FWCore/Framework/interface/Frameworkfwd.h"
00009 #include "FWCore/Framework/interface/EDProducer.h"
00010 #include "FWCore/Framework/interface/Event.h"
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012 #include "FWCore/Framework/interface/EventSetup.h"
00013 #include "FWCore/Framework/interface/MakerMacros.h"
00014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00015 #include "SimDataFormats/SLHC/interface/L1CaloTriggerSetup.h"
00016 #include "SimDataFormats/SLHC/interface/L1CaloTriggerSetupRcd.h"
00017 #include "FWCore/Framework/interface/ESHandle.h"
00018 
00019 
00020 #ifdef __GNUG__
00021 #include <cxxabi.h>
00022 #endif
00023 
00024 
00025 
00026 
00027 template < typename tInputCollection ,  typename tOutputCollection >
00028 class L1CaloAlgoBase: 
00029 public edm::EDProducer
00030 {
00031   public:
00032         explicit L1CaloAlgoBase( const edm::ParameterSet & );
00033         virtual ~L1CaloAlgoBase(  );
00034 
00035         virtual void initialize( ){}
00036 
00037         virtual void algorithm( const int &, const int & ) = 0;
00038 
00039         std::string sourceName() const;
00040 
00041   private:
00042         void produce( edm::Event &, const edm::EventSetup & );
00043 
00044         edm::InputTag mInputCollectionTag;
00045 
00046   protected:
00047         typename tInputCollection::const_iterator fetch( const int &, const int & );
00048 
00049         bool mVerbosity;
00050 
00051         int mPhiOffset, mEtaOffset, mPhiIncrement, mEtaIncrement;
00052 
00053         edm::ESHandle < L1CaloTriggerSetup >  mCaloTriggerSetup;
00054 
00055         edm::Handle < tInputCollection > mInputCollection;
00056         std::auto_ptr < tOutputCollection > mOutputCollection;
00057 };
00058 
00059 
00060 
00061 
00062 
00063 template < typename tInputCollection ,  typename tOutputCollection >
00064 L1CaloAlgoBase< tInputCollection ,  tOutputCollection >::L1CaloAlgoBase ( const edm::ParameterSet & iConfig ):
00065 mInputCollectionTag( iConfig.getParameter < edm::InputTag > ( "src" ) ),
00066 mVerbosity( iConfig.getUntrackedParameter < bool > ( "verbosity", false ) ), 
00067 mPhiOffset( 0 ), 
00068 mEtaOffset( 0 ), 
00069 mPhiIncrement( 1 ), 
00070 mEtaIncrement( 1 )
00071 {
00072         produces < tOutputCollection > (  );
00073 }
00074 
00075 
00076 template < typename tInputCollection ,  typename tOutputCollection >
00077 L1CaloAlgoBase< tInputCollection ,  tOutputCollection >::~L1CaloAlgoBase(  )
00078 {
00079 }
00080 
00081 template < typename tInputCollection ,  typename tOutputCollection >
00082 std::string L1CaloAlgoBase< tInputCollection ,  tOutputCollection >::sourceName() const
00083 {
00084         if( mInputCollectionTag.instance().size() )
00085         {
00086                 return std::string( mInputCollectionTag.label () + " - " + mInputCollectionTag.instance() );
00087         }else{
00088                 return std::string( mInputCollectionTag.label () );
00089         }
00090 }
00091 
00092 template < typename tInputCollection ,  typename tOutputCollection >
00093 typename tInputCollection::const_iterator L1CaloAlgoBase< tInputCollection ,  tOutputCollection >::fetch( const int &aEta, const int &aPhi ){
00094         int lIndex = mCaloTriggerSetup->getBin( aEta, aPhi );
00095         std::pair < int, int >lEtaPhi = mCaloTriggerSetup->getTowerEtaPhi( lIndex );
00096         return mInputCollection->find( lEtaPhi.first , lEtaPhi.second );
00097 }
00098 
00099 
00100 
00101 
00102 
00103 
00104 
00105 template < typename tInputCollection ,  typename tOutputCollection >
00106 void L1CaloAlgoBase< tInputCollection ,  tOutputCollection >::produce( edm::Event & iEvent, const edm::EventSetup & iSetup )
00107 {
00108 
00109         iSetup.get < L1CaloTriggerSetupRcd > (  ).get( mCaloTriggerSetup );
00110         this->initialize();
00111 
00112         iEvent.getByLabel( mInputCollectionTag, mInputCollection );
00113 
00114         mOutputCollection = std::auto_ptr < tOutputCollection > ( new tOutputCollection );
00115 
00116 
00117         int lPhiMin = mCaloTriggerSetup->phiMin(  );
00118         int lPhiMax = mCaloTriggerSetup->phiMax(  ) + mPhiOffset;
00119         int lEtaMin = mCaloTriggerSetup->etaMin(  );
00120         int lEtaMax = mCaloTriggerSetup->etaMax(  ) + mEtaOffset;
00121 
00122         for ( int lEta = lEtaMin; lEta <= lEtaMax; lEta += mEtaIncrement )
00123         {
00124                 for ( int lPhi = lPhiMin; lPhi <= lPhiMax; lPhi += mPhiIncrement )
00125                 {
00126                         this->algorithm( lEta, lPhi );
00127                 }
00128         }
00129 
00130 
00131 #ifdef __GNUG__
00132         if( mVerbosity )
00133         {
00134                 int lStatus=0;
00135                 std::cout << "Algorithm "
00136                                 << abi::__cxa_demangle(typeid(*this).name(), 0,0, &lStatus)
00137                                 << " converted " 
00138                                 << mInputCollection->size()
00139                                 << " x "
00140                                 << abi::__cxa_demangle(typeid(typename tInputCollection::value_type).name(), 0,0, &lStatus)
00141                                 << " into "
00142                                 << mOutputCollection->size() 
00143                                 << " x " 
00144                                 << abi::__cxa_demangle(typeid(typename tOutputCollection::value_type).name(), 0,0, &lStatus)
00145                                 << std::endl;
00146         }
00147 #endif
00148 
00149         iEvent.put( mOutputCollection );
00150 
00151 }
00152 
00153 #endif