CFEL - ASG Software Suite  2.5.0
CASS
pixel_detector_helper.cpp
Go to the documentation of this file.
1 //Copyright (C) 2011 -2014 Lutz Foucar
2 
3 /**
4  * @file pixel_detector_helper.cpp contains classes that extract and add
5  * information of pixel detectors.
6  *
7  * @author Lutz Foucar
8  */
9 
10 #include <tr1/functional>
11 
12 #include "pixel_detector_helper.h"
13 
14 #include "cass_settings.h"
15 #include "advanced_pixeldetector.h"
16 #include "log.h"
17 
18 using namespace cass;
19 using namespace pixeldetector;
20 using namespace std;
21 using std::tr1::bind;
22 using std::tr1::placeholders::_1;
23 
24 
25 //initialize static members//
28 
30 {
31  QMutexLocker lock(&_mutex);
32  if (_instances.find(detector) == _instances.end())
33  {
34  Log::add(Log::VERBOSEINFO, string("DetectorHelper::instance(): creating an") +
35  " instance of the Pixel Detector Helper for detector '" + detector + "'");
36  _instances[detector] = DetectorHelper::shared_pointer(new DetectorHelper(detector));
37  }
38  return _instances[detector];
39 }
40 
42 {
43  QMutexLocker lock(&_mutex);
44  for (instancesmap_t::iterator it(_instances.begin()); it != _instances.end(); ++it)
45  it->second->release(id);
46 }
47 
48 DetectorHelper::DetectorHelper(const instancesmap_t::key_type& detname)
49 {
50  for (size_t i=0; i<NbrOfWorkers+2;++i)
51  _detectorList.push_back(make_pair(0,AdvDet_sptr(new AdvancedDetector(detname))));
52  _lastEntry = _detectorList.begin();
53  Log::add(Log::VERBOSEINFO,string("DetectorHelper::constructor: we are ")+
54  "we are responsible for pixel det '" + detname + "'");
55 }
56 
58 {
59  return (find_if(_detectorList.begin(), _detectorList.end(),
60  std::tr1::bind(equal_to<id_type>(),id,
61  std::tr1::bind<id_type>(&KeyDetPair_t::first,_1))));
62 }
63 
65 {
66  QMutexLocker lock(&_helperMutex);
67  iter_type it(findId(id));
68  if (it != _detectorList.end())
69  it->first = 0;
70 }
71 
73 {
74  QMutexLocker lock(&_helperMutex);
75  iter_type it(findId(evt.id()));
76  if(_detectorList.end() == it)
77  {
78  while(_lastEntry->first)
79  {
80  ++_lastEntry;
81  if (_lastEntry == _detectorList.end())
82  _lastEntry = _detectorList.begin();
83  }
84  it = _lastEntry;
85  it->first = evt.id();
86  it->second->associate(evt);
87  }
88  return it->second;
89 }
90 
92 {
93  CASSSettings s;
94  s.beginGroup("PixelDetectors");
95  detectorList_t::iterator it(_detectorList.begin());
96  detectorList_t::const_iterator end(_detectorList.end());
97  for (; it != end; ++it)
98  it->second->loadSettings(s);
99  s.endGroup();
100 }
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
Settings for CASS.
Definition: cass_settings.h:30
Helper for Advanced Pixel Detector related Postprocessors.
STL namespace.
void release(const id_type &id)
release the detector element in the list by settings its key (eventid) back to 0
iter_type findId(const id_type &id)
find an element with a given id in the list
static void add(Level level, const std::string &line)
add a string to the log
Definition: log.cpp:31
contains classes that extract and add information of pixel detectors.
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
id_t & id()
setters
Definition: cass_event.h:64
DetectorHelper()
prevent people from constructin other than using instance().
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
file contains specialized class that do the settings for cass
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.
const size_t NbrOfWorkers
global variable to set the number of worker threads
Definition: cass.h:274
advanced pixeldetectors
Electron detector
Definition: hdf5-input.ini:62
contains a logger for cass
beginGroup(const QString &prefix)
static instancesmap_t _instances
the helperclass instances.