1 //*-- AUTHOR : Ilse Koenig
2 //*-- Created : 16/08/2004 by Ilse Koenig
3 //*-- Modified : 09/02/2011 by Ilse Koenig
5 //_HADES_CLASS_DESCRIPTION
6 //////////////////////////////////////////////////////////////////////////////
10 // Base class to read slowcontrol data from Oracle
12 //////////////////////////////////////////////////////////////////////////////
14 #include "horaslowreader.h"
15 #include "horaslowmanager.h"
17 #include "horaslowpartition.h"
18 #include "horaslowperiod.h"
22 #define SQLCA_STORAGE_CLASS extern
23 #define ORACA_STORAGE_CLASS extern
25 // Oracle communication area
27 // SQL Communications Area
30 ClassImp(HOraSlowReader)
32 HOraSlowReader::HOraSlowReader() {
38 HOraSlowReader::~HOraSlowReader() {
50 Bool_t HOraSlowReader::open() {
51 // Opens an Oracle connection
52 if (pConn->isOpen()) return kTRUE;
53 return pConn->connectDb(gHOraSlowManager->getOraUser(),gHOraSlowManager->getDbName());
56 void HOraSlowReader::close() {
57 // Disconnects from Oracle
61 Bool_t HOraSlowReader::isOpen() {
62 return pConn->isOpen();
65 void HOraSlowReader::print() {
66 // Prints information about the database connection
68 cout<<"Connected to Oracle-Database db-hades\n";
69 else cout<<"*** no connection to Oracle established ***\n";
72 Bool_t HOraSlowReader::readPartition() {
73 // Reads the start time and end time of the data partion
74 if (!pConn->isOpen()||!pPartition) return kFALSE;
75 TString startTime(pPartition->getStartTime());
76 TString endTime(pPartition->getEndTime());
77 if (startTime.Length()!=0 && endTime.Length()!=0) return kTRUE;
78 EXEC SQL BEGIN DECLARE SECTION;
82 EXEC SQL END DECLARE SECTION;
83 pname=(Char_t*)pPartition->GetName();
84 EXEC SQL WHENEVER SQLERROR GOTO errorfound;
85 EXEC SQL WHENEVER NOT FOUND GOTO notfound;
86 EXEC SQL SELECT TO_CHAR(starttime,'yyyy-mm-dd hh24:mi:ss'),
87 TO_CHAR(NVL(endtime,SYSDATE),'yyyy-mm-dd hh24:mi:ss')
89 FROM hades_slow2.archive_partitionmgnt
90 WHERE partitionname = :pname;
93 if (startTime.Length()==0) startTime=ts;
94 if (endTime.Length()==0) endTime=te;
95 pPartition->setTimeRange(startTime,endTime);
98 Error("readPartition","Partition %s not found",pPartition->GetName());
101 pConn->showSqlError("readPartition");
105 Bool_t HOraSlowReader::readRunPeriods() {
106 // Reads the run periods in the partition range
107 if (!pConn->isOpen()||!pPartition) return kFALSE;
108 TString start=pPartition->getStartTime();
109 TString end=pPartition->getEndTime();
110 if (start.IsNull()||end.IsNull()) {
112 start=pPartition->getStartTime();
113 end=pPartition->getEndTime();
115 if (start.IsNull()||end.IsNull()) return kFALSE;
116 EXEC SQL BEGIN DECLARE SECTION;
126 EXEC SQL END DECLARE SECTION;
127 pname=(Char_t*)pPartition->GetName();
128 pstart=(Char_t*)start.Data();
129 pend=(Char_t*)end.Data();
130 EXEC SQL WHENEVER SQLERROR GOTO errorfound;
131 EXEC SQL WHENEVER NOT FOUND GOTO notfound;
132 EXEC SQL SELECT count(1), min(id), max(id)
133 INTO :nruns:nruns_Ind, :minid:minid_Ind, :maxid:maxid_Ind
134 FROM hades_slow2.hscs_run_period
135 WHERE partition_name = :pname
136 AND starttime BETWEEN TO_DATE(:pstart,'yyyy-mm-dd hh24:mi:ss')
137 AND TO_DATE(:pend,'yyyy-mm-dd hh24:mi:ss');
138 if (nruns_Ind!=-1 && nruns>0) {
139 TObjArray* data=pPartition->setNumPeriods(nruns);
140 return readPeriods(pname,data,nruns,minid,maxid);
143 Error("readRunPeriods","No run summary for partition %s or specified time range",
144 pPartition->GetName());
147 pConn->showSqlError("readRunPeriods");
151 Bool_t HOraSlowReader::readPeriods(Char_t* partitionName,TObjArray* data,Int_t nData,
152 Int_t minPeriodId,Int_t maxPeriodId) {
153 // Private function to read the run periods in the partition range
154 if (!data) return kFALSE;
155 EXEC SQL BEGIN DECLARE SECTION;
161 char ts[NMAX_SCS][20];
162 char te[NMAX_SCS][20];
164 varchar rname[NMAX_SCS][81];
167 short id_Ind[NMAX_SCS];
168 short ts_Ind[NMAX_SCS];
169 short te_Ind[NMAX_SCS];
170 short rid_Ind[NMAX_SCS];
171 short rname_Ind[NMAX_SCS];
173 EXEC SQL END DECLARE SECTION;
179 EXEC SQL WHENEVER SQLERROR GOTO errorfound;
180 EXEC SQL WHENEVER NOT FOUND continue;
181 EXEC SQL DECLARE run_cursor CURSOR FOR
183 TO_CHAR(period_begin,'yyyy-mm-dd hh24:mi:ss'),
184 TO_CHAR(period_end,'yyyy-mm-dd hh24:mi:ss'),
186 FROM hades_slow2.hscs_periods
187 WHERE partition = :pname AND period_id BETWEEN :minid AND :maxid
189 EXEC SQL OPEN run_cursor;
191 EXEC SQL FETCH run_cursor INTO :periods INDICATOR :periods_Ind;
192 nLast=sqlca.sqlerrd[2]-nTot;
193 for (Int_t i=0;i<nLast;i++) {
194 HOraSlowPeriod* p=new HOraSlowPeriod();
195 periods.ts[i][19]='\0';
196 periods.te[i][19]='\0';
197 p->setPeriodId(periods.id[i]);
198 p->setStartTime((Char_t*)(periods.ts[i]));
199 p->setEndTime((Char_t*)(periods.te[i]));
200 if (periods_Ind.rid_Ind[i]!=-1) p->setRunId(periods.rid[i]);
201 if (periods_Ind.rname_Ind[i]!=-1) {
202 periods.rname[i].arr[periods.rname[i].len]='\0';
203 p->setFilename((Char_t*)(periods.rname[i].arr));
208 } while (nLast==NMAX_SCS&&nTot<nData);
209 EXEC SQL CLOSE run_cursor;
210 cout<<"*** Run periods read: "<<nTot<<endl;
211 if (nTot==nData) return kTRUE;
213 Error("readPeriods","Too few data read");
217 pConn->showSqlError("readPeriods");