00001 #ifndef ATLFAST_ASSOCTYPECONVERTER_H
00002 #define ATLFAST_ASSOCTYPECONVERTER_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 DATAMODEL_DATAPTR_H
00019 #include "DataModel/DataPtr.h"
00020 #define DATAMODEL_DATAPTR_H
00021 #endif
00022
00023 #include<typeinfo>
00024 #include "AtlfastAlgs/AssocTypeRecoverer.h"
00025 namespace Atlfast{
00026
00027 template<class T>
00028 class AssocTypeConverter {
00029
00030 public:
00031
00032 AssocTypeConverter(const T&);
00033 AssocTypeConverter(const T*);
00034 AssocTypeConverter(const DataVector<T>& t);
00035
00036 ~AssocTypeConverter(){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 NewNoConst{
00050 public:
00051 T* operator()(const T* t){return new T(*t);}
00052
00053 };
00054
00055
00057 class Associator2{
00058 public:
00059 Associator2(IAssociationManager* iam):m_iam(iam){}
00060 template<class T>
00061 void operator()(T* t){
00062 T* tPtr = t;
00063 IAssociationManager* ia = tPtr;
00064 m_iam->associate(ia);
00065 }
00066 template<class T>
00067 void operator()(DataPtr<T> t){
00068 T* tPtr = t;
00069 IAssociationManager* ia = tPtr;
00070 m_iam->associate(ia);
00071 }
00072 private:
00073 IAssociationManager* m_iam;
00074 };
00076 template<class T>
00077 inline
00078 AssocTypeConverter<T>::AssocTypeConverter(const DataVector<T>& t){
00079 m_am = new SimpleKinematic;
00080 std::for_each(t.begin(), t.end(), Associator2(m_am) );
00081 }
00083 template<class T>
00084 inline
00085 AssocTypeConverter<T>::AssocTypeConverter(const T& t){
00086 m_am = new SimpleKinematic;
00087 std::for_each(t.begin(), t.end(), Associator2(m_am) );
00088 }
00090 template<class T>
00091 inline
00092 AssocTypeConverter<T>::AssocTypeConverter(const T* t){
00093 m_am = new SimpleKinematic;
00094 std::for_each(t->begin(), t->end(), Associator2(m_am) );
00095 }
00097 template<class T>
00098 inline
00099 ITwoCptCellCollection* AssocTypeConverter<T>::cells(){
00100 SimpleKinematic y;
00101 TwoCptCell x;
00102 std::vector<const TwoCptCell*> temp = m_am->associations(x);
00103 ITwoCptCellCollection* collection = new ITwoCptCellCollection;
00104 std::transform(
00105 temp.begin(), temp.end(), std::back_inserter(*collection),
00106 NewNoConst<TwoCptCell>()
00107 );
00108
00109 return collection;
00110 }
00112 template<class T>
00113 inline
00114 ClusterCollection* AssocTypeConverter<T>::clusters(){
00115 std::vector<const Cluster*> temp = m_am->associations(x);
00116
00117 ClusterCollection* collection = new ClusterCollection;
00118 std::transform(
00119 temp.begin(), temp.end(), std::back_inserter(*collection),
00120 NewNoConst<Cluster>()
00121 );
00122
00123 return collection;
00124 }
00126 template<class T>
00127 inline
00128 JetCollection* AssocTypeConverter<T>::jets(){
00129 Jet x;
00130 std::vector<const Jet*> temp = m_am->associations(x);
00131
00132 JetCollection* collection = new JetCollection;
00133 std::transform(
00134 temp.begin(), temp.end(), std::back_inserter(*collection),
00135 NewNoConst<Jet>()
00136 );
00137
00138 return collection;
00139 }
00141 template<class T>
00142 inline
00143 ReconstructedParticleCollection*
00144 AssocTypeConverter<T>::reconstructedParticles(){
00145 ReconstructedParticle x;
00146 std::vector<const ReconstructedParticle*> temp = m_am->associations(x);
00147
00148 ReconstructedParticleCollection* collection =
00149 new ReconstructedParticleCollection;
00150 std::transform(
00151 temp.begin(), temp.end(), std::back_inserter(*collection),
00152 NewNoConst<ReconstructedParticle>()
00153 );
00154
00155 return collection;
00156 }
00158 template<class T>
00159 inline
00160 SimpleKinematicCollection* AssocTypeConverter<T>::simpleKinematics(){
00161 SimpleKinematic x;
00162 std::vector<const SimpleKinematic*> temp = m_am->associations(x);
00163
00164 SimpleKinematicCollection* collection = new SimpleKinematicCollection;
00165 std::transform(
00166 temp.begin(), temp.end(), std::back_inserter(*collection),
00167 NewNoConst<SimpleKinematic>()
00168 );
00169
00170 return collection;
00171 }
00173 template<class T>
00174 inline
00175 TrackCollection* AssocTypeConverter<T>::tracks(){
00176 Track x;
00177 std::vector<const Track*> temp = m_am->associations(x);
00178
00179 TrackCollection* collection = new TrackCollection;
00180 std::transform(
00181 temp.begin(), temp.end(), std::back_inserter(*collection),
00182 NewNoConst<Track>()
00183 );
00184
00185 return collection;
00186 }
00188 template<class T>
00189 inline
00190 IKinematicCollection* AssocTypeConverter<T>::allAsIKinematics(){
00191 std::vector<const IKinematic*> temp = m_am->ikinematics();
00192
00193 IKinematicCollection* collection = new IKinematicCollection;
00194
00195 std::transform(
00196 temp.begin(), temp.end(), std::back_inserter(*collection),
00197 NewNoConst<IKinematic>()
00198 );
00199
00200 return collection;
00201 }
00203 template<class T>
00204 inline
00205 std::vector<IKinematic*>* AssocTypeConverter<T>::vectorOfIKinematics(){
00206 std::vector<const IKinematic*> temp = m_am->ikinematics();
00207
00208 std::vector<IKinematic*>* collection = new std::vector<IKinematic*>;
00209
00210 std::transform(
00211 temp.begin(), temp.end(), std::back_inserter(*collection),
00212 NewNoConst<IKinematic>()
00213 );
00214
00215 return collection;
00216 }
00217 }
00218
00219 #endif
00220
00221
00222
00223
00224