CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions
cond::ExportIOVUtilities Class Reference

#include <ExportIOVUtilities.h>

Inheritance diagram for cond::ExportIOVUtilities:
cond::Utilities

Public Member Functions

int execute ()
 
 ExportIOVUtilities (std::string const &name)
 
 ~ExportIOVUtilities ()
 
- Public Member Functions inherited from cond::Utilities
void addAuthenticationOptions ()
 
void addConfigFileOption ()
 
void addConnectOption ()
 
void addConnectOption (const std::string &connectionOptionName, const std::string &shortName, const std::string &helpEntry)
 
void addDictionaryOption ()
 
void addLogDBOption ()
 
template<typename T >
void addOption (const std::string &fullName, const std::string &shortName, const std::string &helpEntry)
 
template<>
void addOption (const std::string &fullName, const std::string &shortName, const std::string &helpEntry)
 
void addSQLOutputOption ()
 
std::string getAuthenticationPathValue ()
 
std::string getConfigFileValue ()
 
std::string getConnectValue ()
 
std::string getDictionaryValue ()
 
std::string getLogDBValue ()
 
template<typename T >
T getOptionValue (const std::string &fullName)
 
std::string getPasswordValue ()
 
std::string getUserValue ()
 
bool hasDebug ()
 
bool hasOptionValue (const std::string &fullName)
 
void initializePluginManager ()
 
cond::DbSession openDbSession (const std::string &connectionParameterName, bool readOnly=false)
 
cond::DbSession openDbSession (const std::string &connectionParameterName, const std::string &role, bool readOnly=false)
 
void parseCommand (int argc, char **argv)
 
int run (int argc, char **argv)
 
 Utilities (const std::string &commandName, std::string positionalParameter=std::string(""))
 
virtual ~Utilities ()
 

Additional Inherited Members

- Protected Member Functions inherited from cond::Utilities
void initializeForDbConnection ()
 
cond::DbSession newDbSession (const std::string &connectionString, bool readOnly=false)
 
cond::DbSession newDbSession (const std::string &connectionString, const std::string &role, bool readOnly=false)
 
- Protected Attributes inherited from cond::Utilities
edm::ServiceTokenm_currentToken = 0
 

Detailed Description

Definition at line 6 of file ExportIOVUtilities.h.

Constructor & Destructor Documentation

cond::ExportIOVUtilities::ExportIOVUtilities ( std::string const &  name)
explicit

Definition at line 26 of file ExportIOVUtilities.cc.

References cond::Utilities::addAuthenticationOptions(), cond::Utilities::addConfigFileOption(), cond::Utilities::addConnectOption(), cond::Utilities::addDictionaryOption(), cond::Utilities::addLogDBOption(), and cond::Utilities::addSQLOutputOption().

26  :Utilities(name){
31  addConnectOption("sourceConnect","s","source connection string(required)");
32  addConnectOption("destConnect","d","destionation connection string(required)");
33  addOption<std::string>("inputTag","i","tag to export( default = destination tag)");
34  addOption<std::string>("destTag","t","destination tag (required)");
35  addOption<cond::Time_t>("beginTime","b","begin time (first since) (optional)");
36  addOption<cond::Time_t>("endTime","e","end time (last till) (optional)");
37  addOption<bool>("outOfOrder","o","allow out of order merge (optional, default=false)");
38  addOption<size_t>("bunchSize","n","iterate with bunches of specific size (optional)");
39  addOption<std::string>("usertext","x","user text, to be included in usertext column (optional, must be enclosed in double quotes)");
41 }
void addConnectOption()
Definition: Utilities.cc:111
void addAuthenticationOptions()
Definition: Utilities.cc:104
void addSQLOutputOption()
Definition: Utilities.cc:141
void addConfigFileOption()
Definition: Utilities.cc:136
void addLogDBOption()
Definition: Utilities.cc:126
void addDictionaryOption()
Definition: Utilities.cc:131
Utilities(const std::string &commandName, std::string positionalParameter=std::string(""))
Definition: Utilities.cc:25
cond::ExportIOVUtilities::~ExportIOVUtilities ( )

Definition at line 43 of file ExportIOVUtilities.cc.

43  {
44 }

Member Function Documentation

int cond::ExportIOVUtilities::execute ( )
virtual

Reimplemented from cond::Utilities.

Definition at line 46 of file ExportIOVUtilities.cc.

