CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
IOVEditor.cc
Go to the documentation of this file.
3 #include "SessionImpl.h"
4 //
5 
6 namespace cond {
7 
8  namespace persistency {
9 
10  // implementation details. holds only data.
11  class IOVEditorData {
12  public:
13  explicit IOVEditorData():
14  tag( "" ),
15  timeType( cond::invalid ),
16  payloadType(""),
18  description(""),
19  iovBuffer(){
20  }
28  boost::posix_time::ptime creationTime;
29  bool change = false;
30  bool exists = false;
31  // buffer for the iov sequence
32  std::vector<std::tuple<cond::Time_t,cond::Hash,boost::posix_time::ptime> > iovBuffer;
33  bool validationMode = false;
34  };
35 
37  m_data(),
38  m_session(){
39  }
40 
41  IOVEditor::IOVEditor( const std::shared_ptr<SessionImpl>& session ):
42  m_data( new IOVEditorData ),
43  m_session( session ){
44  }
45 
46  IOVEditor::IOVEditor( const std::shared_ptr<SessionImpl>& session,
47  const std::string& tag,
48  cond::TimeType timeType,
49  const std::string& payloadObjectType,
50  cond::SynchronizationType synchronizationType,
51  const boost::posix_time::ptime& creationTime ):
52  m_data( new IOVEditorData ),
53  m_session( session ){
54  m_data->tag = tag;
55  m_data->timeType = timeType;
56  m_data->payloadType = payloadObjectType;
57  m_data->synchronizationType = synchronizationType;
58  m_data->creationTime = creationTime;
59  m_data->change = true;
60  }
61 
63  m_data( rhs.m_data ),
64  m_session( rhs.m_session ){
65  }
66 
68  m_data = rhs.m_data;
69  m_session = rhs.m_session;
70  return *this;
71  }
72 
74  checkTransaction( "IOVEditor::load" );
75  // loads the current header data in memory
76  if( !m_session->iovSchema().tagTable().select( tag, m_data->timeType, m_data->payloadType, m_data->synchronizationType,
77  m_data->endOfValidity, m_data->description, m_data->lastValidatedTime ) ){
78  cond::throwException( "Tag \""+tag+"\" has not been found in the database.","IOVEditor::load");
79  }
80  m_data->tag = tag;
81  m_data->exists = true;
82  m_data->change = false;
83  }
84 
86  return m_data.get()? m_data->tag : "" ;
87  }
88 
89 
91  return m_data.get() ? m_data->timeType : cond::invalid;
92  }
93 
95  return m_data.get() ? m_data->payloadType : "";
96  }
97 
99  return m_data.get()? m_data->synchronizationType : cond::SYNCH_ANY ;
100  }
101 
103  return m_data.get() ? m_data->endOfValidity : cond::time::MIN_VAL;
104  }
105 
107  if( m_data.get() ) {
108  m_data->endOfValidity = time;
109  m_data->change = true;
110  }
111  }
112 
114  return m_data.get() ? m_data->description : "";
115  }
116 
118  if( m_data.get() ) {
119  m_data->description = description;
120  m_data->change = true;
121  }
122  }
123 
125  return m_data.get() ? m_data->lastValidatedTime : cond::time::MIN_VAL;
126  }
127 
129  if( m_data.get() ) {
130  m_data->lastValidatedTime = time;
131  m_data->change = true;
132  }
133  }
134 
136  if( m_data.get() ) m_data->validationMode = true;
137  }
138 
139  void IOVEditor::insert( cond::Time_t since, const cond::Hash& payloadHash, bool checkType ){
140  boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time();
141  insert( since, payloadHash, now, checkType );
142  }
143 
144  void IOVEditor::insert( cond::Time_t since, const cond::Hash& payloadHash, const boost::posix_time::ptime& insertionTime, bool ){
145  if( m_data.get() ){
146  // here the type check could be added
147  m_data->iovBuffer.push_back( std::tie( since, payloadHash, insertionTime ) );
148  }
149  }
150 
151  bool iovSorter( const std::tuple<cond::Time_t,cond::Hash,boost::posix_time::ptime>& f, const std::tuple<cond::Time_t,cond::Hash,boost::posix_time::ptime>& s ){
152  return std::get<0>(f) < std::get<0>(s);
153  }
154 
155  bool IOVEditor::flush( const std::string& logText, const boost::posix_time::ptime& operationTime ){
156  bool ret = false;
157  checkTransaction( "IOVEditor::flush" );
158  if( m_data->change ){
159  if( m_data->description.empty() ) throwException( "A non-empty description string is mandatory.","IOVEditor::flush" );
160  if( m_data->validationMode ) m_session->iovSchema().tagTable().setValidationMode();
161  if( !m_data->exists ){
162  // set the creation time ( only available in the migration from v1...)
163  if( m_data->creationTime.is_not_a_date_time() ) m_data->creationTime = operationTime;
164  m_session->iovSchema().tagTable().insert( m_data->tag, m_data->timeType, m_data->payloadType,
165  m_data->synchronizationType, m_data->endOfValidity,
166  m_data->description, m_data->lastValidatedTime, m_data->creationTime );
167  if( m_session->iovSchema().tagLogTable().exists() )
168  m_session->iovSchema().tagLogTable().insert( m_data->tag, m_data->creationTime, cond::getUserName(),cond::getHostName(), cond::getCommand(),
169  std::string("New tag created."),std::string("-") );
170  m_data->exists = true;
171  ret = true;
172  } else {
173  m_session->iovSchema().tagTable().update( m_data->tag, m_data->endOfValidity, m_data->description,
174  m_data->lastValidatedTime, operationTime );
175  if( m_session->iovSchema().tagLogTable().exists() )
176  m_session->iovSchema().tagLogTable().insert( m_data->tag, operationTime, cond::getUserName(),cond::getHostName(), cond::getCommand(),
177  std::string("Tag header updated."),std::string("-") );
178  ret = true;
179  }
180  m_data->change = false;
181  }
182  if( m_data->iovBuffer.size() ) {
183  std::sort(m_data->iovBuffer.begin(),m_data->iovBuffer.end(),iovSorter);
184  cond::Time_t l = std::get<0>(m_data->iovBuffer.front());
185  //We do not allow for IOV updates (i.e. insertion in the past or overriding) on tags whose syncrosization is not "ANY" or "VALIDATION".
186  //This policy is stricter than the one deployed in the Condition Upload service,
187  //which allows insertions in the past or overriding for IOVs larger than the first condition safe run for HLT ("HLT"/"EXPRESS" synchronizations) and Tier0 ("PROMPT"/"PCL").
188  //This is intended: in the C++ API we have not got a way to determine the first condition safe runs.
189  if( m_data->synchronizationType != cond::SYNCH_ANY && m_data->synchronizationType != cond::SYNCH_VALIDATION ){
190  // retrieve the last since
191  cond::Time_t last = 0;
192  cond::Hash h;
193  m_session->iovSchema().iovTable().getLastIov( m_data->tag, last, h );
194  // check if the min iov is greater then the last since
195  if( l <= last ){
196  std::stringstream msg;
197  msg << "Can't insert iov since "<<l<<" on the tag "<< m_data->tag<<": last since is "<<last<<
198  " and synchronization is \""<<cond::synchronizationTypeNames( m_data->synchronizationType )<<"\"";
199  throwException( msg.str(),"IOVEditor::flush");
200  }
201  }
202  // set the insertion time ( only for the migration from v1 will be available... )
203  for( auto& iov : m_data->iovBuffer ){
204  boost::posix_time::ptime& insertionTime = std::get<2>(iov);
205  if( insertionTime.is_not_a_date_time() ) insertionTime = operationTime;
206  }
207  // insert the new iovs
208  m_session->iovSchema().iovTable().insertMany( m_data->tag, m_data->iovBuffer );
209  std::stringstream msg;
210  msg << m_data->iovBuffer.size() << " iov(s) inserted.";
211  if( m_session->iovSchema().tagLogTable().exists() ){
212  std::string lt = logText;
213  if( lt.empty() ) lt = "-";
214  m_session->iovSchema().tagLogTable().insert( m_data->tag, operationTime, cond::getUserName(), cond::getHostName(), cond::getCommand(),
215  msg.str(),lt );
216  }
217  m_data->iovBuffer.clear();
218  ret = true;
219  }
220  return ret;
221  }
222 
223  bool IOVEditor::flush( const std::string& logText ){
224  return flush( logText, boost::posix_time::microsec_clock::universal_time() );
225  }
226 
227  bool IOVEditor::flush( const boost::posix_time::ptime& operationTime ){
228  return flush( std::string("-"), operationTime );
229  }
230 
232  return flush( std::string("-"), boost::posix_time::microsec_clock::universal_time() );
233  }
234 
236  if( !m_session.get() ) throwException("The session is not active.",ctx );
237  if( !m_session->isTransactionActive( false ) ) throwException("The transaction is not active.",ctx );
238  }
239 
240  }
241 }
tuple ret
prodAgent to be discontinued
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
std::string synchronizationTypeNames(SynchronizationType type)
Definition: Types.cc:46
void checkTransaction(const std::string &ctx)
Definition: IOVEditor.cc:235
const Time_t MIN_VAL(0)
void load(const std::string &tag)
Definition: IOVEditor.cc:73
void setDescription(const std::string &description)
Definition: IOVEditor.cc:117
void setLastValidatedTime(cond::Time_t time)
Definition: IOVEditor.cc:128
std::shared_ptr< SessionImpl > m_session
Definition: IOVEditor.h:87
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:21
TimeType
Definition: Time.h:21
std::string description() const
Definition: IOVEditor.cc:113
unsigned long long Time_t
Definition: Time.h:16
tuple iov
Definition: o2o.py:307
std::string Hash
Definition: Types.h:45
double f[11][100]
IOVEditor & operator=(const IOVEditor &rhs)
Definition: IOVEditor.cc:67
cond::SynchronizationType synchronizationType() const
Definition: IOVEditor.cc:98
cond::Time_t endOfValidity() const
Definition: IOVEditor.cc:102
tuple description
Definition: idDealer.py:66
void insert(cond::Time_t since, const cond::Hash &payloadHash, bool checkType=false)
Definition: IOVEditor.cc:139
std::shared_ptr< IOVEditorData > m_data
Definition: IOVEditor.h:86
bool iovSorter(const std::tuple< cond::Time_t, cond::Hash, boost::posix_time::ptime > &f, const std::tuple< cond::Time_t, cond::Hash, boost::posix_time::ptime > &s)
Definition: IOVEditor.cc:151
cond::TimeType timeType() const
Definition: IOVEditor.cc:90
boost::posix_time::ptime creationTime
Definition: IOVEditor.cc:28
cond::Time_t lastValidatedTime() const
Definition: IOVEditor.cc:124
cond::SynchronizationType synchronizationType
Definition: IOVEditor.cc:24
< trclass="colgroup">< tdclass="colgroup"colspan=5 > DT local reconstruction</td ></tr >< tr >< td >< ahref="classDTRecHit1DPair.html"> DTRecHit1DPair</a ></td >< td >< ahref="DataFormats_DTRecHit.html"> edm::RangeMap & lt
SynchronizationType
Definition: Types.h:29
std::vector< std::tuple< cond::Time_t, cond::Hash, boost::posix_time::ptime > > iovBuffer
Definition: IOVEditor.cc:32
void setEndOfValidity(cond::Time_t validity)
Definition: IOVEditor.cc:106
session
Definition: models.py:201
std::string tag() const
Definition: IOVEditor.cc:85
std::string payloadType() const
Definition: IOVEditor.cc:94
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:14