CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Attributes | Private Types | Private Attributes
DTKeyedConfigCache Class Reference

#include <DTKeyedConfigCache.h>

Public Member Functions

 DTKeyedConfigCache ()
 
 DTKeyedConfigCache (const DTKeyedConfigCache &x)=delete
 
int get (const cond::persistency::KeyList &keyList, int cfgId, const DTKeyedConfig *&obj)
 
void getData (const cond::persistency::KeyList &keyList, int cfgId, std::vector< std::string > &list)
 
const DTKeyedConfigCacheoperator= (const DTKeyedConfigCache &x)=delete
 
void purge ()
 
virtual ~DTKeyedConfigCache ()
 

Static Public Attributes

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

Private Types

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

Private Attributes

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

Detailed Description

Description: Class to hold configuration identifier for chambers

This class was originally defined in CondCore/DTPlugins/interface/DTConfigPluginHandler.h It was moved, renamed, and modified to not be a singleton for thread safety, but otherwise little was changed.

Author
Paolo Ronchese INFN Padova

Definition at line 29 of file DTKeyedConfigCache.h.

Member Typedef Documentation

◆ counted_brick

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

Definition at line 47 of file DTKeyedConfigCache.h.

Constructor & Destructor Documentation

◆ DTKeyedConfigCache() [1/2]

DTKeyedConfigCache::DTKeyedConfigCache ( )

◆ DTKeyedConfigCache() [2/2]

DTKeyedConfigCache::DTKeyedConfigCache ( const DTKeyedConfigCache x)
delete

◆ ~DTKeyedConfigCache()

DTKeyedConfigCache::~DTKeyedConfigCache ( )
virtual

Definition at line 40 of file DTKeyedConfigCache.cc.

References purge().

40 { purge(); }

Member Function Documentation

◆ get()

int DTKeyedConfigCache::get ( const cond::persistency::KeyList keyList,
int  cfgId,
const DTKeyedConfig *&  obj 
)

Definition at line 42 of file DTKeyedConfigCache.cc.

References brickMap, cachedBrickNumber, cachedByteNumber, cachedStringNumber, DTKeyedConfig::dataBegin(), DTKeyedConfig::dataEnd(), MillePedeFileConverter_cfg::e, mps_splice::entry, cppFunctionSkipper::exception, DTKeyedConfig::getId(), cond::persistency::KeyList::getUsingKey(), maxBrickNumber, maxByteNumber, maxStringNumber, getGTfromDQMFile::obj, and findQualityFiles::size.

Referenced by Options.Options::__getitem__(), betterConfigParser.BetterConfigParser::__updateDict(), submitPVValidationJobs.BetterConfigParser::__updateDict(), util.rrapi.RRApi::columns(), rrapi.RRApi::columns(), rrapi.RRApi::count(), util.rrapi.RRApi::count(), rrapi.RRApi::data(), util.rrapi.RRApi::data(), betterConfigParser.BetterConfigParser::getCompares(), betterConfigParser.BetterConfigParser::getGeneral(), betterConfigParser.BetterConfigParser::getResultingSection(), submitPVValidationJobs.BetterConfigParser::getResultingSection(), util.rrapi.RRApi::report(), rrapi.RRApi::report(), rrapi.RRApi::reports(), util.rrapi.RRApi::reports(), rrapi.RRApi::tables(), util.rrapi.RRApi::tables(), util.rrapi.RRApi::tags(), rrapi.RRApi::tags(), rrapi.RRApi::templates(), util.rrapi.RRApi::templates(), util.rrapi.RRApi::workspaces(), and rrapi.RRApi::workspaces().

