AssocTypeConverter.h

Go to the documentation of this file.
00001 #ifndef ATLFAST_ASSOCTYPECONVERTER_H
00002 #define ATLFAST_ASSOCTYPECONVERTER_H
00003 
00004 #ifndef ATLFAST_IASSOCIATIONMANAGER_H
00005 #include "AtlfastEvent/IAOO.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 
00032   template<class T> 
00033   class AssocTypeConverter {
00034     
00035   public:
00036     
00038     AssocTypeConverter(const T&);
00040     AssocTypeConverter(const T*);
00042     AssocTypeConverter(const DataVector<T>& t);
00043 
00045     ~AssocTypeConverter(){delete m_am;}
00046     
00047     
00048     ITwoCptCellCollection*           cells();                   
00049     ClusterCollection*               clusters();                
00050     JetCollection*                   jets();                    
00051     ReconstructedParticleCollection* reconstructedParticles();  
00052     SimpleKinematicCollection*       simpleKinematics();        
00053     TrackCollection*                 tracks();                  
00054     IKinematicCollection*            allAsIKinematics();        
00055     std::vector<IKinematic*>*        vectorOfIKinematics();     
00056 
00057   private:
00058     IAOO*  m_am; 
00059   };
00060 
00062   template<class T> class NewNoConst{
00063   public:
00065     T* operator()(const T* t){return new T(*t);}
00066     //    T* operator()(const T* t){return const_cast<T*>(t);}
00067   };
00068 
00069 
00071 
00072   class Associator2{
00073   public:
00075     Associator2(IAOO* iam):m_iam(iam){}
00077     template<class T>
00078       void operator()(T* t){
00079       T* tPtr = t; 
00080       IAOO* ia = tPtr;
00081       m_iam->associate(ia);
00082     }
00084     template<class T>
00085       void operator()(DataPtr<T> t){
00086       T* tPtr = t; 
00087       IAOO* ia = tPtr;
00088         m_iam->associate(ia);
00089     }
00090   private:
00091     IAOO* m_iam;  
00092   };
00094   template<class T>
00095     inline
00096     AssocTypeConverter<T>::AssocTypeConverter(const DataVector<T>& t){
00097     m_am = new SimpleKinematic;
00098     std::for_each(t.begin(), t.end(), Associator2(m_am) );     
00099   }
00101   template<class T>
00102     inline
00103     AssocTypeConverter<T>::AssocTypeConverter(const T& t){
00104     m_am = new SimpleKinematic;
00105     std::for_each(t.begin(), t.end(), Associator2(m_am) );     
00106   }
00108   template<class T>
00109     inline
00110     AssocTypeConverter<T>::AssocTypeConverter(const T* t){
00111     m_am = new SimpleKinematic;
00112     std::for_each(t->begin(), t->end(), Associator2(m_am) );     
00113   }
00115   template<class T>
00116     inline
00117     ITwoCptCellCollection* AssocTypeConverter<T>::cells(){ 
00118     SimpleKinematic y;
00119     TwoCptCell x;
00120     std::vector<const TwoCptCell*> temp = m_am->associations(x);
00121     ITwoCptCellCollection* collection = new ITwoCptCellCollection;
00122     std::transform(
00123                    temp.begin(), temp.end(), std::back_inserter(*collection),
00124                    NewNoConst<TwoCptCell>()
00125                    );
00126     
00127     return collection;
00128   }
00130   template<class T>
00131     inline
00132     ClusterCollection* AssocTypeConverter<T>::clusters(){
00133     std::vector<const Cluster*> temp = m_am->associations(x);
00134 
00135     ClusterCollection* collection = new ClusterCollection;
00136     std::transform(
00137                    temp.begin(), temp.end(), std::back_inserter(*collection),
00138                    NewNoConst<Cluster>()
00139                    );
00140 
00141     return collection;
00142   }
00144   template<class T>
00145     inline
00146     JetCollection* AssocTypeConverter<T>::jets(){
00147     Jet x;
00148     std::vector<const Jet*> temp = m_am->associations(x);
00149 
00150     JetCollection* collection = new JetCollection;
00151     std::transform(
00152                    temp.begin(), temp.end(), std::back_inserter(*collection),
00153                    NewNoConst<Jet>()
00154                    );
00155 
00156     return collection;
00157   }
00159   template<class T>
00160     inline
00161     ReconstructedParticleCollection*
00162     AssocTypeConverter<T>::reconstructedParticles(){
00163     ReconstructedParticle x;
00164     std::vector<const ReconstructedParticle*> temp = m_am->associations(x);
00165 
00166     ReconstructedParticleCollection* collection = 
00167       new ReconstructedParticleCollection;
00168     std::transform(
00169                    temp.begin(), temp.end(), std::back_inserter(*collection),
00170                    NewNoConst<ReconstructedParticle>()
00171                    );
00172 
00173     return collection;
00174   }
00176   template<class T>
00177     inline
00178     SimpleKinematicCollection* AssocTypeConverter<T>::simpleKinematics(){  
00179     SimpleKinematic x;
00180     std::vector<const SimpleKinematic*> temp = m_am->associations(x);
00181 
00182     SimpleKinematicCollection* collection = new SimpleKinematicCollection;
00183     std::transform(
00184                    temp.begin(), temp.end(), std::back_inserter(*collection),
00185                    NewNoConst<SimpleKinematic>()
00186                    );
00187 
00188     return collection;
00189   }
00191   template<class T>
00192     inline
00193     TrackCollection* AssocTypeConverter<T>::tracks(){  
00194     Track x;
00195     std::vector<const Track*> temp = m_am->associations(x);
00196 
00197     TrackCollection* collection = new TrackCollection;
00198     std::transform(
00199                    temp.begin(), temp.end(), std::back_inserter(*collection),
00200                    NewNoConst<Track>()
00201                    );
00202 
00203     return collection;
00204   }
00206   template<class T>
00207     inline
00208     IKinematicCollection* AssocTypeConverter<T>::allAsIKinematics(){  
00209     std::vector<const IKinematic*> temp = m_am->ikinematics();
00210 
00211     IKinematicCollection* collection = new IKinematicCollection;
00212     
00213     std::transform(
00214                    temp.begin(), temp.end(), std::back_inserter(*collection),
00215                    NewNoConst<IKinematic>()
00216                    );
00217 
00218     return collection;
00219   }
00221   template<class T>
00222     inline
00223     std::vector<IKinematic*>* AssocTypeConverter<T>::vectorOfIKinematics(){  
00224     std::vector<const IKinematic*> temp = m_am->ikinematics();
00225 
00226     std::vector<IKinematic*>* collection = new std::vector<IKinematic*>;
00227     
00228     std::transform(
00229                    temp.begin(), temp.end(), std::back_inserter(*collection),
00230                    NewNoConst<IKinematic>()
00231                    );
00232 
00233     return collection;
00234   }
00235 }//namespace
00236 
00237 #endif
00238 
00239 
00240 
00241 
00242 

Generated on Mon Sep 24 14:19:09 2007 for AtlfastAlgs by  doxygen 1.5.1