next up previous contents
Next: Writing TPhKeyPtr's Up: Database access Previous: TPhKeyPtr's   Contents

Reading TPhKeyPtr's

The first way of making a TPhKeyPtr is to read in an object which already exists in the database. To do this, you just ask for that object by its key:

TPhRunKey runkey(1543);
TPhKeyPtr<TPhRun> run(runkey);
would make run a pointer to a TPhRun object for run 1543. One can condense this syntax and use temporaries:

TPhKeyPtr<TPhRun> run(TPhRunKey(1543));
TPhKeyPtr<TPhPedestalSet>
  peds(TPhCalKey::Select("SIPED",2121,"PHAT5");
where the first statement does the same as in the previous example, and the second statement creates a pointer to a pedestal object referred to by the key discussed in the example in the previous section - the ``best'' set for run 2121.

There are two advantages to using KeyPtr's in this way. First, when you stream an object out to a Root file, any KeyPtr's in the object will write only the key - not the whole object pointed to. When the object is read back in, the key manager will consult the database and recover the object by its stored key, and reattach the pointer. Second, the key manager performs caching of objects, so that objects will generally not be read twice from the database.


next up previous contents
Next: Writing TPhKeyPtr's Up: Database access Previous: TPhKeyPtr's   Contents
Gunther Roland
2000-05-05