Go to the documentation of this file.00001 #include "CondCore/DBCommon/interface/DbSession.h"
00002 #include "CondCore/DBCommon/interface/DbScopedTransaction.h"
00003 #include "CondCore/DBCommon/interface/DbTransaction.h"
00004 #include "CondCore/DBCommon/interface/Exception.h"
00005
00006 #include "CondCore/MetaDataService/interface/MetaData.h"
00007 #include "CondCore/IOVService/interface/IOVService.h"
00008 #include "CondCore/IOVService/interface/IOVProxy.h"
00009 #include "CondCore/IOVService/interface/IOVEditor.h"
00010
00011 #include "CondCore/DBCommon/interface/IOVInfo.h"
00012 #include "CondCore/DBCommon/interface/Logger.h"
00013 #include "CondCore/DBCommon/interface/LogDBEntry.h"
00014 #include "CondCore/DBCommon/interface/UserLogInfo.h"
00015 #include "CondCore/DBCommon/interface/TagInfo.h"
00016 #include "CondCore/Utilities/interface/Utilities.h"
00017
00018 #include "CondCore/ORA/interface/Object.h"
00019 #include "CondCore/DBCommon/interface/DbTransaction.h"
00020 #include "CondCore/DBCommon/interface/Exception.h"
00021 #include "CondCore/MetaDataService/interface/MetaData.h"
00022
00023 #include "CondCore/DBCommon/interface/Time.h"
00024 #include "CondFormats/Common/interface/TimeConversions.h"
00025
00026 #include "CondCore/IOVService/interface/IOVProxy.h"
00027
00028 #include "CondFormats/Alignment/interface/Alignments.h"
00029
00030 #include <iterator>
00031 #include <iostream>
00032 #include <sstream>
00033
00034 namespace cond {
00035 class AlignSplitIOV : public Utilities {
00036 public:
00037 AlignSplitIOV();
00038 ~AlignSplitIOV();
00039 int execute();
00040 };
00041 }
00042
00043 cond::AlignSplitIOV::AlignSplitIOV()
00044 :Utilities("aligncond_split_iov")
00045 {
00046 addConnectOption("sourceConnect","s","source connection string(required)");
00047 addConnectOption("destConnect","d","destionation connection string(required)");
00048 addOption<std::string>("sourceTag","i","tag to export( default = destination tag)");
00049 addOption<std::string>("destTag","t","destination tag (required)");
00050 addAuthenticationOptions();
00051 addOption<bool>("verbose","v","verbose");
00052 }
00053
00054 cond::AlignSplitIOV::~AlignSplitIOV()
00055 {
00056
00057 }
00058
00059 int cond::AlignSplitIOV::execute()
00060 {
00061 initializePluginManager();
00062
00063 std::string sourceConnect = getOptionValue<std::string>("sourceConnect");
00064 std::string destConnect = getOptionValue<std::string>("destConnect");
00065
00066 std::string destTag = getOptionValue<std::string>("destTag");
00067 std::string sourceTag(destTag);
00068 if (hasOptionValue("sourceTag"))
00069 sourceTag = getOptionValue<std::string>("sourceTag");
00070
00071 bool verbose = hasOptionValue("verbose");
00072
00073 cond::Time_t since = std::numeric_limits<cond::Time_t>::min();
00074 cond::Time_t till = std::numeric_limits<cond::Time_t>::max();
00075
00076 std::string sourceiovtoken;
00077 cond::TimeType sourceiovtype;
00078
00079 std::string destiovtoken;
00080
00081 cond::DbSession sourcedb = openDbSession("sourceConnect", false);
00082 cond::DbSession destdb = openDbSession("destConnect");
00083
00084 sourcedb.transaction().start(false);
00085 cond::MetaData sourceMetadata(sourcedb);
00086 sourceiovtoken = sourceMetadata.getToken(sourceTag);
00087 if (sourceiovtoken.empty())
00088 throw std::runtime_error(std::string("tag ") + sourceTag + std::string(" not found"));
00089
00090 if (verbose)
00091 std::cout << "source iov token: " << sourceiovtoken << std::endl;
00092
00093 cond::IOVService iovmanager(sourcedb);
00094 sourceiovtype = iovmanager.timeType(sourceiovtoken);
00095 std::string payloadContainer = iovmanager.payloadContainerName(sourceiovtoken);
00096
00097 if (verbose)
00098 std::cout << "source iov type " << sourceiovtype << std::endl;
00099
00100 since = std::max(since, cond::timeTypeSpecs[sourceiovtype].beginValue);
00101 till = std::min(till, cond::timeTypeSpecs[sourceiovtype].endValue);
00102
00103 cond::IOVProxy iov(sourcedb, sourceiovtoken, true, false);
00104 unsigned int counter = 0;
00105 for (cond::IOVProxy::const_iterator ioviterator = iov.begin();
00106 ioviterator != iov.end();
00107 ++ioviterator) {
00108
00109 std::stringstream newTag;
00110 newTag << destTag << "_" << counter;
00111
00112 std::cout << "iov " << counter << ":\t"
00113 << ioviterator->since() << " \t "
00114 << ioviterator->till() << std::endl;
00115
00116 if (verbose)
00117 std::cout << "\t" << ioviterator->token() << std::endl;
00118
00119 boost::shared_ptr<Alignments> alignments = sourcedb.getTypedObject<Alignments>(ioviterator->token());
00120
00121 cond::DbScopedTransaction transaction(destdb);
00122 transaction.start(false);
00123
00124 std::string objToken = destdb.storeObject(alignments.get(), "Alignments");
00125
00126 cond::IOVEditor editor(destdb);
00127 editor.create(iov.timetype(), cond::timeTypeSpecs[sourceiovtype].endValue);
00128 editor.append(cond::timeTypeSpecs[sourceiovtype].beginValue, objToken);
00129 std::string iovToken = editor.token();
00130 editor.stamp(cond::userInfo(),false);
00131
00132 cond::MetaData metadata(destdb);
00133 metadata.addMapping(newTag.str(), iovToken, sourceiovtype);
00134 transaction.commit();
00135
00136 ::sleep(1);
00137
00138 ++counter;
00139 }
00140
00141 std::cout << "Total # of payload objects: " << counter << std::endl;
00142
00143 return 0;
00144 }
00145
00146 int main( int argc, char** argv )
00147 {
00148 cond::AlignSplitIOV utilities;
00149 return utilities.run(argc,argv);
00150 }