ATLAS Offline Software
Loading...
Searching...
No Matches
Athena::RootConnection Class Reference

This class provides the implementation of Athena::RootConnection class, similar to Gaudi IDataConnection. More...

#include <RootConnection.h>

Collaboration diagram for Athena::RootConnection:

Public Member Functions

 RootConnection (const IInterface *own, const std::string &pfn)
 Standard constructor.
virtual ~RootConnection ()
 Standard destructor.
StatusCode connectRead ()
 Open data stream in read mode.
StatusCode connectWrite (const std::string &mode)
 Open data stream in write mode.
StatusCode commit ()
 Commit data stream to ROOT.
StatusCode disconnect ()
 Release data stream and release implementation dependent resources.
bool isConnected () const
 Check if connected to data source.
StatusCode read (void *const data, size_t len)
 Read root byte buffer from input stream.
StatusCode write (const void *data, unsigned long &len)
 Write root byte buffer to output stream.
StatusCode setContainer (const std::string &container, const std::string &type)
 Set the container name and type, creating TTree and TBranch as needed.

Private Attributes

std::string m_fid
 File ID of the connection.
std::string m_pfn
 Physical file name of the connection.
TFile * m_file
 Age counter.
TTree * m_tree
 Pointer to the main event data tree.
TBranch * m_branch
 Pointer to the current data branch.
char m_branchTypeCode
 Branch typecode for branch we are asked to write out.

Detailed Description

This class provides the implementation of Athena::RootConnection class, similar to Gaudi IDataConnection.

Definition at line 35 of file RootConnection.h.

Constructor & Destructor Documentation

◆ RootConnection()

Athena::RootConnection::RootConnection ( const IInterface * own,
const std::string & pfn )

Standard constructor.

Definition at line 62 of file RootConnection.cxx.

62 :
63 m_fid(),
64 m_pfn(pfn),
65 m_file(0),
66 m_tree(0),
67 m_branch(0),
68 m_branchTypeCode('\0') {
69}
TFile * m_file
Age counter.
std::string m_fid
File ID of the connection.
std::string m_pfn
Physical file name of the connection.
char m_branchTypeCode
Branch typecode for branch we are asked to write out.
TTree * m_tree
Pointer to the main event data tree.
TBranch * m_branch
Pointer to the current data branch.

◆ ~RootConnection()

Athena::RootConnection::~RootConnection ( )
virtual

Standard destructor.

Definition at line 71 of file RootConnection.cxx.

71 {
72}

Member Function Documentation

◆ commit()

StatusCode Athena::RootConnection::commit ( )

Commit data stream to ROOT.

Definition at line 96 of file RootConnection.cxx.

96 {
97 if (m_file == 0) {
98 REPORT_MESSAGE (MSG::ERROR) << "commit: No file connected!";
99 return StatusCode::FAILURE;
100 }
101 if (m_tree !=0 && m_branch != 0) {
102 m_tree->SetEntries(m_branch->GetEntries());
103 }
104 //FIXME: call OptimizeBaskets()
105 //m_tree->AutoSave();
106 //m_tree->FlushBaskets();
107 return StatusCode::SUCCESS;
108}
#define REPORT_MESSAGE(LVL)
Report a message.

◆ connectRead()

StatusCode Athena::RootConnection::connectRead ( )

Open data stream in read mode.

Definition at line 74 of file RootConnection.cxx.

74 {
75 if (m_file == 0) {
76 m_file = TFile::Open(m_pfn.c_str());
77 }
78 if (m_file == 0 || m_file->IsZombie()) {
79 delete m_file; m_file = 0;
80 return StatusCode::FAILURE;
81 }
82 return StatusCode::SUCCESS;
83}

◆ connectWrite()

StatusCode Athena::RootConnection::connectWrite ( const std::string & mode)

Open data stream in write mode.

Definition at line 85 of file RootConnection.cxx.

85 {
86 if (m_file == 0) {
87 m_file = TFile::Open(m_pfn.c_str(), mode.c_str(), "AthenaRoot event data file");
88 }
89 if (m_file == 0 || m_file->IsZombie()) {
90 delete m_file; m_file = 0;
91 return StatusCode::FAILURE;
92 }
93 return StatusCode::SUCCESS;
94}

◆ disconnect()

StatusCode Athena::RootConnection::disconnect ( )

Release data stream and release implementation dependent resources.

Definition at line 110 of file RootConnection.cxx.

110 {
111 if (!this->commit().isSuccess()) {
112 return StatusCode::FAILURE;
113 }
114 if (m_tree != 0 && m_file->IsWritable()) {
115 m_file->cd("/");
116 m_tree->Write(); m_tree = 0;
117 }
118 m_file->Close(); m_file = 0;
119 return StatusCode::SUCCESS;
120}
StatusCode commit()
Commit data stream to ROOT.

◆ isConnected()

bool Athena::RootConnection::isConnected ( ) const

Check if connected to data source.

Definition at line 122 of file RootConnection.cxx.

122 {
123 return false;
124}

◆ read()

