Hi Roger,
On Tue, 2006-07-18 at 09:46 -0230, Roger Mason wrote:
> Hi Christian,
>
> Christian Holm Christensen <cholm_at_nbi.dk> writes:
>
>>> I have seen the examples in the tutorials but they are for MySQL and> > Hence, if you have the appropriate plug-in and setting in your rootrc
> >> Oracle.
> >
> > The SQL database interface of ROOT uses the plug-in architecture.
In many real-life examples, what you want to do is something like
and last but not least
For these cases, and many others, there may exist competing implementation out on the information super high-way - most of them not compatible with each other. Object-Oriented Programming offers a nice way to abstract the tasks mention above into common interface via inheritance. For example
struct Simulation { enum Type { kGeant3, kGeant4, ... }; static Simulation* Create(Type type) { switch (type) { case kGeant3: return new Geant3; case kGeant4: return new Geant4; ... } return 0; } bool Run(); bool Event(); bool MakePrimary(); bool PropagatePrimary(); ... }; struct Geant3 : public Simulation { ... }; struct Geant4 : public Simulation { ... };
There's nothing fancy about this. It's just the power of OOP :-)
ROOT also provides the facilities to load object code dynamically via calls to say `dlopen' or `OpenLibrary'. This means that we could load the concrete implementation of `Simulation' using some sort of look-up or the like:
Simulation*
Simulation::Create(const std::string& name)
{
Library* lib = LibraryLoader::Instance()->Load(name); if (!lib) return 0; Factory* factory = lib->GetFactory("Simulation"); if (!factory) return 0; void* object = factory->Create(); if (!object) return 0; return reinterpretor_cast<Simulation*>(object);}
Combine that with the reflection provided with CINT, which provides the `Factory' part above, and one can load object code on the fly as needed, provided that the code exists, and that you have some sort of mapping from `name' to code. The mapping is by default done in `etc/root/system.rootrc' via simple user editable entries.
This is the `plug-in architecture' or ROOT. The abstract interface, dynamic loading of code based on a mapping look-up.
> > TSQLServer* dbms = TSQLServer::Connect("<dbms>://<host>[:port][/<database>]");
For database connections, the look-up key in the plug-in mapping, is the `<dbms>' part of the connection URI.
> >
> > In your case, using PostgreSQL you need to specify `pgsql' for `<dbms>', that is
> >
> > TSQLServer* dbms = TSQLServer::Connect("pgsql://127.0.0.1/test");
> >
>
> Notwithstanding my comment above, this works. I thought I'd tried
> pgsql://... before posting.
Good chance that you wrote `pqsql' instead of `pgsql' (note that the `g' is miss-typed as a `q') - I know I've done that a thousand times :-)
Yours,
-- ___ | Christian Holm Christensen |_| | ------------------------------------------------------------- | | Address: Sankt Hansgade 23, 1. th. Phone: (+45) 35 35 96 91 _| DK-2200 Copenhagen N Cell: (+45) 24 61 85 91 _| Denmark Office: (+45) 353 25 404 ____| Email: cholm_at_nbi.dk Web: www.nbi.dk/~cholm | |Received on Wed Jul 19 2006 - 01:02:33 MEST
This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:32:00 MET