From 935e6be0f690d402ca3e04c15dfdd16b12cdaacc Mon Sep 17 00:00:00 2001 From: gwm17 Date: Wed, 13 Jul 2022 10:52:22 -0400 Subject: [PATCH] Simplified file API slightly by modifying the algorithm to sort hits from files in CompassRun --- src/evb/CompassFile.h | 1 - src/evb/CompassRun.cpp | 58 ++++++++++++++++++++---------------------- src/evb/CompassRun.h | 6 ++--- 3 files changed, 29 insertions(+), 36 deletions(-) diff --git a/src/evb/CompassFile.h b/src/evb/CompassFile.h index 193bb70..573c8a5 100644 --- a/src/evb/CompassFile.h +++ b/src/evb/CompassFile.h @@ -35,7 +35,6 @@ namespace EventBuilder { inline bool CheckHitHasBeenUsed() const { return m_hitUsedFlag; } //query to find out if we've used the current hit inline void SetHitHasBeenUsed() { m_hitUsedFlag = true; } //flip the flag to indicate the current hit has been used inline bool IsEOF() const { return m_eofFlag; } //see if we've read all available data - inline bool* GetUsedFlagPtr() { return &m_hitUsedFlag; } inline void AttachShiftMap(ShiftMap* map) { m_smap = map; } inline unsigned int GetSize() const { return m_size; } inline unsigned int GetNumberOfHits() const { return m_nHits; } diff --git a/src/evb/CompassRun.cpp b/src/evb/CompassRun.cpp index 0637f3f..35cd7e0 100644 --- a/src/evb/CompassRun.cpp +++ b/src/evb/CompassRun.cpp @@ -114,43 +114,35 @@ namespace EventBuilder { /* GetHitsFromFiles() is the function which actually retrieves and sorts the data from the individual - files. There are several tricks which allow this to happen. First is that, after sorting, it is impossible - to determine which file the data originally came from (short of parsing the name of the file against board/channel). - However, we need to let the file know that we want it to pull the next hit. To do this, a pointer to the UsedFlag of the file - is retrieved along with the data. This flag is flipped so that on the next hit cycle a new hit is pulled. Second is the use - of a rolling start index. Once a file has gone EOF, we no longer need it. If this is the first file in the list, we can just skip + files. Once a file has gone EOF, we no longer need it. If this is the first file in the list, we can just skip that index all together. In this way, the loop can go from N times to N-1 times. */ bool CompassRun::GetHitsFromFiles() { - std::pair earliestHit = std::make_pair(CompassHit(), nullptr); + //std::pair earliestHit = std::make_pair(CompassHit(), nullptr); + CompassFile* earliestHit = nullptr; for(unsigned int i=startIndex; iGetCurrentHit().timestamp) //if earlier + earliestHit = &m_datafiles[i]; } - if(earliestHit.second == nullptr) + if(earliestHit == nullptr) return false; //Make sure that there actually was a hit - hit = earliestHit.first; - *earliestHit.second = true; + m_hit = earliestHit->GetCurrentHit(); + earliestHit->SetHitHasBeenUsed(); return true; } @@ -158,12 +150,12 @@ namespace EventBuilder { TFile* output = TFile::Open(name.c_str(), "RECREATE"); TTree* outtree = new TTree("Data", "Data"); - outtree->Branch("Board", &hit.board); - outtree->Branch("Channel", &hit.channel); - outtree->Branch("Energy", &hit.energy); - outtree->Branch("EnergyShort", &hit.energyShort); - outtree->Branch("Timestamp", &hit.timestamp); - outtree->Branch("Flags", &hit.flags); + outtree->Branch("Board", &m_hit.board); + outtree->Branch("Channel", &m_hit.channel); + outtree->Branch("Energy", &m_hit.energy); + outtree->Branch("EnergyShort", &m_hit.energyShort); + outtree->Branch("Timestamp", &m_hit.timestamp); + outtree->Branch("Flags", &m_hit.flags); if(!m_smap.IsValid()) { @@ -211,6 +203,7 @@ namespace EventBuilder { TFile* output = TFile::Open(name.c_str(), "RECREATE"); TTree* outtree = new TTree("SortTree", "SortTree"); + CoincEvent event; outtree->Branch("event", &event); if(!m_smap.IsValid()) @@ -249,7 +242,7 @@ namespace EventBuilder { killFlag = true; } else - coincidizer.AddHitToEvent(hit); + coincidizer.AddHitToEvent(m_hit); if(coincidizer.IsEventReady()) { @@ -274,6 +267,7 @@ namespace EventBuilder { TFile* output = TFile::Open(name.c_str(), "RECREATE"); TTree* outtree = new TTree("SortTree", "SortTree"); + CoincEvent event; outtree->Branch("event", &event); if(!m_smap.IsValid()) @@ -319,8 +313,8 @@ namespace EventBuilder { } else { - flagger.CheckFlag(hit.board, hit.channel, hit.flags); - coincidizer.AddHitToEvent(hit); + flagger.CheckFlag(m_hit.board, m_hit.channel, m_hit.flags); + coincidizer.AddHitToEvent(m_hit); } if(coincidizer.IsEventReady()) @@ -354,6 +348,7 @@ namespace EventBuilder { TFile* output = TFile::Open(name.c_str(), "RECREATE"); TTree* outtree = new TTree("SPSTree", "SPSTree"); + ProcessedEvent pevent; outtree->Branch("event", &pevent); if(!m_smap.IsValid()) @@ -408,7 +403,7 @@ namespace EventBuilder { } else { - coincidizer.AddHitToEvent(hit); + coincidizer.AddHitToEvent(m_hit); } if(coincidizer.IsEventReady()) @@ -441,6 +436,7 @@ namespace EventBuilder { TFile* output = TFile::Open(name.c_str(), "RECREATE"); TTree* outtree = new TTree("SPSTree", "SPSTree"); + ProcessedEvent pevent; outtree->Branch("event", &pevent); if(!m_smap.IsValid()) @@ -499,8 +495,8 @@ namespace EventBuilder { } else { - flagger.CheckFlag(hit.board, hit.channel, hit.flags); - coincidizer.AddHitToEvent(hit); + flagger.CheckFlag(m_hit.board, m_hit.channel, m_hit.flags); + coincidizer.AddHitToEvent(m_hit); } if(coincidizer.IsEventReady()) diff --git a/src/evb/CompassRun.h b/src/evb/CompassRun.h index c0a1d8f..780f662 100644 --- a/src/evb/CompassRun.h +++ b/src/evb/CompassRun.h @@ -50,10 +50,8 @@ namespace EventBuilder { ShiftMap m_smap; std::unordered_map> m_scaler_map; //maps scaler files to the TParameter to be saved - //Potential branch variables - CompassHit hit; - CoincEvent event; - ProcessedEvent pevent; + //Raw hit + CompassHit m_hit; //what run is this int m_runNum;