References a, cond::MetaData::addMapping(), ora::QueryableVector< Tp >::back(), cond::DbSession::classNameForItem(), cond::DbScopedTransaction::commit(), cond::DbTransaction::commit(), cond::Auth::COND_READER_ROLE, cond::Auth::COND_WRITER_ROLE, cond::IOVNames::container(), filterCSVwithJSON::copy, gather_cfg::cout, cond::IOVEditor::create(), cond::IOVEditor::createIOVContainerIfNecessary(), debug, cond::MetaData::getToken(), cond::MetaData::hasTag(), cond::IOVEditor::importIterator(), HLT_25ns14e33_v1_cff::inputTag, cond::IOVProxy::iov(), cond::IOVSequence::iovs(), getDQMSummary::iter, prof2calltree::last, cond::IOVSequence::lastTill(), cond::IOVEditor::load(), cond::IOVProxy::load(), ora::Database::lockContainer(), bookConverter::max, cond::IOVSequence::metadata(), min(), cond::TimeTypeSpecs::name, template_L1THistoryDQMService_cfg::outOfOrder, cond::IOVProxy::payloadClasses(), cond::UserLogInfo::provenance, cond::IOVEditor::proxy(), cond::IOVEditor::reload(), cond::IOVEditor::setScope(), cond::IOVProxy::size(), contentValuesCheck::ss, cond::DbScopedTransaction::start(), cond::DbTransaction::start(), cond::DbSession::storage(), edmStreamStallGrapher::stream, AlCaHLTBitMon_QueryRunRegistry::string, cond::IOVSequence::Tag, cond::IOVEditor::timetype(), cond::IOVProxy::timetype(), cond::timeTypeSpecs, cond::IOVElement::token(), cond::DbSession::transaction(), python.IdGenerator::transaction, cond::UserLogInfo::usertext, and cms::Exception::what().

