![]() |
|
|
Bdb packages | Design docs | Source docs | Guidelines | Recent releases |
|
Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Compound Members File Members /BdbModules/BdbAbsLoad.cc
Go to the documentation of this file.00001 //-------------------------------------------------------------------------- 00002 // File and Version Information: 00003 // $Id: BdbAbsLoad.cc,v 1.2 2002/06/21 19:13:36 ryd Exp $ 00004 // 00005 // Description: 00006 // Class BdbAbsLoad 00007 // 00008 // Environment: 00009 // Software developed for the BaBar Detector at the SLAC B-Factory. 00010 // 00011 // Author List: 00012 // Stephen J. Gowdy Originator 00013 // 00014 // Copyright Information: 00015 // Copyright (C) 1997 University of Edinburgh 00016 // 00017 //------------------------------------------------------------------------ 00018 #include "BaBar/BaBar.hh" 00019 00020 //----------------------- 00021 // This Class's Header -- 00022 //----------------------- 00023 00024 #include "BdbModules/BdbAbsLoad.hh" 00025 00026 //------------- 00027 // C Headers -- 00028 //------------- 00029 #include <stdlib.h> 00030 extern "C" { 00031 } 00032 00033 //--------------- 00034 // C++ Headers -- 00035 //--------------- 00036 00037 //------------------------------- 00038 // Collaborating Class Headers -- 00039 //------------------------------- 00040 00041 #include <algorithm> 00042 #include <vector> 00043 using std::vector; 00044 #include "BbrStdUtils/BbrCollectionUtils.hh" 00045 00046 00047 #include "BdbConverters/BdbConverterScribe.hh" 00048 #include "BdbConverters/BdbAbsConverter.hh" 00049 #include "BdbScribes/BdbConversionManager.hh" 00050 #include "AbsEvent/AbsEvent.hh" 00051 #include "ProxyDict/Ifd.hh" 00052 #include "ErrLogger/ErrLog.hh" 00053 00054 //----------------------------------------------------------------------- 00055 // Local Macros, Typedefs, Structures, Unions and Forward Declarations -- 00056 //----------------------------------------------------------------------- 00057 00058 static const char rscid[] = "$Id: BdbAbsLoad.cc,v 1.2 2002/06/21 19:13:36 ryd Exp $"; 00059 00060 // Note when this class moves into BdbModules this should move 00061 // into the BdbEventMerge module, and this class should reference that 00062 // function. 00063 const IfdStrKey& 00064 BdbAbsLoad::primaryKey() 00065 { 00066 static IfdStrKey* key = new IfdStrKey( "None" ) ; 00067 return( *key ) ; 00068 } 00069 00070 // ---------------------------------------- 00071 // -- Public Function Member Definitions -- 00072 // ---------------------------------------- 00073 00074 //---------------- 00075 // Constructors -- 00076 //---------------- 00077 BdbAbsLoad::BdbAbsLoad( const char* const theName, 00078 const char* const theDescription ) 00079 : AppModule( theName, theDescription ), 00080 _keyToSecondaryEvent( "keyToSecondaryEvent" , 00081 this , 00082 primaryKey().asString() ) , 00083 _scribes( new vector< BdbGenericScribe* > ) , 00084 _inputScribes( new vector< BdbGenericScribe* > ) , 00085 _outputScribes( new vector< BdbGenericScribe* > ) , 00086 _adaptedConverters( new vector< BdbConverterScribe* > ) 00087 { 00088 commands()->append( &_keyToSecondaryEvent ) ; 00089 } 00090 00091 //-------------- 00092 // Destructor -- 00093 //-------------- 00094 BdbAbsLoad::~BdbAbsLoad() 00095 { 00096 // Clean ourselves up 00097 delete _outputScribes ; 00098 delete _inputScribes ; 00099 std::for_each(_scribes->begin(),_scribes->end(),babar::Collection::DeleteObject()); 00100 00101 delete _scribes ; 00102 00103 delete _adaptedConverters ; 00104 } 00105 00106 //------------- 00107 // Methods -- 00108 //------------- 00109 00110 //------------- 00111 // Operators -- 00112 //------------- 00113 00114 //------------- 00115 // Selectors -- 00116 //------------- 00117 00118 BdbConverterScribe* 00119 BdbAbsLoad::findConverterScribe( BdbAbsConverter* aConverter ) 00120 { 00121 // This should normally be called during "beginJob" therefore 00122 // a linear search should be sufficient. Moreover if the requested 00123 // BdbAbsConverter has already been adapted it is probably the last 00124 // (or one of the last) so a reverse search should locate it most 00125 // efficiently! 00126 BdbConverterScribe* result( 0 ) ; 00127 size_t adaptorIndex( _adaptedConverters->size() ) ; 00128 while( ( 0 != adaptorIndex ) && 00129 ( 0 == result ) ) { 00130 --adaptorIndex ; 00131 if( (*_adaptedConverters)[ adaptorIndex ]->adaptsConverter( aConverter ) ) { 00132 result = (*_adaptedConverters)[ adaptorIndex ] ; 00133 } 00134 } 00135 00136 return( result ) ; 00137 } 00138 00139 //------------- 00140 // Modifiers -- 00141 //------------- 00142 00143 void 00144 BdbAbsLoad::addScribeForInput( BdbGenericScribe* aScribe ) 00145 { 00146 // If already added for input do nothing. 00147 if( std::find(_inputScribes->begin(),_inputScribes->end(), 00148 aScribe )!=_inputScribes->end() ) { 00149 ErrMsg( warning ) << name() 00150 << ": Attempting to add Scribe For Input more than" 00151 << " once.\n" 00152 << "\tWill ignore this attempt." 00153 << endmsg ; 00154 return ; 00155 } 00156 _inputScribes->push_back( aScribe ) ; 00157 00158 // If not already owned by this class, add to list of owned Scribes. 00159 if( std::find(_scribes->begin(),_scribes->end(), aScribe )==_scribes->end() ) { 00160 _scribes->push_back( aScribe ) ; 00161 } 00162 } 00163 00164 void 00165 BdbAbsLoad::addScribeForOutput( BdbGenericScribe* aScribe ) 00166 { 00167 // If already added for output do nothing. 00168 if( std::find(_outputScribes->begin(),_outputScribes->end(), 00169 aScribe )!=_outputScribes->end() ) { 00170 ErrMsg( warning ) << name() 00171 << ": Attempting to add Scribe For Output more than" 00172 << " once.\n" 00173 << "\tWill ignore this attempt." 00174 << endmsg ; 00175 return ; 00176 } 00177 _outputScribes->push_back( aScribe ) ; 00178 00179 // If not already owned by this class, add to list of owned Scribes. 00180 if( std::find(_scribes->begin(),_scribes->end(), aScribe )==_scribes->end() ) { 00181 _scribes->push_back( aScribe ) ; 00182 } 00183 } 00184 00185 00186 void 00187 BdbAbsLoad::addConverter( BdbAbsConverter* aConverter ) 00188 { 00189 // This can be infered from the "useForInput" and "useForOutput" functionns. 00190 } 00191 00192 void 00193 BdbAbsLoad::useForInput( BdbAbsConverter* aConverter ) 00194 { 00195 BdbConverterScribe* adaptedVersion( findConverterScribe( aConverter ) ) ; 00196 00197 // If Converter has not been adapted make necessary adaptor. 00198 if( 0 == adaptedVersion ) { 00199 adaptedVersion = new BdbConverterScribe( aConverter ) ; 00200 _adaptedConverters->push_back( adaptedVersion ) ; 00201 } 00202 00203 addScribeForInput( adaptedVersion ) ; 00204 } 00205 00206 void 00207 BdbAbsLoad::useForOutput( BdbAbsConverter* aConverter ) 00208 { 00209 BdbConverterScribe* adaptedVersion( findConverterScribe( aConverter ) ) ; 00210 00211 // If Converter has not been adapted make necessary adaptor. 00212 if( 0 == adaptedVersion ) { 00213 adaptedVersion = new BdbConverterScribe( aConverter ) ; 00214 _adaptedConverters->push_back( adaptedVersion ) ; 00215 } 00216 00217 addScribeForOutput( adaptedVersion ) ; 00218 } 00219 00220 AppResult 00221 BdbAbsLoad::event( AbsEvent* anEvent ) 00222 { 00223 if ( _verbose.value() ) { 00224 ErrMsg( trace ) << name() 00225 << " event" 00226 << endmsg ; 00227 } 00228 00229 AbsEvent* eventToUse( anEvent ) ; 00230 00231 // If key is set to a secondary event get that event 00232 if( primaryKey() != _keyToSecondaryEvent.value() ) { 00233 eventToUse = Ifd< AbsEvent >::get( anEvent , 00234 _keyToSecondaryEvent.value() ) ; 00235 } 00236 00237 // Get conversion manager from transient event 00238 BdbConversionManager* conversionManager( 0 ) ; 00239 conversionManager = Ifd< BdbConversionManager >::get( eventToUse ) ; 00240 if ( 0 == conversionManager ) { 00241 ErrMsg( fatal ) << name() 00242 << ": failed to find ConversionManager in Event." 00243 << endmsg ; 00244 ::abort() ; 00245 } 00246 00247 // If there are no Scribes registered for input finish. 00248 if( ( _inputScribes->empty() ) && 00249 ( _outputScribes->empty() ) ){ 00250 return AppResult::OK ; 00251 } 00252 00253 // Otherwise add scribes to ConversionManager 00254 size_t finishedInput( _inputScribes->size() ) ; 00255 for( size_t inputIndex( 0 ) ; 00256 finishedInput != inputIndex ; 00257 ++inputIndex ) { 00258 conversionManager->addScribeForInput( *((*_inputScribes)[ inputIndex ]) ) ; 00259 } 00260 00261 size_t finishedOutput( _outputScribes->size() ) ; 00262 for( size_t outputIndex( 0 ) ; 00263 finishedOutput != outputIndex ; 00264 ++outputIndex ) { 00265 conversionManager->addScribeForOutput( *((*_outputScribes)[ outputIndex ]) ) ; 00266 } 00267 00268 return AppResult::OK ; 00269 } 00270 00271 // ----------------------------------------------- 00272 // -- Static Data & Function Member Definitions -- 00273 // ----------------------------------------------- 00274 00275 // ------------------------------------------- 00276 // -- Protected Function Member Definitions -- 00277 // ------------------------------------------- 00278 00279 // ----------------------------------------- 00280 // -- Private Function Member Definitions -- 00281 // ----------------------------------------- 00282 00283 // ----------------------------------- 00284 // -- Internal Function Definitions -- 00285 // -----------------------------------
BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us
Page Owner: Jacek Becla
Last Update: October 04, 2002