00001 #ifndef ATLFAST_ASSOCTYPERECOVERER_H
00002 #define ATLFAST_ASSOCTYPERECOVERER_H
00003
00004 #ifndef ATLFAST_IASSOCIATIONMANAGER_H
00005 #include "AtlfastEvent/IAssociationManager.h"
00006 #endif
00007
00008 #ifndef ATLFAST_COLLECTIONDEFS_H
00009 #include "AtlfastEvent/CollectionDefs.h"
00010 #endif
00011
00012
00013 #ifndef STD_VECTOR_H
00014 #include <vector>
00015 #define STD_VECTOR_H
00016 #endif
00017
00018 #ifndef STOREGATE_DATAPTR_H
00019 #include "DataModel/DataPtr.h"
00020 #define STOREGATE_DATAPTR_H
00021 #endif
00022
00023 #include<typeinfo>
00024
00025 namespace Atlfast{
00026
00027 template<class T>
00028 class AssocTypeRecoverer {
00029
00030 public:
00031
00032 AssocTypeRecoverer(const T&);
00033 AssocTypeRecoverer(const T*);
00034 AssocTypeRecoverer(const DataVector<T>& t);
00035
00036 ~AssocTypeRecoverer(){delete m_am;}
00037
00038 ITwoCptCellCollection* cells();
00039 ClusterCollection* clusters();
00040 JetCollection* jets();
00041 ReconstructedParticleCollection* reconstructedParticles();
00042 SimpleKinematicCollection* simpleKinematics();
00043 TrackCollection* tracks();
00044 IKinematicCollection* allAsIKinematics();
00045 std::vector<IKinematic*>* vectorOfIKinematics();
00046 private:
00047 IAssociationManager* m_am;
00048 };
00049 template<class T> class NoConst{
00050 public:
00051 T* operator()(const T* t){return const_cast<T*>(t);}
00052 };
00054 class Associator{
00055 public:
00056 Associator(IAssociationManager* iam):m_iam(iam){}
00057 template<class T>
00058 void operator()(T* t){
00059 IAssociationManager* ia = t;
00060 std::vector<const IAssociationManager*>::iterator iter = ia->begin();
00061 for(; iter!=ia->end(); ++iter) {
00062 m_iam->associate(*iter);
00063 }
00064 }
00065 template<class T>
00066 void operator()(DataPtr<T> t){
00067 T* tPtr = t;
00068 IAssociationManager* ia = tPtr;
00069 std::vector<const IAssociationManager*>::iterator iter = ia->begin();
00070 for(; iter!=ia->end(); ++iter) {
00071 m_iam->associate(*iter);
00072 }
00073 }
00074 private:
00075 IAssociationManager* m_iam;
00076 };
00077
00079 template<class T>
00080 inline
00081 AssocTypeRecoverer<T>::AssocTypeRecoverer(const DataVector<T>& t){
00082 m_am = new SimpleKinematic;
00083 std::for_each(t.begin(), t.end(), Associator(m_am) );
00084 }
00086 template<class T>
00087 inline
00088 AssocTypeRecoverer<T>::AssocTypeRecoverer(const T& t){
00089 m_am = new SimpleKinematic;
00090 std::for_each(t.begin(), t.end(), Associator(m_am) );
00091 }
00093 template<class T>
00094 inline
00095 AssocTypeRecoverer<T>::AssocTypeRecoverer(const T* t){
00096 m_am = new SimpleKinematic;
00097 std::for_each(t->begin(), t->end(), Associator(m_am) );
00098 }
00100 template<class T>
00101 inline
00102 ITwoCptCellCollection* AssocTypeRecoverer<T>::cells(){
00103 SimpleKinematic y;
00104 TwoCptCell x;
00105 std::vector<const TwoCptCell*> temp = m_am->associations(x);
00106 ITwoCptCellCollection* collection = new ITwoCptCellCollection;
00107 std::transform(
00108 temp.begin(), temp.end(), std::back_inserter(*collection),
00109 NoConst<TwoCptCell>()
00110 );
00111
00112 return collection;
00113 }
00115 template<class T>
00116 inline
00117 ClusterCollection* AssocTypeRecoverer<T>::clusters(){
00118 Cluster x;
00119 std::vector<const Cluster*> temp = m_am->associations(x);
00120
00121 ClusterCollection* collection = new ClusterCollection;
00122 std::transform(
00123 temp.begin(), temp.end(), std::back_inserter(*collection),
00124 NoConst<Cluster>()
00125 );
00126
00127 return collection;
00128 }
00130 template<class T>
00131 inline
00132 JetCollection* AssocTypeRecoverer<T>::jets(){
00133 Jet x;
00134 std::vector<const Jet*> temp = m_am->associations(x);
00135
00136 JetCollection* collection = new JetCollection;
00137 std::transform(
00138 temp.begin(), temp.end(), std::back_inserter(*collection),
00139 NoConst<Jet>()
00140 );
00141
00142 return collection;
00143 }
00145 template<class T>
00146 inline
00147 ReconstructedParticleCollection*
00148 AssocTypeRecoverer<T>::reconstructedParticles(){
00149 ReconstructedParticle x;
00150 std::vector<const ReconstructedParticle*> temp = m_am->associations(x);
00151
00152 ReconstructedParticleCollection* collection =
00153 new ReconstructedParticleCollection;
00154 std::transform(
00155 temp.begin(), temp.end(), std::back_inserter(*collection),
00156 NoConst<ReconstructedParticle>()
00157 );
00158
00159 return collection;
00160 }
00162 template<class T>
00163 inline
00164 SimpleKinematicCollection* AssocTypeRecoverer<T>::simpleKinematics(){
00165 SimpleKinematic x;
00166 std::vector<const SimpleKinematic*> temp = m_am->associations(x);
00167
00168 SimpleKinematicCollection* collection = new SimpleKinematicCollection;
00169 std::transform(
00170 temp.begin(), temp.end(), std::back_inserter(*collection),
00171 NoConst<SimpleKinematic>()
00172 );
00173
00174 return collection;
00175 }
00177 template<class T>
00178 inline
00179 TrackCollection* AssocTypeRecoverer<T>::tracks(){
00180 Track x;
00181 std::vector<const Track*> temp = m_am->associations(x);
00182
00183 TrackCollection* collection = new TrackCollection;
00184 std::transform(
00185 temp.begin(), temp.end(), std::back_inserter(*collection),
00186 NoConst<Track>()
00187 );
00188
00189 return collection;
00190 }
00192 template<class T>
00193 inline
00194 IKinematicCollection* AssocTypeRecoverer<T>::allAsIKinematics(){
00195 std::vector<const IKinematic*> temp = m_am->ikinematics();
00196
00197 IKinematicCollection* collection = new IKinematicCollection;
00198
00199 std::transform(
00200 temp.begin(), temp.end(), std::back_inserter(*collection),
00201 NoConst<IKinematic>()
00202 );
00203
00204 return collection;
00205 }
00207 template<class T>
00208 inline
00209 std::vector<IKinematic*>* AssocTypeRecoverer<T>::vectorOfIKinematics(){
00210 std::vector<const IKinematic*> temp = m_am->ikinematics();
00211
00212 std::vector<IKinematic*>* collection = new std::vector<IKinematic*>;
00213
00214 std::transform(
00215 temp.begin(), temp.end(), std::back_inserter(*collection),
00216 NoConst<IKinematic>()
00217 );
00218
00219 return collection;
00220 }
00221 }
00222
00223 #endif
00224
00225
00226
00227
00228