ROOT logo
//*-- AUTHOR : Ilse Koenig
//*-- Created : 25/05/2010 by Ilse Koenig

//_HADES_CLASS_DESCRIPTION 
///////////////////////////////////////////////////////////////////////////////
// HParOra2Io
//
// Hydra2 interface class to database Oracle
// It is derived from interface base class HParIo.
//
// It contains a pointer to the connection class (type HOra2Conn)  and a list
// of interface classes for the detectors. Each detector has its own interface
// class all inherited from a common base class.
//
///////////////////////////////////////////////////////////////////////////////

using namespace std;
#include "hparora2io.h"
#include "hades.h"
#include "hspectrometer.h"
#include "hdetector.h"
#include "hdetpario.h"
#include "hora2info.h"
#include "hcondparora2io.h"
#include "hspecparora2io.h"
#include "hmdcparora2io.h"
#include "htofparora2io.h"
#include "hrichparora2io.h"
#include "hshowerparora2io.h"
#include "hstartparora2io.h"
#include "hwallparora2io.h"
#include "hrpcparora2io.h"
#include "hemcparora2io.h"
#include "hpiontrackerparora2io.h"
#include <stdio.h>
#include <iostream> 
#include <iomanip>

ClassImp(HParOra2Io)

HParOra2Io::HParOra2Io() {
  // private default constructor
  // creates the connection class but doesn't open a connection
  pConn=new HOra2Conn();
  autoWritable=kFALSE;
  inputName="Oracle";
}


HParOra2Io::~HParOra2Io() {
  // default constructor closes an open connection
  close();
  if (pConn) delete pConn;
}


Bool_t HParOra2Io::open() {
  // opens connection to database Hades as user Hades
  // user Hades has Readonly access to Oracle tables
  // all open()-functions activate the detetctor I/Os
  isConnected=pConn->open();
  return activateDetIo();
}


Bool_t HParOra2Io::open(Char_t *userName) {
  // opens connection to database Hades for user given by name
  // asks for password
  isConnected=pConn->open(userName);
  return activateDetIo();
}


Bool_t HParOra2Io::open(Char_t *dbName, Char_t *userName) {
  // opens connection to database with name dbName for user given by name
  // asks for password
  isConnected=pConn->open(dbName,userName);
  return activateDetIo();
} 


Bool_t HParOra2Io::reconnect() {
  // reopens the connection (only applicable for default user hades_ana)
  isConnected=pConn->reconnect();
  return isConnected;
}


void HParOra2Io::close() {
  // closes the connection with automatic ROLLBACK
  pConn->close();
  isConnected=kFALSE;
  if (detParIoList) detParIoList->Delete();
  if (pInfo) {
    delete pInfo;
    pInfo=0;
  }
}


void HParOra2Io::disconnect() {
  pConn->disconnect();
  isConnected=kFALSE;
}


void HParOra2Io::print() {
  // prints information about the database connection
  pConn->print();
  if (isConnected) {
    TIter next(detParIoList);
    HDetParIo* io;
    cout<<"Hydra2 Oracle interface"<<endl;
    cout<<"detector I/Os: ";
    while ((io=(HDetParIo*)next())) {
      cout<<" "<<io->GetName();
    }
    cout<<endl;
  }
}

Bool_t HParOra2Io::setHistoryDate(const Char_t* timestamp) {
  // Sets the date to retrieve historic data
  // Returns kFALSE when the date string cannot be converted to a valid date.
  return pConn->setHistoryDate(timestamp);
}

Bool_t HParOra2Io::setParamRelease(const Char_t* releaseName) {
  // Sets the history date to the creation date of the parameter release give by name
  // Returns kFALSE when the release is not found.
  return pConn->setParamRelease(releaseName);
}

