Go to the documentation of this file.00001 #include <memory>
00002
00003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00004 #include "Alignment/ReferenceTrajectories/interface/TrajectoryFactoryPlugin.h"
00005
00006 #include <TString.h>
00007 #include <TObjArray.h>
00008
00009 #include "Alignment/ReferenceTrajectories/interface/TrajectoryFactoryBase.h"
00010
00023
00024
00025 class CombinedTrajectoryFactory : public TrajectoryFactoryBase
00026 {
00027
00028 public:
00029
00030 CombinedTrajectoryFactory(const edm::ParameterSet &config);
00031 virtual ~CombinedTrajectoryFactory();
00032
00033 virtual const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup,
00034 const ConstTrajTrackPairCollection &tracks,
00035 const reco::BeamSpot &beamSpot) const;
00036
00037 virtual const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup,
00038 const ConstTrajTrackPairCollection &tracks,
00039 const ExternalPredictionCollection &external,
00040 const reco::BeamSpot &beamSpot) const;
00041
00042 virtual CombinedTrajectoryFactory* clone() const { return new CombinedTrajectoryFactory(*this); }
00043
00044 private:
00045
00046 std::vector<TrajectoryFactoryBase*> theFactories;
00047 bool theUseAllFactories;
00048 };
00049
00053
00054 using namespace std;
00055
00056 CombinedTrajectoryFactory::CombinedTrajectoryFactory( const edm::ParameterSet & config ) :
00057 TrajectoryFactoryBase( config ), theUseAllFactories(config.getParameter<bool>("useAllFactories"))
00058 {
00059 vector<string> factoryNames = config.getParameter< vector<string> >( "TrajectoryFactoryNames" );
00060 vector<string>::iterator itFactoryName;
00061 for ( itFactoryName = factoryNames.begin(); itFactoryName != factoryNames.end(); ++itFactoryName )
00062 {
00063
00064 std::auto_ptr<TObjArray> namePset(TString((*itFactoryName).c_str()).Tokenize(","));
00065 if (namePset->GetEntriesFast() != 2) {
00066 throw cms::Exception("BadConfig") << "@SUB=CombinedTrajectoryFactory"
00067 << "TrajectoryFactoryNames must contain 2 comma "
00068 << "separated strings, but is '" << *itFactoryName << "'";
00069 }
00070 const edm::ParameterSet factoryCfg
00071 = config.getParameter<edm::ParameterSet>(namePset->At(1)->GetName());
00072 theFactories.push_back(TrajectoryFactoryPlugin::get()->create(namePset->At(0)->GetName(),
00073 factoryCfg));
00074 }
00075 }
00076
00077
00078 CombinedTrajectoryFactory::~CombinedTrajectoryFactory( void ) {}
00079
00080
00081 const CombinedTrajectoryFactory::ReferenceTrajectoryCollection
00082 CombinedTrajectoryFactory::trajectories(const edm::EventSetup &setup,
00083 const ConstTrajTrackPairCollection &tracks,
00084 const reco::BeamSpot &beamSpot) const
00085 {
00086 ReferenceTrajectoryCollection trajectories;
00087 ReferenceTrajectoryCollection tmpTrajectories;
00088
00089 vector< TrajectoryFactoryBase* >::const_iterator itFactory;
00090 for ( itFactory = theFactories.begin(); itFactory != theFactories.end(); ++itFactory )
00091 {
00092 tmpTrajectories = ( *itFactory )->trajectories(setup, tracks, beamSpot);
00093 trajectories.insert(trajectories.end(), tmpTrajectories.begin(), tmpTrajectories.end());
00094
00095 if (!theUseAllFactories && !trajectories.empty()) break;
00096 }
00097
00098 return trajectories;
00099 }
00100
00101 const CombinedTrajectoryFactory::ReferenceTrajectoryCollection
00102 CombinedTrajectoryFactory::trajectories(const edm::EventSetup &setup,
00103 const ConstTrajTrackPairCollection &tracks,
00104 const ExternalPredictionCollection &external,
00105 const reco::BeamSpot &beamSpot) const
00106 {
00107 ReferenceTrajectoryCollection trajectories;
00108 ReferenceTrajectoryCollection tmpTrajectories;
00109
00110 vector< TrajectoryFactoryBase* >::const_iterator itFactory;
00111 for ( itFactory = theFactories.begin(); itFactory != theFactories.end(); ++itFactory )
00112 {
00113 tmpTrajectories = ( *itFactory )->trajectories(setup, tracks, external, beamSpot);
00114 trajectories.insert(trajectories.end(), tmpTrajectories.begin(), tmpTrajectories.end());
00115
00116 if (!theUseAllFactories && !trajectories.empty()) break;
00117 }
00118
00119 return trajectories;
00120 }
00121
00122
00123 DEFINE_EDM_PLUGIN( TrajectoryFactoryPlugin, CombinedTrajectoryFactory, "CombinedTrajectoryFactory" );