ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtHDF5ReadTask.cxx
Go to the documentation of this file.
1 #include "AtHDF5ReadTask.h"
2 
3 #include "AtEvent.h"
4 #include "AtHit.h"
5 
6 #include <FairLogger.h> // for LOG
7 #include <FairRootManager.h> // for FairRootManager
8 
9 #include <TObject.h> // for TObject
10 
11 #include <H5Cpp.h>
12 
13 #include <utility> // for move
14 
15 AtHDF5ReadTask::AtHDF5ReadTask(TString fileName, TString outputBranchName)
16  : fInputFileName(std::move(fileName)), fOutputBranchName(std::move(outputBranchName)), fEventArray("AtEvent", 1)
17 {
18 }
19 
21 {
22 
23  FairRootManager *ioMan = FairRootManager::Instance();
24  if (ioMan == nullptr) {
25  LOG(ERROR) << "Cannot find RootManager!";
26  return kERROR;
27  }
28 
29  ioMan->Register(fOutputBranchName, "AtTPC", &fEventArray, fIsPersistence);
30 
31  // TODO: Here is where we will need to open the HDF5 file
32 
33  return kSUCCESS;
34 }
35 
36 void AtHDF5ReadTask::Exec(Option_t *opt)
37 {
38  // You will want to do something like this I think:
39  // http://davis.lbl.gov/Manuals/HDF5-1.6.5/cpplus_RM/h5group_8cpp-example.html starting from the comment "Now reopen
40  // the group in the file"
41 
42  // Because events are indexted by their event number the opening line will be something like
43  auto eventGroup = std::make_unique<H5::Group>(fFile->openGroup(TString::Format("Event_[%d]", fEventNum++)));
44 
45  // Then we create the event to fill
46  auto *event = dynamic_cast<AtEvent *>(fEventArray.ConstructedAt(0, "C")); // Get and clear old event
47 
48  // Then we will look for the hits in the event group and add them to the event. This will involve
49  // iterating through the dataset. The code in the loop will look something like.
50  AtHit_t hitFromFile{};
51  event->AddHit(-1, AtHit::XYZPoint(hitFromFile.x, hitFromFile.y, hitFromFile.z), hitFromFile.A);
52 
53  // After this loop filling the event, I don't think there is anything else to do
54 }
55 
AtHit::XYZPoint
ROOT::Math::XYZPoint XYZPoint
Definition: AtHit.h:29
AtHDF5ReadTask::fOutputBranchName
TString fOutputBranchName
Definition: AtHDF5ReadTask.h:22
AtEvent.h
AtHDF5ReadTask::fEventNum
Int_t fEventNum
Definition: AtHDF5ReadTask.h:28
AtHDF5ReadTask
Definition: AtHDF5ReadTask.h:18
AtHDF5ReadTask::fEventArray
TClonesArray fEventArray
Definition: AtHDF5ReadTask.h:25
AtHDF5ReadTask::Exec
virtual void Exec(Option_t *opt) override
Definition: AtHDF5ReadTask.cxx:36
AtHDF5ReadTask::fIsPersistence
Bool_t fIsPersistence
Definition: AtHDF5ReadTask.h:27
AtEvent
Definition: AtEvent.h:22
AtHDF5ReadTask::fFile
std::unique_ptr< H5::H5File > fFile
Definition: AtHDF5ReadTask.h:24
AtHit.h
AtHDF5ReadTask::Init
virtual InitStatus Init() override
Definition: AtHDF5ReadTask.cxx:20
AtHDF5ReadTask.h
AtHit_t
Definition: AtHit.h:125
AtHDF5ReadTask::AtHDF5ReadTask
AtHDF5ReadTask(TString fileName, TString outputBranchName="AtEventH")
Definition: AtHDF5ReadTask.cxx:15
ClassImp
ClassImp(AtHDF5ReadTask)