Linear Collider Forum

Home » Software Tools » LCIO » Daughter Collections
Re: Daughter Collections [message #1711 is a reply to message #1710] Thu, 19 March 2009 06:12 Go to previous messageGo to previous message
Messages: 125
Registered: July 2005
Location: CERN
Hello Oliver,

I think the LCRelation is not what you want. The Idea behind this is to have a link e.g. from a TrackerHit to the SimTrackerHit it originated from (if I am not mistaken).

Let me start with your second remark:

that the new daughter collections only contain pointers to the original objects

LCCollections always contain pointers to objects, because lcio objects are always created on the heap using new. The special thing about LCCollections is that they own the objects they are pointing to, which means the destructor of LCCollection deletes all objects from memory when the collections itself is deleted.

If you now make a copy of these pointers you have two collections pointing to the same objects, each of them holding the ownership. If you delete one of them, the other one is pointing to objects which no longer exist.

For this purpose there is the subset flag. A collection declared as subset does not take over the ownership, so it does not delete the objects if the collection is deleted. So you want to make the two split collections a subset. The original, unsplit collection just stays intact and own the objects.

  // A collection of tracks from the event.
  LCCollection *trackCollection = event->getCollection("Tracks");

  // We want to split into long an short tracks.
  // These collections are subsets.
  LCCollectionVec *longTracksCollection = new LCCollectionVec(LCIO::TRACK);

  LCCollectionVec *shortTracks = new LCCollectionVec(LCIO::TRACK);

  for (int i = 0; i < trackCollection->getNumberOfElements() ; i++)
    Track * mytrack = dynamic_cast<Track *>(trackCollection->getElementAt(i));

    if (mytrack->getTrackerHits().size() > 5)

  // Add the collections to the event.
  // Make sure the original collection is not set transient, otherwise
  // the track objects are not in the data file.
  event->addCollection( longTracksCollection );
  event->addCollection( shortTracksCollection );



Martin Killenberg

Read Message
Read Message
Read Message
Read Message
Previous Topic:easier way to test if an object is in an collection?
Next Topic:lsh: this event does not exist
Goto Forum:

Current Time: Wed Dec 11 22:33:59 Pacific Standard Time 2019
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.1.
Copyright ©2001-2010 FUDforum Bulletin Board Software