Bool_t HParOra2Io::activateDetIo() {
  // creates the I/O for all detector in the setup
  if (isConnected==kFALSE) return kFALSE;
  pInfo=new HOra2Info(pConn);
  HDetParIo* io=new HCondParOra2Io(pConn);
  detParIoList->Add(io);
  io=new HSpecParOra2Io(pConn);
  detParIoList->Add(io);
  TList* detSet=gHades->getSetup()->getListOfDetectors();
  TIter next(detSet);
  HDetector* det;
  while ((det=(HDetector*)next())) {
    const Char_t* name=det->GetName();
    io=0;
    if (strcmp(name,"Mdc")==0)         io=new HMdcParOra2Io(pConn);
    if (strcmp(name,"Tof")==0)         io=new HTofParOra2Io(pConn);
    if (strcmp(name,"Rich")==0)        io=new HRichParOra2Io(pConn);
    if (strcmp(name,"Shower")==0)      io=new HShowerParOra2Io(pConn);
    if (strcmp(name,"Start")==0)       io=new HStartParOra2Io(pConn);
    if (strcmp(name,"Wall")==0)        io=new HWallParOra2Io(pConn);
    if (strcmp(name,"Rpc")==0)         io=new HRpcParOra2Io(pConn);
    if (strcmp(name,"Emc")==0)         io=new HEmcParOra2Io(pConn);
    if (strcmp(name,"PionTracker")==0) io=new HPionTrackerParOra2Io(pConn);
    if (io) detParIoList->Add(io);
  }
  return kTRUE;
}

void HParOra2Io::setDetParIo(const Text_t* ioName) {
  // creates the specified I/O
  if (isConnected) {
    TObject* io=detParIoList->FindObject(ioName);
    if (!io) {
      if (strcmp(ioName,"HMdcParIo")==0)         io=new HMdcParOra2Io(pConn);
      if (strcmp(ioName,"HTofParIo")==0)         io=new HTofParOra2Io(pConn);
      if (strcmp(ioName,"HRichParIo")==0)        io=new HRichParOra2Io(pConn);
      if (strcmp(ioName,"HShowerParIo")==0)      io=new HShowerParOra2Io(pConn);
      if (strcmp(ioName,"HStartParIo")==0)       io=new HStartParOra2Io(pConn);
      if (strcmp(ioName,"HWallParIo")==0)        io=new HWallParOra2Io(pConn);
      if (strcmp(ioName,"HRpcParIo")==0)         io=new HRpcParOra2Io(pConn);
      if (strcmp(ioName,"HEmcParIo")==0)         io=new HEmcParOra2Io(pConn);
      if (strcmp(ioName,"HPionTrackerParIo")==0) io=new HPionTrackerParOra2Io(pConn);
      if (io) detParIoList->Add(io);
    }
  }
}    

