CFEL - ASG Software Suite  2.5.0
CASS
acqiris_detectors_helper.cpp
Go to the documentation of this file.
1 //Copyright (C) 2010 Lutz Foucar
2 
3 /**
4  * @file acqiris_detectors_helper.cpp file contains definition of classes that
5  * extract information of acqiris detectors.
6  *
7  * @author Lutz Foucar
8  */
9 #include <tr1/functional>
10 #include <string>
11 
13 
14 #include "cass_settings.h"
15 #include "detector_backend.h"
17 #include "convenience_functions.h"
18 #include "log.h"
20 
21 using namespace cass::ACQIRIS;
22 using namespace std;
23 using std::tr1::bind;
24 using std::tr1::placeholders::_1;
25 
26 //initialize static members//
29 
31 {
32  QMutexLocker lock(&_mutex);
33  if (_instances.find(detector) == _instances.end())
34  {
35  Log::add(Log::DEBUG0,string("HelperAcqirisDetectors::instance(): creating an") +
36  " instance of the Acqiris Detector Helper for detector '" + detector + "'");
37  _instances[detector] = shared_pointer(new HelperAcqirisDetectors(detector));
38  }
39  return _instances[detector];
40 }
41 
43 {
44  QMutexLocker lock(&_mutex);
45  for (helperinstancesmap_t::iterator it(_instances.begin()); it != _instances.end(); ++it)
46  it->second->release(id);
47 }
48 
50 {
51  QMutexLocker lock(&_mutex);
52  return _instances;
53 }
54 
55 HelperAcqirisDetectors::HelperAcqirisDetectors(const helperinstancesmap_t::key_type& detname)
56 {
57  CASSSettings s;
58  s.beginGroup("AcqirisDetectors");
60  _dettype = (static_cast<DetectorType>(s.value("DetectorType",ToF).toUInt()));
61  s.endGroup();
62  s.endGroup();
63  for (size_t i=0; i<NbrOfWorkers+2;++i)
64  _detectorList.push_back(make_pair(0,DetectorBackend::instance(_dettype,detname)));
65  _lastEntry = _detectorList.begin();
66  Log::add(Log::DEBUG0,string("AcqirisDetectorHelper::constructor: ") +
67  "we are responsible for det '" + detname + "', which is of type " + toString(_dettype));
68 }
69 
71 {
72  return (find_if(_detectorList.begin(), _detectorList.end(),
73  std::tr1::bind(equal_to<id_type>(),id,
74  std::tr1::bind<id_type>(&KeyDetPair_t::first,_1))));
75 }
76 
78 {
79  QMutexLocker lock(&_helperMutex);
80  iter_type it(findId(id));
81  if (it != _detectorList.end())
82  it->first = 0;
83 }
84 
86 {
87  QMutexLocker lock(&_helperMutex);
88  iter_type it(findId(evt.id()));
89  if(_detectorList.end() == it)
90  {
91  while(_lastEntry->first)
92  {
93  ++_lastEntry;
94  if (_lastEntry == _detectorList.end())
95  _lastEntry = _detectorList.begin();
96  }
97  it = _lastEntry;
98  it->first = evt.id();
99  it->second->associate(evt);
100  }
101  return *it->second;
102 }
103 
105 {
106  CASSSettings s;
107  s.beginGroup("AcqirisDetectors");
108  detectorList_t::iterator it(_detectorList.begin());
109  detectorList_t::const_iterator end(_detectorList.end());
110  for (;it != end ;++it)
111  it->second->loadSettings(s);
112  s.endGroup();
113 }
Event to store all LCLS Data.
Definition: cass_event.h:32
detectorList_t::iterator iter_type
define an iterator for the list
file contains declaration of classes that extract information of acqiris detectors.
Settings for CASS.
Definition: cass_settings.h:30
std::tr1::shared_ptr< HelperAcqirisDetectors > shared_pointer
typedef a shared pointer of this
STL namespace.
static shared_pointer instance(const DetectorType &dettype, const std::string &detname)
create an instance of the requested dectortype
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
static void add(Level level, const std::string &line)
add a string to the log
Definition: log.cpp:31
fromStdString(const std::string &str)
contains the base class declaration for all detectors that are attached to an acqiris device...
DetectorType
the types of detectors that are available
HelperAcqirisDetectors()
prevent people from constructin other than using instance().
file contains base class for all detector analyzers.
file contains declaration of classes and functions that help other processors to do their job...
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.
id_t & id()
setters
Definition: cass_event.h:64
static const helperinstancesmap_t & instances()
return all known instances fo this
std::string toString(const Type &t)
convert any type to a string
Definition: cass.h:63
value(const QString &key, const QVariant &defaultValue=QVariant()
std::map< std::string, shared_pointer > helperinstancesmap_t
typedef describing the instances of the helper
file contains specialized class that do the settings for cass
const size_t NbrOfWorkers
global variable to set the number of worker threads
Definition: cass.h:274
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.
Electron detector
Definition: hdf5-input.ini:62
contains a logger for cass
beginGroup(const QString &prefix)
static QMutex _mutex
Singleton Mutex to lock write operations.
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