CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTConfigPluginHandler.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author Paolo Ronchese INFN Padova
5  *
6  */
7 
8 //-----------------------
9 // This Class' Header --
10 //-----------------------
12 
13 //-------------------------------
14 // Collaborating Class Headers --
15 //-------------------------------
22 
23 //---------------
24 // C++ Headers --
25 //---------------
26 #include <cstdio>
27 #include <iostream>
28 
29 //-------------------
30 // Initializations --
31 //-------------------
34 const int DTConfigPluginHandler::maxByteNumber = 10000000;
35 //DTConfigPluginHandler::handler_map DTConfigPluginHandler::handlerMap;
36 
37 //----------------
38 // Constructors --
39 //----------------
41  cachedBrickNumber( 0 ),
42  cachedStringNumber( 0 ),
43  cachedByteNumber( 0 ) {
44 // std::cout << "===============================" << std::endl;
45 // std::cout << "= =" << std::endl;
46 // std::cout << "= new DTConfigPluginHandler =" << std::endl;
47 // std::cout << "= =" << std::endl;
48 // std::cout << "===============================" << std::endl;
49 // if ( instance == 0 ) instance = this;
50 }
51 
52 
53 //--------------
54 // Destructor --
55 //--------------
57  purge();
58 }
59 
60 
61 //--------------
62 // Operations --
63 //--------------
65  if ( instance == 0 ) instance = new DTConfigPluginHandler;
66 }
67 
68 
70  int cfgId, const DTKeyedConfig*& obj ) {
71  return get( context.get<DTKeyedConfigListRcd>(), cfgId, obj );
72 }
73 
74 
76  int cfgId, const DTKeyedConfig*& obj ) {
77 
78  bool cacheFound = false;
79  int cacheAge = 999999999;
80  std::map<int,counted_brick>::iterator cache_iter = brickMap.begin();
81  std::map<int,counted_brick>::iterator cache_icfg = brickMap.find( cfgId );
82  std::map<int,counted_brick>::iterator cache_iend = brickMap.end();
83  if ( cache_icfg != cache_iend ) {
84  std::pair<const int,counted_brick>& entry = *cache_icfg;
85  counted_brick& cBrick = entry.second;
86  cacheAge = cBrick.first;
87  obj = cBrick.second;
88  cacheFound = true;
89  }
90 
91  std::map<int,const DTKeyedConfig*> ageMap;
92  if ( cacheFound ) {
93  if ( !cacheAge ) return 0;
94  while ( cache_iter != cache_iend ) {
95  std::pair<const int,counted_brick>& entry = *cache_iter++;
96  counted_brick& cBrick = entry.second;
97  int& brickAge = cBrick.first;
98  if ( brickAge < cacheAge ) brickAge++;
99  if ( entry.first == cfgId ) brickAge = 0;
100  }
101  return 0;
102  }
103  else {
104  while ( cache_iter != cache_iend ) {
105  std::pair<const int,counted_brick>& entry = *cache_iter++;
106  counted_brick& cBrick = entry.second;
107  ageMap.insert( std::pair<int,const DTKeyedConfig*>(
108  ++cBrick.first, entry.second.second ) );
109  }
110  }
111 
112 // get dummy brick list
114  keyRecord.get( klh );
115  cond::persistency::KeyList const & kl= *klh.product();
116  cond::persistency::KeyList* keyList = const_cast<cond::persistency::KeyList*>( &kl );
117  if ( keyList == 0 ) return 999;
118 
119  std::vector<unsigned long long> checkedKeys;
120  boost::shared_ptr<DTKeyedConfig> kBrick;
121  checkedKeys.push_back( cfgId );
122  bool brickFound = false;
123  try {
124  keyList->load( checkedKeys );
125  kBrick = keyList->get<DTKeyedConfig>( 0 );
126  if ( kBrick.get() ) brickFound = ( kBrick->getId() == cfgId );
127  }
128  catch ( std::exception const & e ) {
129  }
130  if ( brickFound ) {
131  counted_brick cBrick( 0, obj = new DTKeyedConfig( *kBrick ) );
132  brickMap.insert( std::pair<int,counted_brick>( cfgId, cBrick ) );
133  DTKeyedConfig::data_iterator d_iter = kBrick->dataBegin();
134  DTKeyedConfig::data_iterator d_iend = kBrick->dataEnd();
136  cachedStringNumber += ( d_iend - d_iter );
137  while ( d_iter != d_iend ) cachedByteNumber += ( *d_iter++ ).size();
138  }
139  std::map<int,const DTKeyedConfig*>::reverse_iterator iter = ageMap.rbegin();
140  while ( ( cachedBrickNumber > maxBrickNumber ) ||
143  const DTKeyedConfig* oldestBrick = iter->second;
144  int oldestId = oldestBrick->getId();
146  DTKeyedConfig::data_iterator d_iter = oldestBrick->dataBegin();
147  DTKeyedConfig::data_iterator d_iend = oldestBrick->dataEnd();
148  cachedStringNumber -= ( d_iend - d_iter );
149  while ( d_iter != d_iend ) cachedByteNumber -= ( *d_iter++ ).size();
150  brickMap.erase( oldestId );
151  delete iter->second;
152  iter++;
153  }
154 
155  return 999;
156 
157 }
158 
159 
160 void DTConfigPluginHandler::getData( const edm::EventSetup& context, int cfgId,
161  std::vector<std::string>& list ) {
162  getData( context.get<DTKeyedConfigListRcd>(), cfgId, list );
163  return;
164 }
165 
166 
168  int cfgId,
169  std::vector<std::string>& list ) {
170  const DTKeyedConfig* obj = 0;
171  get( keyRecord, cfgId, obj );
172  if ( obj == 0 ) return;
173  DTKeyedConfig::data_iterator d_iter = obj->dataBegin();
174  DTKeyedConfig::data_iterator d_iend = obj->dataEnd();
175  while ( d_iter != d_iend ) list.push_back( *d_iter++ );
176  DTKeyedConfig::link_iterator l_iter = obj->linkBegin();
177  DTKeyedConfig::link_iterator l_iend = obj->linkEnd();
178  while ( l_iter != l_iend ) getData( keyRecord, *l_iter++, list );
179  return;
180 }
181 
182 
184  std::cout << "DTConfigPluginHandler::purge "
185  << this << " "
186  << cachedBrickNumber << " "
187  << cachedStringNumber << " "
188  << cachedByteNumber << std::endl;
189  std::map<int,counted_brick>::const_iterator iter = brickMap.begin();
190  std::map<int,counted_brick>::const_iterator iend = brickMap.end();
191  while ( iter != iend ) {
192  delete iter->second.second;
193  iter++;
194  }
195  brickMap.clear();
196  cachedBrickNumber = 0;
197  cachedStringNumber = 0;
198  cachedByteNumber = 0;
199  return;
200 }
201 
static const int maxBrickNumber
std::map< int, counted_brick > brickMap
std::pair< int, const DTKeyedConfig * > counted_brick
virtual int get(const edm::EventSetup &context, int cfgId, const DTKeyedConfig *&obj)
get content
boost::shared_ptr< T > get(size_t n) const
Definition: KeyList.h:39
static const int maxByteNumber
data_iterator dataBegin() const
link_iterator linkBegin() const
link_iterator linkEnd() const
static void build()
build static object
void get(HolderT &iHolder) const
std::vector< int >::const_iterator link_iterator
Definition: DTKeyedConfig.h:57
void purge()
purge db copy
virtual void getData(const edm::EventSetup &context, int cfgId, std::vector< std::string > &list)
static const int maxStringNumber
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
int getId() const
std::vector< std::string >::const_iterator data_iterator
Definition: DTKeyedConfig.h:56
tuple cout
Definition: gather_cfg.py:121
static DTConfigAbstractHandler * instance
void load(const std::vector< unsigned long long > &keys)
Definition: KeyList.cc:14
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