TList* HParOra2Io::getListOfRuns(const Char_t* experiment,
                                const Char_t* startAt,const Char_t* endAt) {
  // returns the list of runs for the specifies experiment and range
  // accepts dates (format DD-MON-YYYY HH24:MI:SS), hld-filenames and run ids
  if (isConnected) {
      return pInfo->getListOfRuns(experiment,startAt,endAt);
  }
  Error("getListOfRuns","No connection to Oracle");
  return 0;
}
 hparora2io.cc:1
 hparora2io.cc:2
 hparora2io.cc:3
 hparora2io.cc:4
 hparora2io.cc:5
 hparora2io.cc:6
 hparora2io.cc:7
 hparora2io.cc:8
 hparora2io.cc:9
 hparora2io.cc:10
 hparora2io.cc:11
 hparora2io.cc:12
 hparora2io.cc:13
 hparora2io.cc:14
 hparora2io.cc:15
 hparora2io.cc:16
 hparora2io.cc:17
 hparora2io.cc:18
 hparora2io.cc:19
 hparora2io.cc:20
 hparora2io.cc:21
 hparora2io.cc:22
 hparora2io.cc:23
 hparora2io.cc:24
 hparora2io.cc:25
 hparora2io.cc:26
 hparora2io.cc:27
 hparora2io.cc:28
 hparora2io.cc:29
 hparora2io.cc:30
 hparora2io.cc:31
 hparora2io.cc:32
 hparora2io.cc:33
 hparora2io.cc:34
 hparora2io.cc:35
 hparora2io.cc:36
 hparora2io.cc:37
 hparora2io.cc:38
 hparora2io.cc:39
 hparora2io.cc:40
 hparora2io.cc:41
 hparora2io.cc:42
 hparora2io.cc:43
 hparora2io.cc:44
 hparora2io.cc:45
 hparora2io.cc:46
 hparora2io.cc:47
 hparora2io.cc:48
 hparora2io.cc:49
 hparora2io.cc:50
 hparora2io.cc:51
 hparora2io.cc:52
 hparora2io.cc:53
 hparora2io.cc:54
 hparora2io.cc:55
 hparora2io.cc:56
 hparora2io.cc:57
 hparora2io.cc:58
 hparora2io.cc:59
 hparora2io.cc:60
 hparora2io.cc:61
 hparora2io.cc:62
 hparora2io.cc:63
 hparora2io.cc:64
 hparora2io.cc:65
 hparora2io.cc:66
 hparora2io.cc:67
 hparora2io.cc:68
 hparora2io.cc:69
 hparora2io.cc:70
 hparora2io.cc:71
 hparora2io.cc:72
 hparora2io.cc:73
 hparora2io.cc:74
 hparora2io.cc:75
 hparora2io.cc:76
 hparora2io.cc:77
 hparora2io.cc:78
 hparora2io.cc:79
 hparora2io.cc:80
 hparora2io.cc:81
 hparora2io.cc:82
 hparora2io.cc:83
 hparora2io.cc:84
 hparora2io.cc:85
 hparora2io.cc:86
 hparora2io.cc:87
 hparora2io.cc:88
 hparora2io.cc:89
 hparora2io.cc:90
 hparora2io.cc:91
 hparora2io.cc:92
 hparora2io.cc:93
 hparora2io.cc:94
 hparora2io.cc:95
 hparora2io.cc:96
 hparora2io.cc:97
 hparora2io.cc:98
 hparora2io.cc:99
 hparora2io.cc:100
 hparora2io.cc:101
 hparora2io.cc:102
 hparora2io.cc:103
 hparora2io.cc:104
 hparora2io.cc:105
 hparora2io.cc:106
 hparora2io.cc:107
 hparora2io.cc:108
 hparora2io.cc:109
 hparora2io.cc:110
 hparora2io.cc:111
 hparora2io.cc:112
 hparora2io.cc:113
 hparora2io.cc:114
 hparora2io.cc:115
 hparora2io.cc:116
 hparora2io.cc:117
 hparora2io.cc:118
 hparora2io.cc:119
 hparora2io.cc:120
 hparora2io.cc:121
 hparora2io.cc:122
 hparora2io.cc:123
 hparora2io.cc:124
 hparora2io.cc:125
 hparora2io.cc:126
 hparora2io.cc:127
 hparora2io.cc:128
 hparora2io.cc:129
 hparora2io.cc:130
 hparora2io.cc:131
 hparora2io.cc:132
 hparora2io.cc:133
 hparora2io.cc:134
 hparora2io.cc:135
 hparora2io.cc:136
 hparora2io.cc:137
 hparora2io.cc:138
 hparora2io.cc:139
 hparora2io.cc:140
 hparora2io.cc:141
 hparora2io.cc:142
 hparora2io.cc:143
 hparora2io.cc:144
 hparora2io.cc:145
 hparora2io.cc:146
 hparora2io.cc:147
 hparora2io.cc:148
 hparora2io.cc:149
 hparora2io.cc:150
 hparora2io.cc:151
 hparora2io.cc:152
 hparora2io.cc:153
 hparora2io.cc:154
 hparora2io.cc:155
 hparora2io.cc:156
 hparora2io.cc:157
 hparora2io.cc:158
 hparora2io.cc:159
 hparora2io.cc:160
 hparora2io.cc:161
 hparora2io.cc:162
 hparora2io.cc:163
 hparora2io.cc:164
 hparora2io.cc:165
 hparora2io.cc:166
 hparora2io.cc:167
 hparora2io.cc:168
 hparora2io.cc:169
 hparora2io.cc:170
 hparora2io.cc:171
 hparora2io.cc:172
 hparora2io.cc:173
 hparora2io.cc:174
 hparora2io.cc:175
 hparora2io.cc:176
 hparora2io.cc:177
 hparora2io.cc:178
 hparora2io.cc:179
 hparora2io.cc:180
 hparora2io.cc:181
 hparora2io.cc:182
 hparora2io.cc:183
 hparora2io.cc:184
 hparora2io.cc:185
 hparora2io.cc:186
 hparora2io.cc:187
 hparora2io.cc:188
 hparora2io.cc:189
 hparora2io.cc:190