![]() |
|
|
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 /TagDataP/BdbTagConverter.cc
Go to the documentation of this file.00001 //-------------------------------------------------------------------------- 00002 // File and Version Information: 00003 // $Id: BdbTagConverter.cc,v 1.32 2002/06/17 02:57:59 becla Exp $ 00004 // 00005 // Description: 00006 // Class BdbTagConverter 00007 // 00008 // Environment: 00009 // Software developed for the BaBar Detector at the SLAC B-Factory. 00010 // 00011 // Author List: 00012 // Bob Jacobsen original author 00013 // Stephen J. Gowdy Contributor 00014 // Akbar Mokhtarani modified from Composite converter 00015 // Copyright Information: 00016 // Copyright (C) 1997 LBNL 00017 // 00018 //------------------------------------------------------------------------ 00019 #include "BaBar/BaBar.hh" 00020 00021 //----------------------- 00022 // This Class's Header -- 00023 //----------------------- 00024 #include "TagDataP/BdbTagConverter.hh" 00025 00026 //------------- 00027 // C Headers -- 00028 //------------- 00029 #include <stdlib.h> 00030 extern "C" { 00031 } 00032 00033 //--------------- 00034 // C++ Headers -- 00035 //--------------- 00036 #include <string> 00037 using std::string; 00038 #include <vector> 00039 using std::vector; 00040 00041 //------------------------------- 00042 // Collaborating Class Headers -- 00043 //------------------------------- 00044 #include <rw/cstring.h> 00045 #include <rw/tvordvec.h> 00046 #include <rw/tvhset.h> 00047 00048 #include "ErrLogger/ErrLog.hh" 00049 #include "AbsEvent/AbsEvent.hh" 00050 #include "AbsEventTag/AbsEventTag.hh" 00051 #include "AbsEventTag/AbsEventTagBoolIter.hh" 00052 #include "AbsEventTag/AbsEventTagIntIter.hh" 00053 #include "AbsEventTag/AbsEventTagFloatIter.hh" 00054 #include "BdbScribes/BdbEvtObjLocation.hh" 00055 #include "BdbScribes/BdbEvtObjLocReg.hh" 00056 #include "BdbEvent/BdbEventT.hh" 00057 #include "BdbEvent/BdbEvent.hh" 00058 #include "BdbEvent/BdbEventTag.hh" 00059 #include "BdbEventStore/BdbAbsCollectionT.hh" 00060 #include "BdbModules/BdbEventInput.hh" 00061 #include "BdbModules/BdbEventOutput.hh" 00062 #include "HepODBMS/tagdb/HepExplorableDescr.h" 00063 #include "TagDataP/BdbTagTransient.hh" 00064 #include "TagData/TagDescriptor.hh" 00065 #include "TagDataP/TagAttribute.hh" 00066 00067 //----------------------------------------------------------------------- 00068 // Local Macros, Typedefs, Structures, Unions and Forward Declarations -- 00069 //----------------------------------------------------------------------- 00070 00071 // ---------------------------------------- 00072 // -- Public Function Member Definitions -- 00073 // ---------------------------------------- 00074 00075 //---------------- 00076 // Constructors -- 00077 //---------------- 00078 BdbTagConverter::BdbTagConverter( const IfdKey & key, 00079 const string& comp, 00080 const string& hdr , 00081 bool readAllTags, 00082 const vector<string>& tagsToSkip, 00083 bool keepPersistentTag, 00084 bool aUseOriginalDesc ) 00085 : BdbAbsConverter( key, comp.c_str(), hdr.c_str() ) 00086 , _readAllTags(readAllTags) 00087 , _keepPersistentTag(keepPersistentTag) 00088 , _tagsToSkip(0) 00089 , _useOriginal( aUseOriginalDesc ) 00090 { 00091 // fill hash table with tags to skip 00092 // only works if readAllTags is true 00093 size_t nEntries = tagsToSkip.size(); 00094 if ( _readAllTags && nEntries > 0 ) { 00095 size_t nBuckets = 3; 00096 if ( nEntries > 4 ) { 00097 nBuckets = (int) (nEntries / 1.25); // allow some collisions 00098 } 00099 00100 _tagsToSkip = new RWTValHashSet<RWCString>(&RWCString::hash, nBuckets); 00101 for (size_t i = 0; i<nEntries; i++ ) { 00102 _tagsToSkip->insert(RWCString(tagsToSkip[i].c_str())); 00103 } 00104 } 00105 } 00106 00107 //-------------- 00108 // Destructor -- 00109 //-------------- 00110 BdbTagConverter::~BdbTagConverter() 00111 { 00112 delete _tagsToSkip; 00113 } 00114 00115 //------------- 00116 // Methods -- 00117 //------------- 00118 00119 //------------- 00120 // Operators -- 00121 //------------- 00122 // create the persistent object 00123 bool 00124 BdbTagConverter::output( AbsEvent* anEvent, 00125 BdbEvtObjLocReg& registry, 00126 BdbEventT& aEventT ) const 00127 { 00128 bool result = true; 00129 // find the place to attach the object 00130 BdbHandle(BdbEventTag) thePTagH; 00131 00132 // get the list from the transient event 00133 AbsEventTag* theTag = Ifd< AbsEventTag >::get( anEvent ); 00134 00135 if ( 0 == theTag ) { 00136 00137 // nothing to do, return OK 00138 return true; 00139 } 00140 00141 // create the output object and attach to persistent event 00142 BdbStatus status = ((BdbRef( BdbEvent )&)(aEventT.getPersistent()))->tag( thePTagH ); 00143 if ( ! BdbIsNull( thePTagH ) ) { 00144 00145 ErrMsg( fatal ) << "The persistent Tag already exists for this Event" 00146 << ", can not write new data!" 00147 << endmsg ; 00148 ::abort() ; 00149 } 00150 00151 BdbRefAny theHint( this->getPrimaryHint() ) ; 00152 BdbRef( BdbEvent ) eventR( ((BdbRef( BdbEvent )&)(aEventT.getPersistent())) ) ; 00153 thePTagH = new (theHint) BdbEventTag( eventR ); 00154 assert( ! BdbIsNull( thePTagH ) ); 00155 00156 // Locate the collection that the keys are going to be associated with 00157 BdbAbsCollectionT<BdbEventT>* theColl( 0 ) ; 00158 theColl = Ifd< BdbAbsCollectionT< BdbEventT > >::get( anEvent, 00159 BdbEventOutput::outputCollectionKey() ); 00160 if ( ( 0 != theColl ) && ( ! theColl->isNull( ) ) ) { 00161 00162 // Create the description if necessary 00163 theColl->createDescription( theColl->name( ) ); 00164 BdbHandle(HepExplorableDescr) theDesc; 00165 BdbStatus status = theColl->description( theDesc ); 00166 00167 // Copy contents of the transient tag to the persistent tag. 00168 00169 // First define the keys & types 00170 const char* aKey; 00171 00172 AbsEventTagBoolIter* boolIter = theTag->boolIter( ); 00173 while ( boolIter->next( ) ) { 00174 aKey = boolIter->key( ); 00175 TagAttribute<bool> boolKey( aKey, thePTagH, theDesc ); 00176 } 00177 delete boolIter; 00178 00179 AbsEventTagIntIter* intIter = theTag->intIter( ); 00180 while ( intIter->next( ) ) { 00181 aKey = intIter->key( ); 00182 TagAttribute<int> intKey( aKey, thePTagH, theDesc ); 00183 } 00184 delete intIter; 00185 00186 AbsEventTagFloatIter* floatIter = theTag->floatIter( ); 00187 while ( floatIter->next( ) ) { 00188 aKey = floatIter->key( ); 00189 TagAttribute<float> floatKey( aKey, thePTagH, theDesc ); 00190 } 00191 delete floatIter; 00192 00193 thePTagH->resize( theDesc ); 00194 00195 // Now define the values & save them in the tag 00196 bool aBool; 00197 boolIter = theTag->boolIter( ); 00198 while ( boolIter->next( ) ) { 00199 aBool = boolIter->value( ); 00200 aKey = boolIter->key( ); 00201 TagAttribute<bool> boolAttr( aKey, thePTagH, theDesc ); 00202 boolAttr = aBool; 00203 } 00204 delete boolIter; 00205 00206 int anInt; 00207 intIter = theTag->intIter( ); 00208 while ( intIter->next( ) ) { 00209 anInt = intIter->value( ); 00210 aKey = intIter->key( ); 00211 TagAttribute<int> intAttr( aKey, thePTagH, theDesc ); 00212 intAttr = anInt; 00213 } 00214 delete intIter; 00215 00216 float aFloat; 00217 floatIter = theTag->floatIter( ); 00218 while ( floatIter->next( ) ) { 00219 aFloat = floatIter->value( ); 00220 aKey = floatIter->key( ); 00221 TagAttribute<float> floatAttr( aKey, thePTagH, theDesc ); 00222 floatAttr = aFloat; 00223 } 00224 delete floatIter; 00225 } 00226 00227 // done, return OK 00228 return true; 00229 } 00230 00231 // connect the persistent objects 00232 bool 00233 BdbTagConverter::fillRefs( AbsEvent* anEvent, 00234 BdbEvtObjLocReg& registry, 00235 BdbEventT& aEventT ) const 00236 { 00237 bool result = true; 00238 return result; 00239 } 00240 00241 // create the transient objects 00242 bool 00243 BdbTagConverter::input( AbsEvent* anEvent, 00244 BdbEvtObjLocReg& registry, 00245 BdbEventT& aEventT ) const 00246 { 00247 bool result = false; 00248 BdbAbsCollectionT<BdbEventT>* theColl; 00249 BdbHandle(HepExplorableDescr) theDesc; 00250 BdbHandle(BdbEventTag) theTag; 00251 00252 // locate the input object 00253 BdbStatus status = ((BdbRef( BdbEvent )&)(aEventT.getPersistent()))->tag( theTag ); 00254 if ( ! BdbIsNull( theTag ) ) { 00255 00256 // Check whether a transient tag already exists within the 00257 // event. If it does, it is not bound to the persistent 00258 // tag. This is a policy decision that needs to be reviewed 00259 AbsEventTag* transient = Ifd<AbsEventTag>::get( anEvent ); 00260 if ( 0 == transient ) { 00261 00262 // No transient tag exists within the event. Create it and 00263 // bind it to the persistent tag & descriptor. 00264 00265 // Locate the collection that the keys are associated with 00266 theColl = 00267 Ifd<BdbAbsCollectionT<BdbEventT> >::get( anEvent, 00268 BdbEventInput::inputCollectionKey( ) ); 00269 if ( ! theColl->isNull( ) ) { 00270 00271 // Get tag descriptor from persistent event wrapper 00272 theDesc = aEventT.getCurrentTagDescr(); 00273 if( _useOriginal ) { 00274 theDesc = aEventT.getOriginalTagDescr(); 00275 if( theDesc.isNull() ) { 00276 ErrMsg( warning ) << "Can not assertain correct descriptor" 00277 << " for the tag, will used default!" 00278 << endmsg ; 00279 } 00280 } 00281 00282 assert( ! BdbIsNull( theDesc ) ); 00283 00284 if ( _readAllTags ) { 00285 // fill in all tags 00286 transient = new TagTransient(); 00287 00288 size_t i; 00289 size_t offset; 00290 d_Boolean aBool; 00291 int anInt; 00292 float aFloat; 00293 HepExplorableFieldType type; 00294 00295 size_t max = theDesc->noOfFields( ); 00296 RWCString aName; 00297 for ( i = 0; i < max; i++ ) { 00298 aName = theDesc->getFieldNameById ( i ); 00299 if ( _tagsToSkip != 0 && _tagsToSkip->contains(aName) ) { 00300 // kill this tag 00301 continue; 00302 } 00303 00304 type = theDesc->getFieldTypeById( i ); 00305 switch( type ) { 00306 case eTypeBool: 00307 case eTypePackedBool: 00308 { 00309 TagAttribute<bool> boolAttr(aName, theTag, theDesc); 00310 aBool = boolAttr; 00311 transient->putBool( aBool, aName ); 00312 } 00313 break; 00314 case eTypeLong: 00315 { 00316 TagAttribute<int> longAttr(aName, theTag, theDesc); 00317 anInt = longAttr; 00318 transient->putInt( anInt, aName ); 00319 } 00320 break; 00321 case eTypeFloat: 00322 { 00323 TagAttribute<float> floatAttr(aName, theTag, theDesc); 00324 aFloat = floatAttr; 00325 transient->putFloat( aFloat, aName ); 00326 } 00327 break; 00328 } 00329 } 00330 } else { 00331 transient = new BdbTagTransient( theTag, theDesc ); 00332 } 00333 00334 bool stat = Ifd<AbsEventTag>::put( anEvent, transient ); 00335 assert( stat ); 00336 00337 // merge with defaults in TagDescriptor 00338 TagDescriptor* descriptor = TagDescriptor::instance(); 00339 if ( !descriptor->processProxies(anEvent) ) { 00340 ErrMsg(error) << "Failed to declare all deferred tags" << endmsg; 00341 } 00342 descriptor->lock(); 00343 result = transient->merge(descriptor, _keepPersistentTag); 00344 00345 // lock the tag 00346 if ( _readAllTags) static_cast<TagTransient*>(transient)->lock(); 00347 00348 } 00349 } 00350 } 00351 return result; 00352 } 00353 00354 // connect the transient objects together 00355 bool 00356 BdbTagConverter::fillPointers( AbsEvent* anEvent, 00357 BdbEvtObjLocReg& registry, 00358 BdbEventT& aEventT ) const 00359 { 00360 return true; 00361 } 00362 00363 bool 00364 BdbTagConverter::operator==( const BdbTagConverter& l ) const 00365 { 00366 return this == & l; 00367 } 00368 00369 //------------- 00370 // Selectors -- 00371 //------------- 00372 00373 //------------- 00374 // Modifiers -- 00375 //------------- 00376 00377 // ----------------------------------------------- 00378 // -- Static Data & Function Member Definitions -- 00379 // ----------------------------------------------- 00380 00381 // ------------------------------------------- 00382 // -- Protected Function Member Definitions -- 00383 // ------------------------------------------- 00384 00385 int 00386 BdbTagConverter::numberOfHintsRequired() const 00387 { 00388 return ( 1 ); 00389 } 00390 00391 // ----------------------------------------- 00392 // -- Private Function Member Definitions -- 00393 // ----------------------------------------- 00394 00395 // ----------------------------------- 00396 // -- Internal Function Definitions -- 00397 // -----------------------------------
BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us
Page Owner: Jacek Becla
Last Update: October 04, 2002