CFEL - ASG Software Suite  2.5.0
CASS
pixel_detector_helper.h
Go to the documentation of this file.
1 //Copyright (C) 2011-2014 Lutz Foucar
2 
3 /**
4  * @file pixel_detector_helper.h contains classes that extract and add
5  * information of pixel detectors.
6  *
7  * @author Lutz Foucar
8  */
9 
10 #ifndef _PIXEL_DETECTOR_HELPER_H_
11 #define _PIXEL_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 
26 namespace cass
27 {
28 
29 namespace pixeldetector
30 {
31 class AdvancedDetector;
32 
33 /** Helper for Advanced Pixel Detector related Postprocessors.
34  *
35  * This class will look whether a AdvancedDetector with the name does already
36  * exist. If not it will create it and put it in list so that one event is
37  * always associated with one AdvancedDetector.
38  *
39  * @cassttng PixelDetectors/{Name}\n
40  * Name of the Pixeldetector. See
41  * cass::pixeldetector::AdvancedDetector for more information.
42  *
43  * @author Lutz Foucar
44  */
46 {
47 public:
48  /** typedef a shared pointer of this */
49  typedef std::tr1::shared_ptr<DetectorHelper> shared_pointer;
50 
51  /** typedef describing the instances of the helper */
52  typedef std::map<std::string,shared_pointer> instancesmap_t;
53 
54  /** define a shared pointer of the item to manage */
55  typedef std::tr1::shared_ptr<AdvancedDetector> AdvDet_sptr;
56 
57  /** define the type of the id used */
59 
60  /** defining a key - value pair for the list */
61  typedef std::pair<id_type,AdvDet_sptr> KeyDetPair_t;
62 
63  /** typedef defining the list of detectors for more readable code*/
64  typedef std::vector<KeyDetPair_t> detectorList_t;
65 
66  /** define an iterator for the list */
67  typedef detectorList_t::iterator iter_type;
68 
69 public:
70  /** static function creating instance of this.
71  *
72  * return the instance of the helper that is managing the detector. If the
73  * helper is not yet inside the _instances map the helper instance will be
74  * created and put into the _instances map.
75  *
76  * @return instance of the helper manaing the detector
77  * @param detector key (name) of the detector to find it in the _instances map
78  */
79  static shared_pointer instance(const instancesmap_t::key_type& detector);
80 
81  /** release the detector of all helpers that is blocked for the event
82  *
83  * @param id the eventid that is assinged for the detector
84  */
85  static void releaseDetector(const id_type &id);
86 
87  /** retrieve detector for event
88  *
89  * This function will lock, so that it can be consecutivly called by
90  * different threads.\n
91  * Check if the event is already associated with one of the detectors in
92  * the detector list. If so just return the pointer to the detector that
93  * is associated with this event.\n
94  * If not then take the detector of the last element in the _detectorList
95  * and call its associate() member with this event. Then create a new
96  * element to be put into the _detectorList, where the key of the element
97  * is the id of the event and the value is the pointer to the detector,
98  * that we associated with this event. Put the newly created element in
99  * the beginning of the _detectorList and erase the last element.
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  AdvDet_sptr detector(const CASSEvent& evt);
106 
107  /** load the settings of the detectors in the detector list
108  *
109  * go through the list of detectors and tell each of the detector to load
110  * its settings.
111  *
112  * @param i unused parameter
113  */
114  void loadSettings(size_t i=0);
115 
116 protected:
117  /** list of pairs of id-detectors.
118  *
119  * @note Needs to be at least the size of workers that can possibly call
120  * this helper simultaniously, but should be shrinked if it gets
121  * much bigger than the number of workers.
122  */
123  detectorList_t _detectorList;
124 
125 private:
126  /** prevent people from constructin other than using instance().*/
128 
129  /** private constructor.
130  *
131  * Creates the list of detectors. The detectors are of the user chosen
132  * type. The type can be chosen by the user via the .cass ini setting
133  * dettype. The instance of the detectors are created
134  * by DetectorBackend::instance() \n
135  * The name of the detector is also the key in the instances map.
136  *
137  * @param detname the name of the detector
138  */
139  DetectorHelper(const instancesmap_t::key_type& detname);
140 
141  /** prevent copy-construction*/
143 
144  /** prevent assingment */
146 
147  /** find an element with a given id in the list
148  *
149  * @return iterator to the found element
150  * @param id the id of the element
151  */
152  iter_type findId(const id_type &id);
153 
154  /** release the detector element in the list by settings its key (eventid) back
155  * to 0
156  *
157  * @param id the detector event id that should be released
158  */
159  void release(const id_type & id);
160 
161  /** the helperclass instances.
162  *
163  * the instances of this class put into map
164  * one instance for each available detector
165  */
166  static instancesmap_t _instances;
167 
168  /** Singleton Mutex to lock write operations*/
169  static QMutex _mutex;
170 
171  /** Mutex for each helper*/
173 
174  /** the iterator to the last element returned */
175  iter_type _lastEntry;
176 };
177 
178 } //end namespace pixeldetector
179 } //end namespace cass
180 
181 
182 #endif
detectorList_t _detectorList
list of pairs of id-detectors.
Event to store all LCLS Data.
Definition: cass_event.h:32
static QMutex _mutex
Singleton Mutex to lock write operations.
std::map< std::string, shared_pointer > instancesmap_t
typedef describing the instances of the helper
AdvDet_sptr detector(const CASSEvent &evt)
retrieve detector for event
file contains declaration of the CASSEvent
Helper for Advanced Pixel Detector related Postprocessors.
uint64_t id_t
define the id type
Definition: cass_event.h:52
void release(const id_type &id)
release the detector element in the list by settings its key (eventid) back to 0
DetectorHelper & operator=(const DetectorHelper &)
prevent assingment
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
std::tr1::shared_ptr< AdvancedDetector > AdvDet_sptr
define a shared pointer of the item to manage
void loadSettings(size_t i=0)
load the settings of the detectors in the detector list
DetectorHelper()
prevent people from constructin other than using instance().
std::pair< id_type, AdvDet_sptr > KeyDetPair_t
defining a key - value pair for the list
std::tr1::shared_ptr< DetectorHelper > shared_pointer
typedef a shared pointer of this
detectorList_t::iterator iter_type
define an iterator for the list
CASSEvent::id_t id_type
define the type of the id used
static void releaseDetector(const id_type &id)
release the detector of all helpers that is blocked for the event
static shared_pointer instance(const instancesmap_t::key_type &detector)
static function creating instance of this.
QMutex _helperMutex
Mutex for each helper.
std::vector< KeyDetPair_t > detectorList_t
typedef defining the list of detectors for more readable code
static instancesmap_t _instances
the helperclass instances.