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