CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTHVStatusHandler.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * $Date: 2010/07/21 16:06:53 $
5  * $Revision: 1.10 $
6  * \author Paolo Ronchese INFN Padova
7  *
8  */
9 
10 //-----------------------
11 // This Class' Header --
12 //-----------------------
14 
15 //-------------------------------
16 // Collaborating Class Headers --
17 //-------------------------------
20 
21 
24 
29 #include "RelationalAccess/ISchema.h"
30 #include "RelationalAccess/ITable.h"
31 #include "RelationalAccess/ICursor.h"
32 #include "RelationalAccess/IQuery.h"
33 #include "RelationalAccess/TableDescription.h"
34 #include "RelationalAccess/ITableDataEditor.h"
35 #include "CoralBase/AttributeList.h"
36 #include "CoralBase/AttributeSpecification.h"
37 #include "CoralBase/Attribute.h"
38 #include "CoralBase/TimeStamp.h"
39 
40 //---------------
41 // C++ Headers --
42 //---------------
43 #include <map>
44 #include <sys/time.h>
45 
46 //-------------------
47 // Initializations --
48 //-------------------
49 
50 
51 //----------------
52 // Constructors --
53 //----------------
55  dataTag( ps.getParameter<std::string> ( "tag" ) ),
56  onlineConnect( ps.getParameter<std::string> ( "onlineDB" ) ),
57  utilConnect( ps.getParameter<std::string> ( "utilDB" ) ),
58  onlineAuthentication( ps.getParameter<std::string> (
59  "onlineAuthentication" ) ),
60  bufferConnect( ps.getParameter<std::string> ( "bufferDB" ) ),
61  ySince( ps.getParameter<int> ( "sinceYear" ) ),
62  mSince( ps.getParameter<int> ( "sinceMonth" ) ),
63  dSince( ps.getParameter<int> ( "sinceDay" ) ),
64  hSince( ps.getParameter<int> ( "sinceHour" ) ),
65  pSince( ps.getParameter<int> ( "sinceMinute" ) ),
66  sSince( ps.getParameter<int> ( "sinceSecond" ) ),
67  yUntil( ps.getParameter<int> ( "untilYear" ) ),
68  mUntil( ps.getParameter<int> ( "untilMonth" ) ),
69  dUntil( ps.getParameter<int> ( "untilDay" ) ),
70  hUntil( ps.getParameter<int> ( "untilHour" ) ),
71  pUntil( ps.getParameter<int> ( "untilMinute" ) ),
72  sUntil( ps.getParameter<int> ( "untilSecond" ) ),
73  dumpAtStart( ps.getParameter<bool>( "dumpAtStart" ) ),
74  dumpAtEnd( ps.getParameter<bool>( "dumpAtEnd" ) ),
75  bwdTime( ps.getParameter<long long int> ( "bwdTime" ) ),
76  fwdTime( ps.getParameter<long long int> ( "fwdTime" ) ),
77  minTime( ps.getParameter<long long int> ( "minTime" ) ),
78  omds_conn(),
79  util_conn(),
80  buff_conn(),
81  omds_session(),
82  util_session(),
83  buff_session(),
84  mapVersion( ps.getParameter<std::string> ( "mapVersion" ) ),
85  splitVersion( ps.getParameter<std::string> ( "splitVersion" ) ) {
86  std::cout << " PopCon application for DT HV data export "
88  << std::endl;
90  maxPayload = 1000;
91 }
92 
93 //--------------
94 // Destructor --
95 //--------------
97 }
98 
99 //--------------
100 // Operations --
101 //--------------
103 
104  std::cout << "get new objects..." << std::endl;
105 
106  // online DB connection - data
107  std::cout << "configure omds DbConnection" << std::endl;
108  // conn->configure( cond::CmsDefaults );
111  std::cout << "create omds DbSession" << std::endl;
113  std::cout << "open omds session" << std::endl;
115  std::cout << "start omds transaction" << std::endl;
117  std::cout << "" << std::endl;
118 
119  // online DB connection - util
120  std::cout << "configure util DbConnection" << std::endl;
121  // conn->configure( cond::CmsDefaults );
124  std::cout << "create util DbSession" << std::endl;
126  std::cout << "open util session" << std::endl;
128  std::cout << "startutil transaction" << std::endl;
130  std::cout << "" << std::endl;
131 
132  // buffer DB connection
133  std::cout << "configure buffer DbConnection" << std::endl;
136  std::cout << "create buffer DbSession" << std::endl;
138  std::cout << "open buffer session" << std::endl;
140  std::cout << "start buffer transaction" << std::endl;
142 
143  // offline info
144 
145  //to access the information on the tag inside the offline database:
146  cond::TagInfo const & ti = tagInfo();
147  cond::Time_t last = ti.lastInterval.first;
148  std::cout << "latest DCS data (HV) already copied until: "
149  << last << std::endl;
150 
151  coral::TimeStamp coralSince( ySince, mSince, dSince,
152  hSince, pSince, sSince, 0 );
153  procSince = condTime( coralSince );
154  coral::TimeStamp coralUntil( yUntil, mUntil, dUntil,
155  hUntil, pUntil, sUntil, 0 );
156  procUntil = condTime( coralUntil );
157  lastFound = 0;
158  nextFound = 0;
159  timeLimit = 0;
160  lastStamp = 0;
161 
162  if ( last == 0 ) {
163  DTHVStatus* dummyStatus = new DTHVStatus( dataTag );
164  cond::Time_t snc = 1;
165  m_to_transfer.push_back( std::make_pair( dummyStatus, snc ) );
166  last = procSince + 1;
167  std::cout << "no old data... " << last << std::endl;
168  }
169  else {
170  Ref payload = lastPayload();
171  DTHVStatus::const_iterator paylIter = payload->begin();
172  DTHVStatus::const_iterator paylIend = payload->end();
173  while ( paylIter != paylIend ) {
174  const std::pair<DTHVStatusId,DTHVStatusData>& entry = *paylIter++;
175  const DTHVStatusId& chan = entry.first;
176  const DTHVStatusData& data = entry.second;
177  DTWireId id( chan.wheelId, chan.stationId, chan.sectorId,
178  chan. slId, chan. layerId, chan. partId + 10 );
179  hvChecker->setStatus( id.rawId(),
180  data.flagA, data.flagC, data.flagS,
182  aliasMap, layerMap );
183  }
184  }
185  coral::TimeStamp coralLast = coralTime( last );
186  coral::TimeStamp coralProc = coral::TimeStamp::now();
187  cond::Time_t condProc = condTime( coralProc );
188 
189  if ( procSince > condProc ) {
190  std::cout << "Required time interval in the future: "
191  << std::endl
192  << " copy since " << ySince << " "
193  << mSince << " "
194  << dSince
195  << " ( " << procSince << " )" << std::endl
196  << " current time " << coralProc.year( ) << " "
197  << coralProc.month() << " "
198  << coralProc.day( ) << std::endl;
199  }
200  if ( procUntil > condProc ) procUntil = condProc;
201  if ( last > procSince ) {
202  if ( last < procUntil ) {
203  procSince = last;
204  checkNewData();
205  }
206  else {
207  std::cout << "Required time interval already copied: "
208  << std::endl
209  << " copy until " << yUntil << " "
210  << mUntil << " "
211  << dUntil
212  << " ( " << procUntil << " )" << std::endl
213  << " data until " << coralLast.year( ) << " "
214  << coralLast.month() << " "
215  << coralLast.day( ) << std::endl;
216  }
217  }
218  else {
219  std::cout << "Required time interval not contiguous with copied data: "
220  << std::endl
221  << " data until " << coralLast.year( ) << " "
222  << coralLast.month() << " "
223  << coralLast.day( ) << std::endl
224  << " copy since " << ySince << " "
225  << mSince << " "
226  << dSince
227  << " ( " << procSince << " )" << std::endl;
228  }
229 
234 
235  return;
236 
237 }
238 
239 
241 
242  //to access the information on last successful log entry for this tag:
243 // cond::LogDBEntry const & lde = logDBEntry();
244 
245  //to access the lastest payload (Ref is a smart pointer)
246 // Ref payload = lastPayload();
247 
248  std::cout << "check for new data since "
249  << procSince << " "
250  << coralTime( procSince ).total_nanoseconds() << " "
251  << coralTime( procSince ).year( ) << " "
252  << coralTime( procSince ).month( ) << " "
253  << coralTime( procSince ).day( ) << " "
254  << coralTime( procSince ).hour( ) << " "
255  << coralTime( procSince ).minute() << " "
256  << coralTime( procSince ).second() << std::endl;
257  std::cout << " until "
258  << procUntil << " "
259  << coralTime( procUntil ).total_nanoseconds() << " "
260  << coralTime( procUntil ).year( ) << " "
261  << coralTime( procUntil ).month( ) << " "
262  << coralTime( procUntil ).day( ) << " "
263  << coralTime( procUntil ).hour( ) << " "
264  << coralTime( procUntil ).minute() << " "
265  << coralTime( procUntil ).second() << std::endl;
266 
267  std::set<std::string> omds_lt( omds_session.nominalSchema().listTables() );
268  std::set<std::string>::const_iterator omds_iter = omds_lt.begin();
269  std::set<std::string>::const_iterator omds_iend = omds_lt.end();
270  while ( omds_iter != omds_iend ) {
271  const std::string& istr = *omds_iter++;
272  std::cout << "TABLE: " << istr << std::endl;
273  }
274 
275  std::set<std::string> util_lt( util_session.nominalSchema().listTables() );
276  std::set<std::string>::const_iterator util_iter = util_lt.begin();
277  std::set<std::string>::const_iterator util_iend = util_lt.end();
278  while ( util_iter != util_iend ) {
279  const std::string& istr = *util_iter++;
280  std::cout << "TABLE: " << istr << std::endl;
281  }
282 
283  getLayerSplit();
284  getChannelMap();
285  getChannelSplit();
286 
287  std::cout << "open buffer db..." << std::endl;
288 
289  if ( !( buff_session.nominalSchema().existsTable( "HVSNAPSHOT" ) ) )
290  createSnapshot();
291  updateHVStatus();
292 
293  return;
294 
295 }
296 
297 std::string DTHVStatusHandler::id() const {
298  return "DTHVStatusHandler";
299 }
300 
301 
303 
304  if ( !( buff_session.nominalSchema().existsTable( "HVALIASES" ) ) ) {
305  dumpHVAliases();
306  }
307  else {
308  std::cout << "retrieve aliases table..." << std::endl;
309  coral::ITable& hvalTable =
310  buff_session.nominalSchema().tableHandle( "HVALIASES" );
311  std::auto_ptr<coral::IQuery> hvalQuery( hvalTable.newQuery() );
312  hvalQuery->addToOutputList( "DETID" );
313  hvalQuery->addToOutputList( "DPID" );
314  coral::ICursor& hvalCursor = hvalQuery->execute();
315  int chId;
316  int dpId;
317  while ( hvalCursor.next() ) {
318  chId = hvalCursor.currentRow()["DETID"].data<int>();
319  dpId = hvalCursor.currentRow()[ "DPID"].data<int>();
320  aliasMap.insert( std::pair<int,int>( dpId, chId ) );
321  layerMap.insert( std::pair<int,int>( chId, dpId ) );
322  }
323  }
324 
325  return;
326 
327 }
328 
329 
331  std::cout << "retrieve layer split table..." << std::endl;
332  int whe;
333  int sec;
334  int sta;
335  int qua;
336  int lay;
337  int l_p;
338  int f_c;
339  int l_c;
340  coral::ITable& lsplTable =
341  util_session.nominalSchema().tableHandle( "DT_HV_LAYER_SPLIT" );
342  std::cout << " layer split table got..." << std::endl;
343  std::auto_ptr<coral::IQuery> lsplQuery( lsplTable.newQuery() );
344  coral::AttributeList versionBindVariableList;
345  versionBindVariableList.extend( "version", typeid(std::string) );
346  versionBindVariableList["version"].data<std::string>() = mapVersion;
347  lsplQuery->setCondition( "VERSION=:version", versionBindVariableList );
348  lsplQuery->addToOutputList( "WHEEL" );
349  lsplQuery->addToOutputList( "SECTOR" );
350  lsplQuery->addToOutputList( "STATION" );
351  lsplQuery->addToOutputList( "SUPERLAYER" );
352  lsplQuery->addToOutputList( "LAYER" );
353  lsplQuery->addToOutputList( "PART" );
354  lsplQuery->addToOutputList( "FIRST_CELL" );
355  lsplQuery->addToOutputList( "LAST_CELL" );
356  coral::ICursor& lsplCursor = lsplQuery->execute();
357  while ( lsplCursor.next() ) {
358  whe = lsplCursor.currentRow()["WHEEL" ].data<int>();
359  sec = lsplCursor.currentRow()["SECTOR" ].data<int>();
360  sta = lsplCursor.currentRow()["STATION" ].data<int>();
361  qua = lsplCursor.currentRow()["SUPERLAYER"].data<int>();
362  lay = lsplCursor.currentRow()["LAYER" ].data<int>();
363  l_p = lsplCursor.currentRow()["PART" ].data<int>();
364  f_c = lsplCursor.currentRow()["FIRST_CELL"].data<int>();
365  l_c = lsplCursor.currentRow()[ "LAST_CELL"].data<int>();
366  DTWireId wireId( whe, sta, sec, qua, lay, 10 + l_p );
367  laySplit.insert( std::pair<int,int>( wireId.rawId(),
368  ( f_c * 10000 ) + l_c ) );
369  }
370  std::cout << "channel split table retrieved" << std::endl;
371  return;
372 }
373 
374 
376  std::cout << "retrieve channel split table..." << std::endl;
377  int pwhe;
378  int psec;
379  int psta;
380  int pqua;
381  int play;
382  int pl_p;
383  int snum;
384  int swhe;
385  int ssec;
386  int ssta;
387  int squa;
388  int slay;
389  int sl_p;
390  coral::ITable& csplTable =
391  util_session.nominalSchema().tableHandle( "DT_HV_CHANNEL_SPLIT" );
392  std::auto_ptr<coral::IQuery> csplQuery( csplTable.newQuery() );
393  coral::AttributeList versionBindVariableList;
394  versionBindVariableList.extend( "version", typeid(std::string) );
395  versionBindVariableList["version"].data<std::string>() = splitVersion;
396  csplQuery->setCondition( "VERSION=:version", versionBindVariableList );
397  csplQuery->addToOutputList( "P_WHEEL" );
398  csplQuery->addToOutputList( "P_SECTOR" );
399  csplQuery->addToOutputList( "P_STATION" );
400  csplQuery->addToOutputList( "P_SUPERLAYER" );
401  csplQuery->addToOutputList( "P_LAYER" );
402  csplQuery->addToOutputList( "P_PART" );
403  csplQuery->addToOutputList( "S_NUMBER" );
404  csplQuery->addToOutputList( "S_WHEEL" );
405  csplQuery->addToOutputList( "S_SECTOR" );
406  csplQuery->addToOutputList( "S_STATION" );
407  csplQuery->addToOutputList( "S_SUPERLAYER" );
408  csplQuery->addToOutputList( "S_LAYER" );
409  csplQuery->addToOutputList( "S_PART" );
410  coral::ICursor& csplCursor = csplQuery->execute();
411  while ( csplCursor.next() ) {
412  pwhe = csplCursor.currentRow()["P_WHEEL" ].data<int>();
413  psec = csplCursor.currentRow()["P_SECTOR" ].data<int>();
414  psta = csplCursor.currentRow()["P_STATION" ].data<int>();
415  pqua = csplCursor.currentRow()["P_SUPERLAYER"].data<int>();
416  play = csplCursor.currentRow()["P_LAYER" ].data<int>();
417  pl_p = csplCursor.currentRow()["P_PART" ].data<int>();
418  snum = csplCursor.currentRow()["S_NUMBER" ].data<int>();
419  swhe = csplCursor.currentRow()["S_WHEEL" ].data<int>();
420  ssec = csplCursor.currentRow()["S_SECTOR" ].data<int>();
421  ssta = csplCursor.currentRow()["S_STATION" ].data<int>();
422  squa = csplCursor.currentRow()["S_SUPERLAYER"].data<int>();
423  slay = csplCursor.currentRow()["S_LAYER" ].data<int>();
424  sl_p = csplCursor.currentRow()["S_PART" ].data<int>();
425  DTWireId pId( pwhe, psta, psec, pqua, play, 10 + pl_p );
426  DTWireId sId( swhe, ssta, ssec, squa, slay, 10 + sl_p );
427  int pRaw = pId.rawId();
428  int sRaw = sId.rawId();
429  std::vector<int>* splitList = 0;
430  std::map< int,std::vector<int>* >::iterator iter =
431  channelSplit.find( pRaw );
432  std::map< int,std::vector<int>* >::iterator iend =
433  channelSplit.end();
434  if ( iter == iend ) {
435  channelSplit.insert( std::pair< int,
436  std::vector<int>* >( pRaw, splitList =
437  new std::vector<int> ) );
438  }
439  else {
440  splitList = iter->second;
441  }
442  splitList->push_back( sRaw );
443  }
444  return;
445 }
446 
447 
449 
450  std::cout << "DTHVStatusHandler::dumpHVAliases - begin" << std::endl;
451 
452  std::cout << "create aliases description..." << std::endl;
453  coral::TableDescription hvalDesc;
454  hvalDesc.setName( "HVALIASES" );
455  hvalDesc.insertColumn( "DETID",
456  coral::AttributeSpecification::typeNameForId(
457  typeid(int) ) );
458  hvalDesc.insertColumn( "DPID",
459  coral::AttributeSpecification::typeNameForId(
460  typeid(int) ) );
461  std::cout << "create aliases table..." << std::endl;
462  coral::ITable& hvalTable =
463  buff_session.nominalSchema().createTable( hvalDesc );
464 
465  std::cout << "open DPNAME table..." << std::endl;
466  std::map<int,std::string> idMap;
467  coral::ITable& dpidTable =
468  omds_session.nominalSchema().tableHandle( "DP_NAME2ID" );
469  std::auto_ptr<coral::IQuery> dpidQuery( dpidTable.newQuery() );
470  dpidQuery->addToOutputList( "ID" );
471  dpidQuery->addToOutputList( "DPNAME" );
472  coral::ICursor& dpidCursor = dpidQuery->execute();
473  while( dpidCursor.next() ) {
474  const coral::AttributeList& row = dpidCursor.currentRow();
475  int id = static_cast<int>( 0.01 +
476  row["ID" ].data<float>() );
477  std::string dp = row["DPNAME"].data<std::string>();
478  idMap.insert( std::pair<int,std::string>( id, dp ) );
479  }
480  std::cout << "DPNAME table read... " << idMap.size() << std::endl;
481 
482  std::cout << "open ALIASES table..." << std::endl;
483  std::map<std::string,std::string> cnMap;
484  coral::ITable& nameTable =
485  omds_session.nominalSchema().tableHandle( "ALIASES" );
486  std::auto_ptr<coral::IQuery> nameQuery( nameTable.newQuery() );
487  nameQuery->addToOutputList( "DPE_NAME" );
488  nameQuery->addToOutputList( "ALIAS" );
489  coral::ICursor& nameCursor = nameQuery->execute();
490  while( nameCursor.next() ) {
491  const coral::AttributeList& row = nameCursor.currentRow();
492  std::string dp = row["DPE_NAME"].data<std::string>();
493  std::string an = row["ALIAS" ].data<std::string>();
494  if ( an.length() < 20 ) continue;
495  cnMap.insert( std::pair<std::string,std::string>( dp, an ) );
496  }
497  std::cout << "ALIASES table read... " << cnMap.size() << std::endl;
498 
499  std::map<int,std::string>::const_iterator idIter = idMap.begin();
500  std::map<int,std::string>::const_iterator idIend = idMap.end();
501  std::string outChk( "/outputChannel" );
502  while ( idIter != idIend ) {
503  const std::pair<int,std::string>& ientry = *idIter++;
504  int dpId = ientry.first;
505  std::string dp = ientry.second;
506  int ldp = dp.length();
507  if ( ldp < 20 ) continue;
508  std::string subOut( dp.substr( ldp - 17, 17 ) );
509  std::string subChk( subOut.substr( 0, 14 ) );
510  if ( subChk != outChk ) continue;
511  std::string chName( dp.substr( 0, ldp - 17 ) );
512  chName += ".actual.OvC";
513  int chCode = subOut.c_str()[16] - '0';
514  std::map<std::string,std::string>::const_iterator jter =
515  cnMap.find( chName );
516  if ( jter == cnMap.end() ) continue;
517  const std::pair<std::string,std::string>& jentry = *jter;
518  std::cout << dp << std::endl << chName << " " << chCode << std::endl;
519  std::string an( jentry.second );
520  int al = an.length();
521  int iofw = 7 + an.find( "DT_HV_W", 0 );
522  int iofc = 3 + an.find( "_MB", 0 );
523  int iofs = 2 + an.find( "_S" , 0 );
524  int iofq = 3 + an.find( "_SL", 0 );
525  int iofl = 2 + an.find( "_L" , 0 );
526  if ( ( iofw == al ) ||
527  ( iofc == al ) ||
528  ( iofs == al ) ||
529  ( iofq == al ) ||
530  ( iofl == al ) ) {
531  break;
532  }
533  int ioew = an.find( "_", iofw );
534  int ioec = an.find( "_", iofc );
535  int ioes = an.find( "_", iofs );
536  int ioeq = an.find( "_", iofq );
537  int ioel = an.find( "_", iofl );
538  std::string swhe( an.substr( iofw, ioew - iofw ) );
539  const char* cwhe = swhe.c_str();
540  int whe = cwhe[1] - '0';
541  if ( *cwhe != 'P' ) whe = -whe;
542 
543  std::string scha( an.substr( iofc, ioec - iofc ) );
544  const char* ccha = scha.c_str();
545  int cha = *ccha - '0';
546 
547  std::string ssec( an.substr( iofs, ioes - iofs ) );
548  const char* csec = ssec.c_str();
549  int sec = ( ( *csec - '0' ) * 10 ) + ( csec[1] - '0' );
550  if ( ( csec[2] == 'R' ) && ( sec == 10 ) ) sec = 14;
551  if ( ( csec[2] == 'L' ) && ( sec == 4 ) ) sec = 13;
552 
553  std::string squa( an.substr( iofq, ioeq - iofq ) );
554  const char* cqua = squa.c_str();
555  int qua = *cqua - '0';
556 
557  std::string slay( an.substr( iofl, ioel - iofl ) );
558  const char* clay = slay.c_str();
559  int lay = *clay - '0';
560 
561  DTWireId wireId( whe, cha, sec, qua, lay, 10 + chCode );
562  int chId = wireId.rawId();
563  coral::AttributeList newChan;
564  newChan.extend( "DETID", typeid(int) );
565  newChan.extend( "DPID", typeid(int) );
566  newChan["DETID"].data<int>() = chId;
567  newChan[ "DPID"].data<int>() = dpId;
568  hvalTable.dataEditor().insertRow( newChan );
569  aliasMap.insert( std::pair<int,int>( dpId, chId ) );
570  layerMap.insert( std::pair<int,int>( chId, dpId ) );
571  }
572 
573  std::cout << "DTHVStatusHandler::dumpHVAliases - end" << std::endl;
574  return;
575 }
576 
577 
579  std::cout << "create snapshot description..." << std::endl;
580  coral::TableDescription hvssDesc;
581  hvssDesc.setName( "HVSNAPSHOT" );
582  hvssDesc.insertColumn( "TIME",
583  coral::AttributeSpecification::typeNameForId(
584  typeid(coral::TimeStamp) ) );
585  hvssDesc.insertColumn( "WHEEL",
586  coral::AttributeSpecification::typeNameForId(
587  typeid(int) ) );
588  hvssDesc.insertColumn( "STATION",
589  coral::AttributeSpecification::typeNameForId(
590  typeid(int) ) );
591  hvssDesc.insertColumn( "SECTOR",
592  coral::AttributeSpecification::typeNameForId(
593  typeid(int) ) );
594  hvssDesc.insertColumn( "SUPERLAYER",
595  coral::AttributeSpecification::typeNameForId(
596  typeid(int) ) );
597  hvssDesc.insertColumn( "LAYER",
598  coral::AttributeSpecification::typeNameForId(
599  typeid(int) ) );
600  hvssDesc.insertColumn( "CHAN",
601  coral::AttributeSpecification::typeNameForId(
602  typeid(int) ) );
603  hvssDesc.insertColumn( "TYPE",
604  coral::AttributeSpecification::typeNameForId(
605  typeid(int) ) );
606  hvssDesc.insertColumn( "VALUE",
607  coral::AttributeSpecification::typeNameForId(
608  typeid(float) ) );
609  std::cout << "create snapshot table..." << std::endl;
610  buff_session.nominalSchema().createTable( hvssDesc );
611  coral::ITable& bufferTable =
612  buff_session.nominalSchema().tableHandle( "HVSNAPSHOT" );
613  coral::AttributeList newMeas;
614  newMeas.extend( "TIME", typeid(coral::TimeStamp) );
615  newMeas.extend( "WHEEL", typeid(int) );
616  newMeas.extend( "STATION", typeid(int) );
617  newMeas.extend( "SECTOR", typeid(int) );
618  newMeas.extend( "SUPERLAYER", typeid(int) );
619  newMeas.extend( "LAYER", typeid(int) );
620  newMeas.extend( "CHAN", typeid(int) );
621  newMeas.extend( "TYPE", typeid(int) );
622  newMeas.extend( "VALUE", typeid(float) );
623 
624  long long int zeroTime = 0LL;
625  newMeas["TIME" ].data<coral::TimeStamp>() =
626  coral::TimeStamp( zeroTime );
627  newMeas["VALUE" ].data<float>() = -999999.0;
628 
629  std::map<int,int>::const_iterator iter = aliasMap.begin();
630  std::map<int,int>::const_iterator iend = aliasMap.end();
631  while ( iter != iend ) {
632  const std::pair<int,int>& entry= *iter++;
633  int detId = entry.second;
634  DTWireId chlId( detId );
635  newMeas["WHEEL" ].data<int>() = chlId.wheel ();
636  newMeas["STATION" ].data<int>() = chlId.station ();
637  newMeas["SECTOR" ].data<int>() = chlId.sector ();
638  newMeas["SUPERLAYER"].data<int>() = chlId.superLayer();
639  newMeas["LAYER" ].data<int>() = chlId.layer ();
640  newMeas["CHAN" ].data<int>() = chlId.wire () - 10;
641  int itype;
642  for ( itype = 1; itype <= 2; itype++ ) {
643  newMeas["TYPE" ].data<int>() = itype;
644  bufferTable.dataEditor().insertRow( newMeas );
645  }
646  }
647 
648  std::cout << "create logging info..." << std::endl;
649  if ( buff_session.nominalSchema().existsTable( "LOG" ) )
650  buff_session.nominalSchema(). dropTable( "LOG" );
651  coral::TableDescription infoDesc;
652  infoDesc.setName( "LOG" );
653  infoDesc.insertColumn( "EXECTIME",
654  coral::AttributeSpecification::typeNameForId(
655  typeid(coral::TimeStamp) ) );
656  infoDesc.insertColumn( "SNAPSHOT",
657  coral::AttributeSpecification::typeNameForId(
658  typeid(coral::TimeStamp) ) );
659  buff_session.nominalSchema().createTable( infoDesc );
660  coral::AttributeList newInfo;
661  newInfo.extend( "EXECTIME", typeid(coral::TimeStamp) );
662  newInfo.extend( "SNAPSHOT", typeid(coral::TimeStamp) );
663  newInfo["EXECTIME"].data<coral::TimeStamp>() =
664  coral::TimeStamp( zeroTime );
665  newInfo["SNAPSHOT"].data<coral::TimeStamp>() =
666  coral::TimeStamp( zeroTime );
667  coral::ITable& infoTable =
668  buff_session.nominalSchema().tableHandle( "LOG" );
669  infoTable.dataEditor().insertRow( newInfo );
670 
671  return;
672 
673 }
674 
675 
677  int missingChannels = recoverSnapshot();
678  cond::Time_t snapshotTime = recoverLastTime();
679  std::cout << " snapshot at " << snapshotTime << " ( "
680  << coralTime( snapshotTime )
681  .total_nanoseconds() << " ) "
682  << std::endl;
683  if ( snapshotTime > procSince ) {
684  coral::TimeStamp coralSnap = coralTime( snapshotTime );
685  std::cout << "too recent snapshot: " << std::endl
686  << " snapshot at " << coralSnap.year( ) << " "
687  << coralSnap.month() << " "
688  << coralSnap.day( ) << std::endl
689  << " copy since " << ySince << " "
690  << mSince << " "
691  << dSince
692  << " ( " << procSince << " )" << std::endl;
693  return;
694  }
695  long long int dTime = bwdTime;
696  dTime <<= 32;
697  cond::Time_t condUntil = procSince;
698  cond::Time_t condSince = condUntil - dTime;
699 
700  while ( missingChannels ) {
701  std::cout << "back iteration: "
702  << condSince << " ( " << coralTime( condSince )
703  .total_nanoseconds() << " ) -> "
704  << condUntil << " ( " << coralTime( condUntil )
705  .total_nanoseconds() << " ) "
706  << std::endl;
707  if ( condSince <= snapshotTime ) condSince = snapshotTime;
708  std::cout << "corrected since: "
709  << condSince << " ( " << coralTime( condSince )
710  .total_nanoseconds() << " ) "
711  << std::endl;
712  if ( condSince >= condUntil ) break;
713  std::cout << "missing... " << missingChannels << std::endl;
714  checkForPeriod( condSince, condUntil, missingChannels, false );
715  condUntil = condSince;
716  condSince = condUntil - dTime;
717  }
718 
720 
721  copyHVData();
722 
724 
725  return;
726 }
727 
728 
730  int missingChannels = 0;
731  std::map<int,int>::const_iterator layIter = layerMap.begin();
732  std::map<int,int>::const_iterator layIend = layerMap.end();
733  std::cout << "retrieve snapshot table..." << std::endl;
734  coral::ITable& hvssTable =
735  buff_session.nominalSchema().tableHandle( "HVSNAPSHOT" );
736  std::auto_ptr<coral::IQuery> hvssQuery( hvssTable.newQuery() );
737  hvssQuery->addToOutputList( "TIME" );
738  hvssQuery->addToOutputList( "WHEEL" );
739  hvssQuery->addToOutputList( "STATION" );
740  hvssQuery->addToOutputList( "SECTOR" );
741  hvssQuery->addToOutputList( "SUPERLAYER" );
742  hvssQuery->addToOutputList( "LAYER" );
743  hvssQuery->addToOutputList( "CHAN" );
744  hvssQuery->addToOutputList( "TYPE" );
745  hvssQuery->addToOutputList( "VALUE" );
746  coral::ICursor& hvssCursor = hvssQuery->execute();
747  while ( hvssCursor.next() ) {
748  coral::TimeStamp time =
749  hvssCursor.currentRow()["TIME"].data<coral::TimeStamp>();
750  int whe = hvssCursor.currentRow()["WHEEL" ].data<int>();
751  int sta = hvssCursor.currentRow()["STATION" ].data<int>();
752  int sec = hvssCursor.currentRow()["SECTOR" ].data<int>();
753  int qua = hvssCursor.currentRow()["SUPERLAYER"].data<int>();
754  int lay = hvssCursor.currentRow()["LAYER" ].data<int>();
755  int l_p = hvssCursor.currentRow()["CHAN" ].data<int>();
756  int mty = hvssCursor.currentRow()["TYPE" ].data<int>();
757  float value = hvssCursor.currentRow()["VALUE" ].data<float>();
758  if ( mty > 2 ) continue;
759  DTWireId wireId( whe, sta, sec, qua, lay, 10 + l_p );
760  layIter = layerMap.find( wireId.rawId() );
761  if ( layIter == layIend ) {
762  continue;
763  }
764  int dpId = ( layIter->second * 10 ) + mty;
765  snapshotValues.insert( std::pair<int,timedMeasurement>(
766  dpId, timedMeasurement(
767  time.total_nanoseconds(), value ) ) );
768  missingChannels++;
769  }
770  return missingChannels;
771 }
772 
773 
775  coral::ITable& infoTable =
776  buff_session.nominalSchema().tableHandle( "LOG" );
777  std::auto_ptr<coral::IQuery> infoQuery( infoTable.newQuery() );
778  infoQuery->addToOutputList( "SNAPSHOT" );
779  coral::ICursor& infoCursor = infoQuery->execute();
780  coral::TimeStamp time;
781  while ( infoCursor.next() ) {
782  time = infoCursor.currentRow()["SNAPSHOT"].data<coral::TimeStamp>();
783  }
784  return condTime( time );
785 }
786 
787 
788 void DTHVStatusHandler::dumpSnapshot( const coral::TimeStamp& time ) {
789 
790  std::cout << "dump snapshot to buffer db..." << std::endl;
791  std::string emptyCondition( "" );
792  coral::AttributeList emptyBindVariableList;
793  std::map<int,int>::const_iterator mapIter = aliasMap.begin();
794  std::map<int,int>::const_iterator mapIend = aliasMap.end();
795  coral::ITable& hvssTable =
796  buff_session.nominalSchema().tableHandle( "HVSNAPSHOT" );
797  coral::ITableDataEditor& hvssEditor( hvssTable.dataEditor() );
798  long nRows = hvssEditor.deleteRows( emptyCondition, emptyBindVariableList );
799  std::cout << nRows << " rows deleted" << std::endl;
800 
801  coral::AttributeList newMeas;
802  newMeas.extend( "TIME", typeid(coral::TimeStamp) );
803  newMeas.extend( "WHEEL", typeid(int) );
804  newMeas.extend( "STATION", typeid(int) );
805  newMeas.extend( "SECTOR", typeid(int) );
806  newMeas.extend( "SUPERLAYER", typeid(int) );
807  newMeas.extend( "LAYER", typeid(int) );
808  newMeas.extend( "CHAN", typeid(int) );
809  newMeas.extend( "TYPE", typeid(int) );
810  newMeas.extend( "VALUE", typeid(float) );
811 
812  nRows = 0;
813  std::map<int,timedMeasurement>::const_iterator ssvIter =
814  snapshotValues.begin();
815  std::map<int,timedMeasurement>::const_iterator ssvIend =
816  snapshotValues.end();
817  while ( ssvIter != ssvIend ) {
818  const std::pair<int,timedMeasurement>& entry = *ssvIter++;
819  int dpty = entry.first;
820  int dpId = dpty / 10;
821  int type = dpty % 10;
822  mapIter = aliasMap.find( dpId );
823  if ( mapIter == mapIend ) continue;
824  DTWireId chlId( mapIter->second );
825  const timedMeasurement& tMeas = entry.second;
826  long long int newTime = tMeas.first;
827  newMeas["TIME" ].data<coral::TimeStamp>() =
828  coral::TimeStamp( newTime );
829  newMeas["WHEEL" ].data<int>() = chlId.wheel ();
830  newMeas["STATION" ].data<int>() = chlId.station ();
831  newMeas["SECTOR" ].data<int>() = chlId.sector ();
832  newMeas["SUPERLAYER"].data<int>() = chlId.superLayer();
833  newMeas["LAYER" ].data<int>() = chlId.layer ();
834  newMeas["CHAN" ].data<int>() = chlId.wire () - 10;
835  newMeas["TYPE" ].data<int>() = type;
836  newMeas["VALUE" ].data<float>() = tMeas.second;
837  hvssEditor.insertRow( newMeas );
838  nRows++;
839  }
840  std::cout << nRows << " rows updated" << std::endl;
841 
842  std::cout << "create logging info..." << std::endl;
843  if ( buff_session.nominalSchema().existsTable( "LOG" ) )
844  buff_session.nominalSchema(). dropTable( "LOG" );
845  coral::TableDescription infoDesc;
846  infoDesc.setName( "LOG" );
847  infoDesc.insertColumn( "EXECTIME",
848  coral::AttributeSpecification::typeNameForId(
849  typeid(coral::TimeStamp) ) );
850  infoDesc.insertColumn( "SNAPSHOT",
851  coral::AttributeSpecification::typeNameForId(
852  typeid(coral::TimeStamp) ) );
853  buff_session.nominalSchema().createTable( infoDesc );
854  coral::AttributeList newInfo;
855  newInfo.extend( "EXECTIME", typeid(coral::TimeStamp) );
856  newInfo.extend( "SNAPSHOT", typeid(coral::TimeStamp) );
857  newInfo["EXECTIME"].data<coral::TimeStamp>() = coral::TimeStamp::now();
858  newInfo["SNAPSHOT"].data<coral::TimeStamp>() = time;
859  coral::ITable& infoTable =
860  buff_session.nominalSchema().tableHandle( "LOG" );
861  infoTable.dataEditor().insertRow( newInfo );
862 
863  return;
864 
865 }
866 
867 
869  cond::Time_t condUntil,
870  int& missingChannels,
871  bool copyOffline ) {
872 
873  std::map<int,timedMeasurement>::iterator mapIter = snapshotValues.begin();
874  std::map<int,timedMeasurement>::iterator mapIend = snapshotValues.end();
875 
876  std::map<long long int,channelValue> periodBuffer;
877 
878  coral::ITable& fwccTable =
879  omds_session.nominalSchema().tableHandle( "FWCAENCHANNEL" );
880  std::auto_ptr<coral::IQuery> fwccQuery( fwccTable.newQuery() );
881  fwccQuery->addToOutputList( "DPID" );
882  fwccQuery->addToOutputList( "CHANGE_DATE" );
883  fwccQuery->addToOutputList( "ACTUAL_VMON" );
884  fwccQuery->addToOutputList( "ACTUAL_IMON" );
885  fwccQuery->addToOutputList( "ACTUAL_ISON" );
886  fwccQuery->addToOutputList( "ACTUAL_STATUS" );
887  fwccQuery->addToOutputList( "ACTUAL_OVC" );
888  coral::AttributeList timeBindVariableList;
889  timeBindVariableList.extend( "since", typeid(coral::TimeStamp) );
890  timeBindVariableList.extend( "until", typeid(coral::TimeStamp) );
891  coral::TimeStamp coralSince = coralTime( condSince );
892  coral::TimeStamp coralUntil = coralTime( condUntil );
893  std::cout << "look for data since "
894  << coralSince.year( ) << " "
895  << coralSince.month( ) << " "
896  << coralSince.day( ) << " "
897  << coralSince.hour( ) << ":"
898  << coralSince.minute() << ":"
899  << coralSince.second() << " until "
900  << coralUntil.year( ) << " "
901  << coralUntil.month( ) << " "
902  << coralUntil.day( ) << " "
903  << coralUntil.hour( ) << ":"
904  << coralUntil.minute() << ":"
905  << coralUntil.second() << std::endl;
906  timeBindVariableList["since"].data<coral::TimeStamp>() =
907  coralTime( condSince );
908  timeBindVariableList["until"].data<coral::TimeStamp>() =
909  coralTime( condUntil );
910  fwccQuery->setCondition( "CHANGE_DATE>:since and CHANGE_DATE<:until",
911  timeBindVariableList );
912  fwccQuery->addToOrderList( "CHANGE_DATE" );
913  coral::ICursor& fwccCursor = fwccQuery->execute();
914  int nrows = 0;
915  while ( fwccCursor.next() ) {
916  nrows++;
917  const coral::Attribute& dp = fwccCursor.currentRow()["DPID" ];
918  const coral::Attribute& vmon = fwccCursor.currentRow()["ACTUAL_VMON" ];
919  const coral::Attribute& imon = fwccCursor.currentRow()["ACTUAL_IMON" ];
920  coral::TimeStamp changeTime =
921  fwccCursor.currentRow()["CHANGE_DATE"].data<coral::TimeStamp>();
922  long long int cTimeValue = changeTime.total_nanoseconds();
923  if ( !copyOffline ) cTimeValue = -cTimeValue;
924  if ( dp.isNull() ) {
925  std::cout << "------- " << nrows << std::endl;
926  continue;
927  }
928  int dpId = 10 * static_cast<int>( 0.01 +
929  fwccCursor.currentRow()["DPID"].data<float>() );
930  if ( !( vmon.isNull() ) ) {
931  while ( periodBuffer.find( cTimeValue ) !=
932  periodBuffer.end() ) cTimeValue++;
933  int chan = dpId + 1;
934  periodBuffer.insert( std::pair<long long int,channelValue> (
935  cTimeValue, channelValue( chan,
936  vmon.data<float>() ) ) );
937  }
938  if ( !( imon.isNull() ) ) {
939  while ( periodBuffer.find( cTimeValue ) !=
940  periodBuffer.end() ) cTimeValue++;
941  int chan = dpId + 2;
942  periodBuffer.insert( std::pair<long long int,channelValue> (
943  cTimeValue, channelValue( chan,
944  imon.data<float>() ) ) );
945  }
946  }
947 
948  long long int dTime = minTime;
949  dTime <<= 32;
950  std::cout << "data found in period: " << periodBuffer.size() << std::endl;
951  std::map<long long int,channelValue>::const_iterator bufIter =
952  periodBuffer.begin();
953  std::map<long long int,channelValue>::const_iterator bufIend =
954  periodBuffer.end();
955 
956  bool changedStatus = false;
957  while ( bufIter != bufIend ) {
958  const std::pair<long long int,channelValue>& entry = *bufIter++;
959  long long int mTime = entry.first;
960  if ( !copyOffline ) mTime = -mTime;
961  channelValue cValue = entry.second;
962  int chan = cValue.first;
963  float cont = cValue.second;
964  mapIter = snapshotValues.find( chan );
965  if ( ( mapIter != mapIend ) &&
966  ( mapIter->second.first < mTime ) ) {
967  nextFound = condTime( mTime );
968  if ( changedStatus ) {
969  if ( nextFound > timeLimit ) {
970  DTHVStatus* hvStatus = offlineList();
971  std::cout << "new payload "
972  << hvStatus->end() - hvStatus->begin() << std::endl;
973  tmpContainer.push_back( std::make_pair( hvStatus, lastFound ) );
974  changedStatus = false;
975  if ( !( --maxPayload ) ) {
977  std::cout << "max payload number reached" << std::endl;
978  break;
979  }
980  }
981  }
982  if ( copyOffline && !changedStatus &&
983  checkStatusChange( chan, mapIter->second.second, cont ) ) {
984  timeLimit = nextFound + dTime;
985  changedStatus = true;
986  }
987  mapIter->second = timedMeasurement( lastStamp = mTime, cont );
989  missingChannels--;
990  }
991  }
992 
993  std::cout << nrows << std::endl;
994  return nrows;
995 
996 }
997 
998 
1000  long long int dTime = fwdTime;
1001  dTime <<= 32;
1002 
1003  cond::Time_t condSince = procSince;
1004  cond::Time_t condUntil = condSince + dTime;
1005  if ( condUntil > procUntil ) condUntil = procUntil;
1006 
1007  int dum = 0;
1008  lastStatus = 0;
1009  while ( condSince < condUntil ) {
1010  checkForPeriod( condSince, condUntil, dum, true );
1011  condSince = condUntil;
1012  condUntil = condSince + dTime;
1013  if ( condUntil > procUntil ) condUntil = procUntil;
1014  }
1015  std::cout << "call filterData " << std::endl;
1016  filterData();
1017  std::cout << "filterData return "
1018  << switchOff << " "
1019  << lastFound << " "
1020  << maxPayload << " "
1021  << m_to_transfer.size() << std::endl;
1022  if ( switchOff || ( ( lastFound != 0 ) && ( maxPayload > 0 ) ) ) {
1023  DTHVStatus* hvStatus = offlineList();
1024  m_to_transfer.push_back( std::make_pair( hvStatus, lastFound ) );
1025  }
1026 
1027  return;
1028 }
1029 
1030 
1032  DTHVStatus* hv = new DTHVStatus( dataTag );
1033  int type;
1034  float valueA = 0.0;
1035  float valueL = 0.0;
1036  float valueR = 0.0;
1037  float valueS = 0.0;
1038  float valueC = 0.0;
1039  std::map<int,int>::const_iterator layerIter = layerMap.begin();
1040  std::map<int,int>::const_iterator layerIend = layerMap.end();
1041  while ( layerIter != layerIend ) {
1042  const std::pair<int,int>& chanEntry = *layerIter++;
1043  int rawId = chanEntry.first;
1044  DTWireId chlId( rawId );
1045  int whe = chlId.wheel ();
1046  int sta = chlId.station ();
1047  int sec = chlId.sector ();
1048  int qua = chlId.superLayer();
1049  int lay = chlId.layer ();
1050  int l_p = chlId.wire();
1051  if ( l_p != 10 ) continue;
1052  for ( type = 1; type <= 2; type++ ) {
1053  getLayerValues( rawId, type, valueL, valueR, valueS, valueC );
1054  for ( l_p = 0; l_p <= 1; l_p++ ) {
1055  int rPart = layerId( rawId, l_p ).rawId();
1056  switch ( l_p ) {
1057  case 0:
1058  valueA = valueL;
1059  break;
1060  case 1:
1061  valueA = valueR;
1062  break;
1063  default:
1064  break;
1065  }
1066 // std::cout << "layer values: " << type << " " << valueA << " "
1067 // << valueS << " "
1068 // << valueC << std::endl;
1070  rPart, type,
1071  valueA, valueC, valueS,
1073  aliasMap, layerMap );
1074  if ( !flag.a && !flag.c && !flag.s ) continue;
1075  setChannelFlag( hv, whe, sta, sec, qua, lay, l_p, flag );
1076  std::map< int,std::vector<int>* >::const_iterator m_iter =
1077  channelSplit.find( rPart );
1078  std::map< int,std::vector<int>* >::const_iterator m_iend =
1079  channelSplit.end();
1080  if ( m_iter != m_iend ) {
1081  std::vector<int>* cList = m_iter->second;
1082  std::vector<int>::const_iterator l_iter = cList->begin();
1083  std::vector<int>::const_iterator l_iend = cList->end();
1084  while ( l_iter != l_iend ) {
1085  DTWireId chlId( *l_iter++ );
1086  int wh2 = chlId.wheel ();
1087  int st2 = chlId.station ();
1088  int se2 = chlId.sector ();
1089  int qu2 = chlId.superLayer();
1090  int la2 = chlId.layer ();
1091  int lp2 = chlId.wire() - 10;
1092 // std::cout << "duplicate "
1093 // << whe << " " << sta << " " << sec << " "
1094 // << qua << " " << lay << " " << l_p << " ---> "
1095 // << wh2 << " " << st2 << " " << se2 << " "
1096 // << qu2 << " " << la2 << " " << lp2 << std::endl;
1097  setChannelFlag( hv, wh2, st2, se2, qu2, la2, lp2, flag );
1098  }
1099  }
1100  }
1101  }
1102  }
1103  return hv;
1104 }
1105 
1106 
1108  float& valueL, float& valueR,
1109  float& valueS, float& valueC ) {
1110  valueL =
1111  valueR =
1112  valueS =
1113  valueC = 0.0;
1114  DTWireId chlId( rawId );
1115  std::map<int,timedMeasurement>::const_iterator snapIter =
1116  snapshotValues.begin();
1117  std::map<int,timedMeasurement>::const_iterator snapIend =
1118  snapshotValues.end();
1119  int rawL = layerId( rawId, 0 ).rawId();
1120  int rawR = layerId( rawId, 1 ).rawId();
1121  int rawS = layerId( rawId, 2 ).rawId();
1122  int rawC = layerId( rawId, 3 ).rawId();
1123  std::map<int,int>::const_iterator layerIter;
1124  std::map<int,int>::const_iterator layerIend = layerMap.end();
1125  if ( ( layerIter = layerMap.find( rawL ) ) != layerIend ) {
1126  const std::pair<int,int>& layerEntry = *layerIter;
1127  int dpId = layerEntry.second;
1128  snapIter = snapshotValues.find( ( dpId * 10 ) + type );
1129  if ( snapIter != snapIend ) {
1130  const std::pair<int,timedMeasurement>& snapEntry = *snapIter;
1131  valueL = snapEntry.second.second;
1132  }
1133  else std::cout << "snapR not found" << std::endl;
1134  }
1135  else std::cout << "rawR not found" << std::endl;
1136  if ( ( layerIter = layerMap.find( rawR ) ) != layerIend ) {
1137  const std::pair<int,int>& layerEntry = *layerIter;
1138  int dpId = layerEntry.second;
1139  snapIter = snapshotValues.find( ( dpId * 10 ) + type );
1140  if ( snapIter != snapIend ) {
1141  const std::pair<int,timedMeasurement>& snapEntry = *snapIter;
1142  valueR = snapEntry.second.second;
1143  }
1144  else std::cout << "snapL not found" << std::endl;
1145  }
1146  else std::cout << "rawL not found" << std::endl;
1147  if ( ( layerIter = layerMap.find( rawS ) ) != layerIend ) {
1148  const std::pair<int,int>& layerEntry = *layerIter;
1149  int dpId = layerEntry.second;
1150  snapIter = snapshotValues.find( ( dpId * 10 ) + type );
1151  if ( snapIter != snapIend ) {
1152  const std::pair<int,timedMeasurement>& snapEntry = *snapIter;
1153  valueS = snapEntry.second.second;
1154  }
1155  else std::cout << "snapS not found" << std::endl;
1156  }
1157  else std::cout << "rawS not found" << std::endl;
1158  if ( ( layerIter = layerMap.find( rawC ) ) != layerIend ) {
1159  const std::pair<int,int>& layerEntry = *layerIter;
1160  int dpId = layerEntry.second;
1161  snapIter = snapshotValues.find( ( dpId * 10 ) + type );
1162  if ( snapIter != snapIend ) {
1163  const std::pair<int,timedMeasurement>& snapEntry = *snapIter;
1164  valueC = snapEntry.second.second;
1165  }
1166  else std::cout << "snapC not found" << std::endl;
1167  }
1168  else std::cout << "rawC not found" << std::endl;
1169 // std::cout << "layer values... " << type << " " << valueL << " "
1170 // << valueR << " "
1171 // << valueS << " "
1172 // << valueC << std::endl;
1173  return;
1174 }
1175 
1176 
1178  int whe, int sta, int sec,
1179  int qua, int lay, int l_p,
1180  const DTHVAbstractCheck::flag& flag ) {
1181  int fCell = 0;
1182  int lCell = 99;
1183  int flagA = 0;
1184  int flagC = 0;
1185  int flagS = 0;
1186  int searchStatus = hv->get( whe, sta, sec, qua, lay, l_p,
1187  fCell, lCell, flagA, flagC, flagS );
1188  if ( searchStatus ) {
1189  DTWireId wireId( whe, sta, sec, qua, lay, 10 + l_p );
1190  std::map<int,int>::const_iterator splitIter =
1191  laySplit.find( wireId.rawId() );
1192  std::map<int,int>::const_iterator splitIend =
1193  laySplit.end();
1194  if ( splitIter != splitIend ) {
1195  int code = splitIter->second;
1196  fCell = code / 10000;
1197  lCell = code % 10000;
1198  }
1199  }
1200  flagA |= flag.a;
1201  flagC |= flag.c;
1202  flagS |= flag.s;
1203  hv->set( whe, sta, sec, qua, lay, l_p,
1204  fCell, lCell, flagA, flagC, flagS );
1205  return;
1206 }
1207 
1208 
1210  float oldValue, float newValue ) {
1211  int dpId = chan / 10;
1212  int type = chan % 10;
1213  std::map<int,int>::const_iterator aliasIter = aliasMap.find( dpId );
1214  std::map<int,int>::const_iterator aliasIend = aliasMap.end();
1215  if ( aliasIter == aliasIend ) return false;
1216  int rawId = aliasIter->second;
1217  DTWireId chlId( rawId );
1218  int l_p = chlId.wire();
1219  float valueL = 0.0;
1220  float valueR = 0.0;
1221  float valueS = 0.0;
1222  float valueC = 0.0;
1223  getLayerValues( rawId, type, valueL, valueR, valueS, valueC );
1224 // std::cout << "layer values: " << type << " " << valueL << " "
1225 // << valueR << " "
1226 // << valueS << " "
1227 // << valueC << std::endl;
1229  oldStatusL = hvChecker->checkCurrentStatus( layerId( rawId, 0 ).rawId(),
1230  type,
1231  valueL, valueC, valueS,
1233  aliasMap, layerMap );
1235  oldStatusR = hvChecker->checkCurrentStatus( layerId( rawId, 1 ).rawId(),
1236  type,
1237  valueR, valueC, valueS,
1239  aliasMap, layerMap );
1240  switch ( l_p ) {
1241  case 10:
1242  if ( valueL != oldValue ) std::cout << "*** INCONSISTENT DATA!!!!! "
1243  << type << " " << l_p << " "
1244  << oldValue << " " << valueL << " "
1245  << std::endl;
1246  valueL = newValue;
1247  break;
1248  case 11:
1249  if ( valueR != oldValue ) std::cout << "*** INCONSISTENT DATA!!!!! "
1250  << type << " " << l_p << " "
1251  << oldValue << " " << valueR << " "
1252  << std::endl;
1253  valueR = newValue;
1254  break;
1255  case 12:
1256  if ( valueS != oldValue ) std::cout << "*** INCONSISTENT DATA!!!!! "
1257  << type << " " << l_p << " "
1258  << oldValue << " " << valueS << " "
1259  << std::endl;
1260  valueS = newValue;
1261  break;
1262  case 13:
1263  if ( valueC != oldValue ) std::cout << "*** INCONSISTENT DATA!!!!! "
1264  << type << " " << l_p << " "
1265  << oldValue << " " << valueC << " "
1266  << std::endl;
1267  valueC = newValue;
1268  break;
1269  default:
1270  break;
1271  }
1273  newStatusL = hvChecker->checkCurrentStatus( layerId( rawId, 0 ).rawId(),
1274  type,
1275  valueL, valueC, valueS,
1277  aliasMap, layerMap );
1279  newStatusR = hvChecker->checkCurrentStatus( layerId( rawId, 1 ).rawId(),
1280  type,
1281  valueR, valueC, valueS,
1283  aliasMap, layerMap );
1284 
1285  if ( DTHVAbstractCheck::compare( newStatusL, oldStatusL ) &&
1286  DTHVAbstractCheck::compare( newStatusR, oldStatusR ) ) return 0;
1287  std::cout << "changed status: " << chan << " from "
1288  << oldValue << " to " << newValue << std::endl;
1289  return 1;
1290 }
1291 
1292 
1294 
1295  int maxTime = 100;
1296  int maxTtot = 600;
1297  int minDiff = 88;
1298 
1299  int iTime = 0;
1300  int pTime = 0;
1301  int nTime = 0;
1302  int iSize;
1303  int pSize;
1304  int nSize;
1305 
1306  std::vector< std::pair<DTHVStatus*, cond::Time_t> >::const_iterator iter =
1307  tmpContainer.begin();
1308  std::vector< std::pair<DTHVStatus*, cond::Time_t> >::const_iterator iend =
1309  tmpContainer.end();
1310  std::vector< std::pair<DTHVStatus*, cond::Time_t> >::const_iterator prev;
1311  std::vector< std::pair<DTHVStatus*, cond::Time_t> >::const_iterator next;
1312 
1313  while ( iter != iend ) {
1314  switchOff = false;
1315  next = iter;
1316  prev = next++;
1317  if ( next == iend ) next = prev;
1318  const DTHVStatus* iPtr = iter->first;
1319  const DTHVStatus* pPtr = prev->first;
1320  const DTHVStatus* nPtr = next->first;
1321  iSize = std::distance( iPtr->begin(), iPtr->end() );
1322  pSize = std::distance( pPtr->begin(), pPtr->end() );
1323  nSize = std::distance( nPtr->begin(), nPtr->end() );
1324  int dtot = nSize - pSize;
1325  prev = next;
1326  while ( ++next != iend ) {
1327  pPtr = prev->first;
1328  nPtr = next->first;
1329  pSize = std::distance( pPtr->begin(), pPtr->end() );
1330  nSize = std::distance( nPtr->begin(), nPtr->end() );
1331  int diff = nSize - pSize;
1332  iTime = static_cast<int>( ( iter->second >> 32 ) & 0xffffffff );
1333  pTime = static_cast<int>( ( prev->second >> 32 ) & 0xffffffff );
1334  nTime = static_cast<int>( ( next->second >> 32 ) & 0xffffffff );
1335  if ( ( nTime - pTime ) > maxTime ) break;
1336  if ( ( nTime - iTime ) > maxTtot ) break;
1337  if ( ( dtot * diff ) < 0 ) break;
1338  prev = next;
1339  }
1340  pPtr = prev->first;
1341  iSize = std::distance( iPtr->begin(), iPtr->end() );
1342  pSize = std::distance( pPtr->begin(), pPtr->end() );
1343  dtot = pSize - iSize;
1344  int dist = pTime - iTime;
1345  if ( ( dtot < -minDiff ) &&
1346  ( dist < maxTtot ) ) {
1347  std::cout << " ******** SWITCH ON "
1348  << std::distance( iter, prev ) << " "
1349  << iTime << " " << pTime << " "
1350  << iSize << " " << pSize << std::endl;
1351  m_to_transfer.push_back( std::make_pair( prev->first, prev->second ) );
1352  while ( iter != prev ) delete ( iter++->first );
1353  }
1354  if ( ( dtot > minDiff ) &&
1355  ( dist < maxTtot ) ) {
1356  std::cout << " ******** SWITCH OFF "
1357  << std::distance( iter, prev ) << " "
1358  << iTime << " " << pTime << " "
1359  << iSize << " " << pSize << std::endl;
1360  m_to_transfer.push_back( std::make_pair( prev->first, iter->second ) );
1361  switchOff = true;
1362  while ( iter != prev ) delete ( iter++->first );
1363  }
1364  if ( ( ( dtot >= -minDiff ) && ( dtot <= minDiff ) ) ||
1365  ( dist >= maxTtot ) ) {
1366  while ( iter != next ) {
1367  const std::pair<DTHVStatus*, cond::Time_t>& entry = *iter++;
1368  m_to_transfer.push_back( std::make_pair( entry.first, entry.second ) );
1369  }
1370  }
1371  iter = next;
1372  }
1373 
1374 }
1375 
1376 
1377 DTWireId DTHVStatusHandler::layerId( int rawId, int l_p ) {
1378  DTWireId chlId( rawId );
1379  int whe = chlId.wheel ();
1380  int sta = chlId.station ();
1381  int sec = chlId.sector ();
1382  int qua = chlId.superLayer();
1383  int lay = chlId.layer ();
1384  DTWireId chl( whe, sta, sec, qua, lay, 10 + l_p );
1385  return chl;
1386 }
1387 
1388 
1389 coral::TimeStamp DTHVStatusHandler::coralTime( const cond::Time_t& time ) {
1390  long long int iTime = ( ( ( ( time >> 32 ) & 0xFFFFFFFF ) * 1000000000 ) +
1391  ( ( time & 0xFFFFFFFF ) * 1000 ) );
1392  coral::TimeStamp cTime( iTime );
1393  return cTime;
1394 }
1395 
1396 
1397 cond::Time_t DTHVStatusHandler::condTime( const coral::TimeStamp& time ) {
1398  cond::Time_t cTime = ( ( time.total_nanoseconds() / 1000000000 ) << 32 ) +
1399  ( ( time.total_nanoseconds() % 1000000000 ) / 1000 );
1400  return cTime;
1401 }
1402 
1403 
1405  cond::Time_t cTime = ( ( time / 1000000000 ) << 32 ) +
1406  ( ( time % 1000000000 ) / 1000 );
1407  return cTime;
1408 }
1409 
1410 
std::string id() const
type
Definition: HCALResponse.h:22
int get(int wheelId, int stationId, int sectorId, int slId, int layerId, int partId, int &fCell, int &lCell, int &flagA, int &flagC, int &flagS) const
get content
Definition: DTHVStatus.cc:88
long int flag
Definition: mlp_lapack.h:47
DTHVStatus * lastStatus
long long int lastStamp
std::map< int, int > aliasMap
DTHVAbstractCheck::timedMeasurement timedMeasurement
cond::Time_t lastFound
long long int minTime
DbTransaction & transaction()
Definition: DbSession.cc:153
void open(const std::string &connectionString, bool readOnly=false)
Definition: DbSession.cc:119
cond::Time_t procUntil
int commit()
commit transaction.
DbConnectionConfiguration & configuration()
Definition: DbConnection.cc:89
void getLayerValues(int rawId, int type, float &valueL, float &valueR, float &valueS, float &valueC)
std::string onlineConnect
cond::DbSession buff_session
static DTWireId layerId(int rawId, int l_p)
int layer() const
Return the layer number.
Definition: DTLayerId.h:55
virtual void setStatus(int rawId, int flagA, int flagC, int flagS, const std::map< int, timedMeasurement > &snapshotValues, const std::map< int, int > &aliasMap, const std::map< int, int > &layerMap)
std::map< int, std::vector< int > * > channelSplit
DTHVStatusHandler(const edm::ParameterSet &ps)
DTHVStatus * offlineList()
std::vector< std::pair< DTHVStatus *, cond::Time_t > > tmpContainer
cond::Time_t recoverLastTime()
virtual DTHVAbstractCheck::flag checkCurrentStatus(int rawId, int type, float valueA, float valueC, float valueS, const std::map< int, timedMeasurement > &snapshotValues, const std::map< int, int > &aliasMap, const std::map< int, int > &layerMap)=0
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
cond::DbConnection buff_conn
static coral::TimeStamp coralTime(const cond::Time_t &time)
int checkStatusChange(int type, float oldValue, float newValue)
int start(bool readOnly=false)
start transaction
static bool compare(const DTHVAbstractCheck::flag &fl, const DTHVAbstractCheck::flag &fr)
cond::Time_t nextFound
std::map< int, int > laySplit
unsigned long long Time_t
Definition: Time.h:16
cond::Time_t procSince
long long int fwdTime
void dumpSnapshot(const coral::TimeStamp &time)
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
static cond::Time_t condTime(const coral::TimeStamp &time)
std::map< int, timedMeasurement > snapshotValues
int superLayer() const
Return the superlayer number.
std::map< int, int > layerMap
int checkForPeriod(cond::Time_t condSince, cond::Time_t condUntil, int &missingChannels, bool copyOffline)
static DTHVAbstractCheck * getInstance()
check HV status
std::vector< std::pair< DTHVStatusId, DTHVStatusData > >::const_iterator const_iterator
Access methods to data.
Definition: DTHVStatus.h:173
void setChannelFlag(DTHVStatus *hv, int whe, int sta, int sec, int qua, int lay, int l_p, const DTHVAbstractCheck::flag &flag)
int wire() const
Return the wire number.
Definition: DTWireId.h:58
cond::DbConnection util_conn
long long int bwdTime
std::string onlineAuthentication
DbSession createSession() const
Definition: DbConnection.cc:72
int set(int wheelId, int stationId, int sectorId, int slId, int layerId, int partId, int fCell, int lCell, int flagA, int flagC, int flagS)
Definition: DTHVStatus.cc:283
coral::ISchema & nominalSchema()
Definition: DbSession.cc:175
int cont
cond::DbSession util_session
std::pair< int, float > channelValue
void setAuthenticationPath(const std::string &p)
cond::ValidityInterval lastInterval
Definition: TagInfo.h:11
int sector() const
Definition: DTChamberId.h:63
cond::DbSession omds_session
const_iterator end() const
Definition: DTHVStatus.cc:522
DTHVAbstractCheck * hvChecker
std::string bufferConnect
tuple cout
Definition: gather_cfg.py:41
const_iterator begin() const
Definition: DTHVStatus.cc:517
int station() const
Return the station number.
Definition: DTChamberId.h:53
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47
virtual ~DTHVStatusHandler()
cond::Time_t timeLimit
cond::DbConnection omds_conn
std::string splitVersion