StatusCode Athena::RootConnection::read ( void *const data,
size_t len )

Read root byte buffer from input stream.

Definition at line 126 of file RootConnection.cxx.

126 {
127 return StatusCode::FAILURE;
128}

◆ setContainer()

StatusCode Athena::RootConnection::setContainer ( const std::string & container,
const std::string & type )

Set the container name and type, creating TTree and TBranch as needed.

Definition at line 148 of file RootConnection.cxx.

148 {
149 if (m_file == 0) {
150 return StatusCode::FAILURE;
151 }
152 std::string treeName(container), branchName;
153 for (std::string::iterator itr = treeName.begin(), iend = treeName.end(); itr != iend; ++itr) {
154 if (*itr == '/') *itr = '_';
155 }
156 std::string::size_type inx1 = container.find('(');
157 if (inx1 != std::string::npos) {
158 std::string::size_type inx2 = container.find(')');
159 if (inx2 == std::string::npos || inx2 != container.size() - 1) {
160 return StatusCode::FAILURE;
161 }
162 branchName = treeName.substr(inx1 + 1, inx2 - inx1 - 1);
163 treeName.resize(inx1);//inx1 was already checked
164 }
165 if (m_tree == 0) {
166 m_tree = (TTree*)m_file->Get(treeName.c_str());
167 }
168 if (m_tree == 0 && m_file->IsWritable()) {
169 int splitlevel = 0; //FIXME: Make configurable
170 m_file->cd("/");
171 m_tree = new TTree(treeName.c_str(), "Main event data tree", splitlevel);
172 m_tree->SetDirectory(m_file);
173 m_tree->Reset();
174 }
175 if (!m_tree)
176 return StatusCode::FAILURE;
177 m_branch = m_tree->GetBranch(branchName.c_str());
178 RootType root_type = RootType::ByNameNoQuiet(type);
179 m_branchTypeCode = ::typecode_from_typeid(root_type.TypeInfo());
180 if (m_branch == 0 && m_file->IsWritable()) {
181 int bufsize = 32000; //FIXME: Make configurable
182 int splitlevel = 0; //FIXME: Make configurable
183 if (m_branchTypeCode == '\0') {
184 m_branch = m_tree->Bronch(branchName.c_str(),
185 type.c_str(),
186 0,
187 bufsize,
188 splitlevel);
189 } else {
190 m_branch = m_tree->Branch(branchName.c_str(),
191 0,
192 (branchName + "/" + m_branchTypeCode).c_str(),
193 bufsize);
194 }
195 if (m_branch != 0) {
196 // let the Athena framework deal with deletion
197 m_branch->SetAutoDelete(kFALSE);
198 int level = 1; //FIXME: Make configurable
199 m_branch->SetCompressionLevel(level);
200 }
201 }
202 if (m_branch == 0) {
203 return StatusCode::FAILURE;
204 }
205 return StatusCode::SUCCESS;
206}
TTypeAdapter RootType
Definition RootType.h:211
static TScopeAdapter ByNameNoQuiet(const std::string &name, Bool_t load=kTRUE)
Definition RootType.cxx:586
const std::type_info & TypeInfo() const
Definition RootType.cxx:684

◆ write()

StatusCode Athena::RootConnection::write ( const void * data,
unsigned long & len )

Write root byte buffer to output stream.

Definition at line 130 of file RootConnection.cxx.

130 {
131 void* address ATLAS_THREAD_SAFE = const_cast<void*>(data);
132 if (m_file == 0 || m_tree == 0 || m_branch == 0) {
133 return StatusCode::FAILURE;
134 }
135 if (m_branchTypeCode == '\0') {
136 m_branch->SetAddress(&address);
137 } else {
138 m_branch->SetAddress(address);
139 }
140 int32_t nbytes = m_branch->Fill();
141 if (nbytes < 0) {
142 return StatusCode::FAILURE;
143 }
144 len = m_branch->GetEntryNumber();
145 return StatusCode::SUCCESS;
146}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
#define ATLAS_THREAD_SAFE

Member Data Documentation

◆ m_branch

TBranch* Athena::RootConnection::m_branch
private

Pointer to the current data branch.

Definition at line 82 of file RootConnection.h.

◆ m_branchTypeCode

char Athena::RootConnection::m_branchTypeCode
private

Branch typecode for branch we are asked to write out.

Definition at line 84 of file RootConnection.h.

◆ m_fid

std::string Athena::RootConnection::m_fid
private

File ID of the connection.

Definition at line 69 of file RootConnection.h.

◆ m_file

TFile* Athena::RootConnection::m_file
private

Age counter.

Owner pointer Pointer to the Root event data file

Definition at line 78 of file RootConnection.h.

◆ m_pfn

std::string Athena::RootConnection::m_pfn
private

Physical file name of the connection.

Definition at line 71 of file RootConnection.h.

◆ m_tree

TTree* Athena::RootConnection::m_tree
private

Pointer to the main event data tree.

Definition at line 80 of file RootConnection.h.


The documentation for this class was generated from the following files: