ROOT logo
//*-- AUTHOR : Ilse Koenig
//*-- Modified : 30/12/02 by Ilse Koenig
//*-- Modified : 11/12/01 by Ilse Koenig
//*-- Modified : 29/07/99 by Ilse Koenig
//*-- Modified : 10/05/01 by Dan Magestro

//_HADES_CLASS_DESCRIPTION 
/////////////////////////////////////////////////////////////
// HSpectrometer
//
//  class for the actual setup of the HADES spectrometer used
//  in the analysis.
//  It contains the list of defined detectors.
//
/////////////////////////////////////////////////////////////
using namespace std;
#include "hspectrometer.h"
#include "hdetector.h"
#include "hades.h"
#include "hruntimedb.h"
#include "hpario.h"
#include "hparrootfileio.h"
#include "hdetpario.h"
#include "hcondparrootfileio.h"
#include "hspecparrootfileio.h"
#include "hparasciifileio.h"
#include "hcondparasciifileio.h"
#include "hspecparasciifileio.h"
#include "hgeomshapes.h"
#include "TClass.h"
#include <iostream> 
#include <iomanip>
#include <stdlib.h>

ClassImp(HSpectrometer)

HSpectrometer::HSpectrometer(void) : TNamed("Hades","The Hades spectrometer") {
  // constructor creates an empty list of detectors
  detectors=new TList();
  changed=kFALSE;
  shapes = 0;
}

HSpectrometer::~HSpectrometer(void) {
  // destructor
  detectors->Delete();
  delete detectors;
  if (shapes) { delete shapes; shapes = 0; }
}

void HSpectrometer::addDetector(HDetector* det) {
  // adds a detector to the list of detectors
  detectors->Add(det);
  changed=kTRUE;
}

HDetector* HSpectrometer::getDetector(const Char_t* name) {
  // returns a pointer to the detector called by name
  return ((HDetector*)detectors->FindObject(name));
}

Bool_t HSpectrometer::init(void) {
  // Calls the init function of each detector in the spectrometer.
  // The string level indicates the start level of the analysis
  // Each detector (as e.g. MDC) which needs special initialization
  // before creating the tasks must have an init(...)-function
  TIter next(detectors);
  HDetector *det=0;
  while ((det=(HDetector *)next())) {
    if (!det->init()) return kFALSE;
  }
  return kTRUE;
}

void HSpectrometer::activateParIo(HParIo* io) {
  // activates the spectrometer I/O
  // loops over the list of detectors and activates the
  // corresponding detector I/Os
  const Char_t* ioName=io->IsA()->GetName();
  if (strcmp(ioName,"HParOraIo")==0) {
    io->setDetParIo("HCondParIo");
    io->setDetParIo("HSpecParIo");
  } else {
    if (strcmp(ioName,"HParRootFileIo")==0) {
      HDetParRootFileIo* p=
          new HCondParRootFileIo(((HParRootFileIo*)io)->getParRootFile());
      io->setDetParIo(p);
      p=new HSpecParRootFileIo(((HParRootFileIo*)io)->getParRootFile());
      io->setDetParIo(p);
    } else {
      if (strcmp(ioName,"HParAsciiFileIo")==0) {
        HDetParAsciiFileIo* p=
            new HCondParAsciiFileIo(((HParAsciiFileIo*)io)->getFile());
        io->setDetParIo(p);
        p=new HSpecParAsciiFileIo(((HParAsciiFileIo*)io)->getFile());
        io->setDetParIo(p);
      }
    }
  }
  TIter next(detectors);
  HDetector* det;
  while ((det=(HDetector*)next())) {
    det->activateParIo(io);
  }
}

Bool_t HSpectrometer::write() {
  // writes the actual setup to the output defined in the
  // runtime database
  HParIo* io=gHades->getRuntimeDb()->getOutput();
  if (io) return write(io);
  cerr<<"actual setup couldn't be written to output"<<endl;
  return kFALSE;
}

Bool_t HSpectrometer::write(HParIo* io) {
  // writes the actual setup to the output
  TIter next(detectors);
  HDetector* det=0;
  Bool_t rc=kTRUE;
  while ((det=(HDetector*)next())) {
    if (det->write(io)==kFALSE) rc=kFALSE;
  }
  if (rc==kTRUE) changed=kFALSE;
  else cerr<<"actual setup couldn't be written to output"<<endl;
  return rc;
}

HGeomShapes* HSpectrometer::getShapes() {
  if (shapes==0) shapes=new HGeomShapes();
  return shapes;
}

void HSpectrometer::print() {
  // prints the actual setup
  cout<<"Actual setup for Hades Spectrometer:"<<"\n";
  TIter next(detectors);
  HDetector* det=0;
  while ((det=(HDetector*)next())) {
    det->print();
  }
}

