CFEL - ASG Software Suite  2.5.0
CASS
cbf_output.cpp
Go to the documentation of this file.
1 //Copyright (C) 2012 Lutz Foucar
2 
3 /**
4  * @file cbf_output.cpp output of 2d histograms into the cbf.
5  *
6  * @author Lutz Foucar
7  */
8 
9 #include <QtCore/QDateTime>
10 
11 #include <stdint.h>
12 #include <iomanip>
13 #include <fstream>
14 
15 #include "cbf_output.h"
16 
17 #include "cass_event.h"
18 #include "cass_settings.h"
19 #include "log.h"
20 #include "convenience_functions.h"
21 #include "cbf_handle.hpp"
22 
23 using namespace cass;
24 using namespace std;
25 
26 
27 
28 pp1500::pp1500(const name_t &name)
29  : Processor(name)
30 {
31  loadSettings(0);
32 }
33 
35 {
36  CASSSettings s;
37  s.beginGroup("Processor");
39  setupGeneral();
40  bool allDepsAreThere(true);
41 
42  string hName(s.value("Name","Unknown").toString().toStdString());
43  if (hName != "Unknown")
44  {
45  _pHist = setupDependency("",hName);
46  allDepsAreThere = _pHist && allDepsAreThere;
47  }
48 
49  string summaryName(s.value("SummaryName","Unknown").toString().toStdString());
50  if (summaryName != "Unknown")
51  {
52  _summaryHist = setupDependency("",summaryName);
53  allDepsAreThere = _summaryHist && allDepsAreThere;
54  }
55 
56  bool ret (setupCondition());
57  if (!(ret && allDepsAreThere))
58  return;
59 
60  if (_pHist)
61  {
62  const result_t &hist(_pHist->result());
63  if (hist.dim() != 2)
64  throw invalid_argument("pp1500: The histogram '" + _pHist->name()
65  + "' is not a 2d histogram");
66  }
67 
68  if (_summaryHist)
69  {
70  const result_t &sHist(_summaryHist->result());
71  if (sHist.dim() != 2)
72  throw invalid_argument("pp1500: The summary histogram '" + _summaryHist->name()
73  + "'is not a 2d histogram");
74  }
75 
76  /** when requested add the first subdir to the filename and make sure that the
77  * directory exists.
78  */
79  _basefilename = s.value("FileBaseName",QString::fromStdString(_basefilename)).toString().toStdString();
80  _maxFilePerSubDir = s.value("MaximumNbrFilesPerDir",-1).toInt();
81  _filecounter = 0;
82  if(_maxFilePerSubDir != -1)
84 
85  _hide = true;
86  Log::add(Log::INFO,"Processor '" + name() +
87  "' CBF Writer: " +
88  "Basename '" + _basefilename + "'" +
89  (_pHist? " Histname '" + _pHist->name() +"'" :"") +
90  (_summaryHist? " Summary Histogram '" + _summaryHist->name() + "'":"") +
91  ". Condition is '" + _condition->name() + "'");
92 }
93 
95 {
96  throw logic_error("pp1500::result: '"+name()+"' should never be called");
97 }
98 
100 {
101  /** return if there is no histogram to be written */
102  if (!_pHist)
103  return;
104 
105  /** return if the condition for this pp is false */
106  if (!_condition->result(evt.id()).isTrue())
107  return;
108 
109  QMutexLocker locker(&_lock);
110 
111  /** increment subdir in filename when they should be distributed and the
112  * counter exeeded the maximum amount of files per subdir
113  */
115  {
116  _filecounter = 0;
118  }
119  ++_filecounter;
120 
121  const result_t& hist(_pHist->result(evt.id()));
122 
123  QReadLocker lock(&hist.lock);
124 
125  /** create filename from base filename + event id */
126  string filename(_basefilename + "_" + toString(evt.id()) + ".cbf");
127  CBF::write(filename,hist.begin(),hist.shape());
128 }
129 
131 {
132  /** return if there is no summary to be written */
133  if (!_summaryHist)
134  return;
135 
136  QMutexLocker locker(&_lock);
137  const result_t& sHist(_summaryHist->result());
138  QReadLocker lock(&sHist.lock);
139 
140  /** create filename from base filename, but first remove subdir from filename
141  * when they should be distributed
142  */
143  if (_maxFilePerSubDir != -1)
145  string filename(_basefilename + "_Summary.cbf");
146  CBF::write(filename,sHist.begin(),sHist.shape());
147 }
Event to store all LCLS Data.
Definition: cass_event.h:32
std::string _basefilename
the filename that the data will be written to
Definition: cbf_output.h:61
handle cbf files
const name_t name() const
retrieve the name of this processor
Definition: processor.h:167
file contains declaration of the CASSEvent
shared_pointer _summaryHist
pp containing histogram that will be written as summary to dump to cbf
Definition: cbf_output.h:67
Settings for CASS.
Definition: cass_settings.h:30
pp1500(const name_t &)
constructor
Definition: cbf_output.cpp:28
uint64_t id_t
define the id type
Definition: cass_event.h:52
bool _hide
flag to tell whether this pp should be hidden in the dropdown list
Definition: processor.h:262
STL namespace.
static std::string increaseDirCounter(const std::string &fname)
increase the alpha counter
shared_pointer _pHist
pp containing histogram to dump to cbf
Definition: cbf_output.h:64
static void add(Level level, const std::string &line)
add a string to the log
Definition: log.cpp:31
const_iterator begin() const
retrieve a iterator for read access to beginning
Definition: result.hpp:608
fromStdString(const std::string &str)
base class for processors.
Definition: processor.h:39
shared_pointer setupDependency(const std::string &depVarName, const name_t &name="")
setup the dependecy.
Definition: processor.cpp:114
virtual const result_t & result(const CASSEvent::id_t eventid=0)
overwrite the retrieval of an histogram
Definition: cbf_output.cpp:94
virtual void processEvent(const CASSEvent &)
overwrite process event
Definition: cbf_output.cpp:99
file contains declaration of classes and functions that help other processors to do their job...
QReadWriteLock lock
lock for locking operations on the data of the container
Definition: result.hpp:954
id_t & id()
setters
Definition: cass_event.h:64
std::string toString(const Type &t)
convert any type to a string
Definition: cass.h:63
value(const QString &key, const QVariant &defaultValue=QVariant()
int _maxFilePerSubDir
the number of files in each subdir
Definition: cbf_output.h:70
void setupGeneral()
general setup of the processor
Definition: processor.cpp:85
static std::string removeAlphaSubdir(const std::string &fname)
remove the alpha counter subdir from filename
int _filecounter
counter to count how many files have been written
Definition: cbf_output.h:73
file contains specialized class that do the settings for cass
QMutex _lock
a lock to make the process reentrant
Definition: cbf_output.h:77
output of 2d histograms into the cbf.
shared_pointer _condition
pointer to the processor that will contain the condition
Definition: processor.h:277
virtual void aboutToQuit()
dump dark to cbf just before quitting
Definition: cbf_output.cpp:130
shape_t shape() const
return the shape of the result
Definition: result.hpp:811
bool setupCondition(bool defaultConditionType=true)
setup the condition.
Definition: processor.cpp:94
std::string name_t
define the name type
Definition: processor.h:46
contains a logger for cass
static std::string intializeDir(const std::string &fname)
initialize the directory
beginGroup(const QString &prefix)
void write(const std::string &filename, std::vector< float >::const_iterator data, const std::pair< int, int > &shape)
write cbf file
Definition: cbf_handle.hpp:35
virtual void loadSettings(size_t)
load the settings of this pp
Definition: cbf_output.cpp:34