I’ve used the TTree::MakeSelector to create a selector class to go through some data, and only Store only the first leaf of a branch that has variable sized leafs, into a new rootfile.
Unfortunately, I’m getting only 0’s for each entry in the L.tr.ph branch… but sucessfully copying the data from L.tr.n branch into the new rootfile.
Here’s a snippet of the code I’m using…
(run using:
TChain chain("T")
chain.Add("ROOTfiles/happexsp_1073.root")
chain.Process("src/ObtainData.C++")
I get no ALIC compilation errors).
I think these are the only relevant lines:
In ObtainData.C
void ObtainData::Begin(TTree *tree)
{
Init(tree);
TString option = GetOption();
newFile = new TFile("clean_data.root","recreate");
newTree = new TTree("C","Clean spectrometer data");
newTree->Branch("L.tr.n",&L_tr_n,"L.tr.n/D");
newTree->Branch("L.tr.ph",&L_tr_ph[0],"L.tr.ph/D");
}
Bool_t ObtainData::ProcessCut(Int_t entry)
{
return kTRUE;
}
void ObtainData::ProcessFill(Int_t entry)
{
b_L_tr_ph->GetEntry(entry);
b_L_tr_n->GetEntry(entry);
newTree->Fill();
}
void ObtainData::Terminiate()
{
newFile->Write();
delete newTree;
delete newFile;
}
In ObtainData.h
class ObtainData : public TSelector {
public :
TTree *fChain; //!pointer to the analyzed TTree or TChain
Double_t L_tr_n;
Int_t Ndata_L_tr_ph;
Double_t L_tr_ph[11]; //[Ndata.L.tr.ph]
TBranch *b_L_tr_n; //!
TBranch *b_Ndata_L_tr_ph; //!
TBranch *b_L_tr_ph; //!
ObtainData(TTree *tree=0);
~ObtainData();
void Begin(TTree *tree);
void Init(TTree *tree);
Bool_t Notify();
Bool_t Process(Int_t entry) {return kTRUE;}
Bool_t ProcessCut(Int_t entry);
void ProcessFill(Int_t entry);
void SetOption(const char *option) { fOption = option; }
void SetObject(TObject *obj) { fObject = obj; }
void SetInputList(TList *input) {fInput = input;}
TList *GetOutputList() const { return fOutput; }
void Terminate();
ClassDef(ObtainData,0);
};
#endif
ObtainData::ObtainData(TTree *tree)
{
//
}
ObtainData::~ObtainData()
{
//
}
#ifdef ObtainData_cxx
void ObtainData::Init(TTree *tree)
{ // Set branch addresses
if (tree == 0) return;
fChain = tree;
/* fChain->SetMakeClass(1); */
fChain->SetBranchAddress("L.tr.n",&L_tr_n);
fChain->SetBranchAddress("Ndata.L.tr.ph",&Ndata_L_tr_ph);
fChain->SetBranchAddress("L.tr.ph",L_tr_ph);
Bool_t ObtainData::Notify()
{
b_L_tr_n = fChain->GetBranch("L.tr.n");
b_Ndata_L_tr_ph = fChain->GetBranch("Ndata.L.tr.ph");
b_L_tr_ph = fChain->GetBranch("L.tr.ph");
return kTRUE
}
#endif // #ifdef ObtainData_cxx
Full code is attached… (in all its glory).
ObtainData.tar (70 KB)