/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/lcio/src/cpp/src/IMPL/LCCollectionVec.cc

Go to the documentation of this file.
00001 
00002 #include "IMPL/LCCollectionVec.h"
00003 #include "EVENT/LCIO.h"
00004 #include <iostream>
00005 
00006 // #include "UTIL/LCTOOLS.h"
00007 
00008 using namespace EVENT ;
00009 
00010 namespace IMPL {
00011 
00012 //     std::string _typeName ;
00013 //     int _flag ;
00014 
00015 
00016 LCCollectionVec::LCCollectionVec( const std::string& type ) :
00017   _typeName( type ),
00018   _flag(0){ 
00019   //,
00020   // _access(LCIO::UPDATE ) {
00021 
00022 }
00023   
00024 // LCCollectionVec::LCCollectionVec( const EVENT::LCCollection& col ) :
00025 //   _typeName( col.getTypeName() ),
00026 //   _flag( col.getFlag() ),
00027 //   _access( col._access ) {
00028 
00029 //   // deep copy of all elements  - requires clone of original elements
00030 //   //
00031 //   int nElements = col.getNumberOfElements() ;
00032 
00033 //   for(int i=0; i< nElements ; i++){
00034 //     push_back(  col.getElementAt( i )->clone() ) ;
00035 //   }
00036 
00037 // }
00038 
00039   // overwrite the default implementation
00040   // set flag in all elements
00041   void LCCollectionVec::setReadOnly(bool readOnly){
00042 
00043     AccessChecked::setReadOnly(readOnly ) ;
00044 
00045     LCObjectVec::iterator iter = begin() ;
00046     while( iter != end() ){
00047       AccessChecked* element = dynamic_cast<AccessChecked*>(*iter++) ;
00048       if(element){
00049         element->setReadOnly( readOnly ) ;
00050       }
00051     }
00052   }
00053 
00054 LCCollectionVec::~LCCollectionVec() {
00055 
00056   if( ! isSubset() ){
00057     // delete all elements
00058     LCObjectVec::const_iterator iter = begin() ;
00059     //    std::cout << "deleting collection " 
00060     //              << std::endl ;
00061     //    UTIL::LCTOOLS::printParameters( parameters() )  ;
00062     
00063     while( iter != end() ){
00064       delete *iter++ ;
00065     }
00066   }
00067 }
00068 
00069 
00070 int LCCollectionVec::getNumberOfElements() const{
00071   return size() ;
00072 }
00073 
00074 
00075 const std::string & LCCollectionVec::getTypeName() const{
00076   return _typeName ;
00077 }
00078 
00079 
00080 
00081 EVENT::LCObject * LCCollectionVec::getElementAt(int index) const{
00082   return this->operator[](index) ;
00083 }
00084 
00085 bool LCCollectionVec::isTransient() const { 
00086   return (_flag & (1<<BITTransient) ) ; 
00087 }
00088 
00089 void LCCollectionVec::setTransient(bool val) {
00090   if(val) _flag |= (1<<BITTransient) ;
00091   else _flag &= ~(1<<BITTransient) ;
00092 }
00093 
00094 
00095 bool LCCollectionVec::isDefault() const { 
00096   return (_flag & (1<<BITDefault) ) ; 
00097 }
00098 
00099 void LCCollectionVec::setDefault(bool val) {
00100   if(val) _flag |= (1<<BITDefault) ;
00101   else _flag &= ~(1<<BITDefault) ;
00102 }
00103 
00104 bool LCCollectionVec::isSubset() const { 
00105   return (_flag & (1<<BITSubset) ) ; 
00106 }
00107 
00108 void LCCollectionVec::setSubset(bool val) {
00109   if(val) _flag |= (1<<BITSubset) ;
00110   else _flag &= ~(1<<BITSubset) ;
00111 }
00112 
00113 
00114 int LCCollectionVec::getFlag() const{
00115   return _flag ;
00116 }
00117 
00118 
00119 void LCCollectionVec::setFlag(int flag){
00120   _flag  = flag ;
00121 }
00122 
00123 
00124   void LCCollectionVec::addElement(EVENT::LCObject * obj) throw (ReadOnlyException){
00125     
00126     //    if(_access != LCIO::UPDATE )
00127     //  throw ReadOnlyException("LCCollectionVec::addElement:  event is read only") ;
00128     checkAccess("LCCollectionVec::addElement") ;
00129     this->push_back( obj ) ; 
00130   }
00131 
00132   void LCCollectionVec::removeElementAt(int i) throw (EVENT::ReadOnlyException){
00133     
00134     //    if(_access != LCIO::UPDATE )
00135     //  throw ReadOnlyException("LCCollectionVec::addElement:  event is read only") ;
00136     checkAccess("LCCollectionVec::removeElementAt") ;
00137     this->erase( begin() + i ) ;
00138 
00139   }
00140 
00141 } // namespace IMPL
00142 

Generated on Mon Jan 7 13:15:21 2013 for MicromegasFramework by  doxygen 1.4.7