ATLAS Offline Software
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
ActsExCellWriterSvc Class Reference

#include <ActsExCellWriterSvc.h>

Inheritance diagram for ActsExCellWriterSvc:
Collaboration diagram for ActsExCellWriterSvc:

Public Member Functions

virtual StatusCode initialize () override
 
virtual StatusCode finalize () override
 
 ActsExCellWriterSvc (const std::string &name, ISvcLocator *svc)
 
void store (std::vector< Acts::ExtrapolationCell< Acts::TrackParameters >> &ecells) override
 

Private Types

using ExCellCharged = Acts::ExtrapolationCell< Acts::TrackParameters >
 
using queue_item_t = std::pair< size_t, ExCellCharged >
 

Private Member Functions

void doWrite ()
 

Private Attributes

std::shared_ptr< RootExCellWriter< Acts::TrackParameters > > m_rootEccWriter
 
std::deque< queue_item_tm_queue
 
std::mutex m_chargedMutex
 
std::thread m_writeThread
 
std::atomic< bool > m_doEnd
 
Gaudi::Property< std::string > m_filePath {this, "FilePath", "excells_charged.root", "Output root file for charged particle"}
 
Gaudi::Property< std::string > m_treeName {this, "TreeName", "extrapolation_charged", ""}
 
Gaudi::Property< bool > m_writeBoundary {this, "WriteBoundary", true, ""}
 
Gaudi::Property< bool > m_writeMaterial {this, "WriteMaterial", true, ""}
 
Gaudi::Property< bool > m_writeSensitive {this, "WriteSensitive", true, ""}
 
Gaudi::Property< bool > m_writePassive {this, "WritePassive", true, ""}
 

Detailed Description

Definition at line 34 of file ActsExCellWriterSvc.h.

Member Typedef Documentation

◆ ExCellCharged

using ActsExCellWriterSvc::ExCellCharged = Acts::ExtrapolationCell<Acts::TrackParameters>
private

Definition at line 46 of file ActsExCellWriterSvc.h.

◆ queue_item_t

using ActsExCellWriterSvc::queue_item_t = std::pair<size_t, ExCellCharged>
private

Definition at line 48 of file ActsExCellWriterSvc.h.

Constructor & Destructor Documentation

◆ ActsExCellWriterSvc()

ActsExCellWriterSvc::ActsExCellWriterSvc ( const std::string &  name,
ISvcLocator *  svc 
)

Definition at line 15 of file ActsExCellWriterSvc.cxx.

16 : base_class(name, svc) {
17 }

Member Function Documentation

◆ doWrite()

void ActsExCellWriterSvc::doWrite ( )
private

Definition at line 65 of file ActsExCellWriterSvc.cxx.

66 {
67  using namespace std::chrono_literals;
68  // wait until we have events
69  while(m_queue.empty()) {
70  std::this_thread::sleep_for(2s);
71  if (m_doEnd) return;
72  }
73 
74  while(true) {
75  std::unique_lock<std::mutex> lock(m_chargedMutex);
76 
77  if (m_queue.empty()) {
78  lock.unlock();
79  if (!m_doEnd) {
80  std::this_thread::sleep_for(0.5s);
81  continue;
82  } else {
83  ATH_MSG_INFO("Writer thread caught termination signal. Shutting down.");
84  m_rootEccWriter->endRun();
85  return;
86  }
87  }
88 
89  queue_item_t queue_item = std::move(m_queue.front());
90  m_queue.pop_front();
91 
92  lock.unlock();
93 
94  size_t eventNum = queue_item.first;
95  ExCellCharged ecell = std::move(queue_item.second);
96 
97  m_rootEccWriter->write(ecell, eventNum);
98  }
99 
100  //std::vector<ExCellCharged> writeBuffer;
101 
102  //while(true) {
103  //std::unique_lock<std::mutex> lock(m_chargedMutex);
104  //if (m_exCells.size() < 1000 && !m_doEnd) {
105  //lock.unlock();
106  //std::this_thread::sleep_for(0.2s);
107  //continue;
108  //}
109 
111  //writeBuffer.reserve(m_exCells.size());
112  //while(!m_exCells.empty()) {
113  //writeBuffer.push_back(std::move(m_exCells.front()));
114  //m_exCells.pop_front();
115  //}
116 
118  //lock.unlock();
119 
121  //for(auto &ecell : writeBuffer) {
122  //m_rootEccWriter->write(std::move(ecell));
123  //}
124  //writeBuffer.clear();
125 
126  //if (m_doEnd) {
127  //lock.lock();
128  //while(!m_exCells.empty()) {
129  //m_rootEccWriter->write(std::move(m_exCells.front()));
130  //m_exCells.pop_front();
131  //}
132  //lock.unlock();
133  //break;
134  //}
135 
136  //}
137 
138 }

◆ finalize()

StatusCode ActsExCellWriterSvc::finalize ( )
overridevirtual

Definition at line 41 of file ActsExCellWriterSvc.cxx.

42 {
43  ATH_MSG_INFO("Waiting for writer thread to finish.");
44  m_doEnd = true;
45  m_writeThread.join();
46  ATH_MSG_INFO("Writer thread has terminated.");
47 
48  return StatusCode::SUCCESS;
49 }

◆ initialize()

StatusCode ActsExCellWriterSvc::initialize ( )
overridevirtual

Definition at line 20 of file ActsExCellWriterSvc.cxx.

