Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DEventSourceEVIO.h
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DEventSourceEVIO.h
4 // Created: Sat May 8 13:54:35 EDT 2010
5 // Creator: davidl (on Darwin Amelia.local 9.8.0 i386)
6 //
7 
8 #ifndef _DEventSourceEVIO_
9 #define _DEventSourceEVIO_
10 
11 #include <JANA/jerror.h>
12 #include <JANA/JEventSource.h>
13 #include <JANA/JEvent.h>
14 
16 #include <HDGEOMETRY/DGeometry.h>
18 
19 #include <evioUtil.hxx>
20 #include <evioFileChannel.hxx>
21 #include <vector>
22 
23 using namespace jana;
24 using namespace evio;
25 using namespace std;
26 
27 
28 class DEventSourceEVIO:public JEventSource{
29  public:
30  DEventSourceEVIO(const char* source_name);
31  virtual ~DEventSourceEVIO();
32 
33  jerror_t GetEvent(JEvent &event);
34  void FreeEvent(JEvent &event);
35  jerror_t GetObjects(JEvent &event, JFactory_base *factory);
36 
37  template<class T> const vector<T>& GetVector(evioDOMNodeList* nodeList, string) const;
38 
39  protected:
40 
41  map<string, pair<int, int> > tagMap; // first=tag, second=num
42 
43  jerror_t Extract_DTrackTimeBased(evioDOMTree *evt, JFactory<DTrackTimeBased> *factory);
44 
45  private:
46  evioFileChannel *chan;
47 
50 
51  pthread_mutex_t rt_mutex;
52  map<evioDOMTree*, vector<DReferenceTrajectory*> > rt_by_event;
53  list<DReferenceTrajectory*> rt_pool;
54 };
55 
56 //------------------
57 // GetVector
58 //------------------
59 template<class T>
60 const vector<T>& DEventSourceEVIO::GetVector(evioDOMNodeList* nodeList, string name) const
61 {
62  /// Attempt to get the pointer to a const vector of the specified type for the node
63  /// matching the given name (as appearing in tagMap). If the pointer can't be obtained
64  /// for any reason (e.g. name doesn't appear in tagMap or nodelist doesn't contain
65  /// the tag/num correpsonding to name) then an exception is thrown.
66 
67  // Check that tagMap has name in it
68  map<string, pair<int, int> >::const_iterator iter = tagMap.find(name);
69  if(iter==tagMap.end())throw JException(string("can't find \"")+name+"\" in nodeList");
70 
71  // Loop over nodes and find one with the correct tag/num
72  evioDOMNodeList::const_iterator iter2;
73  for(iter2=nodeList->begin(); iter2!=nodeList->end(); iter2++) {
74  evioDOMNode *node = *iter2;
75  if(*node == iter->second){ // iter->second is pair<int,int> which holds tag/num
76  return *(node->getVector<T>());
77  }
78  }
79 
80  // Didn't find bank with tag/num for this name. Throw exception
81  throw JException(string("can't find with tag/num corresponding to \"")+name+"\" in nodeList");
82 
83  // Unused return value to avoid compiler warnings
84  const vector<T> *tmp = NULL;
85  return *tmp;
86 }
87 
88 #endif // _DEventSourceEVIO_
89 
const vector< T > & GetVector(evioDOMNodeList *nodeList, string) const
DMagneticFieldMap * bfield
map< evioDOMTree *, vector< DReferenceTrajectory * > > rt_by_event
pthread_mutex_t rt_mutex
list< DReferenceTrajectory * > rt_pool
static map< string, pair< uint16_t, uint8_t > > tagMap
evioFileChannel * chan
map< string, pair< int, int > > tagMap