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