21 {
23  reccWriterConfig.filePath = m_filePath;
24  reccWriterConfig.treeName = m_treeName;
25  reccWriterConfig.writeBoundary = m_writeBoundary;
26  reccWriterConfig.writeMaterial = m_writeMaterial;
27  reccWriterConfig.writeSensitive = m_writeSensitive;
28  reccWriterConfig.writePassive = m_writePassive;
30  = std::make_shared<RootExCellWriter<Acts::TrackParameters>>(
31  reccWriterConfig);
32 
33  ATH_MSG_INFO("Starting writer thread");
34  m_doEnd = false;
35  m_writeThread = std::thread(&ActsExCellWriterSvc::doWrite, this);
36 
37  return StatusCode::SUCCESS;
38 }

◆ store()

void ActsExCellWriterSvc::store ( std::vector< Acts::ExtrapolationCell< Acts::TrackParameters >> &  ecells)
override

Definition at line 52 of file ActsExCellWriterSvc.cxx.

53 {
54 
55  const auto& ctx = Gaudi::Hive::currentContext();
56 
57  std::lock_guard<std::mutex> lock(m_chargedMutex);
58 
59  for(size_t i=0;i<ecells.size();++i) {
60  m_queue.emplace_back(ctx.eventID().event_number(), std::move(ecells[i]));
61  }
62 }

Member Data Documentation

◆ m_chargedMutex

std::mutex ActsExCellWriterSvc::m_chargedMutex
private

Definition at line 52 of file ActsExCellWriterSvc.h.

◆ m_doEnd

std::atomic<bool> ActsExCellWriterSvc::m_doEnd
private

Definition at line 54 of file ActsExCellWriterSvc.h.

◆ m_filePath

Gaudi::Property<std::string> ActsExCellWriterSvc::m_filePath {this, "FilePath", "excells_charged.root", "Output root file for charged particle"}
private

Definition at line 59 of file ActsExCellWriterSvc.h.

◆ m_queue

std::deque<queue_item_t> ActsExCellWriterSvc::m_queue
private

Definition at line 51 of file ActsExCellWriterSvc.h.

◆ m_rootEccWriter

std::shared_ptr<RootExCellWriter<Acts::TrackParameters> > ActsExCellWriterSvc::m_rootEccWriter
private

Definition at line 50 of file ActsExCellWriterSvc.h.

◆ m_treeName

Gaudi::Property<std::string> ActsExCellWriterSvc::m_treeName {this, "TreeName", "extrapolation_charged", ""}
private

Definition at line 60 of file ActsExCellWriterSvc.h.

◆ m_writeBoundary

Gaudi::Property<bool> ActsExCellWriterSvc::m_writeBoundary {this, "WriteBoundary", true, ""}
private

Definition at line 61 of file ActsExCellWriterSvc.h.

◆ m_writeMaterial

Gaudi::Property<bool> ActsExCellWriterSvc::m_writeMaterial {this, "WriteMaterial", true, ""}
private

Definition at line 62 of file ActsExCellWriterSvc.h.

◆ m_writePassive

Gaudi::Property<bool> ActsExCellWriterSvc::m_writePassive {this, "WritePassive", true, ""}
private

Definition at line 64 of file ActsExCellWriterSvc.h.

◆ m_writeSensitive

Gaudi::Property<bool> ActsExCellWriterSvc::m_writeSensitive {this, "WriteSensitive", true, ""}
private

Definition at line 63 of file ActsExCellWriterSvc.h.

◆ m_writeThread

std::thread ActsExCellWriterSvc::m_writeThread
private

Definition at line 53 of file ActsExCellWriterSvc.h.


The documentation for this class was generated from the following files:
ActsExCellWriterSvc::m_writeThread
std::thread m_writeThread
Definition: ActsExCellWriterSvc.h:53
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
ActsExCellWriterSvc::m_writePassive
Gaudi::Property< bool > m_writePassive
Definition: ActsExCellWriterSvc.h:64
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ActsExCellWriterSvc::queue_item_t
std::pair< size_t, ExCellCharged > queue_item_t
Definition: ActsExCellWriterSvc.h:48
ActsExCellWriterSvc::m_writeSensitive
Gaudi::Property< bool > m_writeSensitive
Definition: ActsExCellWriterSvc.h:63
ActsExCellWriterSvc::m_writeMaterial
Gaudi::Property< bool > m_writeMaterial
Definition: ActsExCellWriterSvc.h:62
ActsExCellWriterSvc::doWrite
void doWrite()
Definition: ActsExCellWriterSvc.cxx:65
lumiFormat.i
int i
Definition: lumiFormat.py:85
ActsExCellWriterSvc::m_doEnd
std::atomic< bool > m_doEnd
Definition: ActsExCellWriterSvc.h:54
ActsExCellWriterSvc::m_queue
std::deque< queue_item_t > m_queue
Definition: ActsExCellWriterSvc.h:51
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ActsExCellWriterSvc::m_rootEccWriter
std::shared_ptr< RootExCellWriter< Acts::TrackParameters > > m_rootEccWriter
Definition: ActsExCellWriterSvc.h:50
ActsExCellWriterSvc::ExCellCharged
Acts::ExtrapolationCell< Acts::TrackParameters > ExCellCharged
Definition: ActsExCellWriterSvc.h:46
ActsExCellWriterSvc::m_filePath
Gaudi::Property< std::string > m_filePath
Definition: ActsExCellWriterSvc.h:59
ActsExCellWriterSvc::m_writeBoundary
Gaudi::Property< bool > m_writeBoundary
Definition: ActsExCellWriterSvc.h:61
RootExCellWriter
Definition: ActsExCellWriterSvc.h:23
ActsExCellWriterSvc::m_chargedMutex
std::mutex m_chargedMutex
Definition: ActsExCellWriterSvc.h:52
ActsExCellWriterSvc::m_treeName
Gaudi::Property< std::string > m_treeName
Definition: ActsExCellWriterSvc.h:60