CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTUserKeyedConfigHandler.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 //-------------------------------
18 
19 
24 
25 #include "RelationalAccess/ISessionProxy.h"
26 #include "RelationalAccess/ITransaction.h"
27 #include "RelationalAccess/ISchema.h"
28 #include "RelationalAccess/ITable.h"
29 #include "RelationalAccess/ICursor.h"
30 #include "RelationalAccess/IQuery.h"
31 #include "CoralBase/AttributeList.h"
32 #include "CoralBase/AttributeSpecification.h"
33 #include "CoralBase/Attribute.h"
34 
35 //---------------
36 // C++ Headers --
37 //---------------
38 
39 #include <iostream>
40 
41 //-------------------
42 // Initializations --
43 //-------------------
45 
46 //----------------
47 // Constructors --
48 //----------------
50  dataRun( ps.getParameter<int> ( "run" ) ),
51  dataTag( ps.getParameter<std::string> ( "tag" ) ),
52  onlineConnect( ps.getParameter<std::string> ( "onlineDB" ) ),
53  onlineAuthentication( ps.getParameter<std::string> (
54  "onlineAuthentication" ) ),
55  onlineAuthSys( ps.getUntrackedParameter<int>( "onlineAuthSys",1 ) ),
56  brickContainer( ps.getParameter<std::string> ( "container" ) ),
57  writeKeys( ps.getParameter<bool> ( "writeKeys" ) ),
58  writeData( ps.getParameter<bool> ( "writeData" ) ),
59  connection(),
60  isession() {
61  std::cout << " PopCon application for DT configuration export "
62  << onlineAuthentication << std::endl;
63 
64  std::vector<edm::ParameterSet> dtConfigKeys (
65  ps.getParameter< std::vector<edm::ParameterSet> >( "DTConfigKeys" )
66  );
67  std::vector<edm::ParameterSet>::const_iterator iter = dtConfigKeys.begin();
68  std::vector<edm::ParameterSet>::const_iterator iend = dtConfigKeys.end();
69  while ( iter != iend ) {
70  const edm::ParameterSet& cp = *iter++;
71  int configType = cp.getUntrackedParameter<int>( "configType" );
72  int configKey = cp.getUntrackedParameter<int>( "configKey" );
73  std::cout << "config: "
74  << configType << " -> "
75  << configKey << std::endl;
76  DTConfigKey userKey;
77  userKey.confType = configType;
78  userKey.confKey = configKey;
79  userConf.push_back( userKey );
80  }
81 }
82 
83 //--------------
84 // Destructor --
85 //--------------
87 }
88 
89 //--------------
90 // Operations --
91 //--------------
93 
94  //to access the information on the tag inside the offline database:
95  cond::TagInfo const & ti = tagInfo();
96  unsigned int last = ti.lastInterval.first;
97  std::cout << "last configuration key already copied for run: "
98  << last << std::endl;
99 
100  std::vector<DTConfigKey> lastKey;
101 // std::cout << "check for last " << std::endl;
102  if ( last == 0 ) {
103  DTCCBConfig* dummyConf = new DTCCBConfig( dataTag );
104  dummyConf->setStamp( 0 );
105  dummyConf->setFullKey( lastKey );
106  cond::Time_t snc = 1;
107  if ( writeKeys && ( dataRun > 1 ) )
108  m_to_transfer.push_back( std::make_pair( dummyConf, snc ) );
109  }
110  else {
111  std::cout << "get last payload" << std::endl;
112  Ref payload = lastPayload();
113  std::cout << "get last full key" << std::endl;
114  lastKey = payload->fullKey();
115  std::cout << "last key: " << std::endl;
116  std::vector<DTConfigKey>::const_iterator keyIter = lastKey.begin();
117  std::vector<DTConfigKey>::const_iterator keyIend = lastKey.end();
118  while ( keyIter != keyIend ) {
119  const DTConfigKey& keyList = *keyIter++;
120  std::cout << keyList.confType << " : " << keyList.confKey << std::endl;
121  }
122  }
123 
124  std::cout << "configure DbConnection" << std::endl;
125  // conn->configure( cond::CmsDefaults );
129  std::cout << "create/open DbSession" << std::endl;
131  std::cout << "start transaction" << std::endl;
132  isession->transaction().start( true );
133 
134  // get ccb identifiers map
135  std::cout << "retrieve CCB map" << std::endl;
136  std::map<int,DTCCBId> ccbMap;
137  coral::ITable& ccbMapTable =
138  isession->nominalSchema().tableHandle( "CCBMAP" );
139  std::auto_ptr<coral::IQuery>
140  ccbMapQuery( ccbMapTable.newQuery() );
141  ccbMapQuery->addToOutputList( "CCBID" );
142  ccbMapQuery->addToOutputList( "WHEEL" );
143  ccbMapQuery->addToOutputList( "SECTOR" );
144  ccbMapQuery->addToOutputList( "STATION" );
145  coral::ICursor& ccbMapCursor = ccbMapQuery->execute();
146  while( ccbMapCursor.next() ) {
147  const coral::AttributeList& row = ccbMapCursor.currentRow();
148  int ccb = row["CCBID" ].data<int>();
149  int wheel = row["WHEEL" ].data<int>();
150  int sector = row["SECTOR" ].data<int>();
151  int station = row["STATION"].data<int>();
152  DTCCBId ccbId;
153  ccbId. wheelId = wheel;
154  ccbId.stationId = station;
155  ccbId. sectorId = sector;
156  ccbMap.insert( std::pair<int,DTCCBId>( ccb, ccbId ) );
157  }
158 
159  // get brick types
160  std::cout << "retrieve brick types" << std::endl;
161  std::map<int,int> bktMap;
162  coral::AttributeList emptyBindVariableList;
163  std::auto_ptr<coral::IQuery>
164  brickTypeQuery( isession->nominalSchema().newQuery() );
165  brickTypeQuery->addToTableList( "CFGBRICKS" );
166  brickTypeQuery->addToTableList( "BRKT2CSETT" );
167  std::string bTypeCondition = "CFGBRICKS.BRKTYPE=BRKT2CSETT.BRKTYPE";
168  brickTypeQuery->addToOutputList( "CFGBRICKS.BRKID" );
169  brickTypeQuery->addToOutputList( "BRKT2CSETT.CSETTYPE" );
170  brickTypeQuery->setCondition( bTypeCondition, emptyBindVariableList );
171  coral::ICursor& brickTypeCursor = brickTypeQuery->execute();
172  while( brickTypeCursor.next() ) {
173  const coral::AttributeList& row = brickTypeCursor.currentRow();
174  int id = row["CFGBRICKS.BRKID" ].data<int>();
175  int bt = row["BRKT2CSETT.CSETTYPE"].data<short>();
176 // std::cout << "brick " << id << " type " << bt << std::endl;
177 // @@FIX - TEMPORARY PATCH
178 // if ( bt > 3 ) bt = 3;
179  bktMap.insert( std::pair<int,int>( id, bt ) );
180  }
181 
182  // get ccb config keys
183  std::cout << "retrieve CCB configuration keys" << std::endl;
184  std::map<int,std::map<int,int>*> keyMap;
185  std::map<int,int> cckMap;
186  coral::ITable& ccbRelTable =
187  isession->nominalSchema().tableHandle( "CCBRELATIONS" );
188  std::auto_ptr<coral::IQuery>
189  ccbRelQuery( ccbRelTable.newQuery() );
190  ccbRelQuery->addToOutputList( "CONFKEY" );
191  ccbRelQuery->addToOutputList( "CCBID" );
192  ccbRelQuery->addToOutputList( "CONFCCBKEY" );
193  coral::ICursor& ccbRelCursor = ccbRelQuery->execute();
194  // loop over all full configurations
195  while( ccbRelCursor.next() ) {
196  const coral::AttributeList& row = ccbRelCursor.currentRow();
197  int cfg = row["CONFKEY" ].data<int>();
198  int ccb = row["CCBID" ].data<int>();
199  int key = row["CONFCCBKEY"].data<int>();
200  // check for used configurations
201 // if ( cfgMap.find( cfg ) == cfgMap.end() ) continue;
202  if ( userDiscardedKey( cfg ) ) continue;
203  std::map<int,std::map<int,int>*>::const_iterator keyIter =
204  keyMap.find( cfg );
205  std::map<int,std::map<int,int>*>::const_iterator keyIend =
206  keyMap.end();
207  std::map<int,int>* mapPtr = 0;
208  // check for new full configuration
209  if ( keyIter != keyIend ) mapPtr = keyIter->second;
210  else keyMap.insert(
211  std::pair<int,std::map<int,int>*>( cfg,
212  mapPtr = new std::map<int,int> ) );
213  // store ccb config key
214  std::map<int,int>& mapRef( *mapPtr );
215  mapRef.insert( std::pair<int,int>( ccb, key ) );
216  // check for new ccb config key
217  if ( cckMap.find( key ) == cckMap.end() )
218  cckMap.insert( std::pair<int,int>( key, ccb ) );
219  }
220 
221  // get brick keys
222  std::cout << "retrieve CCB configuration bricks" << std::endl;
223  std::map<int,std::vector<int>*> brkMap;
224  coral::ITable& confBrickTable =
225  isession->nominalSchema().tableHandle( "CFG2BRKREL" );
226  std::auto_ptr<coral::IQuery>
227  confBrickQuery( confBrickTable.newQuery() );
228  confBrickQuery->addToOutputList( "CONFID" );
229  confBrickQuery->addToOutputList( "BRKID" );
230  coral::ICursor& confBrickCursor = confBrickQuery->execute();
231  // loop over all brick keys
232  while( confBrickCursor.next() ) {
233  const coral::AttributeList& row = confBrickCursor.currentRow();
234  int key = row["CONFID"].data<int>();
235  int brk = row["BRKID" ].data<int>();
236  // check for used ccb config key
237  if ( cckMap.find( key ) == cckMap.end() ) continue;
238  std::map<int,std::vector<int>*>::const_iterator brkIter =
239  brkMap.find( key );
240  std::map<int,std::vector<int>*>::const_iterator brkIend =
241  brkMap.end();
242  // check for new ccb config key
243  std::vector<int>* brkPtr = 0;
244  if ( brkIter != brkIend ) brkPtr = brkIter->second;
245  else brkMap.insert(
246  std::pair<int,std::vector<int>*>( key,
247  brkPtr = new std::vector<int> ) );
248  // store brick key
249  brkPtr->push_back( brk );
250  }
251 
252  // set run and full configuration in payload
253  DTCCBConfig* fullConf = new DTCCBConfig( dataTag );
254  fullConf->setStamp( 1 );
255  fullConf->setFullKey( userConf );
256  std::map<int,bool> userBricks;
257  std::map<int,bool>::const_iterator uBrkIter = userBricks.begin();
258  std::map<int,bool>::const_iterator uBrkIend = userBricks.end();
259  std::vector<DTConfigKey>::const_iterator cfgIter = userConf.begin();
260  std::vector<DTConfigKey>::const_iterator cfgIend = userConf.end();
261  while ( cfgIter != cfgIend ) {
262  const DTConfigKey& cfgEntry = *cfgIter++;
263  int cft = cfgEntry.confType;
264  int cfg = cfgEntry.confKey;
265  // retrieve ccb config map
266  std::map<int,std::map<int,int>*>::const_iterator keyIter =
267  keyMap.find( cfg );
268  std::map<int,std::map<int,int>*>::const_iterator keyIend =
269  keyMap.end();
270  std::map<int,int>* mapPtr = 0;
271  if ( keyIter != keyIend ) mapPtr = keyIter->second;
272  if ( mapPtr == 0 ) continue;
273  std::map<int,int>::const_iterator ccbIter = mapPtr->begin();
274  std::map<int,int>::const_iterator ccbIend = mapPtr->end();
275  while ( ccbIter != ccbIend ) {
276  const std::pair<int,int>& ccbEntry = *ccbIter++;
277  // get ccb config key
278  int ccb = ccbEntry.first;
279  int key = ccbEntry.second;
280  // retrieve chamber id
281  std::map<int,DTCCBId>::const_iterator ccbIter = ccbMap.find( ccb );
282  std::map<int,DTCCBId>::const_iterator ccbIend = ccbMap.end();
283  if ( ccbIter == ccbIend ) continue;
284  const DTCCBId& chaId = ccbIter->second;
285  // retrieve brick id list
286  std::map<int,std::vector<int>*>::const_iterator brkIter =
287  brkMap.find( key );
288  std::map<int,std::vector<int>*>::const_iterator brkIend =
289  brkMap.end();
290  if ( brkIter == brkIend ) continue;
291  std::vector<int>* brkPtr = brkIter->second;
292  if ( brkPtr == 0 ) continue;
293  // brick id lists in payload
294  std::vector<int> bkList;
295  bkList.reserve( 20 );
296  std::map<int,int>::const_iterator bktIter = bktMap.begin();
297  std::map<int,int>::const_iterator bktIend = bktMap.end();
298  std::vector<int>::const_iterator bkiIter = brkPtr->begin();
299  std::vector<int>::const_iterator bkiIend = brkPtr->end();
300  while ( bkiIter != bkiIend ) {
301  int brickId = *bkiIter++;
302  bktIter = bktMap.find( brickId );
303  if ( bktIter == bktIend ) continue;
304  if ( bktIter->second == cft ) {
305  bkList.push_back( brickId );
306  uBrkIter = userBricks.find( brickId );
307  if ( uBrkIter == uBrkIend )
308  userBricks.insert( std::pair<int,bool>( brickId, true ) );
309  }
310  }
311  fullConf->appendConfigKey( chaId.wheelId,
312  chaId.stationId,
313  chaId.sectorId,
314  bkList );
315  }
316  }
317  cond::Time_t snc = dataRun;
318  if ( writeKeys ) m_to_transfer.push_back( std::make_pair( fullConf, snc ) );
319  std::cout << "writing payload : " << sizeof( *fullConf )
320  << " ( " << ( fullConf->end() - fullConf->begin() )
321  << " ) " << std::endl;
322  if ( writeData ) chkConfigList( userBricks );
323 
324  isession->transaction().commit();
325 
326  return;
327 
328 }
329 
330 
332  const std::map<int,bool>& userBricks ) {
333 
334  std::cout << "open POOL out db " << std::endl;
336 
337  std::map<int,bool>::const_iterator uBrkIter = userBricks.begin();
338  std::map<int,bool>::const_iterator uBrkIend = userBricks.end();
339 
340  coral::ITable& brickConfigTable =
341  isession->nominalSchema().tableHandle( "CFGBRICKS" );
342  std::auto_ptr<coral::IQuery>
343  brickConfigQuery( brickConfigTable.newQuery() );
344  brickConfigQuery->addToOutputList( "BRKID" );
345  brickConfigQuery->addToOutputList( "BRKNAME" );
346  coral::ICursor& brickConfigCursor = brickConfigQuery->execute();
347  DTKeyedConfig* brickData = 0;
348  std::vector<int> missingList;
349  std::vector<unsigned long long> checkedKeys;
350  while( brickConfigCursor.next() ) {
351  const coral::AttributeList& row = brickConfigCursor.currentRow();
352  int brickConfigId = row["BRKID"].data<int>();
353  uBrkIter = userBricks.find( brickConfigId );
354  if ( uBrkIter == uBrkIend ) continue;
355  if ( !( uBrkIter->second ) ) continue;
356  std::string brickConfigName = row["BRKNAME"].data<std::string>();
357  std::cout << "brick " << brickConfigId
358  << " : " << brickConfigName << std::endl;
359  checkedKeys.push_back( brickConfigId );
360  bool brickFound = false;
361  try {
362  std::cout << "load brick " << checkedKeys[0] << std::endl;
363  std::cout << "key list " << keyList << std::endl;
364  keyList->load( checkedKeys );
365  std::cout << "get brick..." << std::endl;
366  boost::shared_ptr<DTKeyedConfig> brickCheck =
367  keyList->get<DTKeyedConfig>( 0 );
368  if ( brickCheck.get() ) {
369  brickFound = ( brickCheck->getId() == brickConfigId );
370  }
371  }
372  catch ( std::exception e ) {
373  }
374  if ( !brickFound ) {
375  std::cout << "brick " << brickConfigId << " missing, copy request"
376  << std::endl;
377  missingList.push_back( brickConfigId );
378  }
379  checkedKeys.clear();
380  }
381  keyList->load( checkedKeys );
382 
383  std::vector<int>::const_iterator brickIter = missingList.begin();
384  std::vector<int>::const_iterator brickIend = missingList.end();
385  while ( brickIter != brickIend ) {
386  int brickConfigId = *brickIter++;
387  coral::AttributeList bindVariableList;
388  bindVariableList.extend( "brickId", typeid(int) );
389  bindVariableList["brickId"].data<int>() = brickConfigId;
390  std::auto_ptr<coral::IQuery>
391  brickDataQuery( isession->nominalSchema().newQuery() );
392  brickDataQuery->addToTableList( "CFGRELATIONS" );
393  brickDataQuery->addToTableList( "CONFIGCMDS" );
395  brickCondition = "CONFIGCMDS.CMDID=CFGRELATIONS.CMDID";
396  brickCondition += " and CFGRELATIONS.BRKID=:brickId";
397  brickDataQuery->addToOutputList( "CFGRELATIONS.BRKID" );
398  brickDataQuery->addToOutputList( "CONFIGCMDS.CONFDATA" );
399  brickDataQuery->setCondition( brickCondition, bindVariableList );
400  coral::ICursor& brickDataCursor = brickDataQuery->execute();
401  brickData = new DTKeyedConfig();
402  brickData->setId( brickConfigId );
403  while( brickDataCursor.next() ) {
404  const coral::AttributeList& row = brickDataCursor.currentRow();
405  brickData->add( row["CONFIGCMDS.CONFDATA"].data<std::string>() );
406  }
407  cond::KeyedElement k( brickData, brickConfigId );
408  std::cout << "now writing brick: " << brickConfigId << std::endl;
409  outdb->writeOne( k.m_obj, k.m_key, brickContainer );
410  }
411 
412  return;
413 
414 }
415 
416 
418  return dataTag;
419 }
420 
421 
423  const std::vector<DTConfigKey>& cfgl,
424  const std::vector<DTConfigKey>& cfgr ) {
425  if ( cfgl.size() != cfgr.size() ) return false;
426  std::map<int,int> lmap;
427  std::vector<DTConfigKey>::const_iterator lIter = cfgl.begin();
428  std::vector<DTConfigKey>::const_iterator lIend = cfgl.end();
429  while ( lIter != lIend ) {
430  const DTConfigKey& entry = *lIter++;
431  lmap.insert( std::pair<int,int>( entry.confType, entry.confKey ) );
432  }
433  std::map<int,int> rmap;
434  std::vector<DTConfigKey>::const_iterator rIter = cfgr.begin();
435  std::vector<DTConfigKey>::const_iterator rIend = cfgr.end();
436  while ( rIter != rIend ) {
437  const DTConfigKey& entry = *rIter++;
438  rmap.insert( std::pair<int,int>( entry.confType, entry.confKey ) );
439  }
440  std::map<int,int>::const_iterator lmIter = lmap.begin();
441  std::map<int,int>::const_iterator lmIend = lmap.end();
442  std::map<int,int>::const_iterator rmIter = rmap.begin();
443  std::map<int,int>::const_iterator rmIend = rmap.end();
444  while ( ( lmIter != lmIend ) &&
445  ( rmIter != rmIend ) ) {
446  const std::pair<int,int>& lEntry = *lmIter++;
447  const std::pair<int,int>& rEntry = *rmIter++;
448  if ( lEntry.first != rEntry.first ) return false;
449  if ( lEntry.second != rEntry.second ) return false;
450  }
451  return true;
452 }
453 
454 
456  std::vector<DTConfigKey>::const_iterator iter = userConf.begin();
457  std::vector<DTConfigKey>::const_iterator iend = userConf.end();
458  while ( iter != iend ) {
459  const DTConfigKey& entry = *iter++;
460  if ( entry.confKey == key ) return false;
461  }
462  return true;
463 }
464 
466  keyList = list;
467 }
468 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
tuple cfg
Definition: looper.py:259
int wheelId
Definition: DTCCBConfig.h:45
void setStamp(int s)
Definition: DTCCBConfig.cc:174
void add(const std::string &data)
boost::shared_ptr< coral::ISessionProxy > createCoralSession(const std::string &connectionString, bool writeCapable=false)
std::vector< DTConfigKey > userConf
boost::shared_ptr< coral::ISessionProxy > isession
static bool sameConfigList(const std::vector< DTConfigKey > &cfgl, const std::vector< DTConfigKey > &cfgr)
boost::shared_ptr< T > get(size_t n) const
Definition: KeyList.h:39
const_iterator end() const
Definition: DTCCBConfig.cc:291
int sectorId
Definition: DTCCBConfig.h:47
cond::ValidityInterval lastInterval
Definition: Types.h:70
static cond::persistency::KeyList * keyList
BaseKeyed * m_obj
Definition: KeyedElement.h:35
unsigned long long Time_t
Definition: Time.h:16
int stationId
Definition: DTCCBConfig.h:46
void setAuthenticationSystem(int authSysCode)
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
DTUserKeyedConfigHandler(const edm::ParameterSet &ps)
void setId(int id)
void chkConfigList(const std::map< int, bool > &userBricks)
tuple cout
Definition: gather_cfg.py:121
void setFullKey(const std::vector< DTConfigKey > &)
Definition: DTCCBConfig.cc:169
void load(const std::vector< unsigned long long > &keys)
Definition: KeyList.cc:14
cond::persistency::ConnectionPool connection
const_iterator begin() const
Definition: DTCCBConfig.cc:286
void setAuthenticationPath(const std::string &p)
static void setList(cond::persistency::KeyList *list)
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:238
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
cond::TagInfo_t const & tagInfo() const