2
// $Id: katrinreader.php 8051 2010-07-08 12:37:47Z s_voec01 $
3
// Author: Sebastian Voecking <sebastian.voecking@uni-muenster.de>
5
ADEI::RequireClass("KDBPhp", true);
7
class KATRINCountrates implements Iterator
12
function __construct(KDBPhp $kdb, OPTIONS &$opts, array &$items,
13
INTERVAL &$ivl, $hardware, $resample)
15
$from = $ivl->GetWindowStart();
16
$to = $ivl->GetWindowEnd();
18
$kdb->GetSql()->GetCountRates($from, $to, $hardware, $items);
24
mysql_data_seek($this->fData, 0);
32
return array_slice($this->fRow, 1, count($this->fRow) - 1);
41
$this->fRow = mysql_fetch_array($this->fData);
43
return $this->valid();
54
return $this->fRow[0];
62
class KATRINRuns implements Iterator
65
private $fSubrunEnd = TRUE;
69
function __construct(KDBPhp &$kdb, OPTIONS &$opts, array &$items,
70
INTERVAL &$ivl, $resample)
72
$from = $ivl->GetWindowStart();
73
$to = $ivl->GetWindowEnd();
74
$this->fItems = $items;
75
$this->fData = $kdb->GetSql()->GetRunData($from, $to);
81
mysql_data_seek($this->fData, 0);
82
$this->fSubrunEnd = TRUE;
89
foreach ($this->fItems as $item) {
92
$value = $this->fRow['run'];
94
$this->fRow['subrun'] / (float) $this->fRow['subruns'];
99
$values[] = $this->fRow['run'];
114
if ($this->fSubrunEnd) {
115
$this->fRow = mysql_fetch_assoc($this->fData);
117
$this->fSubrunEnd = !$this->fSubrunEnd;
119
return $this->valid();
129
if ($this->valid()) {
130
if ($this->fSubrunEnd) {
131
return $this->fRow['end'];
134
return $this->fRow['start'];
140
abstract class KATRINData implements Iterator
142
public $_cPtr = NULL;
143
private $iterator = NULL;
148
KDBDataIter_Rewind($this->_cPtr);
150
catch (Exception $e) {
151
throw new ADEIException($e->getMessage());
158
$r = KDBDataIter_Current($this->_cPtr);
159
$a = vectord_to_array($r);
162
catch (Exception $e) {
163
throw new ADEIException($e->getMessage());
170
return KDBDataIter_Next($this->_cPtr);
172
catch (Exception $e) {
173
throw new ADEIException($e->getMessage());
180
return KDBDataIter_Valid($this->_cPtr);
182
catch (Exception $e) {
183
throw new ADEIException($e->getMessage());
190
return KDBDataIter_Key($this->_cPtr);
192
catch (Exception $e) {
193
throw new ADEIException($e->getMessage());
198
class KATRINReader extends READER
202
function __construct(&$props)
204
parent::__construct($props);
206
$this->kdb = new KDBPhp();
209
$items[] = array('name' => "Total");
210
for ($i = 1; $i < 65; $i++) {
211
$name = "Pixel " . $i;
212
$items[] = array('name' => $name);
215
$this->items = array();
216
$this->items['countrates_uw'] = $items;
217
$this->items['countrates_ipe3'] = $items;
218
$this->items['countrates_ipe4'] = $items;
220
$this->items['runs'] = array();
221
$this->items['runs'][] = array('name' => "Run numbers");
222
$this->items['runs'][] = array('name' => "Run numbers (no subruns)");
223
$this->items['runs'][] = array('name' => "Activity");
225
$this->groups = array(
226
'countrates_uw' => array('name' => "Pixel Countrates (UW)"),
227
'countrates_ipe3' => array('name' => "Pixel Countrates (IPE3)"),
228
'countrates_ipe4' => array('name' => "Pixel Countrates (IPE4)"),
229
'runs' => array('name' => "Runs")
233
function GetGroupInfo(LOGGROUP $grp = NULL, $flags = 0)
237
foreach ($this->groups as $gid => &$group) {
238
if ($grp && strcmp($grp->gid, $gid)) continue;
240
if ($group['name']) $name = $group['name'];
242
if (!$name || ($flags & REQUEST::NEED_INFO)) {
248
$ginfo = array("db_group" => $gid);
249
$grtest = $this->CreateGroup($ginfo);
250
$opts = $this->req->GetGroupOptions($grtest);
254
$name = $opts->Get('name', $gid);
258
$groups[$gid] = array('gid' => $gid, 'name' => $name);
260
if ($flags & REQUEST::NEED_INFO) {
261
$limit = $opts->GetDateLimit(0, time());
262
$groups[$gid]['first'] = $limit[0];
263
$groups[$gid]['last'] = $limit[1];
265
if ($flags & REQUEST::NEED_COUNT) {
266
$period = $opts->Get('period');
267
$groups[$gid]['records'] =
268
($groups[$gid]['last'] - $groups[$gid]['first']) /
272
if ($flags & REQUEST::NEED_ITEMINFO) {
273
$groups[$gid]['items'] = $this->GetItemList($grtest);
278
if ($grp && !$groups) {
279
$error = translate("Invalid group (%s) is specified", $grp->gid);
280
throw new ADEIException($error);
283
return $grp ? $groups[$grp->gid] : $groups;
286
function GetItemList(LOGGROUP $grp = NULL, MASK $mask = NULL, $flags = 0)
288
if ($flags & REQUEST::ONLY_AXISINFO) {
289
if (!$this->req->GetGroupOptions($grp, "axis")) return array();
292
$grp = $this->CheckGroup($grp);
293
if (!$mask) $mask = $this->CreateMask($grp);
297
$opts = $this->req->GetGroupOptions($grp);
298
$items = $opts->Get('items', $this->items[$grp->gid]);
302
for ($i = 0; isset($items[$i]); $i++) {
303
if (!$mask->Check($i)) continue;
305
$item = array("id" => $i, "name" => $items[$i]['name']);
307
if ($items[$i]['uid']) {
308
$item['uid'] = $items[$i]['uid'];
311
if ($flags & REQUEST::NEED_AXISINFO) {
312
if ($grp->GetGroupID() == "countrates_uw" ||
313
$grp->GetGroupID() == "countrates_ipe3" ||
314
$grp->GetGroupID() == "countrates_ipe4") {
315
$item["axis"] = "frequency";
317
elseif ($grp->GetGroupID() == "runs") {
328
function GetMaskList(LOGGROUP $grp = NULL, $flags = 0)
330
//print "KATRINReader::GetMaskList";
332
$grp = $this->CheckGroup($grp);
336
if ($grp->GetGroupID() == "runs") {
338
else if ($grp->GetGroupID() == "countrates_uw" ||
339
$grp->GetGroupID() == "countrates_ipe3" ||
340
$grp->GetGroupID() == "countrates_ipe4") {
342
$mask["id"] = "total";
343
$mask["name"] = "Total";
344
if ($flags & REQUEST::NEED_INFO) {
351
$mask["name"] = "Pixels";
352
if ($flags & REQUEST::NEED_INFO) {
354
for ($i = 1; $i < 65; $i++) {
357
$mask["mask"] = implode(",", $items);
362
return array_merge(parent::GetMaskList($grp, $flags), $masks);
365
function GetRawData(LOGGROUP $grp = NULL, $from = 0, $to = 0,
366
DATAFilter $filter = NULL, &$filter_data = NULL)
368
$grp = $this->CheckGroup($grp);
370
$ivl = $this->CreateInterval($grp);
371
$ivl->Limit($from, $to);
374
$mask = $filter->GetItemMask();
375
$resample = $filter->GetSamplingRate();
376
$limit = $filter->GetVectorsLimit();
377
if ($limit) $ivl->SetItemLimit($limit);
379
if (isset($filter_data)) {
380
if ($mask) $filter_data['masked'] = true;
381
if ($resample) $filter_data['resampled'] = true;
382
if ($limit) $filter_data['limited'] = true;
391
$opts = $this->req->GetGroupOptions($grp);
393
$items = $opts->Get('items', $this->items[$grp->gid]);
394
if ($mask && is_array($ids = $mask->GetIDs())) {
396
foreach ($ids as $id) {
397
if ($id >= sizeof($items)) {
399
translate("Invalid item mask is supplied. " .
400
"The ID:%d refers non-existing item.", $id);
401
throw new ADEIException($error);
403
array_push($tmp, $items[$id]);
408
if ($grp->GetGroupID() == "countrates_uw") {
409
return new KATRINCountrates($this->kdb,
410
$this->req->GetGroupOptions($grp), $items, $ivl, kHardwareUw,
413
else if ($grp->GetGroupID() == "countrates_ipe3") {
414
return new KATRINCountrates($this->kdb,
415
$this->req->GetGroupOptions($grp), $items, $ivl, kHardwareIpe3,
418
else if ($grp->GetGroupID() == "countrates_ipe4") {
419
return new KATRINCountrates($this->kdb,
420
$this->req->GetGroupOptions($grp), $items, $ivl, kHardwareIpe4,
423
else if ($grp->GetGroupID() == "runs") {
424
return new KATRINRuns($this->kdb, $this->req->GetGroupOptions($grp),
425
$items, $ivl, $resample);
432
function HaveData(LOGGROUP $grp = NULL, $from = 0, $to = 0)
434
if (is_null($grp) || $grp->GetGroupID() == "runs") {
435
return $this->kdb->HaveRuns($from, $to);
437
else if ($grp->GetGroupID() == "countrates_uw" ||
438
$grp->GetGroupID() == "countrates_ipe3" ||
439
$grp->GetGroupID() == "countrates_ipe4") {
440
return $this->kdb->HaveCountrates($from, $to);