ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtTabInfoTree.cxx
Go to the documentation of this file.
1 #include "AtTabInfoTree.h"
2 
3 #include <TDirectory.h> // for TDirectory
4 
5 #include <stdexcept> // for invalid_argumet
6 
7 AtTabInfoTree::AtTabInfoTree(TString tree, TString fileName, DataHandling::AtTreeEntry &entryNumber)
8  : AtTabInfoBase(), fReader(tree, TFile::Open(fileName)), fEntryNumber(entryNumber)
9 {
10  // Take ownership of the opened TFile since we are respsonible for deleting the file if opened using
11  // TFile::Open() and fReader has to be directly constructed.
12  fFile = std::unique_ptr<TFile>(dynamic_cast<TFile *>(fReader.GetTree()->GetDirectory()));
13 
14  if (fFile == nullptr)
15  throw std::invalid_argument("Could not open " + fileName);
16  if (fReader.IsZombie())
17  throw std::invalid_argument("Could not find " + tree + " in " + fileName);
18 
19  fEntryNumber.Attach(this); // Done at end so we won't leave a dangling referece in the subject
20 }
22  : AtTabInfoBase(), fReader(tree), fEntryNumber(entryNumber)
23 {
24  if (fReader.IsZombie())
25  throw std::invalid_argument("Could not create TTreeReader! Is the passed tree null?");
26 
27  fEntryNumber.Attach(this); // Done at end so we won't leave a dangling referece in the subject
28 }
30 {
31  if (changedSubject == &fEntryNumber)
32  fReader.SetEntry(fEntryNumber.Get());
33 }
AtTabInfoTree.h
AtTabInfoTree::fFile
std::unique_ptr< TFile > fFile
Definition: AtTabInfoTree.h:32
AtTabInfoBase
Interface for AtTabInfo classes.
Definition: AtTabInfo.h:35
AtTabInfoTree::Update
void Update(DataHandling::AtSubject *changedSubject) override
Definition: AtTabInfoTree.cxx:29
AtTabInfoTree::fEntryNumber
DataHandling::AtTreeEntry & fEntryNumber
Definition: AtTabInfoTree.h:33
DataHandling::AtSubject::Attach
void Attach(AtObserver *observer)
Attach an observer to get notified when this subject changes.
Definition: AtDataSubject.cxx:12
DataHandling::AtSubject
Definition: AtDataSubject.h:24
DataHandling::AtTreeEntry
Subject for the entry number in the FairRoot tree.
Definition: AtViewerManagerSubject.h:17
AtTabInfoTree::fReader
TTreeReader fReader
Definition: AtTabInfoTree.h:31
AtTabInfoTree::AtTabInfoTree
AtTabInfoTree(TString tree, TString fileName, DataHandling::AtTreeEntry &entryNumber)
Definition: AtTabInfoTree.cxx:7
DataHandling::AtTreeEntry::Get
long Get() const
Definition: AtViewerManagerSubject.h:23