GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TDetBuildingLoop.cxx
Go to the documentation of this file.
1#include "TDetBuildingLoop.h"
2
3#include <chrono>
4#include <thread>
5
6#include "TUnpackedEvent.h"
7
9{
10 if(name.length() == 0) {
11 name = "unpack_loop";
12 }
13 auto* loop = static_cast<TDetBuildingLoop*>(StoppableThread::Get(name));
14 if(loop == nullptr) {
15 loop = new TDetBuildingLoop(name);
16 }
17 return loop;
18}
19
21 : StoppableThread(std::move(name)),
22 fInputQueue(std::make_shared<ThreadsafeQueue<std::vector<std::shared_ptr<const TFragment>>>>())
23{
24}
25
27
29{
30 std::vector<std::shared_ptr<const TFragment>> frags;
31
32 InputSize(fInputQueue->Pop(frags));
33 if(InputSize() < 0) {
34 InputSize(0);
35 }
36
37 if(frags.empty()) {
38 if(fInputQueue->IsFinished()) {
39 for(const auto& outQueue : fOutputQueues) {
40 outQueue->SetFinished();
41 }
42 return false;
43 }
44 std::this_thread::sleep_for(std::chrono::milliseconds(100));
45 return true;
46 }
48
49 std::shared_ptr<TUnpackedEvent> outputEvent = std::make_shared<TUnpackedEvent>();
50 outputEvent->SetRawData(frags);
51 outputEvent->Build();
52 for(const auto& outQueue : fOutputQueues) {
53 outQueue->Push(outputEvent);
54 }
55
56 return true;
57}
58
60{
61 std::vector<std::shared_ptr<const TFragment>> rawEvent;
62 while(fInputQueue->Size() != 0u) {
63 fInputQueue->Pop(rawEvent);
64 }
65
66 for(const auto& outQueue : fOutputQueues) {
67 while(outQueue->Size() != 0u) {
68 std::shared_ptr<TUnpackedEvent> event;
69 outQueue->Pop(event);
70 }
71 }
72}
std::atomic_long & InputSize()
static StoppableThread * Get(const std::string &name)
void IncrementItemsPopped()
void ClearQueue() override
std::shared_ptr< ThreadsafeQueue< std::vector< std::shared_ptr< const TFragment > > > > fInputQueue
bool Iteration() override
TDetBuildingLoop(const TDetBuildingLoop &)=delete
std::vector< std::shared_ptr< ThreadsafeQueue< std::shared_ptr< TUnpackedEvent > > > > fOutputQueues
static TDetBuildingLoop * Get(std::string name="")