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::AlignSplitIOV Class Reference
Inheritance diagram for cond::AlignSplitIOV:
cond::Utilities

Public Member Functions

 AlignSplitIOV ()
 
int execute () override
 
template<class T >
std::string processPayloadContainer (cond::DbSession &sourcedb, cond::DbSession &destdb, const std::string &token, const std::string &containerName)
 
 ~AlignSplitIOV ()
 
- 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
cond::DbSession newDbSession (const std::string &connectionString, bool readOnly=false)
 
cond::DbSession newDbSession (const std::string &connectionString, const std::string &role, bool readOnly=false)
 

Detailed Description

Definition at line 35 of file aligncond_split_iov.cc.

Constructor & Destructor Documentation

cond::AlignSplitIOV::AlignSplitIOV ( )

Definition at line 49 of file aligncond_split_iov.cc.

References cond::Utilities::addAuthenticationOptions(), and cond::Utilities::addConnectOption().

50  :Utilities("aligncond_split_iov")
51 {
52  addConnectOption("sourceConnect","s","source connection string(required)");
53  addConnectOption("destConnect","d","destionation connection string(required)");
54  addOption<std::string>("sourceTag","i","tag to export( default = destination tag)");
55  addOption<std::string>("destTag","t","destination tag (required)");
57  addOption<bool>("verbose","v","verbose");
58 }
void addConnectOption()
Definition: Utilities.cc:101
void addAuthenticationOptions()
Definition: Utilities.cc:94
Utilities(const std::string &commandName, std::string positionalParameter=std::string(""))
Definition: Utilities.cc:25
cond::AlignSplitIOV::~AlignSplitIOV ( )

Definition at line 60 of file aligncond_split_iov.cc.

61 {
62 
63 }

Member Function Documentation

int cond::AlignSplitIOV::execute ( )
overridevirtual

Reimplemented from cond::Utilities.

Definition at line 65 of file aligncond_split_iov.cc.

References cond::MetaData::addMapping(), cond::IOVEditor::append(), cond::IOVProxy::begin(), cond::DbSession::classNameForItem(), cond::DbScopedTransaction::commit(), counter, gather_cfg::cout, cond::IOVEditor::create(), idDealer::editor, cond::IOVProxy::end(), cond::TimeTypeSpecs::endValue, cond::MetaData::getToken(), o2o::iov, max(), bookConverter::min, cond::IOVEditor::stamp(), cond::DbScopedTransaction::start(), cond::DbTransaction::start(), AlCaHLTBitMon_QueryRunRegistry::string, cond::IOVProxy::timetype(), cond::timeTypeSpecs, cond::IOVEditor::token(), cond::DbSession::transaction(), python.IdGenerator::transaction, and cond::userInfo().

