CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CondPyInterface.cc
Go to the documentation of this file.
2 
3 #include <exception>
4 #include <iostream>
5 #include <iomanip>
6 #include <fstream>
7 #include <string>
8 #include <vector>
10 
15 
17 
18 
22 //#include "FWCore/PluginManager/interface/PluginCapabilities.h"
24 
33 
34 #include <iterator>
35 #include <iostream>
36 #include <sstream>
37 
38 
39 namespace cond {
40 
41  static void topinit(){
44  return;
45  }
46 
47  namespace impl {
48  struct FWMagic {
49  // A. Instantiate a plug-in manager first.
51  boost::shared_ptr<edm::ServiceRegistry::Operate> operate;
52  };
53  }
54 
56 
57 
58  FWIncantation::FWIncantation() : magic(new impl::FWMagic) {
59  topinit();
60  // B. Load the message service plug-in. Forget this and bad things happen!
61  // In particular, the job hangs as soon as the output buffer fills up.
62  // That's because, without the message service, there is no mechanism for
63  // emptying the buffers.
64  boost::shared_ptr<edm::Presence> theMessageServicePresence;
65  theMessageServicePresence = boost::shared_ptr<edm::Presence>(edm::PresenceFactory::get()->
66  makePresence("MessageServicePresence").release());
67 
68  // C. Manufacture a configuration and establish it.
69 
70  /*
71  std::string config =
72  "process x = {"
73  "service = MessageLogger {"
74  "untracked vstring destinations = {'infos.mlog','warnings.mlog'}"
75  "untracked PSet infos = {"
76  "untracked string threshold = 'INFO'"
77  "untracked PSet default = {untracked int32 limit = 1000000}"
78  "untracked PSet FwkJob = {untracked int32 limit = 0}"
79  "}"
80  "untracked PSet warnings = {"
81  "untracked string threshold = 'WARNING'"
82  "untracked PSet default = {untracked int32 limit = 1000000}"
83  "}"
84  "untracked vstring fwkJobReports = {'FrameworkJobReport.xml'}"
85  "untracked vstring categories = {'FwkJob'}"
86  "untracked PSet FrameworkJobReport.xml = {"
87  "untracked PSet default = {untracked int32 limit = 0}"
88  "untracked PSet FwkJob = {untracked int32 limit = 10000000}"
89  "}"
90  "}"
91  "service = JobReportService{}"
92  "service = SiteLocalConfigService{}"
93  "}";
94  */
95  /*
96  std::string config =
97  "import FWCore.ParameterSet.Config as cms\n"
98  "process = cms.Process('x')\n"
99  "JobReportService = cms.Service('JobReportService')\n"
100  "SiteLocalConfigService = cms.Service('SiteLocalConfigService')\n"
101  ;
102  */
103 
104  boost::shared_ptr<std::vector<edm::ParameterSet> > psets(new std::vector<edm::ParameterSet>);
105  edm::ParameterSet pSet;
106  pSet.addParameter("@service_type",std::string("SiteLocalConfigService"));
107  psets->push_back(pSet);
108 
109  // D. Create the services.
110  edm::ServiceToken tempToken(edm::ServiceRegistry::createSet(*psets.get()));
111 
112  // E. Make the services available.
113  magic->operate.reset(new edm::ServiceRegistry::Operate(tempToken));
114 
115  }
116 
117  //------------------------------------------------------------
118 
119 
120  CondDB::CondDB() : me(){
121  //topinit();
122  }
123  CondDB::CondDB(cond::DbSession& session, boost::shared_ptr<cond::Logger> ilog) :
124  me(session), logger(ilog) {
125  //topinit();
126  }
127 
128  // move ownership....
129  CondDB::CondDB(const CondDB & other) : me(other.me), logger(other.logger) {
130  }
131 
132  CondDB & CondDB::operator=(const CondDB & other) {
133  if (this==&other) return *this; // unless =0 this is an error condition!
134  me = other.me;
135  logger = other.logger;
136  return *this;
137  }
138 
140  }
141 
142 
143  std::string CondDB::allTags() const {
144  std::ostringstream ss;
145 
146  cond::MetaData metadata_svc(me);
147  std::vector<std::string> alltags;
148  metadata_svc.listAllTags(alltags);
149 
150  std::copy (alltags.begin(),
151  alltags.end(),
152  std::ostream_iterator<std::string>(ss," ")
153  );
154  return ss.str();
155  }
156 
157  std::string CondDB::iovToken(std::string const & tag) const {
158  cond::MetaData metadata_svc(me);
159  std::string token=metadata_svc.getToken(tag);
160  return token;
161  }
162 
163  // fix commit problem....
164  IOVProxy CondDB::iov(std::string const & tag) const {
165  return IOVProxy(me,iovToken(tag));
166  }
167 
168  IOVProxy CondDB::iovWithLib(std::string const & tag) const {
169  return IOVProxy(me,iovToken(tag));
170  }
171 
172  IOVElementProxy CondDB::payLoad(std::string const & token) const {
174  return IOVElementProxy(0,0,token);
175  }
176 
177 
178  cond::LogDBEntry CondDB::lastLogEntry(std::string const & tag) const {
180  if (logger)
181  logger->LookupLastEntryByTag(tag,entry,false);
182  return entry;
183  }
184 
185  cond::LogDBEntry CondDB::lastLogEntryOK(std::string const & tag) const{
187  if (logger)
188  logger->LookupLastEntryByTag(tag,entry,true);
189  return entry;
190  }
191 
193  me.transaction().start();
194  }
196  me.transaction().start(true);
197  }
199  me.transaction().commit();
200  }
201 
202  void CondDB::closeSession() const {
203  //FIXME: does the session disconnection fix the socket failure in FroNTier (bug #84265)?
204  me.close();
205  }
206 
207  RDBMS::RDBMS() : connection(new DbConnection) {
208  //topinit();
209  connection->configure( cond::CmsDefaults );
210  }
212 
213  RDBMS::RDBMS(std::string const & authPath, bool debug) : connection(new DbConnection) {
214  //topinit();
215  connection->configuration().setAuthenticationPath(authPath);
216  if (debug)
217  connection->configuration().setMessageLevel( coral::Debug );
218  else
219  connection->configuration().setMessageLevel( coral::Error );
220  connection->configuration().setPoolAutomaticCleanUp( false );
221  connection->configuration().setConnectionTimeOut(0);
222 
223  connection->configure();
224  }
225 
226  RDBMS::RDBMS(std::string const & user,std::string const & pass) : connection(new DbConnection) {
227  //topinit();
228  std::string userenv(std::string("CORAL_AUTH_USER=")+user);
229  std::string passenv(std::string("CORAL_AUTH_PASSWORD=")+pass);
230  ::putenv(const_cast<char*>(userenv.c_str()));
231  ::putenv(const_cast<char*>(passenv.c_str()));
232  connection->configuration().setMessageLevel( coral::Error );
233  connection->configuration().setPoolAutomaticCleanUp( false );
234  connection->configuration().setConnectionTimeOut(0);
235  connection->configure();
236  }
237 
238  void RDBMS::setLogger(std::string const & connstr) {
239  DbSession loggerSession = connection->createSession();
240  logger.reset(new cond::Logger(loggerSession));
241  logger->connect( connstr, true );
242  }
243 
244 
245 
246  CondDB RDBMS::getDB(std::string const & db) {
247  DbSession dbSession = connection->createSession();
248  dbSession.open( db, cond::Auth::COND_WRITER_ROLE );
249  return CondDB(dbSession,logger);
250  }
251 
252  CondDB RDBMS::getReadOnlyDB(std::string const & db) {
253  DbSession dbSession = connection->createSession();
254  dbSession.open( db, cond::Auth::COND_READER_ROLE, true );
255  return CondDB(dbSession,logger);
256  }
257 
258  GlobalTag const & RDBMS::globalTag(std::string const & connstr,
259  std::string const & gname,
260  std::string const & prefix,
261  std::string const & postfix) const {
262  DbSession session = connection->createSession();
263  session.open( connstr, true );
264  session.transaction().start( true );
265  TagCollectionRetriever gtr(session, prefix,postfix);
266  const_cast<GlobalTag&>(m_globalTag).clear();
267  gtr.getTagCollection(gname,const_cast<GlobalTag&>(m_globalTag));
268  session.transaction().commit();
269  return m_globalTag;
270  }
271 
272 
273 }
GlobalTag m_globalTag
boost::shared_ptr< DbConnection > connection
CondDB getDB(std::string const &db)
IOVProxy iov(std::string const &tag) const
cond::LogDBEntry lastLogEntryOK(std::string const &tag) const
GlobalTag const & globalTag(std::string const &connstr, std::string const &gname, std::string const &prefix, std::string const &postfix) const
static PluginManager & configure(const Config &)
DbTransaction & transaction()
Definition: DbSession.cc:189
void open(const std::string &connectionString, bool readOnly=false)
Definition: DbSession.cc:144
IOVProxy iovWithLib(std::string const &tag) const
void getTagCollection(const std::string &globaltag, std::set< cond::TagMetadata > &result)
std::ostream & logger()
Definition: fwLog.cc:41
int commit()
commit transaction.
tuple db
Definition: EcalCondDB.py:151
edm::AssertHandler ah
void commitTransaction() const
void startTransaction() const
const std::string getToken(const std::string &tagname) const
Definition: MetaData.cc:53
std::string allTags() const
CondDB & operator=(const CondDB &other)
DbSession me
cond::LogDBEntry lastLogEntry(std::string const &tag) const
int start(bool readOnly=false)
start transaction
IOVElementProxy payLoad(std::string const &token) const
boost::shared_ptr< cond::Logger > logger
PluginManager::Config config()
Definition: standard.cc:22
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:168
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:145
static const std::string COND_WRITER_ROLE
Definition: Auth.h:18
static void topinit()
static ServiceToken createSet(std::vector< ParameterSet > &)
std::string iovToken(std::string const &tag) const
static const std::string COND_READER_ROLE
Definition: Auth.h:19
static PresenceFactory * get()
void closeSession() const
tuple alltags
Definition: lumiTag.py:77
void startReadOnlyTransaction() const
boost::shared_ptr< edm::ServiceRegistry::Operate > operate
CondDB getReadOnlyDB(std::string const &db)
boost::shared_ptr< impl::FWMagic > magic
#define debug
Definition: MEtoEDMFormat.h:34
void listAllTags(std::vector< std::string > &result) const
Definition: MetaData.cc:83
boost::shared_ptr< cond::Logger > logger
const bool Debug
void setLogger(std::string const &connstr)