#include <CondTools/DT/interface/DTConfigHandler.h>
Public Types | |
typedef std::map< int, cond::TypedRef< DTConfigData > * >::const_iterator | const_iterator |
Access methods to data. | |
Public Member Functions | |
const_iterator | begin () const |
std::string | clone (DTDBSession *newSession, const std::string &newToken, const std::string &objContainer, const std::string &refContainer) |
copy to other DB | |
const_iterator | end () const |
int | get (int cfgId, DTConfigData *&obj) |
const DTConfigList * | getContainer () |
get content | |
void | getData (int cfgId, std::vector< const std::string * > &list) |
void | purge () |
purge db copy | |
int | set (int cfgId, const std::string &token) |
Static Public Member Functions | |
static DTConfigHandler * | create (DTDBSession *session, const std::string &token) |
Operations. | |
static void | remove (const DTConfigHandler *handler) |
static void | remove (const DTDBSession *session) |
Static Public Attributes | |
static int | maxBrickNumber = 50 |
static int | maxByteNumber = 1000000 |
static int | maxStringNumber = 1000 |
Private Types | |
typedef handler_map::const_iterator | c_map_iter |
typedef std::map< const DTDBSession *, DTConfigHandler * > | handler_map |
typedef handler_map::iterator | map_iter |
Private Member Functions | |
std::string | clone (DTDBSession *newSession, const std::string &objContainer, const std::string &refContainer) |
DTConfigHandler (const DTConfigHandler &x) | |
DTConfigHandler (DTDBSession *session, const std::string &token) | |
Constructor. | |
const DTConfigHandler & | operator= (const DTConfigHandler &x) |
virtual | ~DTConfigHandler () |
Destructor. | |
Static Private Member Functions | |
static int | compToken (const std::string &token) |
static std::string | compToken (const std::string &token, int id) |
Private Attributes | |
int | cachedBrickNumber |
int | cachedByteNumber |
int | cachedStringNumber |
DTDBSession * | dbSession |
std::string | objToken |
std::map< int, cond::TypedRef < DTConfigData > * > | refMap |
cond::TypedRef< DTConfigList > * | refSet |
Static Private Attributes | |
static handler_map | handlerMap |
Definition at line 37 of file DTConfigHandler.h.
typedef handler_map::const_iterator DTConfigHandler::c_map_iter [private] |
Definition at line 104 of file DTConfigHandler.h.
typedef std::map< int, cond::TypedRef<DTConfigData>* >::const_iterator DTConfigHandler::const_iterator |
typedef std::map<const DTDBSession*,DTConfigHandler*> DTConfigHandler::handler_map [private] |
Definition at line 103 of file DTConfigHandler.h.
typedef handler_map::iterator DTConfigHandler::map_iter [private] |
Definition at line 105 of file DTConfigHandler.h.
DTConfigHandler::DTConfigHandler | ( | DTDBSession * | session, | |
const std::string & | token | |||
) | [private] |
Constructor.
Definition at line 36 of file DTConfigHandler.cc.
00037 : 00038 dbSession( session ), 00039 objToken( token ), 00040 refSet( 0 ), 00041 cachedBrickNumber( 0 ), 00042 cachedStringNumber( 0 ), 00043 cachedByteNumber( 0 ) { 00044 }
DTConfigHandler::DTConfigHandler | ( | const DTConfigHandler & | x | ) | [private] |
DTConfigHandler::~DTConfigHandler | ( | ) | [private, virtual] |
DTConfigHandler::const_iterator DTConfigHandler::begin | ( | ) | const |
Definition at line 193 of file DTConfigHandler.cc.
References refMap.
00193 { 00194 return refMap.begin(); 00195 }
std::string DTConfigHandler::clone | ( | DTDBSession * | newSession, | |
const std::string & | objContainer, | |||
const std::string & | refContainer | |||
) | [private] |
Definition at line 222 of file DTConfigHandler.cc.
References DTConfigList::begin(), compToken(), GenMuonPlsPt100GeV_cfg::cout, dbSession, DTConfigList::end(), lat::endl(), DTConfigList::get(), getContainer(), DTConfigToken::id, iter, objToken, DTDBSession::poolDB(), cond::TypedRef< T >::ptr(), ptr, DTConfigToken::ref, refSet, DTConfigList::set(), and DTConfigList::version().
00224 { 00225 const DTConfigList* rs = getContainer(); 00226 DTConfigList* rn = new DTConfigList( rs->version() ); 00227 DTConfigList::const_iterator iter = rs->begin(); 00228 DTConfigList::const_iterator iend = rs->end(); 00229 while ( iter != iend ) { 00230 const DTConfigToken& token = iter->second; 00231 std::string actualToken( token.ref ); 00232 int actualId = token.id; 00233 if ( ( actualToken == std::string( "dummyToken" ) ) && 00234 ( actualId > 0 ) ) { 00235 DTConfigToken chkToken; 00236 refSet->ptr()->get( -999999999, chkToken ); 00237 actualToken = compToken( chkToken.ref, actualId ); 00238 } 00239 cond::TypedRef<DTConfigData> sRef( *dbSession->poolDB(), 00240 actualToken ); 00241 std::cout << " copying brick " << sRef->getId() << std::endl; 00242 DTConfigData* ptr = new DTConfigData( *( sRef.ptr() ) ); 00243 cond::TypedRef<DTConfigData> dRef( *newSession->poolDB(), ptr ); 00244 dRef.markWrite( refContainer ); 00245 DTConfigToken objToken; 00246 std::string tokenRef( dRef.token() ); 00247 objToken.ref = tokenRef; 00248 objToken.id = compToken( tokenRef ); 00249 rn->set( iter->first, objToken ); 00250 iter++; 00251 } 00252 cond::TypedRef<DTConfigList> setRef( *newSession->poolDB(), rn ); 00253 setRef.markWrite( objContainer ); 00254 std::string token = setRef.token(); 00255 return token; 00256 }
std::string DTConfigHandler::clone | ( | DTDBSession * | newSession, | |
const std::string & | newToken, | |||
const std::string & | objContainer, | |||
const std::string & | refContainer | |||
) |
copy to other DB
Definition at line 259 of file DTConfigHandler.cc.
References DTConfigList::begin(), compToken(), GenMuonPlsPt100GeV_cfg::cout, dbSession, DTConfigList::end(), lat::endl(), DTConfigList::get(), getContainer(), DTConfigToken::id, iter, cond::TypedRef< T >::markUpdate(), cond::TypedRef< T >::markWrite(), objToken, DTDBSession::poolDB(), cond::TypedRef< T >::ptr(), ptr, DTConfigToken::ref, refSet, DTConfigList::set(), cond::TypedRef< T >::token(), and DTConfigList::version().
Referenced by DTConfigDBCopy::beginJob().
00262 { 00263 00264 if ( !newToken.length() ) return clone( newSession, 00265 objContainer, refContainer ); 00266 00267 const DTConfigList* rs = getContainer(); 00268 std::cout << "look for existing list reference..." << std::endl; 00269 cond::TypedRef<DTConfigList>* setRef = new cond::TypedRef<DTConfigList>( 00270 *newSession->poolDB(), newToken ); 00271 std::cout << "look for existing list pointer..." << std::endl; 00272 DTConfigList* rn = 0; 00273 rn = setRef->ptr(); 00274 std::cout << "existing list pointer got " << rn << std::endl; 00275 bool containerMissing = ( rn == 0 ); 00276 if ( containerMissing ) rn = new DTConfigList( rs->version() ); 00277 00278 DTConfigList::const_iterator iter = rs->begin(); 00279 DTConfigList::const_iterator iend = rs->end(); 00280 while ( iter != iend ) { 00281 const DTConfigToken& token = iter->second; 00282 std::string actualToken( token.ref ); 00283 int actualId = token.id; 00284 if ( ( actualToken == std::string( "dummyToken" ) ) && 00285 ( actualId > 0 ) ) { 00286 DTConfigToken chkToken; 00287 refSet->ptr()->get( -999999999, chkToken ); 00288 actualToken = compToken( chkToken.ref, actualId ); 00289 } 00290 cond::TypedRef<DTConfigData> sRef( *dbSession->poolDB(), 00291 actualToken ); 00292 int cfgId = sRef->getId(); 00293 std::cout << " checking brick " << cfgId << std::endl; 00294 DTConfigToken dumToken; 00295 if ( rn->get( cfgId, dumToken ) ) { 00296 std::cout << " ... copying brick " << cfgId << std::endl; 00297 DTConfigData* ptr = new DTConfigData( *( sRef.ptr() ) ); 00298 cond::TypedRef<DTConfigData> dRef( *newSession->poolDB(), ptr ); 00299 dRef.markWrite( refContainer ); 00300 DTConfigToken objToken; 00301 std::string tokenRef( dRef.token() ); 00302 objToken.ref = tokenRef; 00303 objToken.id = compToken( tokenRef ); 00304 rn->set( iter->first, objToken ); 00305 } 00306 iter++; 00307 } 00308 std::string token( "" ); 00309 if ( containerMissing ) { 00310 setRef = new cond::TypedRef<DTConfigList>( *newSession->poolDB(), rn ); 00311 setRef->markWrite( objContainer ); 00312 token = setRef->token(); 00313 } 00314 else { 00315 setRef->markUpdate(); 00316 } 00317 return token; 00318 }
int DTConfigHandler::compToken | ( | const std::string & | token | ) | [static, private] |
Definition at line 352 of file DTConfigHandler.cc.
References getDQMSummary::key.
00352 { 00353 unsigned int iofb = 0; 00354 unsigned int iofe = 0; 00355 unsigned tokenId; 00356 while ( true ) { 00357 iofb = refToken.find( "[", iofb ); 00358 // if ( iofb == std::string::npos ) break; 00359 if ( iofb >= refToken.length() ) break; 00360 iofe = refToken.find( "]", iofb ); 00361 std::string sub( refToken.substr( iofb, 1 + iofe - iofb ) ); 00362 iofb = sub.find( "=", 0 ); 00363 std::string key( sub.substr( 1, iofb ) ); 00364 if ( key == std::string( "OID=" ) ) { 00365 iofb = 1 + sub.find( "-", 0 ); 00366 std::string val( sub.substr( iofb, sub.length() - iofb - 1 ) ); 00367 sscanf( val.c_str(), "%x", &tokenId ); 00368 break; 00369 } 00370 iofb = iofe; 00371 } 00372 return tokenId; 00373 }
std::string DTConfigHandler::compToken | ( | const std::string & | token, | |
int | id | |||
) | [static, private] |
Definition at line 321 of file DTConfigHandler.cc.
References getDQMSummary::key.
Referenced by clone(), get(), and set().
00321 { 00322 std::string actualToken( "" ); 00323 char* buf = new char[9]; 00324 unsigned int iofb = 0; 00325 unsigned int iofe = 0; 00326 while ( true ) { 00327 iofb = refToken.find( "[", iofb ); 00328 // if ( iofb == std::string::npos ) break; 00329 if ( iofb >= refToken.length() ) break; 00330 iofe = refToken.find( "]", iofb ); 00331 std::string sub( refToken.substr( iofb, 1 + iofe - iofb ) ); 00332 iofb = sub.find( "=", 0 ); 00333 std::string key( sub.substr( 1, iofb ) ); 00334 if ( key == std::string( "OID=" ) ) { 00335 iofb = 1 + sub.find( "-", 0 ); 00336 std::string val( sub.substr( iofb, sub.length() - iofb - 1 ) ); 00337 actualToken += sub.substr( 0, iofb ); 00338 sprintf( buf, "%8.8x", id ); 00339 actualToken += buf; 00340 actualToken += "]"; 00341 } 00342 else { 00343 actualToken += sub; 00344 } 00345 iofb = iofe; 00346 } 00347 delete[] buf; 00348 return actualToken; 00349 }
DTConfigHandler * DTConfigHandler::create | ( | DTDBSession * | session, | |
const std::string & | token | |||
) | [static] |
Operations.
create static object
create static object
Definition at line 61 of file DTConfigHandler.cc.
References handlerMap, and iter.
Referenced by DTConfigDBDump::beginJob(), DTConfigDBCopy::beginJob(), and DTCCBConfigHandler::chkConfigList().
00062 { 00063 00064 DTConfigHandler* handlerPtr = 0; 00065 // c_map_iter iter = handlerMap.find( 00066 // reinterpret_cast<unsigned int>( session ) ); 00067 // if ( iter == handlerMap.end() ) 00068 // handlerMap.insert( std::pair<unsigned int,DTConfigHandler*>( 00069 // reinterpret_cast<unsigned int>( session ), 00070 // handlerPtr = new DTConfigHandler( session, 00071 // token ) ) ); 00072 c_map_iter iter = handlerMap.find( session ); 00073 if ( iter == handlerMap.end() ) 00074 handlerMap.insert( std::pair<const DTDBSession*,DTConfigHandler*>( 00075 session, 00076 handlerPtr = new DTConfigHandler( session, 00077 token ) ) ); 00078 else handlerPtr = iter->second; 00079 return handlerPtr; 00080 00081 }
DTConfigHandler::const_iterator DTConfigHandler::end | ( | ) | const |
Definition at line 198 of file DTConfigHandler.cc.
References refMap.
00198 { 00199 return refMap.end(); 00200 }
int DTConfigHandler::get | ( | int | cfgId, | |
DTConfigData *& | obj | |||
) |
Definition at line 120 of file DTConfigHandler.cc.
References cachedBrickNumber, cachedByteNumber, cachedStringNumber, compToken(), DTConfigData::dataBegin(), DTConfigData::dataEnd(), dbSession, DTConfigList::get(), getContainer(), DTConfigToken::id, iter, maxBrickNumber, maxByteNumber, maxStringNumber, DTDBSession::poolDB(), cond::TypedRef< T >::ptr(), purge(), DTConfigToken::ref, refMap, refSet, and size.
Referenced by DTConfigDBDump::beginJob(), and DTCCBConfigHandler::chkConfigList().
00120 { 00121 00122 getContainer(); 00123 const_iterator iter = refMap.find( cfgId ); 00124 00125 if ( iter != refMap.end() ) { 00126 obj = iter->second->ptr(); 00127 return 0; 00128 } 00129 else { 00130 DTConfigToken token; 00131 if ( refSet->ptr()->get( cfgId, token ) == 0 ) { 00132 std::string actualToken( token.ref ); 00133 int actualId = token.id; 00134 if ( ( actualToken == std::string( "dummyToken" ) ) && 00135 ( actualId > 0 ) ) { 00136 refSet->ptr()->get( -999999999, token ); 00137 actualToken = compToken( token.ref, actualId ); 00138 } 00139 if ( ( cachedBrickNumber > maxBrickNumber ) || 00140 ( cachedStringNumber > maxStringNumber ) || 00141 ( cachedByteNumber > maxByteNumber ) ) purge(); //autoPurge(); 00142 cond::TypedRef<DTConfigData>* refObj = 00143 new cond::TypedRef<DTConfigData>( *dbSession->poolDB(), 00144 actualToken ); 00145 refMap.insert( std::pair<int,cond::TypedRef<DTConfigData>*>( 00146 cfgId, refObj ) ); 00147 obj = refObj->ptr(); 00148 DTConfigData::data_iterator d_iter = obj->dataBegin(); 00149 DTConfigData::data_iterator d_iend = obj->dataEnd(); 00150 cachedBrickNumber++; 00151 cachedStringNumber += ( d_iend - d_iter ); 00152 while ( d_iter != d_iend ) cachedByteNumber += ( *d_iter++ ).size(); 00153 00154 return -1; 00155 } 00156 else { 00157 obj = 0; 00158 return -2; 00159 } 00160 } 00161 return 999; 00162 00163 }
const DTConfigList * DTConfigHandler::getContainer | ( | ) |
get content
Definition at line 112 of file DTConfigHandler.cc.
References dbSession, objToken, DTDBSession::poolDB(), cond::TypedRef< T >::ptr(), and refSet.
Referenced by DTConfigDBDump::beginJob(), DTConfigDBCopy::beginJob(), DTCCBConfigHandler::chkConfigList(), clone(), get(), and set().
00112 { 00113 if ( refSet == 0 ) 00114 refSet = new cond::TypedRef<DTConfigList>( *dbSession->poolDB(), 00115 objToken ); 00116 return refSet->ptr(); 00117 }
Definition at line 166 of file DTConfigHandler.cc.
References DTConfigData::dataBegin(), DTConfigData::dataEnd(), DTConfigData::linkBegin(), DTConfigData::linkEnd(), and VarParsing::obj.
Referenced by DTConfigDBDump::beginJob().
00167 { 00168 DTConfigData* obj = 0; 00169 get( cfgId, obj ); 00170 if ( obj == 0 ) return; 00171 DTConfigData::data_iterator d_iter = obj->dataBegin(); 00172 DTConfigData::data_iterator d_iend = obj->dataEnd(); 00173 while ( d_iter != d_iend ) list.push_back( &( *d_iter++ ) ); 00174 DTConfigData::link_iterator l_iter = obj->linkBegin(); 00175 DTConfigData::link_iterator l_iend = obj->linkEnd(); 00176 while ( l_iter != l_iend ) getData( *l_iter++, list ); 00177 return; 00178 }
const DTConfigHandler& DTConfigHandler::operator= | ( | const DTConfigHandler & | x | ) | [private] |
void DTConfigHandler::purge | ( | ) |
purge db copy
Definition at line 202 of file DTConfigHandler.cc.
References cachedBrickNumber, cachedByteNumber, cachedStringNumber, GenMuonPlsPt100GeV_cfg::cout, dbSession, lat::endl(), iter, and refMap.
Referenced by get(), and ~DTConfigHandler().
00202 { 00203 std::cout << "DTConfigHandler::purge " 00204 << this << " " << dbSession << " " 00205 << cachedBrickNumber << " " 00206 << cachedStringNumber << " " 00207 << cachedByteNumber << std::endl; 00208 const_iterator iter = refMap.begin(); 00209 const_iterator iend = refMap.end(); 00210 while ( iter != iend ) { 00211 delete iter->second; 00212 *iter++; 00213 } 00214 refMap.clear(); 00215 cachedBrickNumber = 0; 00216 cachedStringNumber = 0; 00217 cachedByteNumber = 0; 00218 return; 00219 }
void DTConfigHandler::remove | ( | const DTConfigHandler * | handler | ) | [static] |
Definition at line 96 of file DTConfigHandler.cc.
References handlerMap, and iter.
00096 { 00097 map_iter iter = handlerMap.begin(); 00098 map_iter iend = handlerMap.end(); 00099 while ( iter != iend ) { 00100 if ( iter->second == handler ) { 00101 handlerMap.erase( iter ); 00102 delete handler; 00103 return; 00104 } 00105 iter++; 00106 } 00107 return; 00108 }
void DTConfigHandler::remove | ( | const DTDBSession * | session | ) | [static] |
Definition at line 84 of file DTConfigHandler.cc.
References handlerMap, and iter.
Referenced by DTConfigDBDump::beginJob(), and DTConfigDBCopy::beginJob().
00084 { 00085 // map_iter iter = handlerMap.find( 00086 // reinterpret_cast<unsigned int>( session ) ); 00087 map_iter iter = handlerMap.find( session ); 00088 if ( iter != handlerMap.end() ) { 00089 delete iter->second; 00090 handlerMap.erase( iter ); 00091 } 00092 return; 00093 }
Definition at line 181 of file DTConfigHandler.cc.
References compToken(), getContainer(), DTConfigToken::id, cond::TypedRef< T >::markUpdate(), cond::TypedRef< T >::ptr(), DTConfigToken::ref, refSet, DTConfigList::set(), and StDecayID::status.
Referenced by DTCCBConfigHandler::chkConfigList().
00181 { 00182 getContainer(); 00183 DTConfigToken configToken; 00184 configToken.id = compToken( token ); 00185 configToken.ref = token; 00186 DTConfigList* rs = refSet->ptr(); 00187 int status = rs->set( cfgId, configToken ); 00188 refSet->markUpdate(); 00189 return status; 00190 }
int DTConfigHandler::cachedBrickNumber [private] |
int DTConfigHandler::cachedByteNumber [private] |
int DTConfigHandler::cachedStringNumber [private] |
DTDBSession* DTConfigHandler::dbSession [private] |
Definition at line 94 of file DTConfigHandler.h.
Referenced by clone(), get(), getContainer(), and purge().
DTConfigHandler::handler_map DTConfigHandler::handlerMap [static, private] |
int DTConfigHandler::maxBrickNumber = 50 [static] |
int DTConfigHandler::maxByteNumber = 1000000 [static] |
int DTConfigHandler::maxStringNumber = 1000 [static] |
std::string DTConfigHandler::objToken [private] |
std::map<int,cond::TypedRef<DTConfigData>*> DTConfigHandler::refMap [private] |
cond::TypedRef<DTConfigList>* DTConfigHandler::refSet [private] |
Definition at line 96 of file DTConfigHandler.h.
Referenced by clone(), get(), getContainer(), set(), and ~DTConfigHandler().