66 {
68 
69  std::string sourceConnect = getOptionValue<std::string>("sourceConnect");
70  std::string destConnect = getOptionValue<std::string>("destConnect");
71 
72  std::string destTag = getOptionValue<std::string>("destTag");
73  std::string sourceTag(destTag);
74  if (hasOptionValue("sourceTag"))
75  sourceTag = getOptionValue<std::string>("sourceTag");
76  bool verbose = hasOptionValue("verbose");
77 
80 
81  std::string sourceiovtoken;
82  cond::TimeType sourceiovtype;
83 
84  std::string destiovtoken;
85 
86  cond::DbSession sourcedb = openDbSession("sourceConnect", false);
87  cond::DbSession destdb = openDbSession("destConnect");
88 
89  sourcedb.transaction().start(false);
90  cond::MetaData sourceMetadata(sourcedb);
91  sourceiovtoken = sourceMetadata.getToken(sourceTag);
92  if (sourceiovtoken.empty())
93  throw std::runtime_error(std::string("tag ") + sourceTag + std::string(" not found"));
94 
95  if (verbose)
96  std::cout << "source iov token: " << sourceiovtoken << std::endl;
97 
98  cond::IOVProxy iov(sourcedb, sourceiovtoken);
99  sourceiovtype = iov.timetype();
100  if (verbose)
101  std::cout << "source iov type " << sourceiovtype << std::endl;
102 
103  since = std::max(since, cond::timeTypeSpecs[sourceiovtype].beginValue);
104  till = std::min(till, cond::timeTypeSpecs[sourceiovtype].endValue);
105 
106  unsigned int counter = 0;
107  for (cond::IOVProxy::const_iterator ioviterator = iov.begin();
108  ioviterator != iov.end();
109  ++ioviterator) {
110 
111  std::stringstream newTag;
112  newTag << destTag << "_" << counter;
113 
114  std::cout << "iov " << counter << ":\t"
115  << ioviterator->since() << " \t "
116  << ioviterator->till() << std::endl;
117 
118  if (verbose)
119  std::cout << "\t" << ioviterator->token() << std::endl;
120 
122  transaction.start(false);
123  std::string payloadContainerName = sourcedb.classNameForItem(ioviterator->token());
124  std::string objToken;
125  if (payloadContainerName=="Alignments")
126  objToken = processPayloadContainer<Alignments>(sourcedb, destdb,
127  ioviterator->token(), payloadContainerName);
128  else if (payloadContainerName=="AlignmentErrors")
129  objToken = processPayloadContainer<AlignmentErrors>(sourcedb, destdb,
130  ioviterator->token(), payloadContainerName);
131  else if (payloadContainerName=="AlignmentSurfaceDeformations")
132  objToken = processPayloadContainer<AlignmentSurfaceDeformations>(sourcedb, destdb,
133  ioviterator->token(), payloadContainerName);
134  else {
135  return 1;
136  }
137 
138  cond::IOVEditor editor(destdb);
139  editor.create(iov.timetype(), cond::timeTypeSpecs[sourceiovtype].endValue);
140  editor.append(cond::timeTypeSpecs[sourceiovtype].beginValue, objToken);
141  std::string iovToken = editor.token();
142  editor.stamp(cond::userInfo(),false);
143 
144  cond::MetaData metadata(destdb);
145  metadata.addMapping(newTag.str(), iovToken, sourceiovtype);
146  transaction.commit();
147 
148  ::sleep(1);
149 
150  ++counter;
151  }
152 
153  std::cout << "Total # of payload objects: " << counter << std::endl;
154 
155  return 0;
156 }
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:22
std::string classNameForItem(const std::string &objectId)
Definition: DbSession.cc:292
DbTransaction & transaction()
Definition: DbSession.cc:208
TimeType
Definition: Time.h:21
int start(bool readOnly=false)
start transaction
unsigned long long Time_t
Definition: Time.h:16
tuple iov
Definition: o2o.py:307
const T & max(const T &a, const T &b)
void initializePluginManager()
Definition: Utilities.cc:192
tuple editor
Definition: idDealer.py:73
bool hasOptionValue(const std::string &fullName)
Definition: Utilities.cc:178
static std::atomic< unsigned int > counter
cond::DbSession openDbSession(const std::string &connectionParameterName, bool readOnly=false)
Definition: Utilities.cc:270
std::string userInfo()
Definition: IOVInfo.cc:9
tuple cout
Definition: gather_cfg.py:121
Time_t endValue
Definition: Time.h:46
iov_range_iterator const_iterator
Definition: IOVProxy.h:160
template<class T >
std::string cond::AlignSplitIOV::processPayloadContainer ( cond::DbSession sourcedb,
cond::DbSession destdb,
const std::string &  token,
const std::string &  containerName 
)

Definition at line 159 of file aligncond_split_iov.cc.

References cond::DbSession::createDatabase(), cond::DbSession::getTypedObject(), and cond::DbSession::storeObject().

163 {
164  boost::shared_ptr<T> object = sourcedb.getTypedObject<T>(token);
165  destdb.createDatabase();
166  return destdb.storeObject(object.get(), containerName);
167 }
std::string storeObject(const T *object, const std::string &containerName)
Definition: DbSession.h:132
bool createDatabase()
Definition: DbSession.cc:221
long double T
boost::shared_ptr< T > getTypedObject(const std::string &objectId)
Definition: DbSession.h:126