FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairParSet.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 //*-- AUTHOR : Ilse Koenig
9 //*-- Created : 20/10/2004
10 
12 // FairParSet
13 //
14 // Base class for all parameter containers
16 #include "FairParSet.h"
17 
18 #include "FairLogger.h" // for FairLogger, MESSAGE_ORIGIN
19 #include "FairRuntimeDb.h" // for FairRuntimeDb
20 
21 #include <iostream> // for operator<<, ostream, etc
22 
23 using std::cout;
24 
26 
27 FairParSet::FairParSet(const char* name, const char* title, const char* context, Bool_t owner)
28  : TObject()
29  , fName(name)
30  , fTitle(title)
31  , detName("")
32  , versions()
33  , status(kFALSE)
34  , changed(kFALSE)
35  , owned(owner)
36  , paramContext(context)
37  , author("")
38  , description("")
39  , fLogger(FairLogger::GetLogger())
40 {
41  for (Int_t i = 0; i < 3; i++) {
42  versions[i] = -1;
43  }
44 }
45 
47 {
48  // intitializes the container from an input in run time
49  // database. If this is not successful it is initialized from
50  // the second input. If this failes too, it returns an error.
51  // (calls internally the init function in the derived class)
53  // FairRunAna* fRun =FairRunAna::Instance();
54  // cout << "-I- FairParSet::init() " << GetName() << endl;
55 
56  Bool_t allFound = kFALSE;
57  FairParIo* io = 0;
58  if (rtdb) {
59  io = rtdb->getFirstInput();
60  if (io) {
61  allFound = init(io);
62  }
63  if (!allFound) {
64  io = rtdb->getSecondInput();
65  // cout << "-I FairParSet::init() 2 " << io << std::endl;
66  if (io) {
67  allFound = init(io);
68  }
69  } else {
70  setInputVersion(-1, 2);
71  }
72  }
73  if (allFound) {
74  return kTRUE;
75  }
76  LOG(error) << "init() " << GetName() << " not initialized";
77  return kFALSE;
78 }
79 
81 {
82  // writes the container to the output defined in the runtime database
83  // returns the output version in the ROOT file
84  // returns -1 if error occured
85  // (calls internally the init function in the derived class)
87  if (output) {
88  return write(output);
89  }
90  LOG(error) << "write() " << GetName() << " could not be written to output";
91  return -1;
92 }
93 
95 {
96  // prints information about container (versions,status,hasChanged...)
97  cout << "----- " << GetName() << " -----" << '\n';
98  if (!paramContext.IsNull()) {
99  cout << "Context/Purpose: " << paramContext << '\n';
100  }
101  if (!author.IsNull()) {
102  cout << "Author: " << author << '\n';
103  }
104  if (!description.IsNull()) {
105  cout << "Description: " << description << '\n';
106  }
107  cout << "first input version: " << versions[1] << '\n';
108  cout << "second input version: " << versions[2] << '\n';
109  if (changed) {
110  cout << "has changed" << '\n';
111  } else {
112  cout << "has not changed" << '\n';
113  }
114  if (status) {
115  cout << "is static" << '\n';
116  } else {
117  cout << "is not static" << '\n';
118  }
119 }
120 
122 {
123  // resets the input versions if the container is not static
124  if (!status) {
125  for (Int_t i = 0; i < 3; i++) {
126  versions[i] = -1;
127  }
128  changed = kFALSE;
129  }
130 }
131 
133  : TObject(from)
134  , fName(from.fName)
135  , fTitle(from.fTitle)
136  , detName(from.detName)
137  , versions()
138  , status(from.status)
139  , changed(from.changed)
140  , owned(from.owned)
141  , paramContext(from.paramContext)
142  , author(from.author)
143  , description(from.description)
144  , fLogger(FairLogger::GetLogger())
145 {
146  /*
147  fName = from.fName;
148  fTitle = from.fTitle;
149  detName = from.detName;
150 */
151  for (Int_t i = 0; i < 3; i++)
152  versions[i] = from.versions[i];
153  /*
154  status = from.status;
155  changed = from.changed;
156  owned = from.owned;
157  paramContext = from.paramContext;
158  author = from.author;
159  description = from.description;
160  fLogger = from.fLogger;
161 */
162 }
163 
165 {
166  if (this == &from) {
167  return *this;
168  }
169 
170  TObject::operator=(from);
171  fName = from.fName;
172  fTitle = from.fTitle;
173  detName = from.detName;
174  for (Int_t i = 0; i < 3; i++)
175  versions[i] = from.versions[i];
176  status = from.status;
177  changed = from.changed;
178  owned = from.owned;
179  paramContext = from.paramContext;
180  author = from.author;
181  description = from.description;
182  fLogger = from.fLogger;
183 
184  return *this;
185 }
list of container factories
Definition: FairRuntimeDb.h:24
virtual const char * GetName() const
Definition: FairParSet.h:38
Bool_t status
versions of container in the 2 possible inputs
Definition: FairParSet.h:25
TString fName
Definition: FairParSet.h:21
TString detName
Definition: FairParSet.h:23
virtual Int_t write()
Definition: FairParSet.cxx:80
TString author
Definition: FairParSet.h:29
static FairRuntimeDb * instance(void)
Bool_t owned
flag is kTRUE if parameters have changed
Definition: FairParSet.h:27
Bool_t changed
static flag
Definition: FairParSet.h:26
TString description
Definition: FairParSet.h:30
virtual void print()
Definition: FairParSet.cxx:94
FairParSet & operator=(const FairParSet &)
Definition: FairParSet.cxx:164
ClassImp(FairEventBuilder)
FairParSet(const char *name="", const char *title="", const char *context="", Bool_t owner=kFALSE)
Definition: FairParSet.cxx:27
FairLogger * fLogger
Definition: FairParSet.h:32
virtual Bool_t init()
Definition: FairParSet.cxx:46
TString paramContext
if flag is KTRUE FairDB has the par. class ownership
Definition: FairParSet.h:28
Int_t versions[3]
name of the detector the container belongs to
Definition: FairParSet.h:24
FairParIo * getSecondInput(void)
void setInputVersion(Int_t v=-1, Int_t i=0)
Definition: FairParSet.h:51
FairParIo * getOutput(void)
void resetInputVersions()
Definition: FairParSet.cxx:121
TString fTitle
Definition: FairParSet.h:22
FairParIo * getFirstInput(void)