PseudoJetPlusInfo.hh

00001 //STARTHEADER
00002 // $Id: PseudoJetPlusInfo.hh 1885 2011-01-27 14:50:21Z salam $
00003 //
00004 // Copyright (c) 2005-2010, Matteo Cacciari, Gavin Salam and Gregory Soyez
00005 //
00006 //----------------------------------------------------------------------
00007 // This file is part of FastJet.
00008 //
00009 //  FastJet is free software; you can redistribute it and/or modify
00010 //  it under the terms of the GNU General Public License as published by
00011 //  the Free Software Foundation; either version 2 of the License, or
00012 //  (at your option) any later version.
00013 //
00014 //  The algorithms that underlie FastJet have required considerable
00015 //  development and are described in hep-ph/0512210. If you use
00016 //  FastJet as part of work towards a scientific publication, please
00017 //  include a citation to the FastJet paper.
00018 //
00019 //  FastJet is distributed in the hope that it will be useful,
00020 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022 //  GNU General Public License for more details.
00023 //
00024 //  You should have received a copy of the GNU General Public License
00025 //  along with FastJet; if not, write to the Free Software
00026 //  Foundation, Inc.:
00027 //      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028 //----------------------------------------------------------------------
00029 //ENDHEADER
00030 
00031 #ifndef __PSEUDOJET_PLUS_INFO_HH__
00032 #define __PSEUDOJET_PLUS_INFO_HH__
00033 
00034 #include "fastjet/internal/numconsts.hh"
00035 #include "fastjet/PseudoJet.hh"
00036 #include <vector>
00037 
00038 FASTJET_BEGIN_NAMESPACE
00039 
00040 //-----------------------------------------------
00055 //-----------------------------------------------
00056 template<typename TExtraInfo>
00057 class PseudoJetPlusInfo : public PseudoJet{
00058 public:
00062   PseudoJetPlusInfo(const PseudoJet &pj, const TExtraInfo &ei) : PseudoJet(pj){
00063     const ExtraInfo * extra_info_ptr = extra_info();
00064     if (!extra_info_ptr) {
00065       extra_info_shared().reset(new TExtraInfo(ei));
00066     } else if (dynamic_cast<const TExtraInfo*>(extra_info_ptr)) {
00067       // then this is already a valid PseudoJetPlusInfo
00068       // don't do anything
00069     } else {
00070       // we already have an info but of wrong type!
00071       throw ("invalid extra_info for initialising PseudoJetPlusInfo");
00072     }
00073   }
00074 
00079   PseudoJetPlusInfo(const PseudoJet &pj) : PseudoJet(pj){
00080     const ExtraInfo * extra_info_ptr = pj.extra_info();
00081     if (extra_info_ptr) {
00082       if (dynamic_cast<const TExtraInfo*>(extra_info_ptr)) {
00083         extra_info_shared().reset(pj.extra_info_shared());
00084       } else {
00085         throw("invalid extra_info in copy constructor for PseudoJetPlusInfo");
00086       }
00087     }
00088   }
00089 
00090 
00092   const TExtraInfo* extra_info() const{
00093     if (!extra_info_shared()()) return NULL;
00094     return dynamic_cast<TExtraInfo*>(extra_info_shared().get());
00095   }
00096 };
00097 
00098 
00103 template<typename T, typename U>
00104 std::vector<T> convert_vector_to(const std::vector<U> & in){
00105   std::vector<T> res;
00106   copy(in.begin(), in.end(), back_inserter(res));
00107   return res;
00108 }
00109 
00110 
00111 
00112 
00113 FASTJET_END_NAMESPACE
00114 
00115 #endif  // __PSEUDOJET_PLUS_INFO_HH__