CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTKeyedConfigHandler.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * $Date: 2012/02/15 16:04:16 $
5  * $Revision: 1.9 $
6  * \author Paolo Ronchese INFN Padova
7  *
8  */
9 
10 //-----------------------
11 // This Class' Header --
12 //-----------------------
14 
15 //-------------------------------
16 // Collaborating Class Headers --
17 //-------------------------------
20 
21 
23 
28 
29 #include "RelationalAccess/ISchema.h"
30 #include "RelationalAccess/ITable.h"
31 #include "RelationalAccess/ICursor.h"
32 #include "RelationalAccess/IQuery.h"
33 #include "CoralBase/AttributeList.h"
34 #include "CoralBase/AttributeSpecification.h"
35 #include "CoralBase/Attribute.h"
36 
37 //---------------
38 // C++ Headers --
39 //---------------
40 
41 
42 //-------------------
43 // Initializations --
44 //-------------------
46 
47 //----------------
48 // Constructors --
49 //----------------
51  copyData( ps.getUntrackedParameter<bool> ( "copyData", true ) ),
52  minBrickId( ps.getUntrackedParameter<int> ( "minBrick", 0 ) ),
53  maxBrickId( ps.getUntrackedParameter<int> ( "maxBrick", 999999999 ) ),
54  minRunId( ps.getUntrackedParameter<int> ( "minRun", 0 ) ),
55  maxRunId( ps.getUntrackedParameter<int> ( "maxRun", 999999999 ) ),
56  dataTag( ps.getParameter<std::string> ( "tag" ) ),
57  onlineConnect( ps.getParameter<std::string> ( "onlineDB" ) ),
58  onlineAuthentication( ps.getParameter<std::string> (
59  "onlineAuthentication" ) ),
60  brickContainer( ps.getParameter<std::string> ( "container" ) ),
61  connection(),
62  isession() {
63  std::cout << " PopCon application for DT configuration export "
64  << onlineAuthentication << std::endl;
65 }
66 
67 //--------------
68 // Destructor --
69 //--------------
71 }
72 
73 //--------------
74 // Operations --
75 //--------------
77 
78  //to access the information on the tag inside the offline database:
79  cond::TagInfo const & ti = tagInfo();
80  unsigned int last = ti.lastInterval.first;
81  std::cout << "last configuration key already copied for run: "
82  << last << std::endl;
83 
84  std::vector<DTConfigKey> lastKey;
85  std::cout << "check for last " << std::endl;
86  if ( last == 0 ) {
87  DTCCBConfig* dummyConf = new DTCCBConfig( dataTag );
88  dummyConf->setStamp( 0 );
89  dummyConf->setFullKey( lastKey );
90  cond::Time_t snc = 1;
91  std::cout << "write dummy " << std::endl;
92  m_to_transfer.push_back( std::make_pair( dummyConf, snc ) );
93  }
94  else {
95  std::cout << "get last payload" << std::endl;
96  Ref payload = lastPayload();
97  std::cout << "get last full key" << std::endl;
98  lastKey = payload->fullKey();
99  std::cout << "last key: " << std::endl;
100  std::vector<DTConfigKey>::const_iterator keyIter = lastKey.begin();
101  std::vector<DTConfigKey>::const_iterator keyIend = lastKey.end();
102  while ( keyIter != keyIend ) {
103  const DTConfigKey& cfgKeyList = *keyIter++;
104  std::cout << cfgKeyList.confType << " : "
105  << cfgKeyList.confKey << std::endl;
106  }
107  }
108 
109  //to access the information on last successful log entry for this tag:
110 // cond::LogDBEntry const & lde = logDBEntry();
111 
112  //to access the lastest payload (Ref is a smart pointer)
113 // Ref payload = lastPayload();
114 
115  if ( !copyData ) return;
116 
117  unsigned lastRun = last;
118  std::cout << "check for new runs since " << lastRun << std::endl;
119 
120  std::cout << "configure DbConnection" << std::endl;
121  // conn->configure( cond::CmsDefaults );
124  std::cout << "create DbSession" << std::endl;
126  std::cout << "open session" << std::endl;
128  std::cout << "start transaction" << std::endl;
130 
131  // =========== Update configuration data
132  chkConfigList();
133 
134  // =========== Find latest runs
135  std::cout << "get run config..." << std::endl;
136  std::map<int,std::vector<int>*> runMap;
137  std::map<int,std::vector<DTConfigKey>*> rhcMap;
138  coral::ITable& runHistoryTable =
139  isession.nominalSchema().tableHandle( "RUNHISTORY" );
140  std::auto_ptr<coral::IQuery>
141  runHistoryQuery( runHistoryTable.newQuery() );
142  runHistoryQuery->addToOutputList( "RUN" );
143  runHistoryQuery->addToOutputList( "RHID" );
144  coral::ICursor& runHistoryCursor = runHistoryQuery->execute();
145  while( runHistoryCursor.next() ) {
146  const coral::AttributeList& row = runHistoryCursor.currentRow();
147  int runId = row[ "RUN"].data<int>();
148  int rhcId = static_cast<int>( row["RHID"].data<int>() );
149  // ----------- ignore already copied runs
150  if ( static_cast<unsigned>( runId ) <= lastRun ) continue;
151  // ----------- ignore runs outside required range
152  if ( runId < minRunId ) continue;
153  if ( runId > maxRunId ) continue;
154  std::cout << "schedule config key copy for run "
155  << runId << " ---> RHID " << rhcId << std::endl;
156  // ----------- retrieve or create RH relation list for this run
157  std::vector<int>* rhlPtr = 0;
158  std::map<int,std::vector<int>*>::const_iterator runIter;
159  if ( ( runIter = runMap.find( runId ) ) != runMap.end() )
160  rhlPtr = runIter->second;
161  else runMap.insert( std::pair<int,std::vector<int>*>( runId,
162  rhlPtr = new std::vector<int> ) );
163  // ----------- append RH relation to the list
164  rhlPtr->push_back( rhcId );
165  // ----------- create key list for this RH relation
166  if ( rhcMap.find( rhcId ) == rhcMap.end() )
167  rhcMap.insert( std::pair<int,std::vector<DTConfigKey>*>( rhcId,
168  new std::vector<DTConfigKey> ) );
169  }
170  if ( !runMap.size() ) std::cout << "no new run found" << std::endl;
171 
172  // =========== get ccb identifiers map
173  std::cout << "retrieve CCB map" << std::endl;
174  std::map<int,DTCCBId> ccbMap;
175  coral::ITable& ccbMapTable =
176  isession.nominalSchema().tableHandle( "CCBMAP" );
177  std::auto_ptr<coral::IQuery>
178  ccbMapQuery( ccbMapTable.newQuery() );
179  ccbMapQuery->addToOutputList( "CCBID" );
180  ccbMapQuery->addToOutputList( "WHEEL" );
181  ccbMapQuery->addToOutputList( "SECTOR" );
182  ccbMapQuery->addToOutputList( "STATION" );
183  coral::ICursor& ccbMapCursor = ccbMapQuery->execute();
184  while( ccbMapCursor.next() ) {
185  const coral::AttributeList& row = ccbMapCursor.currentRow();
186  int ccb = row["CCBID" ].data<int>();
187  int wheel = row["WHEEL" ].data<int>();
188  int sector = row["SECTOR" ].data<int>();
189  int station = row["STATION"].data<int>();
190  DTCCBId ccbId;
191  ccbId. wheelId = wheel;
192  ccbId.stationId = station;
193  ccbId. sectorId = sector;
194  ccbMap.insert( std::pair<int,DTCCBId>( ccb, ccbId ) );
195  }
196 
197  // =========== get brick types
198  std::cout << "retrieve brick types" << std::endl;
199  std::map<int,int> bktMap;
200  coral::AttributeList emptyBindVariableList;
201  std::auto_ptr<coral::IQuery>
202  brickTypeQuery( isession.nominalSchema().newQuery() );
203  brickTypeQuery->addToTableList( "CFGBRICKS" );
204  brickTypeQuery->addToTableList( "BRKT2CSETT" );
205  // ----------- join brick type (1-11) to subsystem part (1-6)
206  std::string bTypeCondition = "CFGBRICKS.BRKTYPE=BRKT2CSETT.BRKTYPE";
207  brickTypeQuery->addToOutputList( "CFGBRICKS.BRKID" );
208  brickTypeQuery->addToOutputList( "BRKT2CSETT.CSETTYPE" );
209  brickTypeQuery->setCondition( bTypeCondition, emptyBindVariableList );
210  coral::ICursor& brickTypeCursor = brickTypeQuery->execute();
211  while( brickTypeCursor.next() ) {
212  const coral::AttributeList& row = brickTypeCursor.currentRow();
213  int id = row["CFGBRICKS.BRKID" ].data<int>();
214  int bt = row["BRKT2CSETT.CSETTYPE"].data<short>();
215 // std::cout << "brick " << id << " type " << bt << std::endl;
216 // @@FIX - TEMPORARY PATCH
217 // if ( bt > 3 ) bt = 3;
218  bktMap.insert( std::pair<int,int>( id, bt ) );
219  }
220 
221  // =========== get RH relations
222  std::cout << "retrieve RH relations" << std::endl;
223  std::map<int,int> cfgMap;
224  coral::ITable& rhcRelTable =
225  isession.nominalSchema().tableHandle( "RHRELATIONS" );
226  std::auto_ptr<coral::IQuery>
227  rhcRelQuery( rhcRelTable.newQuery() );
228  rhcRelQuery->addToOutputList( "RHID" );
229  rhcRelQuery->addToOutputList( "CONFKEY" );
230  rhcRelQuery->addToOutputList( "CSETTYPEID" );
231  coral::ICursor& rhcRelCursor = rhcRelQuery->execute();
232  while( rhcRelCursor.next() ) {
233  const coral::AttributeList& row = rhcRelCursor.currentRow();
234  int rhc = row["RHID" ].data<int>();
235  int key = row["CONFKEY" ].data<int>();
236  int cfg = row["CSETTYPEID"].data<int>();
237  // ----------- check for used RH relations, skip unused
238  std::map<int,std::vector<DTConfigKey>*>::iterator rhcIter =
239  rhcMap.find( rhc );
240  std::map<int,std::vector<DTConfigKey>*>::iterator rhcIend =
241  rhcMap.end();
242  if ( rhcIter == rhcIend ) continue;
243  std::vector<DTConfigKey>* keyPtr = rhcIter->second;
244  DTConfigKey confList;
245  confList.confType = cfg;
246  confList.confKey = key;
247  keyPtr->push_back( confList );
248  // ----------- flag config key as used
249  if ( cfgMap.find( cfg ) == cfgMap.end() )
250  cfgMap.insert( std::pair<int,int>( key, rhc ) );
251  }
252 
253  // =========== get ccb config keys
254  std::cout << "retrieve CCB configuration keys" << std::endl;
255  std::map<int,std::map<int,int>*> keyMap;
256  std::map<int,int> cckMap;
257  coral::ITable& ccbRelTable =
258  isession.nominalSchema().tableHandle( "CCBRELATIONS" );
259  std::auto_ptr<coral::IQuery>
260  ccbRelQuery( ccbRelTable.newQuery() );
261  ccbRelQuery->addToOutputList( "CONFKEY" );
262  ccbRelQuery->addToOutputList( "CCBID" );
263  ccbRelQuery->addToOutputList( "CONFCCBKEY" );
264  coral::ICursor& ccbRelCursor = ccbRelQuery->execute();
265  while( ccbRelCursor.next() ) {
266  const coral::AttributeList& row = ccbRelCursor.currentRow();
267  int cfg = row["CONFKEY" ].data<int>();
268  int ccb = row["CCBID" ].data<int>();
269  int key = row["CONFCCBKEY"].data<int>();
270  // ----------- check for used configurations, skip unused
271  if ( cfgMap.find( cfg ) == cfgMap.end() ) continue;
272  // ----------- retrieve or create ccb id-key map for this configuration
273  std::map<int,int>* mapPtr = 0;
274  std::map<int,std::map<int,int>*>::const_iterator keyIter;
275  if ( ( keyIter = keyMap.find( cfg ) ) != keyMap.end() )
276  mapPtr = keyIter->second;
277  else keyMap.insert( std::pair<int,std::map<int,int>*>( cfg,
278  mapPtr = new std::map<int,int> ) );
279 // std::map<int,std::map<int,int>*>::const_iterator keyIter =
280 // keyMap.find( cfg );
281 // std::map<int,std::map<int,int>*>::const_iterator keyIend =
282 // keyMap.end();
283 // if ( keyIter != keyIend ) mapPtr = keyIter->second;
284 // else keyMap.insert(
285 // std::pair<int,std::map<int,int>*>( cfg,
286 // mapPtr = new std::map<int,int> ) );
287  // ----------- store config key for this ccb
288  std::map<int,int>& mapRef( *mapPtr );
289  mapRef.insert( std::pair<int,int>( ccb, key ) );
290  // ----------- flag ccb config key as used
291  if ( cckMap.find( key ) == cckMap.end() )
292  cckMap.insert( std::pair<int,int>( key, ccb ) );
293  }
294 
295  // =========== get brick keys
296  std::cout << "retrieve CCB configuration bricks" << std::endl;
297  std::map<int,std::vector<int>*> brkMap;
298  coral::ITable& confBrickTable =
299  isession.nominalSchema().tableHandle( "CFG2BRKREL" );
300  std::auto_ptr<coral::IQuery>
301  confBrickQuery( confBrickTable.newQuery() );
302  confBrickQuery->addToOutputList( "CONFID" );
303  confBrickQuery->addToOutputList( "BRKID" );
304  coral::ICursor& confBrickCursor = confBrickQuery->execute();
305  while( confBrickCursor.next() ) {
306  const coral::AttributeList& row = confBrickCursor.currentRow();
307  int key = row["CONFID"].data<int>();
308  int brk = row["BRKID" ].data<int>();
309  // ----------- check for used ccb config key, skip unused
310  if ( cckMap.find( key ) == cckMap.end() ) continue;
311 // std::map<int,std::vector<int>*>::const_iterator brkIter =
312 // brkMap.find( key );
313 // std::map<int,std::vector<int>*>::const_iterator brkIend =
314 // brkMap.end();
315  // ----------- retrieve or create brick list for this ccb config
316  std::vector<int>* brkPtr = 0;
317  std::map<int,std::vector<int>*>::const_iterator brkIter;
318 //check for new ccb config key
319  if ( ( brkIter = brkMap.find( key ) ) != brkMap.end() )
320  brkPtr = brkIter->second;
321  else brkMap.insert( std::pair<int,std::vector<int>*>( key,
322  brkPtr = new std::vector<int> ) );
323 // if ( brkIter != brkIend ) brkPtr = brkIter->second;
324 // else brkMap.insert(
325 // std::pair<int,std::vector<int>*>( key,
326 // brkPtr = new std::vector<int> ) );
327  // ----------- store brick key
328  brkPtr->push_back( brk );
329  }
330 
331  // =========== loop over new runs
332  std::map<int,std::vector<int>*>::const_iterator runIter = runMap.begin();
333  std::map<int,std::vector<int>*>::const_iterator runIend = runMap.end();
334  while ( runIter != runIend ) {
335  const std::pair<int,std::vector<int>*>& runEntry = *runIter++;
336  // ----------- get full configuration
337  int run = runEntry.first;
338  std::vector<DTConfigKey> cfl;
339  // ----------- get RH relation list
340  std::vector<int>* rhlPtr = runEntry.second;
341  std::vector<int>::const_iterator rhlIter = rhlPtr->begin();
342  std::vector<int>::const_iterator rhlIend = rhlPtr->end();
343  // ----------- loop over RH relations
344  while ( rhlIter != rhlIend ) {
345  int rhc = *rhlIter++;
346  std::cout << "retrieve configuration bricks for run " << run
347  << " ---> RH " << rhc << std::endl;
348 // std::map<int,std::vector<DTConfigKey>*>::const_iterator
349 // rhcIter = rhcMap.find( rhc );
350 // std::map<int,std::vector<DTConfigKey>*>::const_iterator
351 // rhcIend = rhcMap.end();
352  std::map<int,std::vector<DTConfigKey>*>::const_iterator rhcIter;
353  // ----------- redundant check
354  if ( ( rhcIter = rhcMap.find( rhc ) ) == rhcMap.end() ) continue;
355  std::vector<DTConfigKey>* listPtr = rhcIter->second;
356  // ----------- redundant check
357  if ( listPtr == 0 ) continue;
358  std::vector<DTConfigKey>::const_iterator bkiIter = listPtr->begin();
359  std::vector<DTConfigKey>::const_iterator bkiIend = listPtr->end();
360  while ( bkiIter != bkiIend ) cfl.push_back( *bkiIter++ );
361  }
362  if ( sameConfigList( cfl, lastKey ) ) continue;
363  lastKey = cfl;
364  DTCCBConfig* fullConf = new DTCCBConfig( dataTag );
365  // set run and full configuration in payload
366  fullConf->setStamp( run );
367  fullConf->setFullKey( cfl );
368 
369  std::vector<DTConfigKey>::const_iterator cfgIter = cfl.begin();
370  std::vector<DTConfigKey>::const_iterator cfgIend = cfl.end();
371  while ( cfgIter != cfgIend ) {
372  const DTConfigKey& cfgEntry = *cfgIter++;
373  int cft = cfgEntry.confType;
374  int cfg = cfgEntry.confKey;
375 
376  // =========== retrieve ccb config map
377 // std::map<int,std::map<int,int>*>::const_iterator keyIter =
378 // keyMap.find( cfg );
379 // std::map<int,std::map<int,int>*>::const_iterator keyIend =
380 // keyMap.end();
381  std::map<int,int>* mapPtr = 0;
382  std::map<int,std::map<int,int>*>::const_iterator keyIter;
383  // ----------- redundant check
384 // if ( keyIter != keyIend )
385  if ( ( keyIter = keyMap.find( cfg ) ) != keyMap.end() )
386  mapPtr = keyIter->second;
387  if ( mapPtr == 0 ) continue;
388  std::map<int,int>::const_iterator ccmIter = mapPtr->begin();
389  std::map<int,int>::const_iterator ccmIend = mapPtr->end();
390  while ( ccmIter != ccmIend ) {
391  const std::pair<int,int>& ccmEntry = *ccmIter++;
392  // ----------- get ccb config key
393  int ccb = ccmEntry.first;
394  int key = ccmEntry.second;
395  // retrieve chamber id
396 // std::map<int,DTCCBId>::const_iterator ccbIter = ccbMap.find( ccb );
397 // std::map<int,DTCCBId>::const_iterator ccbIend = ccbMap.end();
398  std::map<int,DTCCBId>::const_iterator ccbIter;
399  // ----------- redundant check
400 // if ( ccbIter == ccbIend ) continue;
401  if ( ( ccbIter = ccbMap.find( ccb ) ) == ccbMap.end() ) continue;
402  const DTCCBId& chaId = ccbIter->second;
403  // ----------- retrieve brick id list
404 // std::map<int,std::vector<int>*>::const_iterator brkIter =
405 // brkMap.find( key );
406 // std::map<int,std::vector<int>*>::const_iterator brkIend =
407 // brkMap.end();
408 // if ( brkIter == brkIend ) continue;
409  std::map<int,std::vector<int>*>::const_iterator brkIter;
410  if ( ( brkIter = brkMap.find( key ) ) == brkMap.end() ) continue;
411  std::vector<int>* brkPtr = brkIter->second;
412  // ----------- redundant check
413  if ( brkPtr == 0 ) continue;
414  // ----------- set brick id lists in payload
415  std::vector<int> bkList;
416  bkList.reserve( 20 );
417 // std::map<int,int>::const_iterator bktIter = bktMap.begin();
418 // std::map<int,int>::const_iterator bktIend = bktMap.end();
419  std::map<int,int>::const_iterator bktIter;
420  std::vector<int>::const_iterator bkiIter = brkPtr->begin();
421  std::vector<int>::const_iterator bkiIend = brkPtr->end();
422  while ( bkiIter != bkiIend ) {
423  int brickId = *bkiIter++;
424 // bktIter = bktMap.find( brickId );
425  // ----------- redundant check
426  if ( ( bktIter = bktMap.find( brickId ) ) == bktMap.end() ) continue;
427  if ( bktIter->second == cft ) bkList.push_back( brickId );
428  }
429  fullConf->appendConfigKey( chaId.wheelId,
430  chaId.stationId,
431  chaId.sectorId,
432  bkList );
433  }
434  }
435  cond::Time_t snc = runEntry.first;
436  m_to_transfer.push_back( std::make_pair( fullConf, snc ) );
437  std::cout << "writing payload : " << sizeof( *fullConf )
438  << " ( " << ( fullConf->end() - fullConf->begin() )
439  << " ) " << std::endl;
440  }
441 
443  isession.close();
444 
445  return;
446 
447 }
448 
449 
451 
452  std::cout << "open POOL out db " << std::endl;
454 
455  std::cout << "start queries " << std::endl;
456  std::map<int,bool> activeConfigMap;
457  coral::ITable& fullConfigTable =
458  isession.nominalSchema().tableHandle( "CONFIGSETS" );
459  std::auto_ptr<coral::IQuery>
460  fullConfigQuery( fullConfigTable.newQuery() );
461  fullConfigQuery->addToOutputList( "CONFKEY" );
462  fullConfigQuery->addToOutputList( "NAME" );
463  fullConfigQuery->addToOutputList( "RUN" );
464  coral::ICursor& fullConfigCursor = fullConfigQuery->execute();
465  while( fullConfigCursor.next() ) {
466  const coral::AttributeList& row = fullConfigCursor.currentRow();
467  int fullConfigId = row["CONFKEY"].data<int>();
468  int fullConfigRN = row["RUN" ].data<int>();
469  if ( fullConfigRN ) activeConfigMap.insert(
470  std::pair<int,bool>( fullConfigId, true ) );
471  else activeConfigMap.insert(
472  std::pair<int,bool>( fullConfigId, false ) );
473  std::string fullConfigName = row["NAME"].data<std::string>();
474  }
475 
476 // std::cout << " =============== CCB config list" << std::endl;
477  std::map<int,bool> activeCCBCfgMap;
478  coral::ITable& fullCCBCfgTable =
479  isession.nominalSchema().tableHandle( "CCBRELATIONS" );
480  std::auto_ptr<coral::IQuery>
481  fullCCBCfgQuery( fullCCBCfgTable.newQuery() );
482  fullCCBCfgQuery->addToOutputList( "CONFKEY" );
483  fullCCBCfgQuery->addToOutputList( "CONFCCBKEY" );
484  coral::ICursor& fullCCBCfgCursor = fullCCBCfgQuery->execute();
485  while( fullCCBCfgCursor.next() ) {
486  const coral::AttributeList& row = fullCCBCfgCursor.currentRow();
487  int fullConfigId = row["CONFKEY" ].data<int>();
488  int fullCCBCfgId = row["CONFCCBKEY"].data<int>();
489 // std::map<int,bool>::const_iterator cfgIter =
490 // activeConfigMap.find( fullConfigId );
491  std::map<int,bool>::const_iterator cfgIter;
492  if ( ( cfgIter = activeConfigMap.find( fullConfigId ) )
493  == activeConfigMap.end() ) continue;
494  if ( !( cfgIter->second ) ) continue;
495  if ( activeCCBCfgMap.find( fullCCBCfgId ) ==
496  activeCCBCfgMap.end() )
497  activeCCBCfgMap.insert( std::pair<int,bool>( fullCCBCfgId, true ) );
498  }
499 
500 // std::cout << " =============== config brick list" << std::endl;
501  std::map<int,bool> activeCfgBrkMap;
502  coral::ITable& ccbConfBrkTable =
503  isession.nominalSchema().tableHandle( "CFG2BRKREL" );
504  std::auto_ptr<coral::IQuery>
505  ccbConfBrickQuery( ccbConfBrkTable.newQuery() );
506  ccbConfBrickQuery->addToOutputList( "CONFID" );
507  ccbConfBrickQuery->addToOutputList( "BRKID" );
508  coral::ICursor& ccbConfBrickCursor = ccbConfBrickQuery->execute();
509  while( ccbConfBrickCursor.next() ) {
510  const coral::AttributeList& row = ccbConfBrickCursor.currentRow();
511  int fullCCBCfgId = row["CONFID"].data<int>();
512  int ccbConfBrkId = row["BRKID" ].data<int>();
513 // std::map<int,bool>::const_iterator ccbIter =
514 // activeCCBCfgMap.find( fullCCBCfgId );
515  std::map<int,bool>::const_iterator ccbIter;
516  if ( ( ccbIter = activeCCBCfgMap.find( fullCCBCfgId ) )
517  == activeCCBCfgMap.end() ) continue;
518  if ( !( ccbIter->second ) ) continue;
519  if ( activeCfgBrkMap.find( ccbConfBrkId ) ==
520  activeCfgBrkMap.end() )
521  activeCfgBrkMap.insert( std::pair<int,bool>( ccbConfBrkId, true ) );
522  }
523 
524 // std::cout << " ===============" << std::endl;
525 
526  coral::ITable& brickConfigTable =
527  isession.nominalSchema().tableHandle( "CFGBRICKS" );
528  std::auto_ptr<coral::IQuery>
529  brickConfigQuery( brickConfigTable.newQuery() );
530  brickConfigQuery->addToOutputList( "BRKID" );
531  brickConfigQuery->addToOutputList( "BRKNAME" );
532  coral::ICursor& brickConfigCursor = brickConfigQuery->execute();
533  DTKeyedConfig* brickData = 0;
534  std::vector<int> missingList;
535  std::vector<unsigned long long> checkedKeys;
536  while( brickConfigCursor.next() ) {
537  const coral::AttributeList& row = brickConfigCursor.currentRow();
538  int brickConfigId = row["BRKID"].data<int>();
539  if ( brickConfigId < minBrickId ) continue;
540  if ( brickConfigId > maxBrickId ) continue;
541 // std::map<int,bool>::const_iterator brkIter =
542 // activeCfgBrkMap.find( brickConfigId );
543  std::map<int,bool>::const_iterator brkIter;
544  if ( ( brkIter = activeCfgBrkMap.find( brickConfigId ) )
545  == activeCfgBrkMap.end() ) continue;
546  if ( !( brkIter->second ) ) continue;
547  std::string brickConfigName = row["BRKNAME"].data<std::string>();
548  std::cout << "brick " << brickConfigId
549  << " : " << brickConfigName << std::endl;
550  checkedKeys.push_back( brickConfigId );
551  bool brickFound = false;
552  try {
553  keyList->load( checkedKeys );
554  const DTKeyedConfig* brickCheck = keyList->get<DTKeyedConfig>( 0 );
555  if ( brickCheck != 0 ) brickFound =
556  ( brickCheck->getId() == brickConfigId );
557  }
558  catch ( std::exception e ) {
559  }
560  if ( !brickFound ) {
561  std::cout << "brick " << brickConfigId << " missing, copy request"
562  << std::endl;
563  missingList.push_back( brickConfigId );
564  }
565  checkedKeys.clear();
566  }
567  keyList->load( checkedKeys );
568 
569  std::vector<int>::const_iterator brickIter = missingList.begin();
570  std::vector<int>::const_iterator brickIend = missingList.end();
571  while ( brickIter != brickIend ) {
572  int brickConfigId = *brickIter++;
573 // std::cout << "get data for brick: " << brickConfigId << std::endl;
574  coral::AttributeList bindVariableList;
575  bindVariableList.extend( "brickId", typeid(int) );
576  bindVariableList["brickId"].data<int>() = brickConfigId;
577  std::auto_ptr<coral::IQuery>
578  brickDataQuery( isession.nominalSchema().newQuery() );
579  brickDataQuery->addToTableList( "CFGRELATIONS" );
580  brickDataQuery->addToTableList( "CONFIGCMDS" );
582  brickCondition = "CONFIGCMDS.CMDID=CFGRELATIONS.CMDID";
583  brickCondition += " and CFGRELATIONS.BRKID=:brickId";
584  brickDataQuery->addToOutputList( "CFGRELATIONS.BRKID" );
585  brickDataQuery->addToOutputList( "CONFIGCMDS.CONFDATA" );
586  brickDataQuery->setCondition( brickCondition, bindVariableList );
587  coral::ICursor& brickDataCursor = brickDataQuery->execute();
588  brickData = new DTKeyedConfig();
589  brickData->setId( brickConfigId );
590  while( brickDataCursor.next() ) {
591  const coral::AttributeList& row = brickDataCursor.currentRow();
592  brickData->add( row["CONFIGCMDS.CONFDATA"].data<std::string>() );
593  }
594  cond::KeyedElement k( brickData, brickConfigId );
595  std::cout << "now writing brick: " << brickConfigId << std::endl;
596  outdb->writeOne( k.m_obj, k.m_key, brickContainer );
597  }
598 
599  return;
600 
601 }
602 
603 
605  return dataTag;
606 }
607 
608 
610  const std::vector<DTConfigKey>& cfgl,
611  const std::vector<DTConfigKey>& cfgr ) {
612  if ( cfgl.size() != cfgr.size() ) return false;
613  std::map<int,int> lmap;
614  std::vector<DTConfigKey>::const_iterator lIter = cfgl.begin();
615  std::vector<DTConfigKey>::const_iterator lIend = cfgl.end();
616  while ( lIter != lIend ) {
617  const DTConfigKey& entry = *lIter++;
618  lmap.insert( std::pair<int,int>( entry.confType, entry.confKey ) );
619  }
620  std::map<int,int> rmap;
621  std::vector<DTConfigKey>::const_iterator rIter = cfgr.begin();
622  std::vector<DTConfigKey>::const_iterator rIend = cfgr.end();
623  while ( rIter != rIend ) {
624  const DTConfigKey& entry = *rIter++;
625  rmap.insert( std::pair<int,int>( entry.confType, entry.confKey ) );
626  }
627  std::map<int,int>::const_iterator lmIter = lmap.begin();
628  std::map<int,int>::const_iterator lmIend = lmap.end();
629  std::map<int,int>::const_iterator rmIter = rmap.begin();
630  std::map<int,int>::const_iterator rmIend = rmap.end();
631  while ( ( lmIter != lmIend ) &&
632  ( rmIter != rmIend ) ) {
633  const std::pair<int,int>& lEntry = *lmIter++;
634  const std::pair<int,int>& rEntry = *rmIter++;
635  if ( lEntry.first != rEntry.first ) return false;
636  if ( lEntry.second != rEntry.second ) return false;
637  }
638  return true;
639 }
640 
641 
643  keyList = list;
644 }
645 
static void setList(cond::KeyList *list)
int wheelId
Definition: DTCCBConfig.h:43
void load(std::vector< unsigned long long > const &keys)
Definition: KeyList.cc:10
void setStamp(int s)
Definition: DTCCBConfig.cc:197
DbTransaction & transaction()
Definition: DbSession.cc:189
void open(const std::string &connectionString, bool readOnly=false)
Definition: DbSession.cc:144
void add(const std::string &data)
int commit()
commit transaction.
DbConnectionConfiguration & configuration()
Definition: DbConnection.cc:89
const_iterator end() const
Definition: DTCCBConfig.cc:345
int sectorId
Definition: DTCCBConfig.h:45
int start(bool readOnly=false)
start transaction
BaseKeyed * m_obj
Definition: KeyedElement.h:35
unsigned long long Time_t
Definition: Time.h:16
int stationId
Definition: DTCCBConfig.h:44
static bool sameConfigList(const std::vector< DTConfigKey > &cfgl, const std::vector< DTConfigKey > &cfgr)
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
T const * get(int n) const
Definition: KeyList.h:39
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
cond::DbConnection connection
std::string id() const
int k[5][pyjets_maxn]
static cond::KeyList * keyList
DbSession createSession() const
Definition: DbConnection.cc:72
coral::ISchema & nominalSchema()
Definition: DbSession.cc:228
void setId(int id)
void setAuthenticationPath(const std::string &p)
int getId() const
list key
Definition: combine.py:13
if(dp >Float(M_PI)) dp-
cond::ValidityInterval lastInterval
Definition: TagInfo.h:11
tuple cout
Definition: gather_cfg.py:121
void setFullKey(const std::vector< DTConfigKey > &)
Definition: DTCCBConfig.cc:192
DTKeyedConfigHandler(const edm::ParameterSet &ps)
const_iterator begin() const
Definition: DTCCBConfig.cc:340
cond::Time_t m_key
Definition: KeyedElement.h:37
int appendConfigKey(int wheelId, int stationId, int sectorId, const std::vector< int > &confKey)
Definition: DTCCBConfig.cc:278
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