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 
32 
33 #include <iterator>
34 #include <iostream>
35 #include <sstream>
36 
37 namespace cond {
38  class AlignSplitIOV : public Utilities {
39  public:
40  AlignSplitIOV();
42  int execute() override;
43 
44  template<class T>
46  cond::DbSession &destdb,
47  const std::string &token,
48  const std::string &containerName);
49  };
50 }
51 
53  :Utilities("aligncond_split_iov")
54 {
55  addConnectOption("sourceConnect","s","source connection string(required)");
56  addConnectOption("destConnect","d","destionation connection string(required)");
57  addOption<std::string>("sourceTag","i","tag to export( default = destination tag)");
58  addOption<std::string>("destTag","t","destination tag (required)");
60  addOption<bool>("verbose","v","verbose");
61 }
62 
64 {
65 
66 }
67 
69 {
70  initializePluginManager();
71 
72  std::string sourceConnect = getOptionValue<std::string>("sourceConnect");
73  std::string destConnect = getOptionValue<std::string>("destConnect");
74 
75  std::string destTag = getOptionValue<std::string>("destTag");
76  std::string sourceTag(destTag);
77  if (hasOptionValue("sourceTag"))
78  sourceTag = getOptionValue<std::string>("sourceTag");
79  bool verbose = hasOptionValue("verbose");
80 
83 
84  std::string sourceiovtoken;
85  cond::TimeType sourceiovtype;
86 
87  std::string destiovtoken;
88 
89  cond::DbSession sourcedb = openDbSession("sourceConnect", false);
90  cond::DbSession destdb = openDbSession("destConnect");
91 
92  sourcedb.transaction().start(false);
93  cond::MetaData sourceMetadata(sourcedb);
94  sourceiovtoken = sourceMetadata.getToken(sourceTag);
95  if (sourceiovtoken.empty())
96  throw std::runtime_error(std::string("tag ") + sourceTag + std::string(" not found"));
97 
98  if (verbose)
99  std::cout << "source iov token: " << sourceiovtoken << std::endl;
100 
101  cond::IOVProxy iov(sourcedb, sourceiovtoken);
102  sourceiovtype = iov.timetype();
103  if (verbose)
104  std::cout << "source iov type " << sourceiovtype << std::endl;
105 
106  since = std::max(since, cond::timeTypeSpecs[sourceiovtype].beginValue);
107  till = std::min(till, cond::timeTypeSpecs[sourceiovtype].endValue);
108 
109  unsigned int counter = 0;
110  for (cond::IOVProxy::const_iterator ioviterator = iov.begin();
111  ioviterator != iov.end();
112  ++ioviterator) {
113 
114  std::stringstream newTag;
115  newTag << destTag << "_" << counter;
116 
117  std::cout << "iov " << counter << ":\t"
118  << ioviterator->since() << " \t "
119  << ioviterator->till() << std::endl;
120 
121  if (verbose)
122  std::cout << "\t" << ioviterator->token() << std::endl;
123 
125  transaction.start(false);
126  std::string payloadContainerName = sourcedb.classNameForItem(ioviterator->token());
127  std::string objToken;
128  if (payloadContainerName=="Alignments")
129  objToken = processPayloadContainer<Alignments>(sourcedb, destdb,
130  ioviterator->token(), payloadContainerName);
131  else if (payloadContainerName=="AlignmentErrors")
132  objToken = processPayloadContainer<AlignmentErrors>(sourcedb, destdb,
133  ioviterator->token(), payloadContainerName);
134  else if (payloadContainerName=="AlignmentSurfaceDeformations")
135  objToken = processPayloadContainer<AlignmentSurfaceDeformations>(sourcedb, destdb,
136  ioviterator->token(), payloadContainerName);
137  else if (payloadContainerName=="SiPixelLorentzAngle")
138  objToken = processPayloadContainer<SiPixelLorentzAngle>(sourcedb, destdb,
139  ioviterator->token(), payloadContainerName);
140  else if (payloadContainerName=="SiStripLorentzAngle")
141  objToken = processPayloadContainer<SiStripLorentzAngle>(sourcedb, destdb,
142  ioviterator->token(), payloadContainerName);
143  else if (payloadContainerName=="SiStripBackPlaneCorrection")
144  objToken = processPayloadContainer<SiStripBackPlaneCorrection>(sourcedb, destdb,
145  ioviterator->token(), payloadContainerName);
146  else {
147  return 1;
148  }
149 
150  cond::IOVEditor editor(destdb);
151  editor.create(iov.timetype(), cond::timeTypeSpecs[sourceiovtype].endValue);
152  editor.append(cond::timeTypeSpecs[sourceiovtype].beginValue, objToken);
153  std::string iovToken = editor.token();
154  editor.stamp(cond::userInfo(),false);
155 
156  cond::MetaData metadata(destdb);
157  metadata.addMapping(newTag.str(), iovToken, sourceiovtype);
158  transaction.commit();
159 
160  ::sleep(1);
161 
162  ++counter;
163  }
164 
165  std::cout << "Total # of payload objects: " << counter << std::endl;
166 
167  return 0;
168 }
169 
170 template<class T>
172  cond::DbSession &destdb,
173  const std::string &token,
174  const std::string &containerName)
175 {
176  boost::shared_ptr<T> object = sourcedb.getTypedObject<T>(token);
177  destdb.createDatabase();
178  return destdb.storeObject(object.get(), containerName);
179 }
180 
181 int main( int argc, char** argv )
182 {
183  cond::AlignSplitIOV utilities;
184  return utilities.run(argc,argv);
185 }
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:22
std::string create(cond::TimeType timetype)
Definition: IOVEditor.cc:260
int run(int argc, char **argv)
Definition: Utilities.cc:53
std::string classNameForItem(const std::string &objectId)
Definition: DbSession.cc:292
DbTransaction & transaction()
Definition: DbSession.cc:208
void addConnectOption()
Definition: Utilities.cc:111
std::string const & token() const
Definition: IOVEditor.cc:542
const_iterator begin() const
Definition: IOVProxy.h:188
const std::string getToken(const std::string &tagname) const
Definition: MetaData.cc:52
const_iterator end() const
Definition: IOVProxy.h:193
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
void addAuthenticationOptions()
Definition: Utilities.cc:104
T min(T a, T b)
Definition: MathUtil.h:58
int start(bool readOnly=false)
start transaction
std::string storeObject(const T *object, const std::string &containerName)
Definition: DbSession.h:132
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:221
unsigned int append(cond::Time_t sinceTime, const std::string &payloadToken)
Definition: IOVEditor.cc:416
tuple argc
Definition: dir2webdir.py:38
static std::atomic< unsigned int > counter
TimeType timetype() const
Definition: IOVProxy.cc:281
void stamp(std::string const &icomment, bool append=false)
Definition: IOVEditor.cc:375
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:126
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