CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 <boost/shared_ptr.hpp>
27 
28 //-------------------
29 // Initializations --
30 //-------------------
31 const int DTKeyedConfigCache::maxBrickNumber = 5000;
32 const int DTKeyedConfigCache::maxStringNumber = 100000;
33 const int DTKeyedConfigCache::maxByteNumber = 10000000;
34 
35 //----------------
36 // Constructors --
37 //----------------
39  cachedBrickNumber( 0 ),
40  cachedStringNumber( 0 ),
41  cachedByteNumber( 0 ) {
42 }
43 
44 
45 //--------------
46 // Destructor --
47 //--------------
49  purge();
50 }
51 
52 
54  int cfgId, const DTKeyedConfig*& obj ) {
55 
56  bool cacheFound = false;
57  int cacheAge = 999999999;
58  std::map<int,counted_brick>::iterator cache_iter = brickMap.begin();
59  std::map<int,counted_brick>::iterator cache_icfg = brickMap.find( cfgId );
60  std::map<int,counted_brick>::iterator cache_iend = brickMap.end();
61  if ( cache_icfg != cache_iend ) {
62  std::pair<const int,counted_brick>& entry = *cache_icfg;
63  counted_brick& cBrick = entry.second;
64  cacheAge = cBrick.first;
65  obj = cBrick.second;
66  cacheFound = true;
67  }
68 
69  std::map<int,const DTKeyedConfig*> ageMap;
70  if ( cacheFound ) {
71  if ( !cacheAge ) return 0;
72  while ( cache_iter != cache_iend ) {
73  std::pair<const int,counted_brick>& entry = *cache_iter++;
74  counted_brick& cBrick = entry.second;
75  int& brickAge = cBrick.first;
76  if ( brickAge < cacheAge ) brickAge++;
77  if ( entry.first == cfgId ) brickAge = 0;
78  }
79  return 0;
80  }
81  else {
82  while ( cache_iter != cache_iend ) {
83  std::pair<const int,counted_brick>& entry = *cache_iter++;
84  counted_brick& cBrick = entry.second;
85  ageMap.insert( std::pair<int,const DTKeyedConfig*>(
86  ++cBrick.first, entry.second.second ) );
87  }
88  }
89 
90 // get dummy brick list
92  keyRecord.get( klh );
93  cond::persistency::KeyList const & kl= *klh.product();
94  // This const_cast and usage of KeyList is a problem
95  // that will need to be addressed in the future.
96  // I'm not fixing now, because I want to finish what I am
97  // fixing. One thing at a time. (This was already in the
98  // the code I copied to make this file)
99  cond::persistency::KeyList* keyList = const_cast<cond::persistency::KeyList*>( &kl );
100  if ( keyList == 0 ) return 999;
101 
102  std::vector<unsigned long long> checkedKeys;
103  boost::shared_ptr<DTKeyedConfig> kBrick;
104  checkedKeys.push_back( cfgId );
105  bool brickFound = false;
106  try {
107  keyList->load( checkedKeys );
108  kBrick = keyList->get<DTKeyedConfig>( 0 );
109  if ( kBrick.get() ) brickFound = ( kBrick->getId() == cfgId );
110  }
111  catch ( std::exception const & e ) {
112  }
113  if ( brickFound ) {
114  counted_brick cBrick( 0, obj = new DTKeyedConfig( *kBrick ) );
115  brickMap.insert( std::pair<int,counted_brick>( cfgId, cBrick ) );
116  DTKeyedConfig::data_iterator d_iter = kBrick->dataBegin();
117  DTKeyedConfig::data_iterator d_iend = kBrick->dataEnd();
119  cachedStringNumber += ( d_iend - d_iter );
120  while ( d_iter != d_iend ) cachedByteNumber += ( *d_iter++ ).size();
121  }
122  std::map<int,const DTKeyedConfig*>::reverse_iterator iter = ageMap.rbegin();
123  while ( ( cachedBrickNumber > maxBrickNumber ) ||
126  const DTKeyedConfig* oldestBrick = iter->second;
127  int oldestId = oldestBrick->getId();
129  DTKeyedConfig::data_iterator d_iter = oldestBrick->dataBegin();
130  DTKeyedConfig::data_iterator d_iend = oldestBrick->dataEnd();
131  cachedStringNumber -= ( d_iend - d_iter );
132  while ( d_iter != d_iend ) cachedByteNumber -= ( *d_iter++ ).size();
133  brickMap.erase( oldestId );
134  delete iter->second;
135  iter++;
136  }
137 
138  return 999;
139 
140 }
141 
142 
144  int cfgId,
145  std::vector<std::string>& list ) {
146  const DTKeyedConfig* obj = 0;
147  get( keyRecord, cfgId, obj );
148  if ( obj == 0 ) return;
149  DTKeyedConfig::data_iterator d_iter = obj->dataBegin();
150  DTKeyedConfig::data_iterator d_iend = obj->dataEnd();
151  while ( d_iter != d_iend ) list.push_back( *d_iter++ );
152  DTKeyedConfig::link_iterator l_iter = obj->linkBegin();
153  DTKeyedConfig::link_iterator l_iend = obj->linkEnd();
154  while ( l_iter != l_iend ) getData( keyRecord, *l_iter++, list );
155  return;
156 }
157 
158 
160  std::map<int,counted_brick>::const_iterator iter = brickMap.begin();
161  std::map<int,counted_brick>::const_iterator iend = brickMap.end();
162  while ( iter != iend ) {
163  delete iter->second.second;
164  iter++;
165  }
166  brickMap.clear();
167  cachedBrickNumber = 0;
168  cachedStringNumber = 0;
169  cachedByteNumber = 0;
170  return;
171 }
172 
std::map< int, counted_brick > brickMap
void getData(const DTKeyedConfigListRcd &keyRecord, int cfgId, std::vector< std::string > &list)
boost::shared_ptr< T > get(size_t n) const
Definition: KeyList.h:39
data_iterator dataBegin() const
link_iterator linkBegin() const
link_iterator linkEnd() const
void get(HolderT &iHolder) 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
T const * product() const
Definition: ESHandle.h:86
int getId() const
list entry
Definition: mps_splice.py:62
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
tuple size
Write out results.
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