CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
aligncond_split_iov.cc
Go to the documentation of this file.
5 
8 
15 
20 
23 
25 
29 
30 #include <iterator>
31 #include <iostream>
32 #include <sstream>
33 
34 namespace cond {
35  class AlignSplitIOV : public Utilities {
36  public:
37  AlignSplitIOV();
39  int execute();
40 
41  template<class T>
42  std::string processPayloadContainer(cond::DbSession &sourcedb,
43  cond::DbSession &destdb,
44  const std::string &token,
45  const std::string &containerName);
46  };
47 }
48 
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 }
59 
61 {
62 
63 }
64 
66 {
67  initializePluginManager();
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 }
157 
158 template<class T>
160  cond::DbSession &destdb,
161  const std::string &token,
162  const std::string &containerName)
163 {
164  boost::shared_ptr<T> object = sourcedb.getTypedObject<T>(token);
165  destdb.createDatabase();
166  return destdb.storeObject(object.get(), containerName);
167 }
168 
169 int main( int argc, char** argv )
170 {
171  cond::AlignSplitIOV utilities;
172  return utilities.run(argc,argv);
173 }
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:22
std::string create(cond::TimeType timetype)
Definition: IOVEditor.cc:244
int run(int argc, char **argv)
Definition: Utilities.cc:54
std::string classNameForItem(const std::string &objectId)
Definition: DbSession.cc:277
DbTransaction & transaction()
Definition: DbSession.cc:189
TimeType timetype() const
Definition: IOVProxy.cc:280
void addConnectOption()
Definition: Utilities.cc:101
std::string const & token() const
Definition: IOVEditor.cc:526
#define min(a, b)
Definition: mlp_lapack.h:161
const_iterator begin() const
Definition: IOVProxy.h:188
const std::string getToken(const std::string &tagname) const
Definition: MetaData.cc:53
const_iterator end() const
Definition: IOVProxy.h:193
void sleep(Duration_t)
Definition: Utils.h:163
TimeType
Definition: Time.h:21
int main(int argc, char **argv)
int start(bool readOnly=false)
start transaction
unsigned long long Time_t
Definition: Time.h:16
bool addMapping(const std::string &name, const std::string &token, cond::TimeType timetype=cond::runnumber)
Definition: MetaData.cc:36
tuple iov
Definition: o2o.py:307
const T & max(const T &a, const T &b)
void addAuthenticationOptions()
Definition: Utilities.cc:94
int start(bool readOnly=false)
start transaction
std::string storeObject(const T *object, const std::string &containerName)
Definition: DbSession.h:131
std::string processPayloadContainer(cond::DbSession &sourcedb, cond::DbSession &destdb, const std::string &token, const std::string &containerName)
tuple editor
Definition: idDealer.py:73
bool createDatabase()
Definition: DbSession.cc:206
unsigned int append(cond::Time_t sinceTime, const std::string &payloadToken)
Definition: IOVEditor.cc:400
tuple argc
Definition: dir2webdir.py:41
void stamp(std::string const &icomment, bool append=false)
Definition: IOVEditor.cc:359
std::string userInfo()
Definition: IOVInfo.cc:9
tuple cout
Definition: gather_cfg.py:121
Time_t endValue
Definition: Time.h:46
long double T
boost::shared_ptr< T > getTypedObject(const std::string &objectId)
Definition: DbSession.h:125
int commit()
commit transaction. Will disconnect from database if connection timeout==0 or connectted time close t...
iov_range_iterator const_iterator
Definition: IOVProxy.h:160