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