00001 #ifndef LCTypedVector_h
00002 #define LCTypedVector_h 1
00003
00004 #include <vector>
00005
00006 #include "EVENT/LCObject.h"
00007 #include "EVENT/LCCollection.h"
00008 #include "Exceptions.h"
00009
00010 #include <sstream>
00011 #include <typeinfo>
00012
00013
00014 namespace UTIL{
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 template <class T>
00029 class LCTypedVector : public std::vector<T*> {
00030
00031 public:
00032
00033 LCTypedVector( EVENT::LCCollection* col ) : _col( col) {
00034
00035 resize( _col->getNumberOfElements() ) ;
00036
00037 for(int i=0;i<_col->getNumberOfElements();i++ ) {
00038
00039 (*this)[i] = dynamic_cast<T*>( col->getElementAt(i) ) ;
00040
00041
00042 if( i == 0 && (*this)[i] == 0 ){
00043
00044 std::stringstream str ;
00045 str << "LCTypedVector: cannot convert " << col->getTypeName() << " to "
00046 << typeid(T).name() ;
00047
00048 throw EVENT::Exception( str.str().c_str() ) ;
00049 }
00050 }
00051 }
00052
00053 EVENT::LCCollection* col() { return _col ; }
00054
00055 protected:
00056 EVENT::LCCollection* _col ;
00057 } ;
00058
00059 }
00060 #endif
00061
00062