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  * $Date: 2010/03/18 16:01:06 $
5  * $Revision: 1.1.2.1 $
6  * \author Paolo Ronchese INFN Padova
7  *
8  */
9 
10 //-----------------------
11 // This Class' Header --
12 //-----------------------
14 
15 //-------------------------------
16 // Collaborating Class Headers --
17 //-------------------------------
24 
25 //---------------
26 // C++ Headers --
27 //---------------
28 //#include <iostream>
29 #include <cstdio>
30 
31 //-------------------
32 // Initializations --
33 //-------------------
37 //DTConfigPluginHandler::handler_map DTConfigPluginHandler::handlerMap;
38 
39 //----------------
40 // Constructors --
41 //----------------
43  cachedBrickNumber( 0 ),
44  cachedStringNumber( 0 ),
45  cachedByteNumber( 0 ) {
46 // std::cout << "===============================" << std::endl;
47 // std::cout << "= =" << std::endl;
48 // std::cout << "= new DTConfigPluginHandler =" << std::endl;
49 // std::cout << "= =" << std::endl;
50 // std::cout << "===============================" << std::endl;
51 // if ( instance == 0 ) instance = this;
52 }
53 
54 
55 //--------------
56 // Destructor --
57 //--------------
59  purge();
60 }
61 
62 
63 //--------------
64 // Operations --
65 //--------------
67  if ( instance == 0 ) instance = new DTConfigPluginHandler;
68 }
69 
70 
72  int cfgId, const DTKeyedConfig*& obj ) {
73  return get( context.get<DTKeyedConfigListRcd>(), cfgId, obj );
74 }
75 
76 
78  int cfgId, const DTKeyedConfig*& obj ) {
79 
80  bool cacheFound = false;
81  int cacheAge = 999999999;
82  std::map<int,counted_brick>::iterator cache_iter = brickMap.begin();
83  std::map<int,counted_brick>::iterator cache_icfg = brickMap.find( cfgId );
84  std::map<int,counted_brick>::iterator cache_iend = brickMap.end();
85  if ( cache_icfg != cache_iend ) {
86  std::pair<const int,counted_brick>& entry = *cache_icfg;
87  counted_brick& cBrick = entry.second;
88  cacheAge = cBrick.first;
89  obj = cBrick.second;
90  cacheFound = true;
91  }
92  if ( cacheFound && !cacheAge ) return 0;
93  std::map<int,DTKeyedConfig*> ageMap;
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  ageMap.insert( std::pair<int,DTKeyedConfig*>(
101  brickAge, new DTKeyedConfig( *cBrick.second ) ) );
102  }
103 
104  if ( cacheFound ) return 0;
105 
106 // get dummy brick list
108  keyRecord.get( klh );
109  cond::KeyList const & kl= *klh.product();
110  cond::KeyList* keyList = const_cast<cond::KeyList*>( &kl );
111  if ( keyList == 0 ) return 999;
112 
113  std::vector<unsigned long long> checkedKeys;
114  const DTKeyedConfig* kBrick = 0;
115  checkedKeys.push_back( cfgId );
116  bool brickFound = false;
117  try {
118  keyList->load( checkedKeys );
119  kBrick = keyList->get<DTKeyedConfig>( 0 );
120  if ( kBrick != 0 ) brickFound = ( kBrick->getId() == cfgId );
121  }
122  catch ( std::exception e ) {
123  }
124  if ( brickFound ) {
125  counted_brick cBrick( 0, obj = new DTKeyedConfig( *kBrick ) );
126  brickMap.insert( std::pair<int,counted_brick>( cfgId, cBrick ) );
127  DTKeyedConfig::data_iterator d_iter = kBrick->dataBegin();
128  DTKeyedConfig::data_iterator d_iend = kBrick->dataEnd();
130  cachedStringNumber += ( d_iend - d_iter );
131  while ( d_iter != d_iend ) cachedByteNumber += ( *d_iter++ ).size();
132  }
133  std::map<int,DTKeyedConfig*>::reverse_iterator iter = ageMap.rbegin();
134  while ( ( cachedBrickNumber > maxBrickNumber ) ||
137  const DTKeyedConfig* oldestBrick = iter->second;
138  int oldestId = oldestBrick->getId();
140  DTKeyedConfig::data_iterator d_iter = oldestBrick->dataBegin();
141  DTKeyedConfig::data_iterator d_iend = oldestBrick->dataEnd();
142  cachedStringNumber -= ( d_iend - d_iter );
143  while ( d_iter != d_iend ) cachedByteNumber -= ( *d_iter++ ).size();
144  brickMap.erase( oldestId );
145  delete iter->second;
146  iter++;
147  }
148 
149  return 999;
150 
151 }
152 
153 
154 void DTConfigPluginHandler::getData( const edm::EventSetup& context, int cfgId,
155  std::vector<std::string>& list ) {
156  getData( context.get<DTKeyedConfigListRcd>(), cfgId, list );
157  return;
158 }
159 
160 
162  int cfgId,
163  std::vector<std::string>& list ) {
164  const DTKeyedConfig* obj = 0;
165  get( keyRecord, cfgId, obj );
166  if ( obj == 0 ) return;
167  DTKeyedConfig::data_iterator d_iter = obj->dataBegin();
168  DTKeyedConfig::data_iterator d_iend = obj->dataEnd();
169  while ( d_iter != d_iend ) list.push_back( *d_iter++ );
170  DTKeyedConfig::link_iterator l_iter = obj->linkBegin();
171  DTKeyedConfig::link_iterator l_iend = obj->linkEnd();
172  while ( l_iter != l_iend ) getData( keyRecord, *l_iter++, list );
173  return;
174 }
175 
176 
178  std::cout << "DTConfigPluginHandler::purge "
179  << this << " "
180  << cachedBrickNumber << " "
181  << cachedStringNumber << " "
182  << cachedByteNumber << std::endl;
183  std::map<int,counted_brick>::const_iterator iter = brickMap.begin();
184  std::map<int,counted_brick>::const_iterator iend = brickMap.end();
185  while ( iter != iend ) {
186  delete iter->second.second;
187  iter++;
188  }
189  brickMap.clear();
190  cachedBrickNumber = 0;
191  cachedStringNumber = 0;
192  cachedByteNumber = 0;
193  return;
194 }
195 
std::map< int, counted_brick > brickMap
void load(std::vector< unsigned long long > const &keys)
Definition: KeyList.cc:10
std::pair< int, const DTKeyedConfig * > counted_brick
virtual int get(const edm::EventSetup &context, int cfgId, const DTKeyedConfig *&obj)
get content
data_iterator dataBegin() const
link_iterator linkBegin() const
tuple obj
Example code starts here #.
Definition: VarParsing.py:655
link_iterator linkEnd() const
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
static void build()
build static object
void get(HolderT &iHolder) const
T const * get(int n) const
Definition: KeyList.h:39
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)
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:41
static DTConfigAbstractHandler * instance
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