00001 #include "CondCore/Utilities/interface/CondBasicIter.h" 00002 00003 CondBasicIter::CondBasicIter(){ 00004 ioviterator = 0; 00005 pooldb = 0; 00006 myconnection = 0; 00007 } 00008 00009 CondBasicIter::~CondBasicIter(){ 00010 if (pooldb) { 00011 pooldb->commit(); 00012 } 00013 if (ioviterator) delete ioviterator; 00014 if (myconnection) delete myconnection; 00015 } 00016 00017 void CondBasicIter::setStartTime(unsigned int start){ 00018 m_startTime = start; 00019 } 00020 00021 void CondBasicIter::setStopTime(unsigned int stop){ 00022 m_stopTime = stop; 00023 } 00024 00025 void CondBasicIter::setTime(unsigned int time){ 00026 m_time = time; 00027 } 00028 00029 00030 void CondBasicIter::create(const std::string & NameDB,const std::string & File,const std::string & User,const std::string & Pass,const std::string & nameBlob){ 00031 00032 00033 00034 std::string Command1; 00035 Command1 = NameDB; 00036 //You need to write all the sintax like "oracle://cms_orcoff_int2r/SOMETHING" 00037 std::string Command4 = " -t "; 00038 std::string Command5 = File; 00039 std::string Command6 = " -u " + User; 00040 std::string Command7 = " -p " + Pass; 00041 00042 00043 std::cout << "Instructions " << Command1 << Command4 << Command5 << Command6 << Command7 << std::endl; 00044 std::cout << "Blob name = " << nameBlob << std::endl; 00045 00046 std::string tag; 00047 std::string connect; 00048 std::string user = User; 00049 std::string pass = Pass; 00050 00051 connect=Command1; 00052 00053 tag=Command5; 00054 00055 00056 cond::DBSession* session=new cond::DBSession; 00057 session->configuration().setAuthenticationMethod( cond::Env ); 00058 00059 if (nameBlob.size()) { 00060 session->configuration().setBlobStreamer(nameBlob.c_str()); 00061 } 00062 00063 session->configuration().setMessageLevel( cond::Error ); 00064 //session->configuration().connectionConfiguration()->setConnectionRetrialTimeOut( 600 ); 00065 //session->configuration().connectionConfiguration()->enableConnectionSharing(); 00066 //session->configuration().connectionConfiguration()->enableReadOnlySessionOnUpdateConnections(); 00067 std::string userenv(std::string("CORAL_AUTH_USER=")+user); 00068 std::string passenv(std::string("CORAL_AUTH_PASSWORD=")+pass); 00069 00070 if (!myconnection){ 00071 myconnection = new cond::Connection(connect,5000000); 00072 } 00073 if (!pooldb) { 00074 putenv(const_cast<char*>(userenv.c_str())); 00075 putenv(const_cast<char*>(passenv.c_str())); 00076 } 00077 00078 00079 session->open(); 00080 myconnection->connect(session); 00081 cond::CoralTransaction& coraldb=myconnection->coralTransaction(); 00082 cond::MetaData metadata_svc(coraldb); 00083 std::string token; 00084 coraldb.start(true); 00085 00086 token=metadata_svc.getToken(tag); 00087 coraldb.commit(); 00088 int test = 0; 00089 if (!pooldb) { 00090 pooldb = &(myconnection->poolTransaction()); 00091 test = 1; 00092 } 00093 00094 // timetype irrelevant 00095 cond::IOVService iovservice(*pooldb); 00096 //----------------------------------------- 00097 if (ioviterator) { 00098 delete ioviterator; 00099 ioviterator = 0; 00100 } 00101 //----------------------------------------- 00102 00103 ioviterator=iovservice.newIOVIterator(token); 00104 00105 00106 if (test==1){ 00107 pooldb->start(true); 00108 } 00109 00110 // printing out the iteratot size 00111 std::cout<< " ioviterator->size() == " << ioviterator->size() << std::endl; 00112 payloadContainer=iovservice.payloadContainerName(token); 00113 00114 00115 00116 delete session; 00117 00118 00119 //---- inizializer 00120 iter_Min = 0; 00121 iter_Max = 0; 00122 00123 } 00124 00125 void CondBasicIter::setRange(unsigned int min,unsigned int max){ 00126 if (min<max) { 00127 iter_Min = (unsigned int) min; 00128 iter_Max = (unsigned int) max; 00129 std::cout << "min = " << iter_Min << " and max = " << iter_Max << std::endl; 00130 } 00131 else std::cout << "Not possible: Minimum > Maximum" <<std::endl; 00132 } 00133 00134 void CondBasicIter::setMin(unsigned int min){ 00135 if (((unsigned int) min)>iter_Max) std::cout << "Not possible: Minimum > Maximum"; 00136 else iter_Min = (unsigned int) min; 00137 std::cout << "min = " << iter_Min << " and max = " << iter_Max<< std::endl; 00138 00139 } 00140 00141 void CondBasicIter::setMax(unsigned int max){ 00142 if (((unsigned int) max)>=iter_Min) iter_Max = (unsigned int) max; 00143 else std::cout << "Not possible: Maximum < Minimum"; 00144 00145 std::cout << "min = " << iter_Min << " and max = " << iter_Max<< std::endl; 00146 00147 } 00148 00149 void CondBasicIter::setRange(int min,int max){ 00150 try{ 00151 if (min<max) { 00152 iter_Min = (unsigned int) min; 00153 iter_Max = (unsigned int) max; 00154 std::cout << "min = " << iter_Min << " and max = " << iter_Max << std::endl; 00155 } 00156 else throw 1; 00157 }catch(int) { 00158 throw cond::Exception("Not possible: Minimum > Maximum"); 00159 } 00160 } 00161 00162 void CondBasicIter::setMin(int min){ 00163 if (((unsigned int) min)>iter_Max) std::cout << "Not possible: Minimum > Maximum"; 00164 else iter_Min = (unsigned int) min; 00165 std::cout << "min = " << iter_Min << " and max = " << iter_Max<< std::endl; 00166 } 00167 00168 void CondBasicIter::setMax(int max){ 00169 if (((unsigned int) max)<iter_Min) std::cout << "Not possible: Maximum < Minimum"; 00170 else iter_Max = (unsigned int) max; 00171 std::cout << "min = " << iter_Min << " and max = " << iter_Max<< std::endl; 00172 } 00173 00174 unsigned int CondBasicIter::getMin(){return iter_Min;} 00175 00176 unsigned int CondBasicIter::getMax(){return iter_Max;} 00177 00178 void CondBasicIter::getRange(unsigned int * Min_out,unsigned int * Max_out){ 00179 *Min_out = iter_Min; 00180 *Max_out = iter_Max; 00181 } 00182 00183 00184 unsigned int CondBasicIter::getTime(){return m_time;} 00185 00186 unsigned int CondBasicIter::getStartTime(){return m_startTime;} 00187 00188 unsigned int CondBasicIter::getStopTime(){return m_stopTime;} 00189 00190 00191