Diana Software
QObject.cc
Go to the documentation of this file.
1 #include "QObject.hh"
2 #include <iostream>
3 #include <sstream>
4 #include "QObjectInspector.hh"
5 #include <TClass.h>
6 
7 using namespace Diana;
8 
9 ClassImp(QObject);
10 
11 
13 
14 QObject* QObject::New(const char* object)
15 {
16  TClass* cl = TClass::GetClass(object);
17  if(!cl) return 0;
18  if(cl->InheritsFrom("Diana::QObject"))
19  return (QObject*)cl->New();
20  return 0;
21 }
22 
24 {
25  InValidate();
26  fTemporaryBits = 0;
27  SetWrite(true);
28  SetIsRequired(true);
29  SetIsJustAdded(false);
30 }
31 
32 QObject& QObject::operator=(const QObject& rhs)
33 {
34  // prevent from copying QObject members.
35  this->TObject::operator=(rhs);
36  return *this;
37 }
38 
39 void QObject::FullyFill(QObject* evData) const
40 {
41  bool valid = false;
42  if(IsValid()) {
43  valid = this->Fill(evData);
44  }
45  if(valid) {
46  evData->Validate();
47  } else {
48  evData->InValidate();
49  }
50  this->CopyBits(evData);
51 }
52 
53 void QObject::Dump(std::ostream& ob) const
54 {
55  // by default use WriteOnStream
56  QObjectInspector insp;
57  ob<<"Dump not implemented, using auto-dump method:"<<std::endl;
58  QError err = insp.DumpOnStream(this,ob);
59  if(err != QERR_SUCCESS) ob << "auto-dump failed with error: "<<err.GetDescription()<<std::endl;
60 }
61 
62 QError QObject::WriteOnStream(std::ostream& ob) const
63 {
64  QObjectInspector insp;
65  return insp.DumpOnStream(this,ob);
66 }
67 
68 QError QObject::ReadFromStream(std::istream& ob)
69 {
70 
71  QObjectInspector insp;
72  return insp.FillFromStream(this,ob);
73 }
74 
75 void QObject::QObjectSetBit(int bit, bool value)
76 {
77  if(value) {
78  fTemporaryBits |= bit;
79  } else {
80  fTemporaryBits &= ~bit;
81  }
82 }
83 
84 void QObject::CopyBits(QObject* obj) const
85 {
86  if(this->IsValid()) {
87  obj->Validate();
88  }
89  obj->fTemporaryBits = fTemporaryBits;
90 }
91 
92 bool QObject::QObjectTestBit(int bit) const
93 {
94  return fTemporaryBits & bit;
95 }
96 
97 
99 
100 std::ostream& operator<<(std::ostream&s,const Diana::QObject&t)
101 {
102  t.Dump(s);
103  return s;
104 }
err
Definition: CheckOF.C:114
histo Fill(1.1)
#define Q_END_NAMESPACE
Definition: QDiana.hh:22
#define Q_BEGIN_NAMESPACE
Definition: QDiana.hh:20
@ QERR_SUCCESS
Definition: QError.hh:27
Q_END_NAMESPACE std::ostream & operator<<(std::ostream &s, const Diana::QObject &t)
Definition: QObject.cc:100
ClassImp(QObject)
error class with error type and description
Definition: QError.hh:115
QError DumpOnStream(const QObject *obj, std::ostream &str)
QError FillFromStream(QObject *obj, std::istream &in)
virtual QError WriteOnStream(std::ostream &o) const
print content to stream (intended for storage in text files)
Definition: QObject.cc:62
virtual void Dump(std::ostream &o) const
print content to stream (intended for screen print or log files)
Definition: QObject.cc:53
void CopyBits(QObject *obj) const
copy validity and temporary bits to another QObject
Definition: QObject.cc:84
void QObjectSetBit(int bit, bool value)
set temporary bit
Definition: QObject.cc:75
bool QObjectTestBit(int bit) const
test temporary bit
Definition: QObject.cc:92
QObject & operator=(const QObject &rhs)
operator=
Definition: QObject.cc:32
virtual QError ReadFromStream(std::istream &o)
fill content from stream (intended for storage in text files)
Definition: QObject.cc:68
static QObject * New(const char *object)
Definition: QObject.cc:14
void FullyFill(QObject *evData) const
calls Fill(QObject*) if this QObject IsValid(). Copies Validity flag and bits
Definition: QObject.cc:39
QObject()
default constructor
Definition: QObject.cc:23
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...