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: 2010/09/29 14:00:28 $
5  * $Revision: 1.6 $
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 ( activeCCBCfgMap.find( fullCCBCfgId ) ==
495  activeCCBCfgMap.end() )
496  activeCCBCfgMap.insert( std::pair<int,bool>( fullCCBCfgId, true ) );
497  }
498 
499 // std::cout << " =============== config brick list" << std::endl;
500  std::map<int,bool> activeCfgBrkMap;
501  coral::ITable& ccbConfBrkTable =
502  isession.nominalSchema().tableHandle( "CFG2BRKREL" );
503  std::auto_ptr<coral::IQuery>
504  ccbConfBrickQuery( ccbConfBrkTable.newQuery() );
505  ccbConfBrickQuery->addToOutputList( "CONFID" );
506  ccbConfBrickQuery->addToOutputList( "BRKID" );
507  coral::ICursor& ccbConfBrickCursor = ccbConfBrickQuery->execute();
508  while( ccbConfBrickCursor.next() ) {
509  const coral::AttributeList& row = ccbConfBrickCursor.currentRow();
510  int fullCCBCfgId = row["CONFID"].data<int>();
511  int ccbConfBrkId = row["BRKID" ].data<int>();
512 // std::map<int,bool>::const_iterator ccbIter =
513 // activeCCBCfgMap.find( fullCCBCfgId );
514  std::map<int,bool>::const_iterator ccbIter;
515  if ( ( ccbIter = activeCCBCfgMap.find( fullCCBCfgId ) )
516  == activeCCBCfgMap.end() ) continue;
517  if ( !( ccbIter->second ) ) continue;
518  if ( activeCfgBrkMap.find( ccbConfBrkId ) ==
519  activeCfgBrkMap.end() )
520  activeCfgBrkMap.insert( std::pair<int,bool>( ccbConfBrkId, true ) );
521  }
522 
523 // std::cout << " ===============" << std::endl;
524 
525  coral::ITable& brickConfigTable =
526  isession.nominalSchema().tableHandle( "CFGBRICKS" );
527  std::auto_ptr<coral::IQuery>
528  brickConfigQuery( brickConfigTable.newQuery() );
529  brickConfigQuery->addToOutputList( "BRKID" );
530  brickConfigQuery->addToOutputList( "BRKNAME" );
531  coral::ICursor& brickConfigCursor = brickConfigQuery->execute();
532  DTKeyedConfig* brickData = 0;
533  std::vector<int> missingList;
534  std::vector<unsigned long long> checkedKeys;
535  while( brickConfigCursor.next() ) {
536  const coral::AttributeList& row = brickConfigCursor.currentRow();
537  int brickConfigId = row["BRKID"].data<int>();
538  if ( brickConfigId < minBrickId ) continue;
539  if ( brickConfigId > maxBrickId ) continue;
540 // std::map<int,bool>::const_iterator brkIter =
541 // activeCfgBrkMap.find( brickConfigId );
542  std::map<int,bool>::const_iterator brkIter;
543  if ( ( brkIter = activeCfgBrkMap.find( brickConfigId ) )
544  == activeCfgBrkMap.end() ) continue;
545  if ( !( brkIter->second ) ) continue;
546  std::string brickConfigName = row["BRKNAME"].data<std::string>();
547  std::cout << "brick " << brickConfigId
548  << " : " << brickConfigName << std::endl;
549  checkedKeys.push_back( brickConfigId );
550  bool brickFound = false;
551  try {
552  keyList->load( checkedKeys );
553  const DTKeyedConfig* brickCheck = keyList->get<DTKeyedConfig>( 0 );
554  if ( brickCheck != 0 ) brickFound =
555  ( brickCheck->getId() == brickConfigId );
556  }
557  catch ( std::exception e ) {
558  }
559  if ( !brickFound ) {
560  std::cout << "brick " << brickConfigId << " missing, copy request"
561  << std::endl;
562  missingList.push_back( brickConfigId );
563  }
564  checkedKeys.clear();
565  }
566  keyList->load( checkedKeys );
567 
568  std::vector<int>::const_iterator brickIter = missingList.begin();
569  std::vector<int>::const_iterator brickIend = missingList.end();
570  while ( brickIter != brickIend ) {
571  int brickConfigId = *brickIter++;
572 // std::cout << "get data for brick: " << brickConfigId << std::endl;
573  coral::AttributeList bindVariableList;
574  bindVariableList.extend( "brickId", typeid(int) );
575  bindVariableList["brickId"].data<int>() = brickConfigId;
576  std::auto_ptr<coral::IQuery>
577  brickDataQuery( isession.nominalSchema().newQuery() );
578  brickDataQuery->addToTableList( "CFGRELATIONS" );
579  brickDataQuery->addToTableList( "CONFIGCMDS" );
580  std::string
581  brickCondition = "CONFIGCMDS.CMDID=CFGRELATIONS.CMDID";
582  brickCondition += " and CFGRELATIONS.BRKID=:brickId";
583  brickDataQuery->addToOutputList( "CFGRELATIONS.BRKID" );
584  brickDataQuery->addToOutputList( "CONFIGCMDS.CONFDATA" );
585  brickDataQuery->setCondition( brickCondition, bindVariableList );
586  coral::ICursor& brickDataCursor = brickDataQuery->execute();
587  brickData = new DTKeyedConfig();
588  brickData->setId( brickConfigId );
589  while( brickDataCursor.next() ) {
590  const coral::AttributeList& row = brickDataCursor.currentRow();
591  brickData->add( row["CONFIGCMDS.CONFDATA"].data<std::string>() );
592  }
593  cond::KeyedElement k( brickData, brickConfigId );
594  std::cout << "now writing brick: " << brickConfigId << std::endl;
595  outdb->writeOne( k.m_obj, 0, k.m_key, brickContainer );
596  }
597 
598  return;
599 
600 }
601 
602 
603 std::string DTKeyedConfigHandler::id() const {
604  return dataTag;
605 }
606 
607 
609  const std::vector<DTConfigKey>& cfgl,
610  const std::vector<DTConfigKey>& cfgr ) {
611  if ( cfgl.size() != cfgr.size() ) return false;
612  std::map<int,int> lmap;
613  std::vector<DTConfigKey>::const_iterator lIter = cfgl.begin();
614  std::vector<DTConfigKey>::const_iterator lIend = cfgl.end();
615  while ( lIter != lIend ) {
616  const DTConfigKey& entry = *lIter++;
617  lmap.insert( std::pair<int,int>( entry.confType, entry.confKey ) );
618  }
619  std::map<int,int> rmap;
620  std::vector<DTConfigKey>::const_iterator rIter = cfgr.begin();
621  std::vector<DTConfigKey>::const_iterator rIend = cfgr.end();
622  while ( rIter != rIend ) {
623  const DTConfigKey& entry = *rIter++;
624  rmap.insert( std::pair<int,int>( entry.confType, entry.confKey ) );
625  }
626  std::map<int,int>::const_iterator lmIter = lmap.begin();
627  std::map<int,int>::const_iterator lmIend = lmap.end();
628  std::map<int,int>::const_iterator rmIter = rmap.begin();
629  std::map<int,int>::const_iterator rmIend = rmap.end();
630  while ( ( lmIter != lmIend ) &&
631  ( rmIter != rmIend ) ) {
632  const std::pair<int,int>& lEntry = *lmIter++;
633  const std::pair<int,int>& rEntry = *rmIter++;
634  if ( lEntry.first != rEntry.first ) return false;
635  if ( lEntry.second != rEntry.second ) return false;
636  }
637  return true;
638 }
639 
640 
642  keyList = list;
643 }
644 
static void setList(cond::KeyList *list)
int wheelId
Definition: DTCCBConfig.h:43
void setFullKey(std::vector< DTConfigKey >)
Definition: DTCCBConfig.cc:192
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:153
void open(const std::string &connectionString, bool readOnly=false)
Definition: DbSession.cc:119
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:175
void setId(int id)
void setAuthenticationPath(const std::string &p)
int getId() const
list key
Definition: combine.py:13
cond::ValidityInterval lastInterval
Definition: TagInfo.h:11
perl if(1 lt scalar(@::datatypes))
Definition: edlooper.cc:31
tuple cout
Definition: gather_cfg.py:41
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