CMS 3D CMS Logo

LHCInfoPopConSourceHandler.cc
Go to the documentation of this file.
6 #include "RelationalAccess/ISessionProxy.h"
7 #include "RelationalAccess/ISchema.h"
8 #include "RelationalAccess/IQuery.h"
9 #include "RelationalAccess/ICursor.h"
10 #include "CoralBase/AttributeList.h"
11 #include "CoralBase/Attribute.h"
12 #include "CoralBase/AttributeSpecification.h"
13 #include "CoralBase/TimeStamp.h"
14 #include <iostream>
15 #include <memory>
16 #include <sstream>
17 #include <utility>
18 #include <vector>
19 #include <cmath>
20 
22  m_debug( pset.getUntrackedParameter<bool>( "debug", false ) )
23  ,m_startTime()
24  ,m_endTime()
25  ,m_samplingInterval( (unsigned int)pset.getUntrackedParameter<unsigned int>( "samplingInterval", 300 ) )
26  ,m_endFill( pset.getUntrackedParameter<bool>( "endFill", true ) )
27  ,m_name( pset.getUntrackedParameter<std::string>( "name", "LHCInfoPopConSourceHandler" ) )
28  ,m_connectionString(pset.getUntrackedParameter<std::string>("connectionString",""))
29  ,m_ecalConnectionString(pset.getUntrackedParameter<std::string>("ecalConnectionString",""))
30  ,m_dipSchema(pset.getUntrackedParameter<std::string>("DIPSchema",""))
31  ,m_authpath(pset.getUntrackedParameter<std::string>("authenticationPath",""))
32  ,m_fillPayload()
33  ,m_prevPayload()
34  ,m_tmpBuffer()
35  ,m_payloadBuffer() {
36  if( pset.exists("startTime") ){
37  m_startTime = boost::posix_time::time_from_string( pset.getUntrackedParameter<std::string>("startTime" ) );
38  }
39  boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
40  m_endTime = now;
41  if( pset.exists("endTime") ){
42  m_endTime = boost::posix_time::time_from_string( pset.getUntrackedParameter<std::string>("endTime" ) );
43  if(m_endTime>now) m_endTime = now;
44  }
45 }
46 //L1: try with different m_dipSchema
47 //L2: try with different m_name
49 
50 namespace LHCInfoImpl {
51 
52  struct IOVComp {
53  bool operator()( const cond::Time_t& x, const std::pair<cond::Time_t,std::shared_ptr<LHCInfo> >& y ){ return ( x < y.first ); }
54  };
55 
56  // function to search in the vector the target time
57  std::vector<std::pair<cond::Time_t,std::shared_ptr<LHCInfo> > >::const_iterator search( const cond::Time_t& val,
58  const std::vector<std::pair<cond::Time_t,std::shared_ptr<LHCInfo> >>& container ){
59  if( container.empty() ) return container.end();
60  auto p = std::upper_bound( container.begin(), container.end(), val, IOVComp() );
61  return (p!= container.begin()) ? p-1 : container.end();
62  }
63 
65  const std::string& conditionString,
66  const coral::AttributeList& fillDataBindVariables,
67  std::unique_ptr<LHCInfo>& targetPayload,
68  bool debug ){
69  coral::ISchema& runTimeLoggerSchema = session.nominalSchema();
70  //prepare the query for table 1:
71  std::unique_ptr<coral::IQuery> fillDataQuery( runTimeLoggerSchema.newQuery() );
72  //FROM clause
73  fillDataQuery->addToTableList( std::string( "RUNTIME_SUMMARY" ) );
74  //SELECT clause
75  fillDataQuery->addToOutputList( std::string( "LHCFILL" ) );
76  fillDataQuery->addToOutputList( std::string( "NBUNCHESBEAM1" ) );
77  fillDataQuery->addToOutputList( std::string( "NBUNCHESBEAM2" ) );
78  fillDataQuery->addToOutputList( std::string( "NCOLLIDINGBUNCHES" ) );
79  fillDataQuery->addToOutputList( std::string( "NTARGETBUNCHES" ) );
80  fillDataQuery->addToOutputList( std::string( "RUNTIME_TYPE_ID" ) );
81  fillDataQuery->addToOutputList( std::string( "PARTY1" ) );
82  fillDataQuery->addToOutputList( std::string( "PARTY2" ) );
83  fillDataQuery->addToOutputList( std::string( "INTENSITYBEAM1" ) );
84  fillDataQuery->addToOutputList( std::string( "INTENSITYBEAM2" ) );
85  fillDataQuery->addToOutputList( std::string( "ENERGY" ) );
86  fillDataQuery->addToOutputList( std::string( "CREATETIME" ) );
87  fillDataQuery->addToOutputList( std::string( "BEGINTIME" ) );
88  fillDataQuery->addToOutputList( std::string( "ENDTIME" ) );
89  fillDataQuery->addToOutputList( std::string( "INJECTIONSCHEME" ) );
90  //WHERE clause
91  fillDataQuery->setCondition( conditionString, fillDataBindVariables );
92  //ORDER BY clause
93  std::string orderStr("BEGINTIME");
94  //define query output
95  coral::AttributeList fillDataOutput;
96  fillDataOutput.extend<unsigned short>( std::string( "LHCFILL" ) );
97  fillDataOutput.extend<unsigned short>( std::string( "NBUNCHESBEAM1" ) );
98  fillDataOutput.extend<unsigned short>( std::string( "NBUNCHESBEAM2" ) );
99  fillDataOutput.extend<unsigned short>( std::string( "NCOLLIDINGBUNCHES" ) );
100  fillDataOutput.extend<unsigned short>( std::string( "NTARGETBUNCHES" ) );
101  fillDataOutput.extend<int>( std::string( "RUNTIME_TYPE_ID" ) );
102  fillDataOutput.extend<int>( std::string( "PARTY1" ) );
103  fillDataOutput.extend<int>( std::string( "PARTY2" ) );
104  fillDataOutput.extend<float>( std::string( "INTENSITYBEAM1" ) );
105  fillDataOutput.extend<float>( std::string( "INTENSITYBEAM2" ) );
106  fillDataOutput.extend<float>( std::string( "ENERGY" ) );
107  fillDataOutput.extend<coral::TimeStamp>( std::string( "CREATETIME" ) );
108  fillDataOutput.extend<coral::TimeStamp>( std::string( "BEGINTIME" ) );
109  fillDataOutput.extend<coral::TimeStamp>( std::string( "ENDTIME" ) );
110  fillDataOutput.extend<std::string>( std::string( "INJECTIONSCHEME" ) );
111  fillDataQuery->defineOutput( fillDataOutput );
112  fillDataQuery->limitReturnedRows( 1 );
113  //execute the query
114  coral::ICursor& fillDataCursor = fillDataQuery->execute();
115  //
116  unsigned short currentFill = 0;
117  unsigned short bunches1 = 0, bunches2 = 0, collidingBunches = 0, targetBunches = 0;
119  LHCInfo::ParticleTypeId particleType1 = LHCInfo::NONE, particleType2 = LHCInfo::NONE;
120  float intensityBeam1 = 0., intensityBeam2 = 0., energy = 0.;
121  coral::TimeStamp stableBeamStartTimeStamp, beamDumpTimeStamp;
122  cond::Time_t creationTime = 0ULL, stableBeamStartTime = 0ULL, beamDumpTime = 0ULL;
123  std::string injectionScheme( "None" );
124  std::ostringstream ss;
125  bool ret = false;
126  if( fillDataCursor.next() ) {
127  ret = true;
128  if( debug ) {
129  std::ostringstream qs;
130  fillDataCursor.currentRow().toOutputStream( qs );
131  }
132  coral::Attribute const & fillAttribute = fillDataCursor.currentRow()[ std::string( "LHCFILL" ) ];
133  if( !fillAttribute.isNull() ){
134  currentFill = fillAttribute.data<unsigned short>();
135  }
136  coral::Attribute const & bunches1Attribute = fillDataCursor.currentRow()[ std::string( "NBUNCHESBEAM1" ) ];
137  if( !bunches1Attribute.isNull() ) {
138  bunches1 = bunches1Attribute.data<unsigned short>();
139  }
140  coral::Attribute const & bunches2Attribute = fillDataCursor.currentRow()[ std::string( "NBUNCHESBEAM2" ) ];
141  if( !bunches2Attribute.isNull() ) {
142  bunches2 = bunches2Attribute.data<unsigned short>();
143  }
144  coral::Attribute const & collidingBunchesAttribute = fillDataCursor.currentRow()[ std::string( "NCOLLIDINGBUNCHES" ) ];
145  if( !collidingBunchesAttribute.isNull() ) {
146  collidingBunches = collidingBunchesAttribute.data<unsigned short>();
147  }
148  coral::Attribute const & targetBunchesAttribute = fillDataCursor.currentRow()[ std::string( "NTARGETBUNCHES" ) ];
149  if( !targetBunchesAttribute.isNull() ) {
150  targetBunches = targetBunchesAttribute.data<unsigned short>();
151  }
152  //RUNTIME_TYPE_ID IS NOT NULL
153  fillType = static_cast<LHCInfo::FillTypeId>( fillDataCursor.currentRow()[ std::string( "RUNTIME_TYPE_ID" ) ].data<int>() );
154  coral::Attribute const & particleType1Attribute = fillDataCursor.currentRow()[ std::string( "PARTY1" ) ];
155  if( !particleType1Attribute.isNull() ) {
156  particleType1 = static_cast<LHCInfo::ParticleTypeId>( particleType1Attribute.data<int>() );
157  }
158  coral::Attribute const & particleType2Attribute = fillDataCursor.currentRow()[ std::string( "PARTY2" ) ];
159  if( !particleType2Attribute.isNull() ) {
160  particleType2 = static_cast<LHCInfo::ParticleTypeId>( particleType2Attribute.data<int>() );
161  }
162  coral::Attribute const & intensityBeam1Attribute = fillDataCursor.currentRow()[ std::string( "INTENSITYBEAM1" ) ];
163  if( !intensityBeam1Attribute.isNull() ) {
164  intensityBeam1 = intensityBeam1Attribute.data<float>();
165  }
166  coral::Attribute const & intensityBeam2Attribute = fillDataCursor.currentRow()[ std::string( "INTENSITYBEAM2" ) ];
167  if( !intensityBeam2Attribute.isNull() ) {
168  intensityBeam2 = intensityBeam2Attribute.data<float>();
169  }
170  coral::Attribute const & energyAttribute = fillDataCursor.currentRow()[ std::string( "ENERGY" ) ];
171  if( !energyAttribute.isNull() ){
172  energy = energyAttribute.data<float>();
173  }
174  }
175  if( ret ){
176  //CREATETIME IS NOT NULL
177  creationTime = cond::time::from_boost( fillDataCursor.currentRow()[ std::string( "CREATETIME" ) ].data<coral::TimeStamp>().time() );
178  //BEGINTIME is imposed to be NOT NULL in the WHERE clause
179  stableBeamStartTimeStamp = fillDataCursor.currentRow()[ std::string( "BEGINTIME" ) ].data<coral::TimeStamp>();
180  stableBeamStartTime = cond::time::from_boost( stableBeamStartTimeStamp.time() );
181  coral::Attribute const & beamDumpTimeAttribute = fillDataCursor.currentRow()[ std::string( "ENDTIME" ) ];
182  if( !beamDumpTimeAttribute.isNull() ) {
183  beamDumpTimeStamp = beamDumpTimeAttribute.data<coral::TimeStamp>();
184  beamDumpTime = cond::time::from_boost( beamDumpTimeStamp.time() );
185  }
186  coral::Attribute const & injectionSchemeAttribute = fillDataCursor.currentRow()[ std::string( "INJECTIONSCHEME" ) ];
187  if( !injectionSchemeAttribute.isNull() ) {
188  injectionScheme = injectionSchemeAttribute.data<std::string>();
189  }
190  //fix an inconsistency in RunTimeLogger: if the fill type is defined, the particle type should reflect it!
191  if( fillType != LHCInfo::UNKNOWN && ( particleType1 == LHCInfo::NONE || particleType2 == LHCInfo::NONE ) ) {
192  switch( fillType ) {
193  case LHCInfo::PROTONS :
194  particleType1 = LHCInfo::PROTON;
195  particleType2 = LHCInfo::PROTON;
196  break;
197  case LHCInfo::IONS :
198  particleType1 = LHCInfo::PB82;
199  particleType2 = LHCInfo::PB82;
200  break;
201  case LHCInfo::UNKNOWN :
202  case LHCInfo::COSMICS :
203  case LHCInfo::GAP :
204  break;
205  }
206  }
207  targetPayload.reset( new LHCInfo() );
208  targetPayload->setFillNumber( currentFill );
209  targetPayload->setBunchesInBeam1( bunches1 );
210  targetPayload->setBunchesInBeam2( bunches2 );
211  targetPayload->setCollidingBunches( collidingBunches );
212  targetPayload->setTargetBunches( targetBunches );
213  targetPayload->setFillType( fillType );
214  targetPayload->setParticleTypeForBeam1( particleType1 );
215  targetPayload->setParticleTypeForBeam2( particleType2 );
216  targetPayload->setIntensityForBeam1( intensityBeam1 );
217  targetPayload->setIntensityForBeam2( intensityBeam2 );
218  targetPayload->setEnergy( energy );
219  targetPayload->setCreationTime( creationTime );
220  targetPayload->setBeginTime( stableBeamStartTime );
221  targetPayload->setEndTime( beamDumpTime );
222  targetPayload->setInjectionScheme( injectionScheme );
223  }
224  return ret;
225  }
226 
227 }
228 
230  const boost::posix_time::ptime& targetTime,
231  bool ended ){
232  // Prepare the WHERE clause
233  coral::AttributeList fillDataBindVariables;
234  fillDataBindVariables.extend<coral::TimeStamp>(std::string("targetTime"));
235  fillDataBindVariables[ std::string( "targetTime")].data<coral::TimeStamp>()= coral::TimeStamp( targetTime + boost::posix_time::seconds(1) );
236  //by imposing BEGINTIME IS NOT NULL, we remove fills which never went into stable beams,
237  //by additionally imposing ENDTIME IS NOT NULL, we select only finished fills
238  std::string conditionStr = "BEGINTIME IS NOT NULL AND CREATETIME > :targetTime AND LHCFILL IS NOT NULL";
239  if( ended ) conditionStr += " AND ENDTIME IS NOT NULL";
240  return LHCInfoImpl::makeFillDataQuery( session, conditionStr, fillDataBindVariables, m_fillPayload, m_debug );
241 }
242 
244  unsigned short fillId ){
245  // Prepare the WHERE clause
246  coral::AttributeList fillDataBindVariables;
247  fillDataBindVariables.extend<unsigned short>(std::string("fillId"));
248  fillDataBindVariables[ std::string( "fillId")].data<unsigned short>()= fillId;
249  std::string conditionStr = "LHCFILL=:fillId";
250  return LHCInfoImpl::makeFillDataQuery( session, conditionStr, fillDataBindVariables, m_fillPayload, m_debug );
251 }
252 
254  const boost::posix_time::ptime& beginFillTime,
255  const boost::posix_time::ptime& endFillTime ){
256  coral::ISchema& runTimeLoggerSchema = session.nominalSchema();
257  //prepare the query for table 2:
258  std::unique_ptr<coral::IQuery> fillDataQuery2( runTimeLoggerSchema.newQuery() );
259  //FROM clause
260  fillDataQuery2->addToTableList( std::string( "LUMI_SECTIONS" ) );
261  //SELECT clause
262  fillDataQuery2->addToOutputList( std::string( "DELIVLUMI" ) );
263  fillDataQuery2->addToOutputList( std::string( "LIVELUMI" ) );
264  fillDataQuery2->addToOutputList( std::string( "INSTLUMI" ) );
265  fillDataQuery2->addToOutputList( std::string( "INSTLUMIERROR" ) );
266  fillDataQuery2->addToOutputList( std::string( "STARTTIME" ) );
267  fillDataQuery2->addToOutputList( std::string( "LHCFILL" ) );
268  //WHERE clause
269  coral::AttributeList fillDataBindVariables;
270  fillDataBindVariables.extend<coral::TimeStamp>(std::string("start"));
271  fillDataBindVariables.extend<coral::TimeStamp>(std::string("stop"));
272  fillDataBindVariables[ std::string( "start")].data<coral::TimeStamp>()= coral::TimeStamp( beginFillTime );
273  fillDataBindVariables[ std::string( "stop")].data<coral::TimeStamp>()= coral::TimeStamp( endFillTime );
274  std::string conditionStr = "DELIVLUMI IS NOT NULL AND STARTTIME >= :start AND STARTTIME< :stop";
275  fillDataQuery2->setCondition( conditionStr, fillDataBindVariables );
276  //ORDER BY clause
277  fillDataQuery2->addToOrderList( std::string( "STARTTIME" ) );
278  //define query output*/
279  coral::AttributeList fillDataOutput2;
280  fillDataOutput2.extend<float>( std::string( "DELIVEREDLUMI" ) );
281  fillDataOutput2.extend<float>( std::string( "RECORDEDLUMI" ) );
282  fillDataOutput2.extend<float>( std::string( "INSTLUMI" ) );
283  fillDataOutput2.extend<float>( std::string( "INSTLUMIERROR" ) );
284  fillDataOutput2.extend<coral::TimeStamp>( std::string( "STARTTIME" ) );
285  fillDataOutput2.extend<int>( std::string( "LHCFILL" ) );
286  fillDataQuery2->defineOutput( fillDataOutput2 );
287  //execute the query
288  coral::ICursor& fillDataCursor2 = fillDataQuery2->execute();
289 
290  size_t nlumi = 0;
291  while( fillDataCursor2.next()){
292  nlumi++;
293  float delivLumi = 0., recLumi = 0., instLumi = 0, instLumiErr = 0.;
294  cond::Time_t since = 0;
295  coral::Attribute const & delivLumiAttribute = fillDataCursor2.currentRow()[ std::string( "DELIVEREDLUMI" ) ];
296  if( !delivLumiAttribute.isNull() ){
297  delivLumi = delivLumiAttribute.data<float>() / 1000.;
298  }
299  coral::Attribute const & recLumiAttribute = fillDataCursor2.currentRow()[ std::string( "RECORDEDLUMI" ) ];
300  if( !recLumiAttribute.isNull() ){
301  recLumi = recLumiAttribute.data<float>() / 1000.;
302  }
303  coral::Attribute const & instLumiAttribute = fillDataCursor2.currentRow()[ std::string( "INSTLUMI" ) ];
304  if( !instLumiAttribute.isNull() ){
305  instLumi = instLumiAttribute.data<float>() / 1000.;
306  }
307  coral::Attribute const & instLumiErrAttribute = fillDataCursor2.currentRow()[ std::string( "INSTLUMIERROR" ) ];
308  if( !instLumiErrAttribute.isNull() ){
309  instLumiErr = instLumiErrAttribute.data<float>() / 1000.;
310  }
311  coral::Attribute const & startLumiSectionAttribute = fillDataCursor2.currentRow()[ std::string( "STARTTIME" ) ];
312  if( !startLumiSectionAttribute.isNull() ) {
313  since = cond::time::from_boost( startLumiSectionAttribute.data<coral::TimeStamp>().time() );
314  }
315  LHCInfo* thisLumiSectionInfo = m_fillPayload->cloneFill();
316  m_tmpBuffer.emplace_back(std::make_pair(since,thisLumiSectionInfo));
317  LHCInfo& payload = *thisLumiSectionInfo;
318  payload.setDelivLumi( delivLumi );
319  payload.setRecLumi( recLumi );
320  payload.setInstLumi( instLumi );
321  payload.setInstLumiError( instLumiErr );
322  }
323  return nlumi;
324 }
325 
326 namespace LHCInfoImpl {
328 
329  LumiSectionFilter( const std::vector<std::pair<cond::Time_t,std::shared_ptr<LHCInfo> > >& samples ):
330  currLow( samples.begin() ),
331  currUp( samples.begin() ),
332  end( samples.end() ){
333  currUp++;
334  }
335 
336  void reset( const std::vector<std::pair<cond::Time_t,std::shared_ptr<LHCInfo> > >& samples ){
337  currLow = samples.begin();
338  currUp = samples.begin();
339  currUp++;
340  end = samples.end();
341  currentDipTime = 0;
342  }
343 
344  bool process( cond::Time_t dipTime ){
345  if( currLow == end ) return false;
346  bool search = false;
347  if( currentDipTime == 0 ){
348  search = true;
349  } else {
350  if( dipTime == currentDipTime ) return true;
351  else {
353  if(currUp != end ) upper = currUp->first;
354  if( dipTime < upper ) return false;
355  else {
356  search = true;
357  }
358  }
359  }
360  if( search ){
361  while(currUp != end and currUp->first < dipTime ){
362  currLow++;
363  currUp++;
364  }
365  currentDipTime = dipTime;
366  return currLow != end;
367  }
368  return false;
369  }
370 
371  cond::Time_t currentSince() { return currLow->first; }
372  LHCInfo& currentPayload() { return *currLow->second; }
373 
374  std::vector<std::pair<cond::Time_t,std::shared_ptr<LHCInfo> > >::const_iterator current(){
375  return currLow;
376  }
377  std::vector<std::pair<cond::Time_t,std::shared_ptr<LHCInfo> > >::const_iterator currLow;
378  std::vector<std::pair<cond::Time_t,std::shared_ptr<LHCInfo> > >::const_iterator currUp;
379  std::vector<std::pair<cond::Time_t,std::shared_ptr<LHCInfo> > >::const_iterator end;
380  cond::Time_t currentDipTime = 0;
381  };
382 }
383 
385  const boost::posix_time::ptime& beginFillTime,
386  const boost::posix_time::ptime& endFillTime ){
387  //run the third and fourth query against the schema hosting detailed DIP information
388  coral::ISchema& beamCondSchema = session.coralSession().schema( m_dipSchema );
389  //start the transaction against the DIP "deep" database backend schema
390  //prepare the WHERE clause for both queries
391  coral::AttributeList bunchConfBindVariables;
392  bunchConfBindVariables.extend<coral::TimeStamp>(std::string("beginFillTime"));
393  bunchConfBindVariables.extend<coral::TimeStamp>(std::string("endFillTime"));
394  bunchConfBindVariables[ std::string( "beginFillTime")].data<coral::TimeStamp>()= coral::TimeStamp( beginFillTime );
395  bunchConfBindVariables[ std::string( "endFillTime")].data<coral::TimeStamp>()= coral::TimeStamp( endFillTime );
396  std::string conditionStr = std::string( "DIPTIME >= :beginFillTime and DIPTIME< :endFillTime" );
397  //define the output types for both queries
398  coral::AttributeList bunchConfOutput;
399  bunchConfOutput.extend<coral::TimeStamp>( std::string( "DIPTIME" ) );
400  bunchConfOutput.extend<unsigned short>( std::string( "BUCKET" ) );
401  //execute query for Beam 1
402  std::unique_ptr<coral::IQuery> bunchConf1Query(beamCondSchema.newQuery());
403  bunchConf1Query->addToTableList( std::string( "LHC_CIRCBUNCHCONFIG_BEAM1" ), std::string( "BEAMCONF\", TABLE( BEAMCONF.VALUE ) \"BUCKETS" ) );
404  bunchConf1Query->addToOutputList( std::string( "BEAMCONF.DIPTIME" ), std::string( "DIPTIME" ) );
405  bunchConf1Query->addToOutputList( std::string( "BUCKETS.COLUMN_VALUE" ), std::string( "BUCKET" ) );
406  bunchConf1Query->setCondition( conditionStr, bunchConfBindVariables );
407  bunchConf1Query->addToOrderList( std::string( "DIPTIME" ) );
408  bunchConf1Query->limitReturnedRows( LHCInfo::availableBunchSlots ); //maximum number of filled bunches
409  bunchConf1Query->defineOutput( bunchConfOutput );
410 
411  coral::ICursor& bunchConf1Cursor = bunchConf1Query->execute();
412  std::bitset<LHCInfo::bunchSlots+1> bunchConfiguration1( 0ULL );
413  bool ret = false;
414  cond::Time_t lumiSectionTime = 0;
415  while( bunchConf1Cursor.next() ) {
416  if( m_debug ) {
417  std::ostringstream b1s;
418  bunchConf1Cursor.currentRow().toOutputStream( b1s );
419  }
420  coral::Attribute const & dipTimeAttribute = bunchConf1Cursor.currentRow()[ std::string( "DIPTIME" ) ];
421  coral::Attribute const & bunchConf1Attribute = bunchConf1Cursor.currentRow()[ std::string( "BUCKET" ) ];
422  if( !dipTimeAttribute.isNull() and !bunchConf1Attribute.isNull() ){
423  cond::Time_t dipTime = cond::time::from_boost( dipTimeAttribute.data<coral::TimeStamp>().time() );
424  // assuming only one sample has been selected...
425  unsigned short slot = ( bunchConf1Attribute.data<unsigned short>() - 1 ) / 10 + 1;
426  if( lumiSectionTime == 0 or lumiSectionTime == dipTime){
427  bunchConfiguration1[slot] = true;
428  } else break;
429  lumiSectionTime = dipTime;
430  }
431  }
432  if( ret ){
433  m_fillPayload->setBunchBitsetForBeam1(bunchConfiguration1);
434  }
435 
436  //execute query for Beam 2
437  std::unique_ptr<coral::IQuery> bunchConf2Query(beamCondSchema.newQuery());
438  bunchConf2Query->addToTableList( std::string( "LHC_CIRCBUNCHCONFIG_BEAM2" ), std::string( "BEAMCONF\", TABLE( BEAMCONF.VALUE ) \"BUCKETS" ) );
439  bunchConf2Query->addToOutputList( std::string( "BEAMCONF.DIPTIME" ), std::string( "DIPTIME" ) );
440  bunchConf2Query->addToOutputList( std::string( "BUCKETS.COLUMN_VALUE" ), std::string( "BUCKET" ) );
441  bunchConf2Query->setCondition( conditionStr, bunchConfBindVariables );
442  bunchConf2Query->addToOrderList( std::string( "DIPTIME" ) );
443  bunchConf2Query->limitReturnedRows( LHCInfo::availableBunchSlots ); //maximum number of filled bunches
444  bunchConf2Query->defineOutput( bunchConfOutput );
445  coral::ICursor& bunchConf2Cursor = bunchConf2Query->execute();
446 
447  std::bitset<LHCInfo::bunchSlots+1> bunchConfiguration2( 0ULL );
448  ret = false;
449  lumiSectionTime = 0;
450  while( bunchConf2Cursor.next() ) {
451  if( m_debug ) {
452  std::ostringstream b2s;
453  bunchConf2Cursor.currentRow().toOutputStream( b2s );
454  }
455  coral::Attribute const & dipTimeAttribute = bunchConf2Cursor.currentRow()[ std::string( "DIPTIME" ) ];
456  coral::Attribute const & bunchConf2Attribute = bunchConf2Cursor.currentRow()[ std::string( "BUCKET" ) ];
457  if( !dipTimeAttribute.isNull() and !bunchConf2Attribute.isNull() ){
458  ret = true;
459  cond::Time_t dipTime = cond::time::from_boost( dipTimeAttribute.data<coral::TimeStamp>().time() );
460  // assuming only one sample has been selected...
461  unsigned short slot = ( bunchConf2Attribute.data<unsigned short>() - 1 ) / 10 + 1;
462  if( lumiSectionTime == 0 or lumiSectionTime == dipTime){
463  bunchConfiguration2[slot] = true;
464  } else break;
465  lumiSectionTime = dipTime;
466  }
467  }
468  if(ret){
469  m_fillPayload->setBunchBitsetForBeam2( bunchConfiguration2 );
470  }
471  //execute query for lumiPerBX
472  std::unique_ptr<coral::IQuery> lumiDataQuery(beamCondSchema.newQuery());
473  lumiDataQuery->addToTableList( std::string( "CMS_LHC_LUMIPERBUNCH" ), std::string( "LUMIPERBUNCH\", TABLE( LUMIPERBUNCH.LUMI_BUNCHINST ) \"VALUE" ) );
474  lumiDataQuery->addToOutputList( std::string( "LUMIPERBUNCH.DIPTIME" ), std::string( "DIPTIME" ) );
475  lumiDataQuery->addToOutputList( std::string( "VALUE.COLUMN_VALUE" ), std::string( "LUMI_BUNCH" ) );
476  coral::AttributeList lumiDataBindVariables;
477  lumiDataBindVariables.extend<coral::TimeStamp>( std::string( "beginFillTime" ) );
478  lumiDataBindVariables.extend<coral::TimeStamp>( std::string( "endFillTime" ) );
479  lumiDataBindVariables[ std::string( "beginFillTime" ) ].data<coral::TimeStamp>() = coral::TimeStamp(beginFillTime);
480  lumiDataBindVariables[ std::string( "endFillTime" ) ].data<coral::TimeStamp>() = coral::TimeStamp(endFillTime);
481  conditionStr = std::string( "DIPTIME BETWEEN :beginFillTime AND :endFillTime" );
482  lumiDataQuery->setCondition( conditionStr, lumiDataBindVariables );
483  lumiDataQuery->addToOrderList( std::string( "DIPTIME" ) );
484  lumiDataQuery->limitReturnedRows(3564); //Maximum number of bunches.
485  //define query output
486  coral::AttributeList lumiDataOutput;
487  lumiDataOutput.extend<coral::TimeStamp>( std::string( "DIPTIME" ) );
488  lumiDataOutput.extend<float>( std::string( "LUMI_BUNCH" ) );
489  lumiDataQuery->defineOutput( lumiDataOutput );
490  //execute the query
491  coral::ICursor& lumiDataCursor = lumiDataQuery->execute();
492 
493  std::vector<float> lumiPerBX;
494  ret = false;
495  lumiSectionTime = 0;
496  while( lumiDataCursor.next() ) {
497  if( m_debug ) {
498  std::ostringstream lpBX;
499  lumiDataCursor.currentRow().toOutputStream( lpBX );
500  }
501  coral::Attribute const & dipTimeAttribute = lumiDataCursor.currentRow()[ std::string( "DIPTIME" ) ];
502  coral::Attribute const & lumiBunchAttribute = lumiDataCursor.currentRow()[ std::string( "LUMI_BUNCH" ) ];
503  if( !dipTimeAttribute.isNull() and !lumiBunchAttribute.isNull() ){
504  ret = true;
505  cond::Time_t dipTime = cond::time::from_boost( dipTimeAttribute.data<coral::TimeStamp>().time() );
506  // assuming only one sample has been selected...
507  float lumi_b = lumiBunchAttribute.data<float>();
508  if( lumiSectionTime == 0 or lumiSectionTime == dipTime){
509  if( lumi_b != 0.00 ) lumiPerBX.push_back( lumi_b );
510  } else break;
511  lumiSectionTime = dipTime;
512  }
513  }
514  if( ret){
515  m_fillPayload->setLumiPerBX( lumiPerBX );
516  }
517  return ret;
518  }
519 
521  const boost::posix_time::ptime& beginFillTime,
522  const boost::posix_time::ptime& endFillTime ){
523  //run the fifth query against the CTPPS schema
524  //Initializing the CMS_CTP_CTPPS_COND schema.
525  coral::ISchema& CTPPS = session.coralSession().schema("CMS_CTP_CTPPS_COND");
526  //execute query for CTPPS Data
527  std::unique_ptr<coral::IQuery> CTPPSDataQuery( CTPPS.newQuery() );
528  //FROM clause
529  CTPPSDataQuery->addToTableList( std::string( "CTPPS_LHC_MACHINE_PARAMS" ) );
530  //SELECT clause
531  CTPPSDataQuery->addToOutputList( std::string( "DIP_UPDATE_TIME" ) );
532  CTPPSDataQuery->addToOutputList( std::string( "LHC_STATE" ) );
533  CTPPSDataQuery->addToOutputList( std::string( "LHC_COMMENT" ) );
534  CTPPSDataQuery->addToOutputList( std::string( "CTPPS_STATUS" ) );
535  CTPPSDataQuery->addToOutputList( std::string( "LUMI_SECTION" ) );
536  CTPPSDataQuery->addToOutputList( std::string( "XING_ANGLE_URAD" ) );
537  CTPPSDataQuery->addToOutputList( std::string( "BETA_STAR_CMS" ) );
538  //WHERE CLAUSE
539  coral::AttributeList CTPPSDataBindVariables;
540  CTPPSDataBindVariables.extend<coral::TimeStamp>( std::string( "beginFillTime" ) );
541  CTPPSDataBindVariables.extend<coral::TimeStamp>( std::string( "endFillTime" ) );
542  CTPPSDataBindVariables[ std::string( "beginFillTime" ) ].data<coral::TimeStamp>() = coral::TimeStamp( beginFillTime );
543  CTPPSDataBindVariables[ std::string( "endFillTime" ) ].data<coral::TimeStamp>() = coral::TimeStamp( endFillTime );
544  std::string conditionStr = std::string( "DIP_UPDATE_TIME>= :beginFillTime and DIP_UPDATE_TIME< :endFillTime" );
545  CTPPSDataQuery->setCondition( conditionStr, CTPPSDataBindVariables );
546  //ORDER BY clause
547  CTPPSDataQuery->addToOrderList( std::string( "DIP_UPDATE_TIME" ) );
548  //define query output
549  coral::AttributeList CTPPSDataOutput;
550  CTPPSDataOutput.extend<coral::TimeStamp>( std::string( "DIP_UPDATE_TIME" ) );
551  CTPPSDataOutput.extend<std::string>( std::string( "LHC_STATE" ) );
552  CTPPSDataOutput.extend<std::string>( std::string( "LHC_COMMENT" ) );
553  CTPPSDataOutput.extend<std::string>( std::string( "CTPPS_STATUS" ) );
554  CTPPSDataOutput.extend<int>( std::string( "LUMI_SECTION" ) );
555  CTPPSDataOutput.extend<float>( std::string( "XING_ANGLE_URAD" ) );
556  CTPPSDataOutput.extend<float>( std::string( "BETA_STAR_CMS" ) );
557  CTPPSDataQuery->defineOutput( CTPPSDataOutput );
558  //execute the query
559  coral::ICursor& CTPPSDataCursor = CTPPSDataQuery->execute();
560  cond::Time_t dipTime = 0;
561  std::string lhcState = "", lhcComment = "", ctppsStatus = "";
562  unsigned int lumiSection = 0;
563  float crossingAngle = 0., betastar = 0.;
564 
565  bool ret = false;
567  while( CTPPSDataCursor.next() ) {
568  if( m_debug ) {
569  std::ostringstream CTPPS;
570  CTPPSDataCursor.currentRow().toOutputStream( CTPPS );
571  }
572  coral::Attribute const & dipTimeAttribute = CTPPSDataCursor.currentRow()[ std::string( "DIP_UPDATE_TIME" ) ];
573  if( !dipTimeAttribute.isNull() ) {
574  dipTime = cond::time::from_boost( dipTimeAttribute.data<coral::TimeStamp>().time() );
575  if( filter.process( dipTime ) ){
576  ret = true;
577  coral::Attribute const & lhcStateAttribute = CTPPSDataCursor.currentRow()[ std::string( "LHC_STATE" ) ];
578  if( !lhcStateAttribute.isNull() ) {
579  lhcState = lhcStateAttribute.data<std::string>();
580  }
581  coral::Attribute const & lhcCommentAttribute = CTPPSDataCursor.currentRow()[ std::string( "LHC_COMMENT" ) ];
582  if( !lhcCommentAttribute.isNull() ) {
583  lhcComment = lhcCommentAttribute.data<std::string>();
584  }
585  coral::Attribute const & ctppsStatusAttribute = CTPPSDataCursor.currentRow()[ std::string( "CTPPS_STATUS" ) ];
586  if( !ctppsStatusAttribute.isNull() ) {
587  ctppsStatus = ctppsStatusAttribute.data<std::string>();
588  }
589  coral::Attribute const & lumiSectionAttribute = CTPPSDataCursor.currentRow()[ std::string( "LUMI_SECTION" ) ];
590  if( !lumiSectionAttribute.isNull() ) {
591  lumiSection = lumiSectionAttribute.data<int>();
592  }
593  coral::Attribute const & crossingAngleAttribute = CTPPSDataCursor.currentRow()[ std::string( "XING_ANGLE_URAD" ) ];
594  if( !crossingAngleAttribute.isNull() ) {
595  crossingAngle = crossingAngleAttribute.data<float>();
596  }
597  coral::Attribute const & betaStarAttribute = CTPPSDataCursor.currentRow()[ std::string( "BETA_STAR_CMS" ) ];
598  if( !betaStarAttribute.isNull() ) {
599  betastar = betaStarAttribute.data<float>();
600  }
601  for( auto it = filter.current(); it!=m_tmpBuffer.end(); it++ ){
602  // set the current values to all of the payloads of the lumi section samples after the current since
603  LHCInfo& payload = *(it->second);
604  payload.setCrossingAngle( crossingAngle );
605  payload.setBetaStar( betastar );
606  payload.setLhcState( lhcState );
607  payload.setLhcComment( lhcComment );
608  payload.setCtppsStatus( ctppsStatus );
609  payload.setLumiSection( lumiSection );
610  }
611  }
612  }
613  }
614  return ret;
615  }
616 
617 namespace LHCInfoImpl {
618  static const std::map<std::string, int> vecMap = {{"Beam1/beamPhaseMean",1},{"Beam2/beamPhaseMean",2},{"Beam1/cavPhaseMean",3},{"Beam2/cavPhaseMean",4}};
620  unsigned int elementNr, float value,
621  LHCInfo& payload, std::set<cond::Time_t>& initList ){
622  if( initList.find(since)==initList.end() ){
623  payload.beam1VC().resize( LHCInfo::bunchSlots ,0.);
624  payload.beam2VC().resize( LHCInfo::bunchSlots ,0.);
625  payload.beam1RF().resize( LHCInfo::bunchSlots,0.);
626  payload.beam2RF().resize( LHCInfo::bunchSlots,0.);
627  initList.insert(since);
628  }
629  // set the current values to all of the payloads of the lumi section samples after the current since
630  if( elementNr < LHCInfo::bunchSlots ){
631  switch( vecMap.at(dipVal) ){
632  case 1:
633  payload.beam1VC()[elementNr]=value;
634  break;
635  case 2:
636  payload.beam2VC()[elementNr]=value;
637  break;
638  case 3:
639  payload.beam1RF()[elementNr]=value;
640  break;
641  case 4:
642  payload.beam2RF()[elementNr]=value;
643  break;
644  default:
645  break;
646  }
647  }
648  }
649 }
650 
652  const boost::posix_time::ptime& lowerTime,
653  const boost::posix_time::ptime& upperTime,
654  bool update ){
655  //run the sixth query against the CMS_DCS_ENV_PVSS_COND schema
656  //Initializing the CMS_DCS_ENV_PVSS_COND schema.
657  coral::ISchema& ECAL = session.nominalSchema();
658  //start the transaction against the fill logging schema
659  //execute query for ECAL Data
660  std::unique_ptr<coral::IQuery> ECALDataQuery( ECAL.newQuery() );
661  //FROM clause
662  ECALDataQuery->addToTableList( std::string( "BEAM_PHASE" ) );
663  //SELECT clause
664  ECALDataQuery->addToOutputList( std::string( "CHANGE_DATE" ) );
665  ECALDataQuery->addToOutputList( std::string( "DIP_value" ) );
666  ECALDataQuery->addToOutputList( std::string( "element_nr" ) );
667  ECALDataQuery->addToOutputList( std::string( "VALUE_NUMBER" ) );
668  //WHERE CLAUSE
669  coral::AttributeList ECALDataBindVariables;
670  ECALDataBindVariables.extend<coral::TimeStamp>( std::string( "lowerTime" ) );
671  ECALDataBindVariables.extend<coral::TimeStamp>( std::string( "upperTime" ) );
672  ECALDataBindVariables[ std::string( "lowerTime" ) ].data<coral::TimeStamp>() = coral::TimeStamp( lowerTime );
673  ECALDataBindVariables[ std::string( "upperTime" ) ].data<coral::TimeStamp>() = coral::TimeStamp( upperTime );
674  std::string conditionStr =
675  std::string( "(DIP_value LIKE '%beamPhaseMean%' OR DIP_value LIKE '%cavPhaseMean%') AND CHANGE_DATE >= :lowerTime AND CHANGE_DATE < :upperTime" );
676 
677  ECALDataQuery->setCondition( conditionStr, ECALDataBindVariables );
678  //ORDER BY clause
679  ECALDataQuery->addToOrderList( std::string( "CHANGE_DATE" ) );
680  ECALDataQuery->addToOrderList( std::string( "DIP_value" ) );
681  ECALDataQuery->addToOrderList( std::string( "element_nr" ) );
682  //define query output
683  coral::AttributeList ECALDataOutput;
684  ECALDataOutput.extend<coral::TimeStamp>( std::string( "CHANGE_DATE" ) );
685  ECALDataOutput.extend<std::string>( std::string( "DIP_value" ) );
686  ECALDataOutput.extend<unsigned int>( std::string( "element_nr" ) );
687  ECALDataOutput.extend<float>( std::string( "VALUE_NUMBER" ) );
688  //ECALDataQuery->limitReturnedRows( 14256 ); //3564 entries per vector.
689  ECALDataQuery->defineOutput( ECALDataOutput );
690  //execute the query
691  coral::ICursor& ECALDataCursor = ECALDataQuery->execute();
692  cond::Time_t changeTime = 0;
693  cond::Time_t firstTime = 0;
694  std::string dipVal = "";
695  unsigned int elementNr = 0;
696  float value = 0.;
697  std::set<cond::Time_t> initializedVectors;
699  bool ret = false;
700  if(m_prevPayload.get()){
701  for(auto& lumiSlot: m_tmpBuffer){
702  lumiSlot.second->setBeam1VC( m_prevPayload->beam1VC() );
703  lumiSlot.second->setBeam2VC( m_prevPayload->beam2VC() );
704  lumiSlot.second->setBeam1RF( m_prevPayload->beam1RF() );
705  lumiSlot.second->setBeam2RF( m_prevPayload->beam2RF() );
706  }
707  }
708  std::map<cond::Time_t,cond::Time_t> iovMap;
709  cond::Time_t lowerLumi = m_tmpBuffer.front().first;
710  while( ECALDataCursor.next() ) {
711  if( m_debug ) {
712  std::ostringstream ECAL;
713  ECALDataCursor.currentRow().toOutputStream( ECAL );
714  }
715  coral::Attribute const & changeDateAttribute = ECALDataCursor.currentRow()[ std::string( "CHANGE_DATE" ) ];
716  if( !changeDateAttribute.isNull() ) {
717  ret = true;
718  boost::posix_time::ptime chTime = changeDateAttribute.data<coral::TimeStamp>().time();
719  // move the first IOV found to the start of the fill interval selected
720  if( changeTime == 0 ) {
721  firstTime = cond::time::from_boost( chTime );
722  }
723  changeTime = cond::time::from_boost( chTime );
724  cond::Time_t iovTime = changeTime;
725  if( !update and changeTime == firstTime ) iovTime = lowerLumi;
726  coral::Attribute const & dipValAttribute = ECALDataCursor.currentRow()[ std::string( "DIP_value" ) ];
727  coral::Attribute const & valueNumberAttribute = ECALDataCursor.currentRow()[ std::string( "VALUE_NUMBER" ) ];
728  coral::Attribute const & elementNrAttribute = ECALDataCursor.currentRow()[ std::string( "element_nr" ) ];
729  if( !dipValAttribute.isNull() and !valueNumberAttribute.isNull() ) {
730  dipVal = dipValAttribute.data<std::string>();
731  elementNr = elementNrAttribute.data<unsigned int>();
732  value = valueNumberAttribute.data<float>();
733  if( isnan( value ) ) value = 0.;
734  if( filter.process( iovTime ) ){
735  iovMap.insert(std::make_pair( changeTime, filter.current()->first ) );
736  for( auto it = filter.current(); it!=m_tmpBuffer.end(); it++ ){
737  LHCInfo& payload = *(it->second);
738  LHCInfoImpl::setElementData(it->first, dipVal, elementNr, value, payload, initializedVectors );
739  }
740  }
741  //}
742  }
743  }
744  }
745  if( m_debug ){
746  for( auto& im: iovMap ){
747  edm::LogInfo(m_name) <<"Found iov="<<im.first<<" ("<<cond::time::to_boost(im.first)<<" ) moved to "<<im.second<<" ( "<<cond::time::to_boost(im.second)<<" )";
748  }
749  }
750  return ret;
751 }
752 
753 
755  bool add = false;
756  if( m_to_transfer.empty() ){
757  if( !m_lastPayloadEmpty ) add = true;
758  } else {
759  LHCInfo* lastAdded = m_to_transfer.back().first;
760  if( lastAdded->fillNumber() != 0 ) {
761  add = true;
762  }
763  }
764  if( add ) {
765  auto newPayload = std::make_shared<LHCInfo>();
766  m_to_transfer.push_back( std::make_pair( newPayload.get(), iov ) );
767  m_payloadBuffer.push_back(newPayload);
768  m_prevPayload = newPayload;
769  }
770 }
771 
772 namespace LHCInfoImpl {
773  bool comparePayloads( const LHCInfo& rhs, const LHCInfo& lhs ){
774  if( rhs.fillNumber() != lhs.fillNumber() ) return false;
775  if( rhs.delivLumi() != lhs.delivLumi() ) return false;
776  if( rhs.recLumi() != lhs.recLumi() ) return false;
777  if( rhs.instLumi() != lhs.instLumi() ) return false;
778  if( rhs.instLumiError() != lhs.instLumiError() ) return false;
779  if( rhs.crossingAngle() != rhs.crossingAngle() ) return false;
780  if( rhs.betaStar() != rhs.betaStar() ) return false;
781  if( rhs.lhcState() != rhs.lhcState() ) return false;
782  if( rhs.lhcComment() != rhs.lhcComment() ) return false;
783  if( rhs.ctppsStatus() != rhs.ctppsStatus() ) return false;
784  return true;
785  }
786 
787  size_t transferPayloads( const std::vector<std::pair<cond::Time_t,std::shared_ptr<LHCInfo> > >& buffer,
788  std::vector<std::shared_ptr<LHCInfo> >& payloadBuffer,
789  std::vector<std::pair<LHCInfo*,cond::Time_t> >& vecToTransfer,
790  std::shared_ptr<LHCInfo>& prevPayload ){
791  size_t niovs = 0;
792  for( auto& iov: buffer ){
793  bool add = false;
794  LHCInfo& payload = *iov.second;
795  cond::Time_t since = iov.first;
796  if( vecToTransfer.empty() ){
797  add = true;
798  } else {
799  LHCInfo& lastAdded = *vecToTransfer.back().first;
800  if( !comparePayloads( lastAdded,payload ) ) {
801  add = true;
802  }
803  }
804  if( add ) {
805  niovs++;
806  vecToTransfer.push_back( std::make_pair( &payload, since ) );
807  payloadBuffer.push_back( iov.second );
808  prevPayload = iov.second;
809  }
810  }
811  return niovs;
812  }
813 
814 }
815 
817  //reference to the last payload in the tag
818  Ref previousFill;
819 
820  //if a new tag is created, transfer fake fill from 1 to the first fill for the first time
821  if ( tagInfo().name.empty() ) {
822  edm::LogInfo( m_name ) << "New tag "<< tagInfo().name << "; from " << m_name << "::getNewObjects";
823  } else {
824  //check what is already inside the database
825  edm::LogInfo( m_name ) << "got info for tag " << tagInfo().name
826  << ", IOVSequence token " << tagInfo().token
827  << ": size " << tagInfo().size
828  << ", last object valid since " << tagInfo().lastInterval.first
829  << " ( "<< boost::posix_time::to_iso_extended_string( cond::time::to_boost( tagInfo().lastInterval.first ) )
830  << " ); from " << m_name << "::getNewObjects";
831  }
832 
833  cond::Time_t lastSince = tagInfo().lastInterval.first;
834  if( lastSince == 0 ){
835  // for a new or empty tag, an empty payload should be added on top with since=1
836  addEmptyPayload( 1 );
837  } else {
838  edm::LogInfo( m_name ) << "The last Iov in tag " << tagInfo().name
839  << " valid since " << lastSince
840  << "from " << m_name << "::getNewObjects";
841  }
842 
843  boost::posix_time::ptime executionTime = boost::posix_time::second_clock::local_time();
844  cond::Time_t targetSince = 0;
845  cond::Time_t endIov = cond::time::from_boost( executionTime );
846  if( !m_startTime.is_not_a_date_time() ){
847  targetSince = cond::time::from_boost(m_startTime);
848  }
849  if( lastSince > targetSince ) targetSince = lastSince;
850 
851  edm::LogInfo(m_name) <<"Starting sampling at "<<boost::posix_time::to_simple_string(cond::time::to_boost(targetSince));
852 
853  //retrieve the data from the relational database source
855  //configure the connection
856  if( m_debug ) {
857  connection.setMessageVerbosity( coral::Debug );
858  } else {
859  connection.setMessageVerbosity( coral::Error );
860  }
861  connection.setAuthenticationPath( m_authpath );
862  connection.configure();
863  //create the sessions
865  cond::persistency::Session session2 = connection.createSession( m_ecalConnectionString, false );
866  // fetch last payload when available
867  if( !tagInfo().lastPayloadToken.empty() ){
869  session3.transaction().start(true);
871  session3.transaction().commit();
872  }
873 
874  bool iovAdded = false;
875  while( true ){
876  if( targetSince >= endIov ){
877  edm::LogInfo( m_name ) <<"Sampling ended at the time "<<boost::posix_time::to_simple_string(cond::time::to_boost( endIov ));
878  break;
879  }
880  bool updateEcal=false;
881  boost::posix_time::ptime targetTime = cond::time::to_boost( targetSince );
882  boost::posix_time::ptime startSampleTime;
883  boost::posix_time::ptime endSampleTime;
884  if( !m_endFill and m_prevPayload->fillNumber() and m_prevPayload->endTime()==0ULL){
885  // execute the query for the current fill
886  session.transaction().start(true);
887  edm::LogInfo( m_name ) <<"Searching started fill #"<<m_prevPayload->fillNumber();
888  bool foundFill = getFillData( session, m_prevPayload->fillNumber() );
889  session.transaction().commit();
890  if(!foundFill ){
891  edm::LogError( m_name )<<"Could not find fill #"<<m_prevPayload->fillNumber();
892  break;
893  }
894  updateEcal = true;
895  startSampleTime = cond::time::to_boost(lastSince);
896  } else {
897  session.transaction().start(true);
898  edm::LogInfo( m_name ) <<"Searching new fill after "<<boost::posix_time::to_simple_string(targetTime);
899  bool foundFill = getNextFillData( session, targetTime, m_endFill );
900  session.transaction().commit();
901  if ( !foundFill ){
902  edm::LogInfo( m_name )<<"No fill found - END of job.";
903  if( iovAdded ) addEmptyPayload( targetSince );
904  break;
905  }
906  startSampleTime = cond::time::to_boost(m_fillPayload->createTime());
907  }
908  cond::Time_t startFillTime = m_fillPayload->createTime();
909  cond::Time_t endFillTime = m_fillPayload->endTime();
910  unsigned short lhcFill = m_fillPayload->fillNumber();
911  if( endFillTime == 0ULL ){
912  edm::LogInfo( m_name ) <<"Found ongoing fill "<<lhcFill<<" created at "<<cond::time::to_boost(startFillTime);
913  endSampleTime = executionTime;
914  targetSince = endIov;
915  } else {
916  edm::LogInfo( m_name ) <<"Found fill "<<lhcFill<<" created at "<<cond::time::to_boost(startFillTime)<<" ending at "<<cond::time::to_boost(endFillTime);
917  endSampleTime = cond::time::to_boost(endFillTime);
918  targetSince = endFillTime;
919  }
920 
921  session.transaction().start(true);
922  getDipData( session, startSampleTime, endSampleTime );
923  size_t nlumi = getLumiData( session, startSampleTime, endSampleTime );
924  edm::LogInfo( m_name ) <<"Found "<<nlumi<<" lumisections during the fill "<<lhcFill;
925  boost::posix_time::ptime flumiStart = cond::time::to_boost(m_tmpBuffer.front().first);
926  boost::posix_time::ptime flumiStop = cond::time::to_boost(m_tmpBuffer.back().first);
927  edm::LogInfo( m_name ) <<"First lumi starts at "<<flumiStart<<" last lumi starts at "<<flumiStop;
928  getCTTPSData( session, startSampleTime, endSampleTime );
929  session.transaction().commit();
930  session2.transaction().start(true);
931  getEcalData( session2, startSampleTime, endSampleTime, updateEcal );
932  session2.transaction().commit();
933  //
935  edm::LogInfo( m_name ) <<"Added "<<niovs<<" iovs within the Fill time";
936  m_tmpBuffer.clear();
937  iovAdded = true;
938  //if(m_prevPayload->fillNumber() and m_prevPayload->endTime()!=0ULL) addEmptyPayload( m_fillPayload->endTime() );
939  if(m_prevPayload->fillNumber() and m_fillPayload->endTime()!=0ULL) addEmptyPayload( m_fillPayload->endTime() );
940  }
941 }
942 
944  return m_name;
945 }
bool operator()(const cond::Time_t &x, const std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > &y)
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > >::const_iterator end
std::string const & lhcState() const
Definition: LHCInfo.cc:232
cond::persistency::Session & dbSession() const
edm::ErrorSummaryEntry Error
T getUntrackedParameter(std::string const &, T const &) const
void setLumiSection(unsigned int const &lumiSection)
Definition: LHCInfo.cc:410
void setInstLumi(float const &instLumi)
Definition: LHCInfo.cc:370
bool getFillData(cond::persistency::Session &session, unsigned short fillId)
static const std::map< std::string, int > vecMap
double seconds()
boost::posix_time::ptime m_startTime
bool getCTTPSData(cond::persistency::Session &session, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > >::const_iterator currLow
size_t getLumiData(cond::persistency::Session &session, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
std::unique_ptr< LHCInfo > m_fillPayload
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > >::const_iterator search(const cond::Time_t &val, const std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > >> &container)
void setInstLumiError(float const &instLumiError)
Definition: LHCInfo.cc:374
void start(bool readOnly=true)
Definition: Session.cc:22
bool comparePayloads(const LHCInfo &rhs, const LHCInfo &lhs)
void reset(const std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > > &samples)
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool getEcalData(cond::persistency::Session &session, const boost::posix_time::ptime &lowerTime, const boost::posix_time::ptime &upperTime, bool update)
size_t size
Definition: Types.h:78
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > >::const_iterator current()
void setDelivLumi(float const &delivLumi)
Definition: LHCInfo.cc:362
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:218
std::string const & ctppsStatus() const
Definition: LHCInfo.cc:240
std::shared_ptr< LHCInfo > m_prevPayload
Transaction & transaction()
Definition: Session.cc:66
std::string name
Definition: Types.h:74
size_t transferPayloads(const std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > > &buffer, std::vector< std::shared_ptr< LHCInfo > > &payloadBuffer, std::vector< std::pair< LHCInfo *, cond::Time_t > > &vecToTransfer, std::shared_ptr< LHCInfo > &prevPayload)
bool getDipData(cond::persistency::Session &session, const boost::posix_time::ptime &beginFillTime, const boost::posix_time::ptime &endFillTime)
void setLhcComment(std::string const &lhcComment)
Definition: LHCInfo.cc:402
float const delivLumi() const
Definition: LHCInfo.cc:196
float const crossingAngle() const
Definition: LHCInfo.cc:176
float const instLumiError() const
Definition: LHCInfo.cc:208
cond::ValidityInterval lastInterval
Definition: Types.h:76
std::vector< std::shared_ptr< LHCInfo > > m_payloadBuffer
unsigned long long Time_t
Definition: Time.h:16
std::string const & lhcComment() const
Definition: LHCInfo.cc:236
boost::posix_time::ptime m_endTime
void setBetaStar(float const &betaStar)
Definition: LHCInfo.cc:346
std::vector< float > const & beam1VC() const
Definition: LHCInfo.cc:248
bool isnan(float x)
Definition: math.h:13
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
std::vector< float > const & beam2RF() const
Definition: LHCInfo.cc:260
coral::ISchema & nominalSchema()
Definition: Session.cc:241
Session createSession(const std::string &connectionString, bool writeCapable=false)
std::vector< float > const & beam1RF() const
Definition: LHCInfo.cc:256
#define end
Definition: vmac.h:39
Definition: value.py:1
void setLhcState(std::string const &lhcState)
Definition: LHCInfo.cc:398
void setMessageVerbosity(coral::MsgLevel level)
Time_t from_boost(boost::posix_time::ptime bt)
LumiSectionFilter(const std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > > &samples)
void setRecLumi(float const &recLumi)
Definition: LHCInfo.cc:366
ParticleType
Definition: LHCInfo.h:15
static size_t const availableBunchSlots
Definition: LHCInfo.h:34
#define debug
Definition: HDRShower.cc:19
float const instLumi() const
Definition: LHCInfo.cc:204
void setElementData(cond::Time_t since, const std::string &dipVal, unsigned int elementNr, float value, LHCInfo &payload, std::set< cond::Time_t > &initList)
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > >::const_iterator currUp
std::string lastPayloadToken
Definition: Types.h:77
std::vector< float > const & beam2VC() const
Definition: LHCInfo.cc:252
bool makeFillDataQuery(cond::persistency::Session &session, const std::string &conditionString, const coral::AttributeList &fillDataBindVariables, std::unique_ptr< LHCInfo > &targetPayload, bool debug)
float const recLumi() const
Definition: LHCInfo.cc:200
coral::ISessionProxy & coralSession()
Definition: Session.cc:236
void setCtppsStatus(std::string const &ctppsStatus)
Definition: LHCInfo.cc:406
#define begin
Definition: vmac.h:32
float const betaStar() const
Definition: LHCInfo.cc:180
#define update(a, b)
unsigned short const fillNumber() const
Definition: LHCInfo.cc:144
std::string id() const override
void setAuthenticationPath(const std::string &p)
const bool Debug
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
std::string token
Definition: Types.h:75
void setCrossingAngle(float const &angle)
Definition: LHCInfo.cc:342
std::vector< std::pair< cond::Time_t, std::shared_ptr< LHCInfo > > > m_tmpBuffer
boost::posix_time::ptime to_boost(Time_t iValue)
static size_t const bunchSlots
Definition: LHCInfo.h:31
bool getNextFillData(cond::persistency::Session &session, const boost::posix_time::ptime &targetTime, bool ended)
FillType
Definition: LHCInfo.h:14
int add(value_type *payload, Summary *summary, Time_t time)
cond::TagInfo_t const & tagInfo() const
LHCInfoPopConSourceHandler(const edm::ParameterSet &pset)