ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
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. More...
 
virtual ~RootConnection ()
 Standard destructor. More...
 
StatusCode connectRead ()
 Open data stream in read mode. More...
 
StatusCode connectWrite (const std::string &mode)
 Open data stream in write mode. More...
 
StatusCode commit ()
 Commit data stream to ROOT. More...
 
StatusCode disconnect ()
 Release data stream and release implementation dependent resources. More...
 
bool isConnected () const
 Check if connected to data source. More...
 
StatusCode read (void *const data, size_t len)
 Read root byte buffer from input stream. More...
 
StatusCode write (const void *data, unsigned long &len)
 Write root byte buffer to output stream. More...
 
StatusCode setContainer (const std::string &container, const std::string &type)
 Set the container name and type, creating TTree and TBranch as needed. More...
 

Private Attributes

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

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 }

◆ ~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 }

◆ 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 }

◆ 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());
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 }

◆ 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 }

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:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
TScopeAdapter::ByNameNoQuiet
static TScopeAdapter ByNameNoQuiet(const std::string &name, Bool_t load=kTRUE)
Definition: RootType.cxx:581
Athena::RootConnection::m_pfn
std::string m_pfn
Physical file name of the connection.
Definition: RootConnection.h:71
Athena::RootConnection::commit
StatusCode commit()
Commit data stream to ROOT.
Definition: RootConnection.cxx:96
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
TScopeAdapter::TypeInfo
const std::type_info & TypeInfo() const
Definition: RootType.cxx:679
Athena::RootConnection::m_fid
std::string m_fid
File ID of the connection.
Definition: RootConnection.h:69
Athena::RootConnection::m_file
TFile * m_file
Age counter.
Definition: RootConnection.h:78
dumpFileToPlots.treeName
string treeName
Definition: dumpFileToPlots.py:20
Preparation.mode
mode
Definition: Preparation.py:94
RTTAlgmain.address
address
Definition: RTTAlgmain.py:55
REPORT_MESSAGE
#define REPORT_MESSAGE(LVL)
Report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:365
Athena::RootConnection::m_tree
TTree * m_tree
Pointer to the main event data tree.
Definition: RootConnection.h:80
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
Athena::RootConnection::m_branch
TBranch * m_branch
Pointer to the current data branch.
Definition: RootConnection.h:82
Athena::RootConnection::m_branchTypeCode
char m_branchTypeCode
Branch typecode for branch we are asked to write out.
Definition: RootConnection.h:84
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
TScopeAdapter
Definition: RootType.h:119