TClonesArray with integer elements?

Hello all,

I have an application where I want to have a TTree whose branches are TClonesArrays, and then the TClonesArrays contain simple things like TVector3 or TMCParticle objects. Now, I have need of a branch with a TClonesArray where I want the elements of the TClonesArray to be lists of simple integers. If I could get away with it, having the TClonesArray contain vector elements would work nicely.

Failing that, I don’t see anything I can use as the container class in place of the vector, because the ROOT container classes like TList, etc. require their Add() methods to be passed a TObject-inherited object. I could use a TList of TObjStrings, but that’s terribly wasteful to convert ints to strings just to store them (the same applies for TNtuple, as I have below). I need something like a TObjInt, I suppose, or an alternative solution altogether. This doesn’t seem like it should be this hard though.

I’ve included an excerpt of my script to clarify what I’m doing (it likely will not execute, it’s just to illustrate the main ideas). seg_arr would ideally be some sort of TClonesArray of lists of ints.

  // See tutorials/tree/tcl.C for the example that inspired this:
  TClonesArray *cluster_arr = new TClonesArray("TVector3");
  TClonesArray &cluster_ar = *cluster_arr;

  TClonesArray *ghit_arr = new TClonesArray("TVector3");
  TClonesArray &ghit_ar = *ghit_arr;

  TClonesArray *mc_arr = new TClonesArray("TMCParticle");
  TClonesArray &mc_ar = *mc_arr;

  TClonesArray *seg_arr = new TClonesArray("TNtuple");
  TClonesArray &seg_ar = *seg_arr;

  TFile* out_file = new TFile(outfile, "RECREATE");
  TTree* treeOut = new TTree("events", "Event Data");
  treeOut->Branch("cluster", &cluster_arr, 256000, 0);
  treeOut->Branch("ghit", &ghit_arr, 256000, 0);
  treeOut->Branch("mc", &mc_arr, 256000, 0);
  treeOut->Branch("seg", &seg_arr, 256000, 0);
  cluster_arr->BypassStreamer();
  ghit_arr->BypassStreamer();
  mc_arr->BypassStreamer();
  seg_arr->BypassStreamer();

Thanks,
Matthew Lockner

Hi,

a TClonesArray of vector would almost completely spoil the whole reason of having a TClonesArray. You should instead use a TArrayI - but as that doesn’t derive from TObject you have to wrap it, e.g. like TParameter does in root.cern.ch/root/html/src/TPara … le_.h.html You might be able to use TParameter directly, or you could create your own little wrapper. If all fails just store TH1I which derived from TArrayI.

Cheers, Axel.