JANA 0.6.2
|
JANA Data Factory (base class for algorithms) More...
#include <JFactory.h>
Public Types | |
enum | data_origin_t { ORIGIN_NONE, ORIGIN_FACTORY, ORIGIN_EXTERNAL } |
Public Member Functions | |
const char * | className (void) |
jerror_t | CopyFrom (vector< const T * > &data) |
jerror_t | CopyTo (vector< T * > &data) |
jerror_t | Get (vector< const T * > &d) |
vector< void * > & | Get (void) |
Get pointers to factories objects (as void*). | |
const JObject * | GetByID (JObject::oid_t id) |
Find object pointer in factory's _data vector and return it. | |
const T * | GetByIDT (JObject::oid_t id) |
int | GetCheckSourceFirst (void) |
const char * | GetDataClassName (void) |
Return the pointer to the class's name which this factory provides. | |
int | GetDataClassSize (void) |
Returns the size of the data class on which this factory is based. | |
data_origin_t | GetDataOrigin (void) |
int | GetEventCalled (void) |
int | GetNrows (void) |
Returns the number of rows. | |
JFactory (const char *tag="") | |
virtual const char * | Tag (void) |
The data tag string associated with this factory. Most factories will not overide this. | |
void | toStrings (vector< vector< pair< string, string > > > &items, bool append_types=false) const |
~JFactory () | |
Protected Member Functions | |
jerror_t | HardReset (void) |
Delete the factory's data regardless of the flags. | |
jerror_t | Reset (void) |
Delete the factory's data depending on the flags. | |
void | SetFactoryPointers (void) |
Protected Attributes | |
vector< T * > | _data |
vector< void * > | _vdata |
data_origin_t | data_origin |
const char * | tag_str |
int | use_factory |
Friends | |
class | JEventLoop |
JANA Data Factory (base class for algorithms)
All data (except that read from the data source) must be derived from the data that was read from the source. One JFactory object should exist for each type of data that is "generated". For example: Clusters in a calorimeter are generated from individual "Hits" in the calorimeter.
JFactory is the templated base class which all factories are derived from.
At the user level, factory classes will be defined which inherit from this templated base class. By inheriting from a template, the derived factory class will automatically have a high degree of type safety since the "_data" vector will be specific to the type of objects the factory produces. This class (JFactory) inherits from JFactory_base so that all factories can be treated equally (polymorphism) by the JEventLoop object.
Instantiating a JFactory<T> object itself would be pointless since they would use the default init(), brun(),evnt(),erun(), and fini() methods from JEventProcessor which do nothing. Instead, A new class should be derived from this one which implements its own init(), brun(),evnt(),erun(), and fini() methods.
Definition at line 63 of file JFactory.h.
enum jana::JFactory::data_origin_t |
Definition at line 71 of file JFactory.h.
jana::JFactory< T >::JFactory | ( | const char * | tag = "" | ) |
This is a base class that specific factories inherit from. my_devent will be kept and used to allow this factory to access other factories.
Definition at line 115 of file JFactory.h.
jana::JFactory< T >::~JFactory | ( | ) |
Delete all objects in _data container.
Definition at line 143 of file JFactory.h.
const char* jana::JFactory< T >::className | ( | void | ) | [inline, virtual] |
Reimplemented from jana::JEventProcessor.
Definition at line 81 of file JFactory.h.
Referenced by jana::JFactory< JObjectDummy >::GetDataClassName().
jerror_t jana::JFactory< T >::CopyFrom | ( | vector< const T * > & | data | ) |
Copy object pointers from private vector into "data" vector. This does not check if the evnt() routine was called, and it does not generate the data objects (use the Get(vector<const T*>) method for that). This only copies pointers to already existing objects.
Definition at line 388 of file JFactory.h.
References NOERROR.
Referenced by jana::JEventLoop::GetFromFactory(), and jana::JEvent::GetObjects().
jerror_t jana::JFactory< T >::CopyTo | ( | vector< T * > & | data | ) |
Copy object pointers into factory. Object ownership is transferred to the factory here so the caller should not delete the objects after calling this unless the factory's NOT_OBJECT OWNER flag is set (see SetFactoryFlag(JFactory_base::NOT_OBJECT_OWNER)) This is how an external source such as a file can create the objects and put them in the factory. The objects will then be treated as though they were generated by the factory. i.e. they will be returned in subsequent calls to Get() and deleted at the start of the next event (sans the NOT_OBJECT_OWNER or PERSISTANT flags).
Definition at line 356 of file JFactory.h.
References NOERROR.
Referenced by JEventSourceTest::GetObjects().
vector< void * > & jana::JFactory< T >::Get | ( | void | ) | [virtual] |
Get pointers to factories objects (as void*).
This gets typecast in the template member function also named "Get()" in the JEventLoop class. Since there is no base class for vector objects, we give it something that should at least be the same size i.e. vector<void*>
Return a STL vector of pointers to the objects produced by the factory. The pointers are type cast as void* so this can be accessed through the JFactory_base base class. This just dispatches to the type specific Get(vector<const T*> &) method.
Implements jana::JFactory_base.
Definition at line 153 of file JFactory.h.
Referenced by jana::JEventLoop::GetFromFactory().
jerror_t jana::JFactory< T >::Get | ( | vector< const T * > & | d | ) |
Copy pointers to the objects produced by the factory into the vector reference passed. Note that this method is accessed primarily from two places: This main one is JEventLoop::GetFromFactory which is called from JEventLoop::Get , the primary access method for factories and event processors. The second is through the JFactory<T>::Get() which is called through the JFactory_base::Get virtual method. That is used mainly by things that need to loop over all objects of all factories.
This method will check first to make sure this factory hasn't already been called for this event.
This also uses a busy flag to ensure we're not called recursively. i.e. we call a factory who calls another factory who eventually calls us. An exception is thrown (type jerror_t) with a value INFINITE_RECURSION if that situation is detected.
Definition at line 174 of file JFactory.h.
References jana::JEventLoop::error_call_stack_t::factory_name, jana::JEventLoop::error_call_stack_t::filename, jana::JEventLoop::error_call_stack_t::line, NOERROR, and jana::JEventLoop::error_call_stack_t::tag.
const JObject* jana::JFactory< T >::GetByID | ( | JObject::oid_t | id | ) | [inline, virtual] |
Find object pointer in factory's _data vector and return it.
Implements jana::JFactory_base.
Definition at line 91 of file JFactory.h.
const T * jana::JFactory< T >::GetByIDT | ( | JObject::oid_t | id | ) |
Definition at line 405 of file JFactory.h.
Referenced by jana::JFactory< JObjectDummy >::GetByID().
int jana::JFactory< T >::GetCheckSourceFirst | ( | void | ) | [inline] |
Definition at line 87 of file JFactory.h.
Referenced by jana::JEventLoop::GetFromFactory().
const char* jana::JFactory< T >::GetDataClassName | ( | void | ) | [inline, virtual] |
Return the pointer to the class's name which this factory provides.
Implements jana::JFactory_base.
Definition at line 82 of file JFactory.h.
int jana::JFactory< T >::GetDataClassSize | ( | void | ) | [inline, virtual] |
Returns the size of the data class on which this factory is based.
Implements jana::JFactory_base.
Definition at line 85 of file JFactory.h.
data_origin_t jana::JFactory< T >::GetDataOrigin | ( | void | ) | [inline] |
Definition at line 80 of file JFactory.h.
int jana::JFactory< T >::GetEventCalled | ( | void | ) | [inline] |
Definition at line 86 of file JFactory.h.
int jana::JFactory< T >::GetNrows | ( | void | ) | [virtual] |
Returns the number of rows.
Return the number of objects for this factory for the current event. If the objects have not yet been created for the event, this will cause them to be generated (or retreived from the source).
Implements jana::JFactory_base.
Definition at line 271 of file JFactory.h.
jerror_t jana::JFactory< T >::HardReset | ( | void | ) | [protected, virtual] |
Delete the factory's data regardless of the flags.
Clear out the factories current contents.
Implements jana::JFactory_base.
Definition at line 316 of file JFactory.h.
References NOERROR.
jerror_t jana::JFactory< T >::Reset | ( | void | ) | [protected, virtual] |
Delete the factory's data depending on the flags.
Clear out the factories current contents unless the PERSISTANT flag is set.
Implements jana::JFactory_base.
Definition at line 299 of file JFactory.h.
References NOERROR.
void jana::JFactory< T >::SetFactoryPointers | ( | void | ) | [protected] |
Set the JFactory_base pointers for all JObjects in _data to point back to this factory. Each item in _data is dynamic_cast as a JObject* first and if that succeeds, then the object's SetFactoryPointer() method is called.
This is called from JEventLoop::GetFromFactory so that the pointers are set just after object creation so that the user doesn't have to explicitly.
Definition at line 336 of file JFactory.h.
References jana::JObject::SetFactoryPointer().
Referenced by jana::JEventLoop::GetFromFactory().
virtual const char* jana::JFactory< T >::Tag | ( | void | ) | [inline, virtual] |
The data tag string associated with this factory. Most factories will not overide this.
Reimplemented from jana::JFactory_base.
Reimplemented in JObjectDummy_factory_tag.
Definition at line 84 of file JFactory.h.
Referenced by jana::JEventLoop::GetFromFactory().
void jana::JFactory< T >::toStrings | ( | vector< vector< pair< string, string > > > & | items, |
bool | append_types = false |
||
) | const [inline, virtual] |
Get the data for all objects already created by this factory for the given event by calling the toStrings() method of each one.
Note that this will not activate the factory to generate the objects if they do not already exist.
The value of append_types is used to set the append_types flag for each of the objects prior to calling its toStrings method. Afterwards, the value of the objects' append_types flag is reset to whatever value it had upon entry. Please see the documentation of the AddString method of JObject for more details on what this flag does.
The items vector is cleared upon entry.
Implements jana::JFactory_base.
Definition at line 416 of file JFactory.h.
friend class JEventLoop [friend] |
Definition at line 65 of file JFactory.h.
vector<T*> jana::JFactory< T >::_data [protected] |
Definition at line 95 of file JFactory.h.
vector<void*> jana::JFactory< T >::_vdata [protected] |
Definition at line 96 of file JFactory.h.
data_origin_t jana::JFactory< T >::data_origin [protected] |
Definition at line 104 of file JFactory.h.
Referenced by jana::JFactory< JObjectDummy >::GetDataOrigin().
const char* jana::JFactory< T >::tag_str [protected] |
Definition at line 98 of file JFactory.h.
Referenced by jana::JFactory< JObjectDummy >::Tag().
int jana::JFactory< T >::use_factory [protected] |
Definition at line 97 of file JFactory.h.
Referenced by jana::JFactory< JObjectDummy >::GetCheckSourceFirst().