CFEL - ASG Software Suite  2.5.0
CASS
acqiris_detectors_helper.h
Go to the documentation of this file.
1 //Copyright (C) 2010 - 2014 Lutz Foucar
2 
3 /**
4  * @file acqiris_detectors_helper.h file contains declaration of classes that
5  * extract information of acqiris detectors.
6  *
7  * @author Lutz Foucar
8  */
9 
10 #ifndef _DETECTOR_HELPER_H_
11 #define _DETECTOR_HELPER_H_
12 
13 #include <stdint.h>
14 #include <utility>
15 #include <algorithm>
16 #include <vector>
17 #include <string>
18 #include <map>
19 #include <tr1/memory>
20 
21 #include <QtCore/QMutex>
22 #include <QtCore/QMutexLocker>
23 
24 #include "cass_event.h"
25 #include "detector_backend.h"
27 
28 namespace cass
29 {
30 class CASSEvent;
31 
32 namespace ACQIRIS
33 {
34 
35 /** Helper for Acqiris related Postprocessors.
36  *
37  * This class will return the requested detector, which signals are going to
38  * a Acqiris Instrument. It is implemented as a singleton such that every processor
39  * can call it without knowing about it.
40  *
41  * @cassttng AcqirisDetectors/\%name\%/{DetectorType}\n
42  * Type of the detector that this helper should be managing.
43  * Default is 1 (TofDetector). Possible choises are
44  * - 0: Delayline: see cass::ACQIRIS::DelaylineDetector
45  * - 1: Time of Flight Detector: see cass::ACQIRIS::TofDetector
46  *
47  * @todo make sure that the detectors are protected from beeing written
48  * while they are read from
49  *
50  * @author Lutz Foucar
51  */
53 {
54 public:
55  /** typedef a shared pointer of this */
56  typedef std::tr1::shared_ptr<HelperAcqirisDetectors> shared_pointer;
57 
58  /** typedef describing the instances of the helper */
59  typedef std::map<std::string,shared_pointer> helperinstancesmap_t;
60 
61  /** a shared pointer of the detector backend */
62  typedef std::tr1::shared_ptr<DetectorBackend> Det_sptr;
63 
64  /** define the type of the id used */
66 
67  /** defining a key - value pair for the list */
68  typedef std::pair<id_type,Det_sptr> KeyDetPair_t;
69 
70  /** typedef defining the list of detectors for more readable code*/
71  typedef std::vector<KeyDetPair_t> detectorList_t;
72 
73  /** define an iterator for the list */
74  typedef detectorList_t::iterator iter_type;
75 
76 public:
77  /** static function creating instance of this.
78  *
79  * return the instance of the helper that is managing the detector. If the
80  * helper is not yet inside the _instances map the helper instance will be
81  * created and put into the _instances map.
82  *
83  * @return instance of the helper manaing the detector
84  * @param detector key (name) of the detector to find it in the _instances map
85  */
86  static shared_pointer instance(const helperinstancesmap_t::key_type& detector);
87 
88  /** release the detector of all helpers that is blocked for the event
89  *
90  * @param id the eventid that is assinged for the detector
91  */
92  static void releaseDetector(const id_type &id);
93 
94  /** return all known instances fo this */
95  static const helperinstancesmap_t& instances();
96 
97  /** retrieve detector for event
98  *
99  * this just calls validate(). See validate() for further information
100  *
101  * @return pointer to the detector that contains the data related to the
102  * requested event
103  * @param evt the event whos data we need to relate to the detector.
104  */
105  DetectorBackend& detector(const CASSEvent& evt) {return validate(evt);}
106 
107  /** retrieve detector
108  *
109  * this just retrieves the first detector from the _detectorList. Can be
110  * used for chekcking the properties of the detector.
111  *
112  * @return const pointer to the first detector in _detectorList
113  */
114  const DetectorBackend& detector()const {return *_detectorList.front().second;}
115 
116 
117  /** load the settings of the detectors in the detector list
118  *
119  * go through the list of detectors and tell each of the detector to load
120  * its settings.
121  *
122  * @param i unused parameter
123  */
124  void loadSettings(size_t i=0);
125 
126  /** retrieve the detector type that the helper is there for */
128 
129 protected:
130  /** validate that this event has been associated with the detector.
131  *
132  * This function will lock, so that it can be consecutivly called by
133  * different threads.\n
134  * Check if the event is already associated with one of the detectors in
135  * the detector list. If so just return the pointer to the detector that
136  * is associated with this event.\n
137  * If not then take the detector of the last element in the _detectorList
138  * and call its associate() member with this event. Then create a new
139  * element to be put into the _detectorList, where the key of the element
140  * is the id of the event and the value is the pointer to the detector,
141  * that we associated with this event. Put the newly created element in
142  * the beginning of the _detectorList and erase the last element.
143  *
144  * @return reference to the validated detector
145  * @param evt the cass event to validate
146  */
147  DetectorBackend& validate(const CASSEvent &evt);
148 
149  /** list of pairs of id-detectors.
150  *
151  * @note Needs to be at least the size of workers that can possibly call
152  * this helper simultaniously, but should be shrinked if it gets
153  * much bigger than the number of workers.
154  */
155  detectorList_t _detectorList;
156 
157 private:
158  /** prevent people from constructin other than using instance().*/
160 
161  /** private constructor.
162  *
163  * Creates the list of detectors. The detectors are of the user chosen
164  * type. The type can be chosen by the user via the .cass ini setting
165  * dettype. The instance of the detectors are created
166  * by DetectorBackend::instance() \n
167  * The name of the detector is also the key in the instances map.
168  *
169  * @param detname the name of the detector
170  */
171  HelperAcqirisDetectors(const helperinstancesmap_t::key_type& detname);
172 
173  /** prevent copy-construction*/
175 
176  /** prevent assingment */
178 
179  /** find an element with a given id in the list
180  *
181  * @return iterator to the found element
182  * @param id the id of the element
183  */
184  iter_type findId(const id_type &id);
185 
186  /** release the detector element in the list by settings its key (eventid) back
187  * to 0
188  *
189  * @param id the detector event id that should be released
190  */
191  void release(const id_type & id);
192 
193  /** the helperclass instances.
194  *
195  * the instances of this class put into map
196  * one instance for each available detector
197  */
198  static helperinstancesmap_t _instances;
199 
200  /** Singleton Mutex to lock write operations*/
201  static QMutex _mutex;
202 
203  /** Mutex for each helper*/
205 
206  /** the type of detector that the individual helper is there for */
208 
209  /** the iterator to the last element returned */
210  iter_type _lastEntry;
211 };
212 }//end namespace ACQIRIS
213 }//end namespace cass
214 
215 
216 #endif
Event to store all LCLS Data.
Definition: cass_event.h:32
detectorList_t::iterator iter_type
define an iterator for the list
const DetectorBackend & detector() const
retrieve detector
std::tr1::shared_ptr< DetectorBackend > Det_sptr
a shared pointer of the detector backend
file contains declaration of the CASSEvent
DetectorBackend & detector(const CASSEvent &evt)
retrieve detector for event
std::tr1::shared_ptr< HelperAcqirisDetectors > shared_pointer
typedef a shared pointer of this
uint64_t id_t
define the id type
Definition: cass_event.h:52
std::vector< KeyDetPair_t > detectorList_t
typedef defining the list of detectors for more readable code
void release(const id_type &id)
release the detector element in the list by settings its key (eventid) back to 0
static helperinstancesmap_t _instances
the helperclass instances.
iter_type findId(const id_type &id)
find an element with a given id in the list
iter_type _lastEntry
the iterator to the last element returned
contains the base class declaration for all detectors that are attached to an acqiris device...
DetectorType detectortype()
retrieve the detector type that the helper is there for
DetectorType
the types of detectors that are available
detectorList_t _detectorList
list of pairs of id-detectors.
HelperAcqirisDetectors()
prevent people from constructin other than using instance().
QMutex _helperMutex
Mutex for each helper.
contains the global definitions for acqiris analysis
static void releaseDetector(const id_type &id)
release the detector of all helpers that is blocked for the event
Helper for Acqiris related Postprocessors.
static const helperinstancesmap_t & instances()
return all known instances fo this
HelperAcqirisDetectors & operator=(const HelperAcqirisDetectors &)
prevent assingment
DetectorType _dettype
the type of detector that the individual helper is there for
std::map< std::string, shared_pointer > helperinstancesmap_t
typedef describing the instances of the helper
Base class for all Detectors attached to an Acqiris Instrument.
static shared_pointer instance(const helperinstancesmap_t::key_type &detector)
static function creating instance of this.
static QMutex _mutex
Singleton Mutex to lock write operations.
std::pair< id_type, Det_sptr > KeyDetPair_t
defining a key - value pair for the list
DetectorBackend & validate(const CASSEvent &evt)
validate that this event has been associated with the detector.
void loadSettings(size_t i=0)
load the settings of the detectors in the detector list
CASSEvent::id_t id_type
define the type of the id used