Diana Software
MRunDataLoader.cc
Go to the documentation of this file.
1 #include "MRunDataLoader.hh"
2 #include "QEvent.hh"
3 #include "QRawEvent.hh"
4 #include "QError.hh"
5 #include "QBaseType.hh"
6 #include "QRunDataHandle.hh"
7 
8 
9 using namespace Diana;
10 
12 
14 {
15 }
16 
18 {
19 }
20 
22 {
23  fIsOnline = GetBool("IsOnline",false,false);
24  fRunDataOwner = GetString("RunDataOwner","DAQ",false);
25  fRunDataInput = GetString("Input" ,"DB");
26  fRunDataOutputFile = GetString("Output","",false);
27  fWriteIntoEvent = GetBool("WriteIntoEvent",false,false);
28  if(fWriteIntoEvent) {
29  ev.Add<QChannelRunData>("ChannelRunData");
30  }
31  fSaveRunData = (fRunDataOutputFile != "");
32  if(fSaveRunData) {
33  fRunDataOutputFile2 = GetString("Output2","",false);
34  }
35  fThisRun = -9999999;
36  ev.Require<QHeader>("DAQ","Header");
37  int dataset = GetInt("Dataset",-1,false);
38  if(dataset > 0) {
39  if(fWriteIntoEvent) {
40  ev.Add<QInt>("Dataset");
41  }
42  GlobalHandle<QInt> dHandle("Dataset");
43  dHandle.Set(dataset);
44  GlobalData().Set(&dHandle,"");
45  }
46  fRunsInput = GetString("RunsInput",fRunDataInput,false);
47 }
48 
50 {
51  const QHeader& raw = ev.Get<QHeader>("DAQ","Header");
52  const int currRun = raw.GetRun();
53 
54  bool load = false;
55  if(currRun != fThisRun) {
56  fThisRun = currRun;
57  fRunData.Reset();
58  load = true;
59  }
60 
61  if(load) {
62  // get rundata
63  QRunDataHandle rdh(fThisRun);
64  rdh.SetIsOnline(fIsOnline);
65  GlobalData().Get(fRunDataOwner,&rdh,fRunDataInput);
66  if(!rdh.IsValid()) {
67  Error("RunData is not valid for run %d. Error: %s",fThisRun,rdh.GetError().GetDescription().c_str());
68  load = false;
69  } else {
70  fRunData = rdh.Get();
71 
72  // save rundata to files
73  if(fSaveRunData) {
74  GlobalData().Set(&rdh,fRunDataOutputFile);
75  if(fRunDataOutputFile2 != "")
76  GlobalData().Set(&rdh,fRunDataOutputFile2);
77  }
78  // print rundata
79  Info("RunData:");
80  std::stringstream dump;
81  rdh.Get().Dump(dump);
82  Info("%s",dump.str().c_str());
83  }
84  GlobalHandle<QInt> dHandle("Dataset");
85  GlobalData().Get(&dHandle,"");
86  if(dHandle.IsValid() && fRunsInput != "NONE") {
87  // MV FIXME: check that runnumber is in dataset
88  } // dataset
89  }
90 
91  if(fWriteIntoEvent) {
92  // save into event channel based information
93  const QPulseInfo& pi = ev.Get<QPulseInfo>("DAQ","PulseInfo");
94  const int channel = pi.GetChannelId();
95 
96  if(fRunData.IsValid()) {
97  const QChannelRunData& channelRunData = fRunData.GetChannelRunData(channel);
98  ev.Get<QChannelRunData>("ChannelRunData") = channelRunData;
99  }
100  GlobalHandle<QInt> dHandle("Dataset");
101  GlobalData().Get(&dHandle,"");
102  if(dHandle.IsValid()) {
103  ev.Get<QInt>("Dataset") = dHandle.Get();
104  }
105  }
106 
107  return;
108 }
109 
111 {
112 }
const int channel
#define REGISTER_MODULE(clazz)
Definition: QDriver.hh:133
Module to load commonly used run and detector information.
virtual void Done()
virtual void Do(Diana::QEvent &ev)
virtual ~MRunDataLoader()
virtual void Init(Diana::QEvent &ev)
base types wrapped into a QObject. Currently implemented types are QInt QDouble and QFloat....
Definition: QBaseType.hh:17
basic channel and run based info. Used in the QRunData object.
diana event
Definition: QEvent.hh:46
void Require(const std::string &owner, const std::string &name) const
notify the QEvent that we need a QObject, if not found an exception is thrown
Definition: QEvent.hh:232
void Get(const char *owner, ReadHandle< Q > &handle) const
Get a QObject Handle in read mode.
Definition: QEvent.hh:74
void Add(WriteHandle< Q > &handle)
Add a QObject to the event.
Definition: QEvent.hh:193
Raw event: basic information like run number and time.
Definition: QHeader.hh:16
int GetRun() const
destructor
Definition: QHeader.hh:22
Raw event: bolometer channel, trigger positions and types.
Definition: QPulseInfo.hh:18
const int & GetChannelId() const
Get ChannelId.
Definition: QPulseInfo.hh:22
global handle for QRunData
void SetIsOnline(bool isOnline=true)
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...