42  {
43  bool cacheFound = false;
44  int cacheAge = 999999999;
45  std::map<int, counted_brick>::iterator cache_iter = brickMap.begin();
46  std::map<int, counted_brick>::iterator cache_icfg = brickMap.find(cfgId);
47  std::map<int, counted_brick>::iterator cache_iend = brickMap.end();
48  if (cache_icfg != cache_iend) {
49  std::pair<const int, counted_brick>& entry = *cache_icfg;
50  counted_brick& cBrick = entry.second;
51  cacheAge = cBrick.first;
52  obj = cBrick.second;
53  cacheFound = true;
54  }
55 
56  std::map<int, const DTKeyedConfig*> ageMap;
57  if (cacheFound) {
58  if (!cacheAge)
59  return 0;
60  while (cache_iter != cache_iend) {
61  std::pair<const int, counted_brick>& entry = *cache_iter++;
62  counted_brick& cBrick = entry.second;
63  int& brickAge = cBrick.first;
64  if (brickAge < cacheAge)
65  brickAge++;
66  if (entry.first == cfgId)
67  brickAge = 0;
68  }
69  return 0;
70  } else {
71  while (cache_iter != cache_iend) {
72  std::pair<const int, counted_brick>& entry = *cache_iter++;
73  counted_brick& cBrick = entry.second;
74  ageMap.insert(std::pair<int, const DTKeyedConfig*>(++cBrick.first, entry.second.second));
75  }
76  }
77 
78  std::shared_ptr<DTKeyedConfig> kBrick;
79  bool brickFound = false;
80  try {
81  kBrick = keyList.getUsingKey<DTKeyedConfig>(cfgId);
82  if (kBrick.get())
83  brickFound = (kBrick->getId() == cfgId);
84  } catch (std::exception const& e) {
85  }
86  if (brickFound) {
87  counted_brick cBrick(0, obj = new DTKeyedConfig(*kBrick));
88  brickMap.insert(std::pair<int, counted_brick>(cfgId, cBrick));
89  DTKeyedConfig::data_iterator d_iter = kBrick->dataBegin();
90  DTKeyedConfig::data_iterator d_iend = kBrick->dataEnd();
92  cachedStringNumber += (d_iend - d_iter);
93  while (d_iter != d_iend)
94  cachedByteNumber += (*d_iter++).size();
95  }
96  std::map<int, const DTKeyedConfig*>::reverse_iterator iter = ageMap.rbegin();
99  const DTKeyedConfig* oldestBrick = iter->second;
100  int oldestId = oldestBrick->getId();
102  DTKeyedConfig::data_iterator d_iter = oldestBrick->dataBegin();
103  DTKeyedConfig::data_iterator d_iend = oldestBrick->dataEnd();
104  cachedStringNumber -= (d_iend - d_iter);
105  while (d_iter != d_iend)
106  cachedByteNumber -= (*d_iter++).size();
107  brickMap.erase(oldestId);
108  delete iter->second;
109  iter++;
110  }
111 
112  return 999;
113 }
size
Write out results.
std::map< int, counted_brick > brickMap
data_iterator dataBegin() const
std::pair< int, const DTKeyedConfig * > counted_brick
data_iterator dataEnd() const
static const int maxByteNumber
std::vector< std::string >::const_iterator data_iterator
Definition: DTKeyedConfig.h:54
int getId() const
static const int maxBrickNumber
static const int maxStringNumber
std::shared_ptr< T > getUsingKey(unsigned long long key) const
Definition: KeyList.h:57

◆ getData()

void DTKeyedConfigCache::getData ( const cond::persistency::KeyList keyList,
int  cfgId,
std::vector< std::string > &  list 
)

Definition at line 115 of file DTKeyedConfigCache.cc.

References getGTfromDQMFile::obj.

Referenced by DTConfigDBProducer::readDTCCBConfig().

115  {
116  const DTKeyedConfig* obj = nullptr;
117  get(keyList, cfgId, obj);
118  if (obj == nullptr)
119  return;
120  DTKeyedConfig::data_iterator d_iter = obj->dataBegin();
121  DTKeyedConfig::data_iterator d_iend = obj->dataEnd();
122  while (d_iter != d_iend)
123  list.push_back(*d_iter++);
124  DTKeyedConfig::link_iterator l_iter = obj->linkBegin();
125  DTKeyedConfig::link_iterator l_iend = obj->linkEnd();
126  while (l_iter != l_iend)
127  getData(keyList, *l_iter++, list);
128  return;
129 }
void getData(const cond::persistency::KeyList &keyList, int cfgId, std::vector< std::string > &list)
std::vector< int >::const_iterator link_iterator
Definition: DTKeyedConfig.h:55
std::vector< std::string >::const_iterator data_iterator
Definition: DTKeyedConfig.h:54

◆ operator=()

const DTKeyedConfigCache& DTKeyedConfigCache::operator= ( const DTKeyedConfigCache x)
delete

◆ purge()

void DTKeyedConfigCache::purge ( )

Definition at line 131 of file DTKeyedConfigCache.cc.

References brickMap, cachedBrickNumber, cachedByteNumber, and cachedStringNumber.

Referenced by ~DTKeyedConfigCache().

131  {
132  std::map<int, counted_brick>::const_iterator iter = brickMap.begin();
133  std::map<int, counted_brick>::const_iterator iend = brickMap.end();
134  while (iter != iend) {
135  delete iter->second.second;
136  iter++;
137  }
138  brickMap.clear();
139  cachedBrickNumber = 0;
140  cachedStringNumber = 0;
141  cachedByteNumber = 0;
142  return;
143 }
std::map< int, counted_brick > brickMap

Member Data Documentation

◆ brickMap

std::map<int, counted_brick> DTKeyedConfigCache::brickMap
private

Definition at line 48 of file DTKeyedConfigCache.h.

Referenced by get(), and purge().

◆ cachedBrickNumber

int DTKeyedConfigCache::cachedBrickNumber
private

Definition at line 49 of file DTKeyedConfigCache.h.

Referenced by get(), and purge().

◆ cachedByteNumber

int DTKeyedConfigCache::cachedByteNumber
private

Definition at line 51 of file DTKeyedConfigCache.h.

Referenced by get(), and purge().

◆ cachedStringNumber

int DTKeyedConfigCache::cachedStringNumber
private

Definition at line 50 of file DTKeyedConfigCache.h.

Referenced by get(), and purge().

◆ maxBrickNumber

const int DTKeyedConfigCache::maxBrickNumber = 5000
static

Definition at line 42 of file DTKeyedConfigCache.h.

Referenced by get().

◆ maxByteNumber

const int DTKeyedConfigCache::maxByteNumber = 10000000
static

Definition at line 44 of file DTKeyedConfigCache.h.

Referenced by get().

◆ maxStringNumber

const int DTKeyedConfigCache::maxStringNumber = 100000
static

Definition at line 43 of file DTKeyedConfigCache.h.

Referenced by get().