void HSpectrometer::Streamer(TBuffer &R__b)
{
   // Stream an object of class HSpectrometer

   if (R__b.IsReading()) {
      Version_t R__v = R__b.ReadVersion(); if (R__v) { }
      TObject::Streamer(R__b);
      R__b >> detectors;
      R__b >> shapes;
      if (detectors->GetSize() == 0) {
                  printf(" detectors list empty ! \n");
                  exit(0);
                    }
   } else {
      R__b.WriteVersion(HSpectrometer::IsA());
      TObject::Streamer(R__b);
      R__b << detectors;
      R__b << shapes;

   }
}

 hspectrometer.cc:1
 hspectrometer.cc:2
 hspectrometer.cc:3
 hspectrometer.cc:4
 hspectrometer.cc:5
 hspectrometer.cc:6
 hspectrometer.cc:7
 hspectrometer.cc:8
 hspectrometer.cc:9
 hspectrometer.cc:10
 hspectrometer.cc:11
 hspectrometer.cc:12
 hspectrometer.cc:13
 hspectrometer.cc:14
 hspectrometer.cc:15
 hspectrometer.cc:16
 hspectrometer.cc:17
 hspectrometer.cc:18
 hspectrometer.cc:19
 hspectrometer.cc:20
 hspectrometer.cc:21
 hspectrometer.cc:22
 hspectrometer.cc:23
 hspectrometer.cc:24
 hspectrometer.cc:25
 hspectrometer.cc:26
 hspectrometer.cc:27
 hspectrometer.cc:28
 hspectrometer.cc:29
 hspectrometer.cc:30
 hspectrometer.cc:31
 hspectrometer.cc:32
 hspectrometer.cc:33
 hspectrometer.cc:34
 hspectrometer.cc:35
 hspectrometer.cc:36
 hspectrometer.cc:37
 hspectrometer.cc:38
 hspectrometer.cc:39
 hspectrometer.cc:40
 hspectrometer.cc:41
 hspectrometer.cc:42
 hspectrometer.cc:43
 hspectrometer.cc:44
 hspectrometer.cc:45
 hspectrometer.cc:46
 hspectrometer.cc:47
 hspectrometer.cc:48
 hspectrometer.cc:49
 hspectrometer.cc:50
 hspectrometer.cc:51
 hspectrometer.cc:52
 hspectrometer.cc:53
 hspectrometer.cc:54
 hspectrometer.cc:55
 hspectrometer.cc:56
 hspectrometer.cc:57
 hspectrometer.cc:58
 hspectrometer.cc:59
 hspectrometer.cc:60
 hspectrometer.cc:61
 hspectrometer.cc:62
 hspectrometer.cc:63
 hspectrometer.cc:64
 hspectrometer.cc:65
 hspectrometer.cc:66
 hspectrometer.cc:67
 hspectrometer.cc:68
 hspectrometer.cc:69
 hspectrometer.cc:70
 hspectrometer.cc:71
 hspectrometer.cc:72
 hspectrometer.cc:73
 hspectrometer.cc:74
 hspectrometer.cc:75
 hspectrometer.cc:76
 hspectrometer.cc:77
 hspectrometer.cc:78
 hspectrometer.cc:79
 hspectrometer.cc:80
 hspectrometer.cc:81
 hspectrometer.cc:82
 hspectrometer.cc:83
 hspectrometer.cc:84
 hspectrometer.cc:85
 hspectrometer.cc:86
 hspectrometer.cc:87
 hspectrometer.cc:88
 hspectrometer.cc:89
 hspectrometer.cc:90
 hspectrometer.cc:91
 hspectrometer.cc:92
 hspectrometer.cc:93
 hspectrometer.cc:94
 hspectrometer.cc:95
 hspectrometer.cc:96
 hspectrometer.cc:97
 hspectrometer.cc:98
 hspectrometer.cc:99
 hspectrometer.cc:100
 hspectrometer.cc:101
 hspectrometer.cc:102
 hspectrometer.cc:103
 hspectrometer.cc:104
 hspectrometer.cc:105
 hspectrometer.cc:106
 hspectrometer.cc:107
 hspectrometer.cc:108
 hspectrometer.cc:109
 hspectrometer.cc:110
 hspectrometer.cc:111
 hspectrometer.cc:112
 hspectrometer.cc:113
 hspectrometer.cc:114
 hspectrometer.cc:115
 hspectrometer.cc:116
 hspectrometer.cc:117
 hspectrometer.cc:118
 hspectrometer.cc:119
 hspectrometer.cc:120
 hspectrometer.cc:121
 hspectrometer.cc:122
 hspectrometer.cc:123
 hspectrometer.cc:124
 hspectrometer.cc:125
 hspectrometer.cc:126
 hspectrometer.cc:127
 hspectrometer.cc:128
 hspectrometer.cc:129
 hspectrometer.cc:130
 hspectrometer.cc:131
 hspectrometer.cc:132
 hspectrometer.cc:133
 hspectrometer.cc:134
 hspectrometer.cc:135
 hspectrometer.cc:136
 hspectrometer.cc:137
 hspectrometer.cc:138
 hspectrometer.cc:139
 hspectrometer.cc:140
 hspectrometer.cc:141
 hspectrometer.cc:142
 hspectrometer.cc:143
 hspectrometer.cc:144
 hspectrometer.cc:145
 hspectrometer.cc:146
 hspectrometer.cc:147
 hspectrometer.cc:148
 hspectrometer.cc:149
 hspectrometer.cc:150
 hspectrometer.cc:151
 hspectrometer.cc:152
 hspectrometer.cc:153
 hspectrometer.cc:154
 hspectrometer.cc:155
 hspectrometer.cc:156
 hspectrometer.cc:157
 hspectrometer.cc:158
 hspectrometer.cc:159
 hspectrometer.cc:160
 hspectrometer.cc:161
 hspectrometer.cc:162
 hspectrometer.cc:163
 hspectrometer.cc:164
 hspectrometer.cc:165