HYDRA_development_version
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hspectrometer.cc
Go to the documentation of this file.
1 //*-- AUTHOR : Ilse Koenig
2 //*-- Modified : 30/12/02 by Ilse Koenig
3 //*-- Modified : 11/12/01 by Ilse Koenig
4 //*-- Modified : 29/07/99 by Ilse Koenig
5 //*-- Modified : 10/05/01 by Dan Magestro
6 
7 //_HADES_CLASS_DESCRIPTION
8 /////////////////////////////////////////////////////////////
9 // HSpectrometer
10 //
11 // class for the actual setup of the HADES spectrometer used
12 // in the analysis.
13 // It contains the list of defined detectors.
14 //
15 /////////////////////////////////////////////////////////////
16 using namespace std;
17 #include "hspectrometer.h"
18 #include "hdetector.h"
19 #include "hades.h"
20 #include "hruntimedb.h"
21 #include "hpario.h"
22 #include "hparrootfileio.h"
23 #include "hdetpario.h"
24 #include "hcondparrootfileio.h"
25 #include "hspecparrootfileio.h"
26 #include "hparasciifileio.h"
27 #include "hcondparasciifileio.h"
28 #include "hspecparasciifileio.h"
29 #include "hgeomshapes.h"
30 #include "TClass.h"
31 #include <iostream>
32 #include <iomanip>
33 #include <stdlib.h>
34 
36 
37 HSpectrometer::HSpectrometer(void) : TNamed("Hades","The Hades spectrometer") {
38  // constructor creates an empty list of detectors
39  detectors=new TList();
40  changed=kFALSE;
41  shapes = 0;
42 }
43 
45  // destructor
46  detectors->Delete();
47  delete detectors;
48  if (shapes) { delete shapes; shapes = 0; }
49 }
50 
52  // adds a detector to the list of detectors
53  detectors->Add(det);
54  changed=kTRUE;
55 }
56 
57 HDetector* HSpectrometer::getDetector(const Char_t* name) {
58  // returns a pointer to the detector called by name
59  return ((HDetector*)detectors->FindObject(name));
60 }
61 
62 Bool_t HSpectrometer::init(void) {
63  // Calls the init function of each detector in the spectrometer.
64  // The string level indicates the start level of the analysis
65  // Each detector (as e.g. MDC) which needs special initialization
66  // before creating the tasks must have an init(...)-function
67  TIter next(detectors);
68  HDetector *det=0;
69  while ((det=(HDetector *)next())) {
70  if (!det->init()) return kFALSE;
71  }
72  return kTRUE;
73 }
74 
76  // activates the spectrometer I/O
77  // loops over the list of detectors and activates the
78  // corresponding detector I/Os
79  const Char_t* ioName=io->IsA()->GetName();
80  if (strcmp(ioName,"HParOraIo")==0) {
81  io->setDetParIo("HCondParIo");
82  io->setDetParIo("HSpecParIo");
83  } else {
84  if (strcmp(ioName,"HParRootFileIo")==0) {
86  new HCondParRootFileIo(((HParRootFileIo*)io)->getParRootFile());
87  io->setDetParIo(p);
88  p=new HSpecParRootFileIo(((HParRootFileIo*)io)->getParRootFile());
89  io->setDetParIo(p);
90  } else {
91  if (strcmp(ioName,"HParAsciiFileIo")==0) {
93  new HCondParAsciiFileIo(((HParAsciiFileIo*)io)->getFile());
94  io->setDetParIo(p);
95  p=new HSpecParAsciiFileIo(((HParAsciiFileIo*)io)->getFile());
96  io->setDetParIo(p);
97  }
98  }
99  }
100  TIter next(detectors);
101  HDetector* det;
102  while ((det=(HDetector*)next())) {
103  det->activateParIo(io);
104  }
105 }
106 
108  // writes the actual setup to the output defined in the
109  // runtime database
111  if (io) return write(io);
112  cerr<<"actual setup couldn't be written to output"<<endl;
113  return kFALSE;
114 }
115 
117  // writes the actual setup to the output
118  TIter next(detectors);
119  HDetector* det=0;
120  Bool_t rc=kTRUE;
121  while ((det=(HDetector*)next())) {
122  if (det->write(io)==kFALSE) rc=kFALSE;
123  }
124  if (rc==kTRUE) changed=kFALSE;
125  else cerr<<"actual setup couldn't be written to output"<<endl;
126  return rc;
127 }
128 
130  if (shapes==0) shapes=new HGeomShapes();
131  return shapes;
132 }
133 
135  // prints the actual setup
136  cout<<"Actual setup for Hades Spectrometer:"<<"\n";
137  TIter next(detectors);
138  HDetector* det=0;
139  while ((det=(HDetector*)next())) {
140  det->print();
141  }
142 }
143 
144 void HSpectrometer::Streamer(TBuffer &R__b)
145 {
146  // Stream an object of class HSpectrometer
147 
148  if (R__b.IsReading()) {
149  Version_t R__v = R__b.ReadVersion(); if (R__v) { }
150  TObject::Streamer(R__b);
151  R__b >> detectors;
152  R__b >> shapes;
153  if (detectors->GetSize() == 0) {
154  printf(" detectors list empty ! \n");
155  exit(0);
156  }
157  } else {
158  R__b.WriteVersion(HSpectrometer::IsA());
159  TObject::Streamer(R__b);
160  R__b << detectors;
161  R__b << shapes;
162 
163  }
164 }
165 
HGeomShapes * getShapes()
Bool_t init(void)
void activateParIo(HParIo *io)
virtual Bool_t write(HParIo *)
Definition: hdetector.h:32
HRuntimeDb * getRuntimeDb(void)
Definition: hades.h:111
virtual void setDetParIo(HDetParIo *)
Definition: hpario.cc:34
void addDetector(HDetector *det)
Definition: hpario.h:11
virtual void activateParIo(HParIo *)
Definition: hdetector.h:33
HDetector * getDetector(const Char_t *name)
ClassImp(HSpectrometer) HSpectrometer
Hades * gHades
Definition: hades.cc:1213
Bool_t rc
void print()
Definition: hdetector.cc:104
Definition: hades.h:37
virtual Bool_t init(void)
Definition: hdetector.h:31
HParIo * getOutput(void)
Definition: hruntimedb.cc:646