Diana Software
GlobalDataManagerExample.C
example macro on the use of
QGlobalDataManager
in the CINT/ROOT interpreter.
Author
Marco Vignati
{
// using namespace Diana;
// Avoid to put "Diana::" in front of diana objects.
// This turns out to be mandatory in Cint since there are
// problems with namespaces in conjunction with templates and
// typedefs
using namespace
Diana
;
gSystem->Load(
"libqroot"
);
// In diana there is a common instance of QGlobalDataManager
// that is accessed via QBaseModule::GlobalData().
// Here instead we have to create it.
QGlobalDataManager
dm
;
// set the owner of the new QObjects that we will save
// in diana this method is not accessible, and the owner is
// set to the current module being executed.
dm
.
SetOwner
(
"DataManagerTest"
);
// Create two QVectors and save to file
QVector
vec
(3),
vec2
(4);
vec
[0] = 1;
vec
[1] = 2;
vec
[2] = 3;
vec2
[0] = -1;
vec2
[1] = 0;
vec2
[2] = 1;
vec2
[3] = 2;
// Create a GlobalHandle instance to manage each QVector
// with the QGlobalDataManager. In the first we set Channel as key.
GlobalHandle<QVector>
hvec
(
"MyQVector"
);
hvec
.SetChannel(3);
hvec
.Set(
vec
);
dm
.
Set
(&
hvec
,
"dmtest.root"
);
// In the second we set Run as key
GlobalHandle<QVector>
hvec2
(
"MyQVector2"
);
hvec2
.SetRun(753);
hvec2
.Set(
vec2
);
dm
.
Set
(&
hvec2
,
"dmtest.root"
);
// Get RunData from DB and save it to file, owner will remain "DAQ".
// since object is not modified.
// The QRunData QObject has a specialized handle, the QRunDataHandle,
// that implements the specific DB queries
QRunDataHandle
rHandle
(753);
dm
.
Get
(
"DAQ"
,&
rHandle
,
"DB"
);
dm
.
Set
(&
rHandle
,
"dmtest.txt"
);
// Modify QRunData and set to file, owner will be "DataManagerTest" since we modified it.
// We have to create a new handle, since each object needs its own handle
QRunData
newRunData
=
rHandle
.Get();
const
int
channel
=
newRunData
.
fBolometerChannels
[0];
// modify sampling frequency of this channel;
QChannelRunData
chanRunData
=
newRunData
.
GetChannelRunData
(
channel
);
chanRunData
.
fSamplingFrequency
= 250;
newRunData
.
SetChannelRunData
(
channel
,
chanRunData
);
QRunDataHandle
rHandle2
(
newRunData
.
fNumber
);
rHandle2
.Set(
newRunData
);
dm
.
Set
(&
rHandle2
,
"dmtest.root"
);
// Write a TObject using a TObjectHandle onto a .root file
TH1D
histo
(
"histo"
,
"My histogram"
,10,-5,5);
histo
.Fill(1.1);
histo
.Fill(3);
QTObjectHandle<TH1D>
hHandle
(
"MyHisto"
);
hHandle
.SetChannel(3);
hHandle
.SetRun(753);
hHandle
.Set(
histo
);
dm
.
Set
(&
hHandle
,
"dmtest.root"
);
// print objects in cache
dm
.
Dump
(cout);
cout<<
"***** ATTENTION: Errors below are generated intentionally ******"
<<endl;
// Here we show how a write error appears
QInt
testInt = 2;
GlobalHandle<QInt>
intHandle2
(
"MyFakeInt"
);
intHandle2
.Set(testInt);
// if we are not root we have no write permissions
dm
.
Set
(&
intHandle2
,
"/root/dianaglobal.root"
);
// Here we show how a read error appears
GlobalHandle<QInt>
intHandle2
(
"MyFakeInt2"
);
dm
.
Get
(
"MyFakeOwner"
,&
intHandle2
,
"fakefile.txt"
);
int
myInt
;
// the Get() call in the line below will abort the program
// since the object is not valid.
myInt
=
intHandle2
.Get();
// To not abort, comment the above line and handle the error as follows:
if
(!
intHandle2
.IsValid()) {
cout<<
intHandle2
.GetError()<<endl;
}
else
{
myInt
=
intHandle2
.Get();
}
}
intHandle2
dm Set & intHandle2
Definition:
GlobalDataManagerExample.C:78
rHandle
QRunDataHandle rHandle(753)
Definition:
GlobalDataManagerExample.C:46
myInt
int myInt
Definition:
GlobalDataManagerExample.C:83
channel
const int channel
Definition:
GlobalDataManagerExample.C:51
vec
QVector vec(3)
Definition:
GlobalDataManagerExample.C:26
histo
TH1D histo("histo","My histogram", 10,-5, 5)
hvec2
GlobalHandle< QVector > hvec2("MyQVector2")
Definition:
GlobalDataManagerExample.C:38
chanRunData
QChannelRunData chanRunData
Definition:
GlobalDataManagerExample.C:52
rHandle2
dm Set & rHandle2
Definition:
GlobalDataManagerExample.C:57
hvec
GlobalHandle< QVector > hvec("MyQVector")
Definition:
GlobalDataManagerExample.C:33
dm
QGlobalDataManager dm
Definition:
GlobalDataManagerExample.C:18
hHandle
QTObjectHandle< TH1D > hHandle("MyHisto")
Definition:
GlobalDataManagerExample.C:67
newRunData
QRunData newRunData
Definition:
GlobalDataManagerExample.C:50
vec2
QVector vec2(4)
Definition:
GlobalDataManagerExample.C:27
GlobalHandle
template class to handle diana global QObject with QGlobalDataManager
Definition:
QGlobalHandle.hh:41
QBaseType
base types wrapped into a QObject. Currently implemented types are QInt QDouble and QFloat....
Definition:
QBaseType.hh:17
QChannelRunData
basic channel and run based info. Used in the QRunData object.
Definition:
QChannelRunData.hh:15
QChannelRunData::fSamplingFrequency
double fSamplingFrequency
sampling frequency in Hz
Definition:
QChannelRunData.hh:33
QGlobalDataManager
Object to manage I/O (DB, file, or memory) of diana global quantities.
Definition:
QGlobalDataManager.hh:48
QGlobalDataManager::SetOwner
void SetOwner(const std::string &owner)
set the module that is accessing this object
Definition:
QGlobalDataManager.hh:163
QGlobalDataManager::Set
QError Set(GlobalHandle< Q > *gh, const std::string &outSource, bool printError=true) const
Set a QObject using a GlobalHandle.
Definition:
QGlobalDataManager.hh:304
QGlobalDataManager::Get
QError Get(const std::string &owner, GlobalHandle< Q > *gh, const std::string &inSource, bool printError=true) const
Get an object using a global handle.
Definition:
QGlobalDataManager.hh:220
QGlobalDataManager::Dump
void Dump(std::ostream &o) const
Dump cached objects to stream.
Definition:
QGlobalDataManager.cc:58
QRunDataHandle
global handle for QRunData
Definition:
QRunDataHandle.hh:17
QRunData
Basic run based info.
Definition:
QRunData.hh:20
QRunData::fNumber
int fNumber
Run Number.
Definition:
QRunData.hh:41
QRunData::GetChannelRunData
const QChannelRunData & GetChannelRunData(const int channel) const
get channel based run data quantities
Definition:
QRunData.cc:339
QRunData::fBolometerChannels
std::vector< int > fBolometerChannels
Bolometers channels (thermistors glued to a crystal)
Definition:
QRunData.hh:49
QRunData::SetChannelRunData
void SetChannelRunData(const int channel, const QChannelRunData &chanRunData)
set channel based run data quantities
Definition:
QRunData.cc:352
QTObjectHandle
global handle for generic TObject
Definition:
QTObjectHandle.hh:15
QVector
Interface for vectors in Diana analysis.
Definition:
QVector.hh:30
Diana
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...
Generated by
1.9.1