CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes

DTConfigPluginHandler Class Reference

#include <DTConfigPluginHandler.h>

Inheritance diagram for DTConfigPluginHandler:
DTConfigAbstractHandler

List of all members.

Public Member Functions

virtual int get (const edm::EventSetup &context, int cfgId, const DTKeyedConfig *&obj)
 get content
virtual int get (const DTKeyedConfigListRcd &keyRecord, int cfgId, const DTKeyedConfig *&obj)
virtual void getData (const DTKeyedConfigListRcd &keyRecord, int cfgId, std::vector< std::string > &list)
virtual void getData (const edm::EventSetup &context, int cfgId, std::vector< std::string > &list)
void purge ()
 purge db copy
virtual ~DTConfigPluginHandler ()

Static Public Member Functions

static void build ()
 build static object

Static Public Attributes

static int maxBrickNumber = 5000
static int maxByteNumber = 10000000
static int maxStringNumber = 100000

Private Types

typedef std::pair< int, const
DTKeyedConfig * > 
counted_brick

Private Member Functions

 DTConfigPluginHandler ()
 DTConfigPluginHandler (const DTConfigPluginHandler &x)
const DTConfigPluginHandleroperator= (const DTConfigPluginHandler &x)

Private Attributes

std::map< int, counted_brickbrickMap
int cachedBrickNumber
int cachedByteNumber
int cachedStringNumber

Detailed Description

Description: Class to hold configuration identifier for chambers

Date:
2010/05/14 11:43:02
Revision:
1.2
Author:
Paolo Ronchese INFN Padova

Definition at line 34 of file DTConfigPluginHandler.h.


Member Typedef Documentation

typedef std::pair<int,const DTKeyedConfig*> DTConfigPluginHandler::counted_brick [private]

Definition at line 71 of file DTConfigPluginHandler.h.


Constructor & Destructor Documentation

DTConfigPluginHandler::~DTConfigPluginHandler ( ) [virtual]

Destructor

Definition at line 58 of file DTConfigPluginHandler.cc.

References purge().

                                              {
  purge();
}
DTConfigPluginHandler::DTConfigPluginHandler ( ) [private]

Constructor

Definition at line 42 of file DTConfigPluginHandler.cc.

Referenced by build().

                                            :
  cachedBrickNumber(  0 ),
  cachedStringNumber( 0 ),
  cachedByteNumber(   0 ) {
//  std::cout << "===============================" << std::endl;
//  std::cout << "=                             =" << std::endl;
//  std::cout << "=  new DTConfigPluginHandler  =" << std::endl;
//  std::cout << "=                             =" << std::endl;
//  std::cout << "===============================" << std::endl;
//  if ( instance == 0 ) instance = this;
}
DTConfigPluginHandler::DTConfigPluginHandler ( const DTConfigPluginHandler x) [private]

Member Function Documentation

void DTConfigPluginHandler::build ( ) [static]

build static object

Operations

Definition at line 66 of file DTConfigPluginHandler.cc.

References DTConfigPluginHandler(), and DTConfigAbstractHandler::instance.

                                  {
  if ( instance == 0 ) instance = new DTConfigPluginHandler;
}
int DTConfigPluginHandler::get ( const edm::EventSetup context,
int  cfgId,
const DTKeyedConfig *&  obj 
) [virtual]

get content

Reimplemented from DTConfigAbstractHandler.

Definition at line 71 of file DTConfigPluginHandler.cc.

References edm::EventSetup::get().

                                                                       {
  return get( context.get<DTKeyedConfigListRcd>(), cfgId, obj );
}
int DTConfigPluginHandler::get ( const DTKeyedConfigListRcd keyRecord,
int  cfgId,
const DTKeyedConfig *&  obj 
) [virtual]

Reimplemented from DTConfigAbstractHandler.

Definition at line 77 of file DTConfigPluginHandler.cc.