46  {
47 
48  std::string sourceConnect = getOptionValue<std::string>("sourceConnect");
49  std::string destConnect = getOptionValue<std::string>("destConnect");
50 
51  std::string destTag = getOptionValue<std::string>("destTag");
52  std::string inputTag(destTag);
53  if( hasOptionValue("inputTag") ) inputTag = getOptionValue<std::string>("inputTag");
54  std::string usertext("no user comments");
55  if( hasOptionValue("usertext")) usertext = getOptionValue<std::string>("usertext");
56  bool doLog = hasOptionValue("logDB");
57 
59  if( hasOptionValue("beginTime" )) since = getOptionValue<cond::Time_t>("beginTime");
61  if( hasOptionValue("endTime" )) till = getOptionValue<cond::Time_t>("endTime");
62 
63  size_t bunchSize = 1;
64  if(hasOptionValue("bunchSize")) bunchSize = getOptionValue<size_t>("bunchSize");
65 
66  std::string sqlOutputFileName("sqlmonitoring.out");
67  bool debug=hasDebug();
68  bool outOfOrder = hasOptionValue("outOfOrder");
69 
70  std::string sourceIovToken("");
71  std::string destIovToken("");
72  bool newIOV = false;
73  cond::TimeType sourceIovType;
74 
75  cond::DbSession sourceDb = openDbSession("sourceConnect", Auth::COND_READER_ROLE, true);
76  cond::DbSession destDb = openDbSession("destConnect", Auth::COND_WRITER_ROLE );
77 
78  std::auto_ptr<cond::Logger> logDb;
79  cond::DbSession logSession;
80 
81  std::string payloadToken("");
82  std::string payloadClasses("");
83  int iovSize = 0;
84  int ncopied = 0;
86  if (doLog) {
87  logSession = openDbSession( "logDB",Auth::COND_WRITER_ROLE );
88  logDb.reset(new cond::Logger(logSession));
89  logDb->createLogDBIfNonExist();
90  a.provenance=sourceConnect+"/"+inputTag;
91  a.usertext="exportIOV V4.0;";
92  }
93 
94  // find tag in source
95  sourceDb.transaction().start(true);
96  cond::MetaData sourceMetadata(sourceDb);
97  sourceIovToken=sourceMetadata.getToken(inputTag);
98  if(sourceIovToken.empty())
99  throw std::runtime_error(std::string("tag ")+inputTag+std::string(" not found") );
100 
101  if(debug){
102  std::cout<<"source iov token "<<sourceIovToken<<std::endl;
103  }
104 
105  cond::IOVProxy sourceIov( sourceDb );
106  sourceIov.load( sourceIovToken );
107  sourceIovType = sourceIov.timetype();
108  std::string const & timetypestr = cond::timeTypeSpecs[sourceIovType].name;
109  if(debug){
110  std::cout<<"source iov type "<<sourceIovType<<std::endl;
111  }
112 
113  if( doLog ){
114  std::set<std::string> pclasses = sourceIov.payloadClasses();
115  iovSize = sourceIov.size();
116  std::ostringstream stream;
117  std::copy(pclasses.begin(), pclasses.end(), std::ostream_iterator<std::string>(stream, ", "));
118  payloadClasses = stream.str();
119  }
120 
121  try{
122  // find tag in destination
124  transaction.start(false);
125 
126  int oldSize=0;
127  cond::IOVEditor destIov( destDb );
128  destIov.createIOVContainerIfNecessary();
130 
131  cond::MetaData destMetadata( destDb );
132  if( destMetadata.hasTag(destTag) ){
133  destIovToken=destMetadata.getToken(destTag);
134  destIov.load( destIovToken );
135  oldSize = destIov.proxy().size();
136  if (sourceIovType!=destIov.timetype()) {
137  throw std::runtime_error("iov type in source and dest differs");
138  }
139  } else {
140  newIOV = true;
141  destIovToken=destIov.create( sourceIovType, sourceIov.iov().lastTill(),sourceIov.iov().metadata() );
142  destMetadata.addMapping(destTag,destIovToken,sourceIovType);
143  destIov.setScope( cond::IOVSequence::Tag );
144  }
145  if(debug){
146  std::cout<<"dest iov token "<<destIovToken<<std::endl;
147  std::cout<<"dest iov type "<<sourceIovType<<std::endl;
148  }
149 
150  since = std::max(since, cond::timeTypeSpecs[sourceIovType].beginValue);
151  till = std::min(till, cond::timeTypeSpecs[sourceIovType].endValue);
152 
153  boost::shared_ptr<IOVImportIterator> importIterator = destIov.importIterator();
154  importIterator->setUp( sourceIov, since, till, outOfOrder, bunchSize );
155 
156  size_t totalImported = 0;
157  if( bunchSize>1 ){
158  unsigned int iter = 0;
159  while( importIterator->hasMoreElements() ){
160  if(iter>0){
161  transaction.commit();
162  transaction.start();
163  destIov.reload();
164  }
165  iter++;
166  size_t imported = importIterator->importMoreElements();
167  totalImported += imported;
168  std::cout <<"Iteration #"<<iter<<": "<<imported<<" element(s)."<<std::endl;
169  }
170  } else {
171  totalImported = importIterator->importAll();
172  }
173  std::cout <<totalImported<<" element(s) exported."<<std::endl;
174 
175  ::sleep(1);
176 
177  // grab info
178  // call IOV proxy with keep open option: it is required to lookup the payload class. A explicit commit will be needed at the end.
179  if (doLog) {
180  IOVProxy diov = destIov.proxy();
181  std::ostringstream stream;
182  std::copy(diov.payloadClasses().begin(), diov.payloadClasses().end(), std::ostream_iterator<std::string>(stream, ", "));
183  payloadClasses = stream.str();
184  iovSize = diov.size();
185  ncopied = iovSize-oldSize;
186  if ( ncopied == 1) {
187  // get last object
188  const IOVElement& last = diov.iov().iovs().back();
189  payloadToken=last.token();
190  payloadClasses = destDb.classNameForItem( payloadToken );
191  }
192  if (newIOV) a.usertext+= "new tag;";
193  std::ostringstream ss;
194  ss << "since="<< since <<", till="<< till << ", " << usertext << ";";
195  ss << " copied="<< ncopied <<";";
196  a.usertext +=ss.str();
197  logDb->logOperationNow(a,destConnect,payloadClasses,payloadToken,destTag,timetypestr,iovSize-1,since);
198  }
199  transaction.commit();
200  sourceDb.transaction().commit();
201  }catch ( cond::Exception const& er ){
202  if (doLog) {
203  if (newIOV) a.usertext+= "new tag;";
204  std::ostringstream ss;
205  ss << "since="<< since <<", till="<< till << ", " << usertext << ";";
206  ss << " copied="<< ncopied <<";";
207  a.usertext +=ss.str();
208  logDb->logFailedOperationNow(a,destConnect,payloadClasses,payloadToken,destTag,timetypestr,iovSize-1,since,std::string(er.what()));
209  }
210  sourceDb.transaction().commit();
211  throw;
212  }
213 
214  return 0;
215 }
virtual char const * what() const
Definition: Exception.cc:141
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:22
std::string usertext
Definition: LogDBEntry.h:9
std::string classNameForItem(const std::string &objectId)
Definition: DbSession.cc:292
DbTransaction & transaction()
Definition: DbSession.cc:208
int commit()
commit transaction.
TimeType
Definition: Time.h:21
bool lockContainer(const std::string &name)
Definition: Database.cc:265
int start(bool readOnly=false)
start transaction
unsigned long long Time_t
Definition: Time.h:16
static const std::string COND_WRITER_ROLE
Definition: Auth.h:18
std::string provenance
Definition: LogDBEntry.h:8
T min(T a, T b)
Definition: MathUtil.h:58
static const std::string COND_READER_ROLE
Definition: Auth.h:19
#define debug
Definition: HDRShower.cc:19
std::string name
Definition: Time.h:43
bool hasOptionValue(const std::string &fullName)
Definition: Utilities.cc:188
static std::string container()
Definition: IOVNames.h:7
double a
Definition: hdecay.h:121
cond::DbSession openDbSession(const std::string &connectionParameterName, bool readOnly=false)
Definition: Utilities.cc:267
tuple cout
Definition: gather_cfg.py:121
ora::Database & storage()
Definition: DbSession.cc:215