Diana Software
DataManager.cxx
Go to the documentation of this file.
1 
7 #include "QGlobalDataManager.hh"
8 #include "QGlobalRWFactory.hh"
9 #include "QVector.hh"
10 #include "QRunDataHandle.hh"
11 #include <iostream>
12 
13 using namespace Diana;
14 using std::cout;
15 
16 int main()
17 {
18  // Create the GlobalDataManager, in diana there is a common instance that
19  // is accessed via QBaseModule::GlobalData()
21  // set the owner of the new objects that we will save
22  dm.SetOwner("DataManagerTest");
23 
24  // Save a QVector to file
25  QVector vec(3);
26  vec[0] = 1; vec[1] = 2; vec[2] = 3;
27  GlobalHandle<QVector> hvec("MyQVector");
28  hvec.Set(vec);
29  dm.Set(&hvec,"dmtest.root");
30 
31  // Get RunData from DB and save it to file, owner will remain "DAQ"
33  dm.Get("DAQ",&rHandle,"DB");
34  dm.Set(&rHandle,"dmtest.root");
35 
36  // Modify RunData and set to file, owner will be "DataManagerTest" since we modified it
37  QRunData newRunData = rHandle.Get();
38  newRunData.SetThermometerChannel(69);
39  // create a new handle, since each object needs its own handle
40  QRunDataHandle nHandle(newRunData.GetNumber());
41  nHandle.Set(newRunData);
42  dm.Set(&nHandle,"dmtest.root");
43 
44  // print objects in cache
45  dm.Dump(cout);
46 
47  return 0;
48 }
int main()
Definition: DataManager.cxx:16
QRunDataHandle rHandle(753)
QVector vec(3)
GlobalHandle< QVector > hvec("MyQVector")
QGlobalDataManager dm
QRunData newRunData
Object to manage I/O (DB, file, or memory) of diana global quantities.
void SetOwner(const std::string &owner)
set the module that is accessing this object
QError Set(GlobalHandle< Q > *gh, const std::string &outSource, bool printError=true) const
Set a QObject using a GlobalHandle.
QError Get(const std::string &owner, GlobalHandle< Q > *gh, const std::string &inSource, bool printError=true) const
Get an object using a global handle.
void Dump(std::ostream &o) const
Dump cached objects to stream.
global handle for QRunData
Basic run based info.
Definition: QRunData.hh:20
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...