References brickMap, cachedBrickNumber, cachedByteNumber, cachedStringNumber, DTKeyedConfig::dataBegin(), DTKeyedConfig::dataEnd(), exception, cond::KeyList::get(), edm::eventsetup::EventSetupRecord::get(), DTKeyedConfig::getId(), cond::KeyList::load(), maxBrickNumber, maxByteNumber, maxStringNumber, edm::ESHandle< T >::product(), and findQualityFiles::size.

                                                                       {

  bool cacheFound = false;
  int cacheAge = 999999999;
  std::map<int,counted_brick>::iterator cache_iter = brickMap.begin();
  std::map<int,counted_brick>::iterator cache_icfg = brickMap.find( cfgId );
  std::map<int,counted_brick>::iterator cache_iend = brickMap.end();
  if ( cache_icfg != cache_iend ) {
    std::pair<const int,counted_brick>& entry = *cache_icfg;
    counted_brick& cBrick = entry.second;
    cacheAge = cBrick.first;
    obj = cBrick.second;
    cacheFound = true;
  }
  if ( cacheFound && !cacheAge ) return 0;
  std::map<int,DTKeyedConfig*> ageMap;
  while ( cache_iter != cache_iend ) {
    std::pair<const int,counted_brick>& entry = *cache_iter++;
    counted_brick& cBrick = entry.second;
    int& brickAge = cBrick.first;
    if ( brickAge < cacheAge ) brickAge++;
    if ( entry.first == cfgId ) brickAge = 0;
    ageMap.insert( std::pair<int,DTKeyedConfig*>( 
                   brickAge, new DTKeyedConfig( *cBrick.second ) ) );
  }

  if ( cacheFound ) return 0;

// get dummy brick list
  edm::ESHandle<cond::KeyList> klh;
  keyRecord.get( klh );
  cond::KeyList const &  kl= *klh.product();
  cond::KeyList* keyList = const_cast<cond::KeyList*>( &kl );
  if ( keyList == 0 ) return 999;

  std::vector<unsigned long long> checkedKeys;
  const DTKeyedConfig* kBrick = 0;
  checkedKeys.push_back( cfgId );
  bool brickFound = false;
  try {
    keyList->load( checkedKeys );
    kBrick = keyList->get<DTKeyedConfig>( 0 );
    if ( kBrick != 0 ) brickFound = ( kBrick->getId() == cfgId );
  }
  catch ( std::exception e ) {
  }
  if ( brickFound ) {
    counted_brick cBrick( 0, obj = new DTKeyedConfig( *kBrick ) );
    brickMap.insert( std::pair<int,counted_brick>( cfgId, cBrick ) );
    DTKeyedConfig::data_iterator d_iter = kBrick->dataBegin();
    DTKeyedConfig::data_iterator d_iend = kBrick->dataEnd();
    cachedBrickNumber++;
    cachedStringNumber += ( d_iend - d_iter );
    while ( d_iter != d_iend ) cachedByteNumber += ( *d_iter++ ).size();
  }
  std::map<int,DTKeyedConfig*>::reverse_iterator iter = ageMap.rbegin();
  while ( ( cachedBrickNumber  > maxBrickNumber  ) ||
          ( cachedStringNumber > maxStringNumber ) ||
          ( cachedByteNumber   > maxByteNumber   ) ) {
    const DTKeyedConfig* oldestBrick = iter->second;
    int oldestId = oldestBrick->getId();
    cachedBrickNumber--;
    DTKeyedConfig::data_iterator d_iter = oldestBrick->dataBegin();
    DTKeyedConfig::data_iterator d_iend = oldestBrick->dataEnd();
    cachedStringNumber -= ( d_iend - d_iter );
    while ( d_iter != d_iend ) cachedByteNumber -= ( *d_iter++ ).size();
    brickMap.erase( oldestId );
    delete iter->second;
    iter++;
  }

  return 999;

}
void DTConfigPluginHandler::getData ( const DTKeyedConfigListRcd keyRecord,
int  cfgId,
std::vector< std::string > &  list 
) [virtual]

Reimplemented from DTConfigAbstractHandler.

Definition at line 161 of file DTConfigPluginHandler.cc.

References DTKeyedConfig::dataBegin(), DTKeyedConfig::dataEnd(), getData(), DTKeyedConfig::linkBegin(), DTKeyedConfig::linkEnd(), and VarParsing::obj.

                                                                  {
  const DTKeyedConfig* obj = 0;
  get( keyRecord, cfgId, obj );
  if ( obj == 0 ) return; 
  DTKeyedConfig::data_iterator d_iter = obj->dataBegin();
  DTKeyedConfig::data_iterator d_iend = obj->dataEnd();
  while ( d_iter != d_iend ) list.push_back( *d_iter++ );
  DTKeyedConfig::link_iterator l_iter = obj->linkBegin();
  DTKeyedConfig::link_iterator l_iend = obj->linkEnd();
  while ( l_iter != l_iend ) getData( keyRecord, *l_iter++, list );
  return;
}
void DTConfigPluginHandler::getData ( const edm::EventSetup context,
int  cfgId,
std::vector< std::string > &  list 
) [virtual]

Reimplemented from DTConfigAbstractHandler.

Definition at line 154 of file DTConfigPluginHandler.cc.

References edm::EventSetup::get().

Referenced by getData().

                                                                  {
  getData( context.get<DTKeyedConfigListRcd>(), cfgId, list );
  return;
}
const DTConfigPluginHandler& DTConfigPluginHandler::operator= ( const DTConfigPluginHandler x) [private]
void DTConfigPluginHandler::purge ( ) [virtual]

purge db copy

Reimplemented from DTConfigAbstractHandler.

Definition at line 177 of file DTConfigPluginHandler.cc.

References brickMap, cachedBrickNumber, cachedByteNumber, cachedStringNumber, and gather_cfg::cout.

Referenced by ~DTConfigPluginHandler().

                                  {
  std::cout << "DTConfigPluginHandler::purge "
            << this << " "
            << cachedBrickNumber  << " "
            << cachedStringNumber << " "
            << cachedByteNumber   << std::endl;
  std::map<int,counted_brick>::const_iterator iter = brickMap.begin();
  std::map<int,counted_brick>::const_iterator iend = brickMap.end();
  while ( iter != iend ) {
    delete iter->second.second;
    iter++;
  }
  brickMap.clear();
  cachedBrickNumber  = 0;
  cachedStringNumber = 0;
  cachedByteNumber   = 0;
  return;
}

Member Data Documentation

Definition at line 72 of file DTConfigPluginHandler.h.

Referenced by get(), and purge().

Definition at line 73 of file DTConfigPluginHandler.h.

Referenced by get(), and purge().

Definition at line 75 of file DTConfigPluginHandler.h.

Referenced by get(), and purge().

Definition at line 74 of file DTConfigPluginHandler.h.

Referenced by get(), and purge().

Definition at line 59 of file DTConfigPluginHandler.h.

Referenced by get().

int DTConfigPluginHandler::maxByteNumber = 10000000 [static]

Definition at line 61 of file DTConfigPluginHandler.h.

Referenced by get().

Definition at line 60 of file DTConfigPluginHandler.h.

Referenced by get().