JANA2
C++ framework for multi-threaded data processing
JObject Class Reference
Inheritance diagram for JObject:
[legend]

Public Member Functions

virtual const std::string className () const
 
void AddAssociatedObject (const JObject *obj)
 
void AddAssociatedObjectAutoDelete (JObject *obj, bool auto_delete=true)
 
void RemoveAssociatedObject (const JObject *obj)
 
void ClearAssociatedObjects (void)
 
bool IsAssociated (const JObject *locObject) const
 
template<class T >
const T * GetSingle () const
 
template<class T >
std::vector< const T * > Get () const
 
template<typename T >
void GetSingle (const T *&ptrs, std::string classname="") const
 The following have been added purely for compatibility with JANA1, in order to make porting halld_recon more tractable. More...
 
template<typename T >
void GetT (std::vector< const T * > &ptrs) const
 
template<typename T >
void Get (std::vector< const T * > &ptrs, std::string classname="", int max_depth=1000000) const
 
template<typename T >
void GetAssociatedAncestors (std::set< const JObject * > &already_checked, int &max_depth, std::set< const T * > &objs_found, std::string classname="") const
 
virtual void Summarize (JObjectSummary &summary) const
 

Protected Attributes

std::set< const JObject * > associated
 
std::set< JObject * > auto_delete
 

Member Function Documentation

◆ AddAssociatedObject()

void JObject::AddAssociatedObject ( const JObject obj)
inline

Add a JObject to the list of associated objects

Referenced by AddAssociatedObjectAutoDelete().

◆ AddAssociatedObjectAutoDelete()

void JObject::AddAssociatedObjectAutoDelete ( JObject obj,
bool  auto_delete = true 
)
inline

Add a JObject to the list of associated objects. If the auto_delete flag is true, then automatically delete it when this object is deleted. Otherwise, this behaves identically to the AddAssociatedObject method.

Note that if the object is removed via RemoveAssociatedObject(...) then the object is NOT deleted. BUT, if the entire list of associated objects is cleared via ClearAssociatedObjects, then the object will be deleted.

References AddAssociatedObject().

◆ className()

virtual const std::string JObject::className ( void  ) const
inlinevirtual

className returns a string representation of the name of this class. This won't automatically do the right thing – in each JObject subclass, the user either needs to use the JOBJECT_PUBLIC macro, or override this method while keeping the same method body.

◆ ClearAssociatedObjects()

void JObject::ClearAssociatedObjects ( void  )
inline

Remove all associated objects from the associated objects list. This will also delete any objects that were added via the AddAssociatedObjectAutoDelete(...) method with the auto_delete flag set.

◆ Get() [1/2]

template<typename T >
std::vector< const T * > JObject::Get

Returns a vector of pointers to all associated objects of type T.

◆ Get() [2/2]

template<typename T >
void JObject::Get ( std::vector< const T * > &  ptrs,
std::string  classname = "",
int  max_depth = 1000000 
) const

Fill the given vector with pointers to the associated objects of the type on which the vector is based. The objects are chosen by matching their class names (obtained via JObject::className()) either to the one provided in classname or to T::static_className() if classname is an empty string. Associations will be searched to a level of max_depth to find all objects of the requested type. By default, max_depth is set to a very large number so that all associations are found. To limit the search to only objects directly associated with this one, set max_depth to either "0" or "1".

The contents of ptrs are cleared upon entry.

References GetAssociatedAncestors().

◆ GetAssociatedAncestors()

template<typename T >
void JObject::GetAssociatedAncestors ( std::set< const JObject * > &  already_checked,
int &  max_depth,
std::set< const T * > &  objs_found,
std::string  classname = "" 
) const

Get associated objects of the specified type (either "T" or classname). Check also for associated objects of any associated objects to a level of max_depth associations. This method calls itself recursively so care is taken to only check the associated objects of each object encountered only once.

The "already_checked" parameter should be passed in as an empty container that is used to keep track of which objects had their direct associations checked. "max_depth" indicates the maximum level of associations to check (n.b. both "0" and "1" means only check direct associations.) This must be passed as a reference to an existing int since it is modified in order to keep track of the current depth in the recursive calls. Set max_depth to a very high number (like 1000000) to check all associations. The "objs_found" container will contain the actual associated objects found. The objects are chosen by matching their class names (obtained via JObject::className()) either to the one provided in "classname" or to T::static_className() if classname is an empty string.

Referenced by Get().

◆ GetSingle() [1/2]

template<class T >
const T * JObject::GetSingle

This is a convenience method that can be used to get a pointer to the single associated object of type T. If no object is found, this will return nullptr. If multiple objects are found, this will throw a JException.

◆ GetSingle() [2/2]

template<class T >
void JObject::GetSingle ( const T *&  ptrs,
std::string  classname = "" 
) const

The following have been added purely for compatibility with JANA1, in order to make porting halld_recon more tractable.

This is a convenience method that can be used to get a pointer to the single associate object of type T.

The objects are chosen by matching their class names (obtained via JObject::className()) either to the one provided in classname or to T::static_className() if classname is an empty string.

If no object of the specified type is found, a NULL pointer is returned.

◆ GetT()

template<typename T >
void JObject::GetT ( std::vector< const T * > &  ptrs) const

Fill the given vector with pointers to the associated JObjects of the type on which the vector is based. This is similar to the Get() method except objects are selected by attempting a dynamic_cast to type const T*. This allows one to select a list of all objects who have a type T somewhere in their inheritance chain.

A potential issue with this method is that the dynamic_cast does not always work correctly for objects created via a plugin when the cast occurs outside of the plugin or vice versa.

The contents of ptrs are cleared upon entry.

◆ RemoveAssociatedObject()

void JObject::RemoveAssociatedObject ( const JObject obj)
inline

Remove the specified JObject from the list of associated objects. This will NOT delete the object even if the object was added with the AddAssociatedObjectAutoDelete(...) method with the auto_delete flag set.

◆ Summarize()

void JObject::Summarize ( JObjectSummary summary) const
inlinevirtual

A virtual method which allows the user to display the contents of a JObject in a formatted, structured way. This is optional, but recommended.

Fill in the JObjectSummary container with information for each member variable of the JObject using JObjectSummary::add(...). This accepts a reference to the variable itself, the variable name, a printf-style format string, and an optional description string which is good for communicating things like units.

For convenience, we provide a NAME_OF macro, which will turn the member variable name into a string, rather than having the user write it out manually. This is useful if you use automatic refactoring tools, which otherwise might allow the variable name and the stringified name to get out of sync.

References JObjectSummary::add().


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