CMS 3D CMS Logo

DTKeyedConfigCache.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * This class was originally defined in
5  * CondCore/DTPlugins/src/DTConfigPluginHandler.cc
6  * It was moved, renamed, and modified to not be a singleton
7  * for thread safety, but otherwise little was changed.
8  *
9  * \author Paolo Ronchese INFN Padova
10  *
11  */
12 
13 //-----------------------
14 // This Class' Header --
15 //-----------------------
17 
18 //-------------------------------
19 // Collaborating Class Headers --
20 //-------------------------------
25 
26 #include <memory>
27 //-------------------
28 // Initializations --
29 //-------------------
30 const int DTKeyedConfigCache::maxBrickNumber = 5000;
31 const int DTKeyedConfigCache::maxStringNumber = 100000;
32 const int DTKeyedConfigCache::maxByteNumber = 10000000;
33 
34 //----------------
35 // Constructors --
36 //----------------
38  cachedBrickNumber( 0 ),
39  cachedStringNumber( 0 ),
40  cachedByteNumber( 0 ) {
41 }
42 
43 
44 //--------------
45 // Destructor --
46 //--------------
48  purge();
49 }
50 
51 
53  int cfgId, const DTKeyedConfig*& obj ) {
54 
55  bool cacheFound = false;
56  int cacheAge = 999999999;
57  std::map<int,counted_brick>::iterator cache_iter = brickMap.begin();
58  std::map<int,counted_brick>::iterator cache_icfg = brickMap.find( cfgId );
59  std::map<int,counted_brick>::iterator cache_iend = brickMap.end();
60  if ( cache_icfg != cache_iend ) {
61  std::pair<const int,counted_brick>& entry = *cache_icfg;
62  counted_brick& cBrick = entry.second;
63  cacheAge = cBrick.first;
64  obj = cBrick.second;
65  cacheFound = true;
66  }
67 
68  std::map<int,const DTKeyedConfig*> ageMap;
69  if ( cacheFound ) {
70  if ( !cacheAge ) return 0;
71  while ( cache_iter != cache_iend ) {
72  std::pair<const int,counted_brick>& entry = *cache_iter++;
73  counted_brick& cBrick = entry.second;
74  int& brickAge = cBrick.first;
75  if ( brickAge < cacheAge ) brickAge++;
76  if ( entry.first == cfgId ) brickAge = 0;
77  }
78  return 0;
79  }
80  else {
81  while ( cache_iter != cache_iend ) {
82  std::pair<const int,counted_brick>& entry = *cache_iter++;
83  counted_brick& cBrick = entry.second;
84  ageMap.insert( std::pair<int,const DTKeyedConfig*>(
85  ++cBrick.first, entry.second.second ) );
86  }
87  }
88 
89 // get dummy brick list
91  keyRecord.get( klh );
92  cond::persistency::KeyList const & kl= *klh.product();
93  // This const_cast and usage of KeyList is a problem
94  // that will need to be addressed in the future.
95  // I'm not fixing now, because I want to finish what I am
96  // fixing. One thing at a time. (This was already in the
97  // the code I copied to make this file)
98  cond::persistency::KeyList* keyList = const_cast<cond::persistency::KeyList*>( &kl );
99  if ( keyList == nullptr ) return 999;
100 
101  std::vector<unsigned long long> checkedKeys;
102  std::shared_ptr<DTKeyedConfig> kBrick;
103  checkedKeys.push_back( cfgId );
104  bool brickFound = false;
105  try {
106  keyList->load( checkedKeys );
107  kBrick = keyList->get<DTKeyedConfig>( 0 );
108  if ( kBrick.get() ) brickFound = ( kBrick->getId() == cfgId );
109  }
110  catch ( std::exception const & e ) {
111  }
112  if ( brickFound ) {
113  counted_brick cBrick( 0, obj = new DTKeyedConfig( *kBrick ) );
114  brickMap.insert( std::pair<int,counted_brick>( cfgId, cBrick ) );
115  DTKeyedConfig::data_iterator d_iter = kBrick->dataBegin();
116  DTKeyedConfig::data_iterator d_iend = kBrick->dataEnd();
118  cachedStringNumber += ( d_iend - d_iter );
119  while ( d_iter != d_iend ) cachedByteNumber += ( *d_iter++ ).size();
120  }
121  std::map<int,const DTKeyedConfig*>::reverse_iterator iter = ageMap.rbegin();
122  while ( ( cachedBrickNumber > maxBrickNumber ) ||
125  const DTKeyedConfig* oldestBrick = iter->second;
126  int oldestId = oldestBrick->getId();
128  DTKeyedConfig::data_iterator d_iter = oldestBrick->dataBegin();
129  DTKeyedConfig::data_iterator d_iend = oldestBrick->dataEnd();
130  cachedStringNumber -= ( d_iend - d_iter );
131  while ( d_iter != d_iend ) cachedByteNumber -= ( *d_iter++ ).size();
132  brickMap.erase( oldestId );
133  delete iter->second;
134  iter++;
135  }
136 
137  return 999;
138 
139 }
140 
141 
143  int cfgId,
144  std::vector<std::string>& list ) {
145  const DTKeyedConfig* obj = nullptr;
146  get( keyRecord, cfgId, obj );
147  if ( obj == nullptr ) return;
148  DTKeyedConfig::data_iterator d_iter = obj->dataBegin();
149  DTKeyedConfig::data_iterator d_iend = obj->dataEnd();
150  while ( d_iter != d_iend ) list.push_back( *d_iter++ );
151  DTKeyedConfig::link_iterator l_iter = obj->linkBegin();
152  DTKeyedConfig::link_iterator l_iend = obj->linkEnd();
153  while ( l_iter != l_iend ) getData( keyRecord, *l_iter++, list );
154  return;
155 }
156 
157 
159  std::map<int,counted_brick>::const_iterator iter = brickMap.begin();
160  std::map<int,counted_brick>::const_iterator iend = brickMap.end();
161  while ( iter != iend ) {
162  delete iter->second.second;
163  iter++;
164  }
165  brickMap.clear();
166  cachedBrickNumber = 0;
167  cachedStringNumber = 0;
168  cachedByteNumber = 0;
169  return;
170 }
171 
size
Write out results.
std::map< int, counted_brick > brickMap
void getData(const DTKeyedConfigListRcd &keyRecord, int cfgId, std::vector< std::string > &list)
data_iterator dataBegin() const
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
link_iterator linkBegin() const
link_iterator linkEnd() const
int get(const DTKeyedConfigListRcd &keyRecord, int cfgId, const DTKeyedConfig *&obj)
std::vector< int >::const_iterator link_iterator
Definition: DTKeyedConfig.h:59
static const int maxByteNumber
std::shared_ptr< T > get(size_t n) const
Definition: KeyList.h:40
int getId() const
std::vector< std::string >::const_iterator data_iterator
Definition: DTKeyedConfig.h:58
static const int maxBrickNumber
void load(const std::vector< unsigned long long > &keys)
Definition: KeyList.cc:14
std::pair< int, const DTKeyedConfig * > counted_brick
static const int maxStringNumber
T const * product() const
Definition: ESHandle.h:86
data_iterator dataEnd() const
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run