Bdb packages | Design docs | Source docs | Guidelines | Recent releases

Search | Site Map .

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/CdbBdbWrapper/CdbBdbWConditionItr.cc

Go to the documentation of this file.
00001 /// The implementation of the CdbBdbWConditionItr class.
00002 /**
00003   * @see CdbBdbWConditionItr
00004   */
00005 
00006 #include "CdbBdbWrapper/CdbBdbWConditionItr.hh"
00007 
00008 #include "CdbBase/CdbFolder.hh"
00009 #include "CdbBase/CdbPathName.hh"
00010 
00011 #include "BdbCond/BdbObsoleteDatabase.hh"
00012 
00013 #include <string.h>
00014 
00015 #include <vector>
00016 using std::vector;
00017 #include <string>
00018 using std::string;
00019 
00020 CdbBdbWConditionItr::CdbBdbWConditionItr( const CdbFolderPtr& theParent ) :
00021     _isValid(false),
00022     _hasEverBeenAdvanced(false),
00023     _myParent(theParent),
00024     _isLoaded(false),
00025     _current(0),
00026     _num(0),
00027     _conditions(0)
00028 { }
00029 
00030 CdbBdbWConditionItr::CdbBdbWConditionItr( const CdbBdbWConditionItr& theItr ) :
00031     _isValid(false),
00032     _hasEverBeenAdvanced(false),
00033     _myParent(0),
00034     _isLoaded(false),
00035     _current(0),
00036     _num(0),
00037     _conditions(0)
00038 {
00039     setUpSelf( theItr );
00040 }
00041 
00042 CdbBdbWConditionItr::~CdbBdbWConditionItr( )
00043 {
00044     destroySelf( );
00045 }
00046 
00047 CdbBdbWConditionItr&
00048 CdbBdbWConditionItr::operator=( const CdbBdbWConditionItr& theItr )
00049 {
00050     if( this != &theItr ) {
00051         destroySelf( );
00052         setUpSelf( theItr );
00053     }
00054     return *this;
00055 }
00056 
00057 CdbStatus
00058 CdbBdbWConditionItr::reset( )
00059 {
00060     _isValid             = false;
00061     _hasEverBeenAdvanced = false;
00062     _current             = 0;
00063 
00064     return CdbStatus::Success;
00065 }
00066 
00067 bool
00068 CdbBdbWConditionItr::next( )
00069 {
00070   // Remember, that conditions are only allowed at the detector/subsystem level
00071   // of folders. The simple check below will ensure this.
00072 
00073     if( !_myParent.isNull( ) &&
00074         !_myParent->parentFolder( ).isNull( ) &&
00075          _myParent->parentFolder( )->parentFolder( ).isNull( )) {
00076 
00077       // Make sure a list of condition names is loaded.
00078 
00079         loadListOfConditions( );
00080 
00081         if( _hasEverBeenAdvanced )
00082             if( 1 + _current >= _num ) _isValid = false;
00083             else ++_current;
00084         else {
00085             if( _num > 0 ) {
00086                 _isValid             = true;
00087                 _hasEverBeenAdvanced = true;
00088                 _current             = 0;
00089             }
00090         }
00091     }
00092     return _isValid;
00093 }
00094 
00095 CdbBdbWConditionItr::ValueType
00096 CdbBdbWConditionItr::value( )
00097 {
00098     if( _isValid ) return _conditions[_current];
00099     return 0;
00100 }
00101 
00102 bool
00103 CdbBdbWConditionItr::isValid( )
00104 {
00105     return _isValid;
00106 }
00107 
00108 CdbBdbWConditionItr::InterfaceType*
00109 CdbBdbWConditionItr::clone( ) const
00110 {
00111     return new CdbBdbWConditionItr( *this );
00112 }
00113 
00114 void
00115 CdbBdbWConditionItr::destroySelf( )
00116 {
00117     if( 0 != _conditions ) {
00118         for( size_t i = 0; i < _num; i++ ) delete [] _conditions[i];
00119         delete [] _conditions;
00120         _num        = 0;
00121         _conditions = 0;
00122     }
00123 }
00124 
00125 void
00126 CdbBdbWConditionItr::setUpSelf( const CdbBdbWConditionItr& theItr )
00127 {
00128     _isValid             = theItr._isValid;
00129     _hasEverBeenAdvanced = theItr._hasEverBeenAdvanced;
00130     _myParent            = theItr._myParent;
00131     _isLoaded            = theItr._isLoaded;
00132     _current             = theItr._current;
00133     _num                 = theItr._num;
00134     if( _num > 0 ) {
00135         _conditions = new char* [_num];
00136         for( size_t i = 0; i < _num; i++ ) {
00137             _conditions[i] = new char [ 1 + strlen( theItr._conditions[i] )];
00138             strcpy( _conditions[i], theItr._conditions[i] );
00139         }
00140     }
00141 }
00142 
00143 void
00144 CdbBdbWConditionItr::loadListOfConditions( )
00145 {
00146   // We have only one attempt (no matter what would be its result)
00147   // to try loading the list.
00148 
00149     if( _isLoaded ) return;
00150     _isLoaded = true;
00151 
00152   // Extract detector name from the parent folder.
00153 
00154     CdbPathName detectorPath( _myParent->name( ));
00155     if( detectorPath.isValid( ) &&
00156         ! detectorPath.isAbsolute( ) &&
00157         ! detectorPath.isComposite( )) {
00158 
00159         BdbObsoleteDatabase                   db( _myParent->name( ));
00160         vector<string> vec;
00161 
00162         if( BdbcSuccess == db.listAllClasses( vec )) {
00163 
00164             _num = vec.size( );
00165             if( _num > 0 ) {
00166                 _conditions = new char* [_num];
00167                 for( size_t i = 0; i < _num; i++ ) {
00168                     const char* ptr = vec[i].c_str();
00169                     _conditions[i] = new char [ 1 + strlen( ptr )];
00170                     strcpy( _conditions[i], ptr );
00171                 }
00172             }
00173         }
00174     }
00175 }
00176 
00177 /////////////////
00178 // End Of File //
00179 /////////////////

 


BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us

Page Owner: Jacek Becla
Last Update: October 04, 2002