|
ATLAS Offline Software
|
D3PD class used for generating ROOT D3PDReader classes.
More...
#include <RootReaderD3PD_v1.h>
|
typedef unsigned int | Dim_t |
| Currently unimplemented — see design note. More...
|
|
|
| RootReaderD3PD_v1 () |
| Quite empty constructor. More...
|
|
StatusCode | createReader (const std::string &classname, const std::string &dir="./") const |
| Function creating the D3PDReader C++ code. More...
|
|
virtual StatusCode | addVariable (const std::string &name, const std::type_info &ti, void *&ptr, const std::string &docstring="", const void *defval=0) |
| Main function for adding a variable to the D3PD. More...
|
|
template<class T > |
StatusCode | addVariable (const std::string &name, T *&ptr, const std::string &docstring="") |
| Add a variable to the tuple. More...
|
|
template<class T , class U > |
StatusCode | addVariable (const std::string &name, T *&ptr, const std::string &docstring, const U &defval) |
| Add a variable to the tuple. More...
|
|
virtual StatusCode | addDimensionedVariable (const std::string &name, const std::type_info &ti, void *&ptr, const std::string &dim, const std::string &docstring="", const void *defval=0) |
| Function currently not used by the D3PDMaker code. More...
|
|
template<class T > |
StatusCode | addDimensionedVariable (const std::string &name, T *&ptr, const std::string &dim, const std::string &docstring="") |
| Add a variable to the tuple. More...
|
|
template<class T , class U > |
StatusCode | addDimensionedVariable (const std::string &name, T *&ptr, const std::string &dim, const std::string &docstring, const U &defval) |
| Add a variable to the tuple. More...
|
|
virtual StatusCode | addMetadata (const std::string &key, const void *obj, const std::type_info &ti) |
| Function adding metadata to the D3PD. Not implemented here! More...
|
|
template<class T > |
StatusCode | addMetadata (const std::string &key, const T *obj) |
| Add a new piece of metadata to the tuple. More...
|
|
virtual StatusCode | capture () |
| Function capturing the current value of the D3PD variables. Not implemented here! More...
|
|
virtual StatusCode | clear () |
| Function clearing the D3PD variables. Not implemented here! More...
|
|
virtual StatusCode | redim (const Dim_t *ptr) |
| Function currently not used by the D3PDMaker code. More...
|
|
virtual void | setIsContainer (bool isContainer) |
| Set the "isCollection" parameter of the object. More...
|
|
virtual bool | isContainer () const |
| Get the "isCollection" parameter of the object. More...
|
|
virtual void | setPrefix (const std::string &prefix) |
| Set the common prefix of the variables. More...
|
|
virtual const std::string & | prefix () const |
| Get the common prefix of the variables. More...
|
|
D3PD class used for generating ROOT D3PDReader classes.
Version 1 of the D3PDReader implementation.
- Author
- Attila Krasznahorkay Attil.nosp@m.a.Kr.nosp@m.aszna.nosp@m.hork.nosp@m.ay@ce.nosp@m.rn.c.nosp@m.h
- Revision
- 462802
- Date
- 2011-10-12 18:06:24 +0200 (Wed, 12 Oct 2011)
Definition at line 26 of file RootReaderD3PD_v1.h.
◆ Dim_t
Currently unimplemented — see design note.
Definition at line 52 of file ID3PD.h.
◆ RootReaderD3PD_v1()
D3PD::RootReaderD3PD_v1::RootReaderD3PD_v1 |
( |
| ) |
|
◆ addDimensionedVariable() [1/3]
StatusCode D3PD::RootReaderD3PDBase::addDimensionedVariable |
( |
const std::string & |
name, |
|
|
const std::type_info & |
ti, |
|
|
void *& |
ptr, |
|
|
const std::string & |
dim, |
|
|
const std::string & |
docstring = "" , |
|
|
const void * |
defval = 0 |
|
) |
| |
|
virtualinherited |
◆ addDimensionedVariable() [2/3]
template<class T , class U >
StatusCode D3PD::IAddVariable::addDimensionedVariable |
( |
const std::string & |
name, |
|
|
T *& |
ptr, |
|
|
const std::string & |
dim, |
|
|
const std::string & |
docstring, |
|
|
const U & |
defval |
|
) |
| |
|
inherited |
Add a variable to the tuple.
- Parameters
-
name | The name of the variable. |
ptr | Pointer to the type of the variable. The pointer need not be initialized; the D3PD software will set the pointer prior to calling fill() . |
dim | Dimension for the variable. (Presently unimplemented!) |
docstring | Documentation string for this variable. |
defval | Pointer to the default value to use for this variable. Only works for basic types. |
If called from the constructor, the only effect is to clear ptr
.
◆ addDimensionedVariable() [3/3]
template<class T >
StatusCode D3PD::IAddVariable::addDimensionedVariable |
( |
const std::string & |
name, |
|
|
T *& |
ptr, |
|
|
const std::string & |
dim, |
|
|
const std::string & |
docstring = "" |
|
) |
| |
|
inherited |
Add a variable to the tuple.
- Parameters
-
name | The name of the variable. |
ptr | Pointer to the type of the variable. The pointer need not be initialized; the D3PD software will set the pointer prior to calling fill() . |
dim | Dimension for the variable. (Presently unimplemented!) |
docstring | Documentation string for this variable. |
If called from the constructor, the only effect is to clear ptr
.
◆ addMetadata() [1/2]
template<class T >
StatusCode D3PD::ID3PD::addMetadata |
( |
const std::string & |
key, |
|
|
const T * |
obj |
|
) |
| |
|
inherited |
Add a new piece of metadata to the tuple.
- Parameters
-
key | - The key for this object. Any existing object will be overwritten. |
obj | - Pointer to the object to write. |
The interpretation of the key
parameter is up to the concrete D3PD implementation. However, a key name with a trailing slash NAME/ indicates that all metadata items with this name should be grouped together in a collection called NAME (for example, in a Root directory with that name).
◆ addMetadata() [2/2]
StatusCode D3PD::RootReaderD3PDBase::addMetadata |
( |
const std::string & |
key, |
|
|
const void * |
obj, |
|
|
const std::type_info & |
ti |
|
) |
| |
|
virtualinherited |
Function adding metadata to the D3PD. Not implemented here!
Implements D3PD::ID3PD.
Definition at line 107 of file RootReaderD3PDBase.cxx.
112 <<
"addMetadata(...) not implemented";
113 return StatusCode::FAILURE;
◆ addSTLHeader()
void D3PD::RootReaderD3PDBase::addSTLHeader |
( |
std::ostream & |
out, |
|
|
const char * |
name |
|
) |
| const |
|
protectedinherited |
Function adding STL include statements to the header when needed.
This function is used internally to decide if specific STL headers are needed for the generated code or not.
The code just checks if the header name appears in the variable types somewhere, and if it does, it adds the requested header.
- Parameters
-
out | Output stream where the include statement has to be written |
name | Name of the STL header that the code should process |
Definition at line 167 of file RootReaderD3PDBase.cxx.
170 bool header_needed =
false;
171 std::set< D3PD::ObjectMetadata::Variable >::const_iterator itr =
173 std::set< D3PD::ObjectMetadata::Variable >::const_iterator
end =
175 for( ; itr !=
end; ++itr ) {
176 if( itr->type().find(
name ) != std::string::npos ) {
177 header_needed =
true;
183 if( header_needed ) {
184 out <<
"#include <" <<
name <<
">" << std::endl;
◆ addVariable() [1/3]
StatusCode D3PD::RootReaderD3PDBase::addVariable |
( |
const std::string & |
name, |
|
|
const std::type_info & |
ti, |
|
|
void *& |
ptr, |
|
|
const std::string & |
docstring = "" , |
|
|
const void * |
defval = 0 |
|
) |
| |
|
virtualinherited |
◆ addVariable() [2/3]
template<class T , class U >
StatusCode D3PD::IAddVariable::addVariable |
( |
const std::string & |
name, |
|
|
T *& |
ptr, |
|
|
const std::string & |
docstring, |
|
|
const U & |
defval |
|
) |
| |
|
inherited |
Add a variable to the tuple.
- Parameters
-
name | The name of the variable. |
ptr | Pointer to the type of the variable. The pointer need not be initialized; the D3PD software will set the pointer prior to calling fill() . |
docstring | Documentation string for this variable. |
defval | Pointer to the default value to use for this variable. Only works for basic types. |
If called from the constructor, the only effect is to clear ptr
.
◆ addVariable() [3/3]
template<class T >
StatusCode D3PD::IAddVariable::addVariable |
( |
const std::string & |
name, |
|
|
T *& |
ptr, |
|
|
const std::string & |
docstring = "" |
|
) |
| |
|
inherited |
Add a variable to the tuple.
- Parameters
-
name | The name of the variable. |
ptr | Pointer to the type of the variable. The pointer need not be initialized; the D3PD software will set the pointer prior to calling fill() . |
docstring | Documentation string for this variable. |
If called from the constructor, the only effect is to clear ptr
.
◆ capture()
StatusCode D3PD::RootReaderD3PDBase::capture |
( |
| ) |
|
|
virtualinherited |
Function capturing the current value of the D3PD variables. Not implemented here!
Implements D3PD::ID3PD.
Definition at line 116 of file RootReaderD3PDBase.cxx.
119 <<
"capture() not implemented";
120 return StatusCode::FAILURE;
◆ clear()
StatusCode D3PD::RootReaderD3PDBase::clear |
( |
| ) |
|
|
virtualinherited |
Function clearing the D3PD variables. Not implemented here!
Implements D3PD::ID3PD.
Definition at line 123 of file RootReaderD3PDBase.cxx.
126 <<
"clear() not implemented";
127 return StatusCode::FAILURE;
◆ createReader()
StatusCode D3PD::RootReaderD3PD_v1::createReader |
( |
const std::string & |
classname, |
|
|
const std::string & |
dir = "./" |
|
) |
| const |
|
virtual |
Function creating the D3PDReader C++ code.
This is the most interesting function of this class.
It generates a C++ header and source file from all the information that it gathered so far.
- Parameters
-
classname | Name of the C++ class to generate |
dir | Directory where the generated sources should be put |
prefix | Common prefix of the declared variables |
Implements D3PD::IReaderD3PD.
Definition at line 44 of file RootReaderD3PD_v1.cxx.
53 return StatusCode::SUCCESS;
◆ isContainer()
bool D3PD::RootReaderD3PDBase::isContainer |
( |
| ) |
const |
|
virtualinherited |
◆ prefix()
const std::string & D3PD::RootReaderD3PDBase::prefix |
( |
| ) |
const |
|
virtualinherited |
◆ redim()
StatusCode D3PD::RootReaderD3PDBase::redim |
( |
const Dim_t * |
ptr | ) |
|
|
virtualinherited |
Function currently not used by the D3PDMaker code.
Implements D3PD::ID3PD.
Definition at line 130 of file RootReaderD3PDBase.cxx.
133 <<
"redim(...) not implemented";
134 return StatusCode::FAILURE;
◆ setIsContainer()
void D3PD::RootReaderD3PDBase::setIsContainer |
( |
bool |
isContainer | ) |
|
|
virtualinherited |
◆ setPrefix()
void D3PD::RootReaderD3PDBase::setPrefix |
( |
const std::string & |
prefix | ) |
|
|
virtualinherited |
◆ writeHeader()
StatusCode D3PD::RootReaderD3PD_v1::writeHeader |
( |
const std::string & |
classname, |
|
|
const std::string & |
dir |
|
) |
| const |
|
private |
Function creating the D3PDReader C++ header.
Definition at line 56 of file RootReaderD3PD_v1.cxx.
61 <<
"Generating file: " <<
dir <<
"/" << classname <<
".h";
64 std::fstream
header( (
dir +
"/" + classname +
".h" ).c_str(),
68 header << CODE_COMMENT << std::endl;
69 header <<
"#ifndef D3PDREADER_" << classname <<
"_H" << std::endl;
70 header <<
"#define D3PDREADER_" << classname <<
"_H" << std::endl << std::endl;
79 header <<
"#include <TNamed.h>" << std::endl;
80 header <<
"#include <TString.h>" << std::endl << std::endl;
83 header <<
"class TTree;" << std::endl;
84 header <<
"class TBranch;" << std::endl << std::endl;
89 header <<
"namespace " << CODE_NAMESPACE <<
" {" << std::endl << std::endl;
90 header <<
" /**" << std::endl;
91 header <<
" * Code generated by RootD3PDReader_v1 on:" << std::endl;
92 header <<
" * host = " << System::hostName() << std::endl;
93 header <<
" * OS = " << System::osName() <<
" / " << System::osVersion()
95 header <<
" * user = " << System::accountName() << std::endl;
96 time_t rawtime =
time( NULL );
98 header <<
" * time = " << ctime_r( &rawtime, buf );
99 header <<
" */" << std::endl;
100 header <<
" class " << classname <<
" : public TNamed {" << std::endl << std::endl;
101 header <<
" public:" << std::endl;
106 header <<
" /// Constructor specifying the needed parameters" << std::endl;
107 header <<
" " << classname <<
"( Long64_t* master, const char* prefix = \""
113 header <<
" /// Get the currently configured prefix value" << std::endl;
114 header <<
" const char* getPrefix() const;" << std::endl;
115 header <<
" /// Set the prefix to the ntuple variables" << std::endl;
116 header <<
" void setPrefix( const char* prefix );" << std::endl << std::endl;
117 header <<
" /// Connect the object to a new TTree" << std::endl;
118 header <<
" void connect( TTree* tree );" << std::endl << std::endl;
123 std::set< D3PD::ObjectMetadata::Variable >::const_iterator itr =
125 std::set< D3PD::ObjectMetadata::Variable >::const_iterator
end =
127 for( ; itr !=
end; ++itr ) {
128 if( itr->doc() !=
"" ) {
129 header <<
" /// " << itr->doc() << std::endl;
131 header <<
" " << itr->type()
132 << ( itr->primitive() ?
" " :
"* " ) << itr->name() <<
"();"
136 header << std::endl <<
" private:" << std::endl;
141 header <<
" // Variables used in the TTree reading:" << std::endl;
144 for( ; itr !=
end; ++itr ) {
145 header <<
" " << itr->type()
146 << ( itr->primitive() ?
"" :
"*" ) <<
" m_"
147 << itr->name() <<
";" << std::endl;
155 header <<
" // TBranch variables used in the TTree reading:" << std::endl;
158 for( ; itr !=
end; ++itr ) {
159 header <<
" ::TBranch* m_b_" << itr->name() <<
"; //!" << std::endl;
163 header << std::endl <<
" ::TTree* m_tree;" << std::endl;
164 header <<
" Long64_t* m_master;" << std::endl;
165 header <<
" ::TString m_prefix;" << std::endl << std::endl;
168 header <<
" ClassDef( " << classname <<
", 0 )" << std::endl << std::endl;
169 header <<
" }; // class " << classname << std::endl << std::endl;
170 header <<
"} // namespace " << CODE_NAMESPACE << std::endl << std::endl;
171 header <<
"#endif // D3PDREADER_" << classname <<
"_H" << std::endl;
175 return StatusCode::SUCCESS;
◆ writeSource()
StatusCode D3PD::RootReaderD3PD_v1::writeSource |
( |
const std::string & |
classname, |
|
|
const std::string & |
dir |
|
) |
| const |
|
private |
Function creatig the D3PDReader C++ source.
Definition at line 178 of file RootReaderD3PD_v1.cxx.
183 <<
"Generating file: " <<
dir <<
"/" << classname <<
".cxx";
186 std::fstream
source( (
dir +
"/" + classname +
".cxx" ).c_str(),
190 source << CODE_COMMENT << std::endl << std::endl;
193 source <<
"#include <TTree.h>" << std::endl;
194 source <<
"#include <TBranch.h>" << std::endl << std::endl;
197 source <<
"#include \"" << classname <<
".h\"" << std::endl << std::endl;
199 source <<
"ClassImp( D3PDReader::" << classname <<
" )" << std::endl << std::endl;
201 source <<
"namespace " << CODE_NAMESPACE <<
" {" << std::endl << std::endl;
206 source <<
" /**" << std::endl;
207 source <<
" * @param master Pointer to the variable holding the current "
208 <<
"event number" << std::endl;
209 source <<
" * @param prefix Prefix of the variables in the D3PD" << std::endl;
210 source <<
" */" << std::endl;
211 source <<
" " << classname <<
"::" << classname
212 <<
"( Long64_t* master, const char* prefix )" << std::endl;
213 source <<
" : TNamed( \"" << classname <<
"\", \"D3PDReader class\" ),"
215 std::set< D3PD::ObjectMetadata::Variable >::const_iterator itr =
217 std::set< D3PD::ObjectMetadata::Variable >::const_iterator
end =
219 for( ; itr !=
end; ++itr ) {
220 if( itr->primitive() )
continue;
221 source <<
" m_" << itr->name() <<
"( 0 )," << std::endl;
225 for( ; itr !=
end; ++itr ) {
226 source <<
" m_b_" << itr->name() <<
"( 0 )," << std::endl;
228 source <<
" m_tree( 0 ), m_master( master )," << std::endl;
229 source <<
" m_prefix( prefix ) {" << std::endl << std::endl;
230 source <<
" }" << std::endl << std::endl;
235 source <<
" const char* " << classname <<
"::getPrefix() const {" << std::endl
237 source <<
" return m_prefix;" << std::endl;
238 source <<
" }" << std::endl << std::endl;
239 source <<
" void " << classname <<
"::setPrefix( const char* prefix ) {"
240 << std::endl << std::endl;
241 source <<
" m_prefix = prefix;" << std::endl;
242 source <<
" return;" << std::endl;
243 source <<
" }" << std::endl << std::endl;
248 source <<
" /**" << std::endl;
249 source <<
" * This function should be called every time a new TFile is opened"
251 source <<
" * by your analysis code." << std::endl;
252 source <<
" *" << std::endl;
253 source <<
" * @param tree Pointer to the TTree with the variables" << std::endl;
254 source <<
" */" << std::endl;
255 source <<
" void " << classname <<
"::connect( TTree* tree ) {" << std::endl
259 for( ; itr !=
end; ++itr ) {
260 if( ! itr->primitive() ) {
261 source <<
" if( m_" << itr->name() <<
" ) delete m_" << itr->name()
263 source <<
" m_" << itr->name() <<
" = 0;" << std::endl;
265 source <<
" m_b_" << itr->name() <<
" = 0;" << std::endl << std::endl;
267 source <<
" m_tree = tree;" << std::endl << std::endl;
268 source <<
" return;" << std::endl;
269 source <<
" }" << std::endl << std::endl;
276 for( ; itr !=
end; ++itr ) {
277 source <<
" " << itr->type() << ( itr->primitive() ?
" " :
"* " )
278 << classname <<
"::" << itr->name()
279 <<
"() {" << std::endl << std::endl;
280 source <<
" if( ! m_b_" << itr->name() <<
" ) {" << std::endl;
281 source <<
" if( ! m_tree ) {" << std::endl;
282 source <<
" Error( \"Connect\", \"Object not connected yet!\" );"
284 source <<
" return 0;" << std::endl;
285 source <<
" }" << std::endl;
286 source <<
" if( ! m_tree->GetBranch( m_prefix + \"" << itr->name()
287 <<
"\" ) ) {" << std::endl;
288 source <<
" Error( \"Connect\", "
289 <<
"\"The following variable doesn't exist: %s\", "
290 <<
"( m_prefix + \"" << itr->name() <<
"\" ).Data() );" << std::endl;
291 source <<
" return 0;" << std::endl;
292 source <<
" }" << std::endl;
293 source <<
" m_tree->SetBranchAddress( m_prefix + \"" << itr->name()
294 <<
"\", &m_" << itr->name() <<
", &m_b_" << itr->name() <<
" );"
296 source <<
" }" << std::endl;
297 source <<
" if( *m_master != m_b_" << itr->name() <<
"->GetReadEntry() ) {"
299 source <<
" m_b_" << itr->name() <<
"->GetEntry( *m_master );"
301 source <<
" }" << std::endl;
302 source <<
" return m_" << itr->name() <<
";" << std::endl;
303 source <<
" }" << std::endl << std::endl;
306 source <<
"} // namespace " << CODE_NAMESPACE << std::endl;
310 return StatusCode::SUCCESS;
◆ m_metadata
The documentation for this class was generated from the following files:
ObjectMetadata m_metadata
Object holding the information about the variables.
StatusCode writeSource(const std::string &classname, const std::string &dir) const
Function creatig the D3PDReader C++ source.
StatusCode writeHeader(const std::string &classname, const std::string &dir) const
Function creating the D3PDReader C++ header.
#define CHECK(...)
Evaluate an expression and check for errors.
virtual bool isContainer() const
Get the "isCollection" parameter of the object.
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
def time(flags, cells_name, *args, **kw)
void addSTLHeader(std::ostream &out, const char *name) const
Function adding STL include statements to the header when needed.
virtual const std::string & prefix() const
Get the common prefix of the variables.