/openshift/adei

To get this branch, use:
bzr branch http://darksoft.org/webbzr/openshift/adei

« back to all changes in this revision

Viewing changes to setups/katrin/classes/readers/katrinreader.php

  • Committer: Suren A. Chilingaryan
  • Date: 2012-02-07 22:44:15 UTC
  • Revision ID: csa@dside.dyndns.org-20120207224415-sy360wa1ammhd1ph
Use localization subsystem, updated Katrin configs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
// $Id: katrinreader.php 8051 2010-07-08 12:37:47Z s_voec01 $
3
 
// Author: Sebastian Voecking <sebastian.voecking@uni-muenster.de>
4
 
 
5
 
ADEI::RequireClass("KDBPhp", true);
6
 
 
7
 
class KATRINCountrates implements Iterator
8
 
{
9
 
    private $fData;
10
 
    private $fRow;
11
 
    
12
 
    function __construct(KDBPhp $kdb, OPTIONS &$opts, array &$items,
13
 
        INTERVAL &$ivl, $hardware, $resample)
14
 
    {
15
 
        $from = $ivl->GetWindowStart();
16
 
        $to = $ivl->GetWindowEnd();
17
 
        $this->fData =
18
 
            $kdb->GetSql()->GetCountRates($from, $to, $hardware, $items);
19
 
        $this->next();
20
 
    }
21
 
    
22
 
    function rewind()
23
 
    {
24
 
        mysql_data_seek($this->fData, 0);
25
 
 
26
 
        $this->next();
27
 
    }
28
 
 
29
 
    function current()
30
 
    {
31
 
        if ($this->valid()) {
32
 
            return array_slice($this->fRow, 1, count($this->fRow) - 1);
33
 
        }
34
 
        else {
35
 
            return FALSE;
36
 
        }
37
 
    }
38
 
 
39
 
    function next()
40
 
    {
41
 
        $this->fRow = mysql_fetch_array($this->fData);
42
 
 
43
 
        return $this->valid();
44
 
    }
45
 
 
46
 
    function valid()
47
 
    {
48
 
        return $this->fRow;
49
 
    }
50
 
 
51
 
    function key()
52
 
    {
53
 
        if ($this->valid()) {
54
 
            return $this->fRow[0];
55
 
        }
56
 
        else {
57
 
            return FALSE;
58
 
        }
59
 
    }
60
 
}
61
 
 
62
 
class KATRINRuns implements Iterator
63
 
{
64
 
    private $fData;
65
 
    private $fSubrunEnd = TRUE;
66
 
    private $fRow;
67
 
    private $fItems;
68
 
    
69
 
    function __construct(KDBPhp &$kdb, OPTIONS &$opts, array &$items,
70
 
        INTERVAL &$ivl, $resample)
71
 
    {
72
 
        $from = $ivl->GetWindowStart();
73
 
        $to = $ivl->GetWindowEnd();
74
 
        $this->fItems = $items;
75
 
        $this->fData = $kdb->GetSql()->GetRunData($from, $to);
76
 
        $this->next();
77
 
    }
78
 
    
79
 
    function rewind()
80
 
    {
81
 
        mysql_data_seek($this->fData, 0);
82
 
        $this->fSubrunEnd = TRUE;
83
 
        $this->next();
84
 
    }
85
 
 
86
 
    function current()
87
 
    {
88
 
        $values = array();
89
 
        foreach ($this->fItems as $item) {
90
 
            switch ($item) {
91
 
                case 0:
92
 
                    $value = $this->fRow['run'];
93
 
                    $value +=
94
 
                        $this->fRow['subrun'] / (float) $this->fRow['subruns'];
95
 
                    $values[] = $value;
96
 
                    break;
97
 
                    
98
 
                case 1:
99
 
                    $values[] = $this->fRow['run'];
100
 
                    break;
101
 
                    
102
 
                case 2:
103
 
                    $values[] = 1;
104
 
                    break;
105
 
                    
106
 
                default:
107
 
                    $values[] = 0;
108
 
            }
109
 
        }
110
 
    }
111
 
 
112
 
    function next()
113
 
    {
114
 
        if ($this->fSubrunEnd) {
115
 
            $this->fRow = mysql_fetch_assoc($this->fData);
116
 
        }
117
 
        $this->fSubrunEnd = !$this->fSubrunEnd;
118
 
 
119
 
        return $this->valid();
120
 
    }
121
 
 
122
 
    function valid()
123
 
    {
124
 
        return $this->fRow;
125
 
    }
126
 
 
127
 
    function key()
128
 
    {
129
 
        if ($this->valid()) {
130
 
            if ($this->fSubrunEnd) {
131
 
                return $this->fRow['end'];
132
 
            }
133
 
            else {
134
 
                return $this->fRow['start'];
135
 
            }
136
 
        }
137
 
    }
138
 
}
139
 
 
140
 
abstract class KATRINData implements Iterator
141
 
{
142
 
    public $_cPtr = NULL;
143
 
    private $iterator = NULL;
144
 
 
145
 
    function rewind()
146
 
    {
147
 
        try {
148
 
            KDBDataIter_Rewind($this->_cPtr);
149
 
        }
150
 
        catch (Exception $e) {
151
 
            throw new ADEIException($e->getMessage());
152
 
        }
153
 
    }
154
 
 
155
 
    function current()
156
 
    {
157
 
        try {
158
 
            $r = KDBDataIter_Current($this->_cPtr);
159
 
            $a = vectord_to_array($r);
160
 
            return $a;
161
 
        }
162
 
        catch (Exception $e) {
163
 
            throw new ADEIException($e->getMessage());
164
 
        }
165
 
    }
166
 
 
167
 
    function next()
168
 
    {
169
 
        try {
170
 
            return KDBDataIter_Next($this->_cPtr);
171
 
        }
172
 
        catch (Exception $e) {
173
 
            throw new ADEIException($e->getMessage());
174
 
        }
175
 
    }
176
 
 
177
 
    function valid()
178
 
    {
179
 
        try {
180
 
            return KDBDataIter_Valid($this->_cPtr);
181
 
        }
182
 
        catch (Exception $e) {
183
 
            throw new ADEIException($e->getMessage());
184
 
        }
185
 
    }
186
 
 
187
 
    function key()
188
 
    {
189
 
        try {
190
 
            return KDBDataIter_Key($this->_cPtr);
191
 
        }
192
 
        catch (Exception $e) {
193
 
            throw new ADEIException($e->getMessage());
194
 
        }
195
 
    }
196
 
}
197
 
 
198
 
class KATRINReader extends READER
199
 
{
200
 
    public $kdb = NULL;
201
 
 
202
 
    function __construct(&$props)
203
 
    {
204
 
        parent::__construct($props);
205
 
 
206
 
        $this->kdb = new KDBPhp();
207
 
 
208
 
        $items = array();
209
 
        $items[] = array('name' => "Total");
210
 
        for ($i = 1; $i < 65; $i++) {
211
 
            $name = "Pixel " . $i;
212
 
            $items[] = array('name' => $name);
213
 
        }
214
 
 
215
 
        $this->items = array();
216
 
        $this->items['countrates_uw'] = $items;
217
 
        $this->items['countrates_ipe3'] = $items;
218
 
        $this->items['countrates_ipe4'] = $items;
219
 
 
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");
224
 
 
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")
230
 
        );
231
 
    }
232
 
 
233
 
    function GetGroupInfo(LOGGROUP $grp = NULL, $flags = 0)
234
 
    {
235
 
        $groups = array();
236
 
 
237
 
        foreach ($this->groups as $gid => &$group) {
238
 
            if ($grp && strcmp($grp->gid, $gid)) continue;
239
 
 
240
 
            if ($group['name']) $name = $group['name'];
241
 
 
242
 
            if (!$name || ($flags & REQUEST::NEED_INFO)) {
243
 
                if ($grp) {
244
 
                    $grtest = $grp;
245
 
                    $opts = $this->opts;
246
 
                }
247
 
                else {
248
 
                    $ginfo = array("db_group" => $gid);
249
 
                    $grtest = $this->CreateGroup($ginfo);
250
 
                    $opts = $this->req->GetGroupOptions($grtest);
251
 
                }
252
 
 
253
 
                if (!$name) {
254
 
                    $name = $opts->Get('name', $gid);
255
 
                }
256
 
            }
257
 
 
258
 
            $groups[$gid] = array('gid' => $gid, 'name' => $name);
259
 
 
260
 
            if ($flags & REQUEST::NEED_INFO) {
261
 
                $limit = $opts->GetDateLimit(0, time());
262
 
                $groups[$gid]['first'] = $limit[0];
263
 
                $groups[$gid]['last'] = $limit[1];
264
 
 
265
 
                if ($flags & REQUEST::NEED_COUNT) {
266
 
                    $period = $opts->Get('period');
267
 
                    $groups[$gid]['records'] =
268
 
                        ($groups[$gid]['last'] - $groups[$gid]['first']) /
269
 
                        $period;
270
 
                }
271
 
 
272
 
                if ($flags & REQUEST::NEED_ITEMINFO) {
273
 
                    $groups[$gid]['items'] = $this->GetItemList($grtest);
274
 
                }
275
 
            }
276
 
        }
277
 
 
278
 
        if ($grp && !$groups) {
279
 
            $error = translate("Invalid group (%s) is specified", $grp->gid);
280
 
            throw new ADEIException($error);
281
 
        }
282
 
 
283
 
        return $grp ? $groups[$grp->gid] : $groups;
284
 
    }
285
 
 
286
 
    function GetItemList(LOGGROUP $grp = NULL, MASK $mask = NULL, $flags = 0)
287
 
    {
288
 
        if ($flags & REQUEST::ONLY_AXISINFO) {
289
 
            if (!$this->req->GetGroupOptions($grp, "axis")) return array();
290
 
        }
291
 
 
292
 
        $grp = $this->CheckGroup($grp);
293
 
        if (!$mask) $mask = $this->CreateMask($grp);
294
 
 
295
 
        $items = array();
296
 
 
297
 
        $opts = $this->req->GetGroupOptions($grp);
298
 
        $items = $opts->Get('items', $this->items[$grp->gid]);
299
 
 
300
 
        $res = array();
301
 
 
302
 
        for ($i = 0; isset($items[$i]); $i++) {
303
 
            if (!$mask->Check($i)) continue;
304
 
 
305
 
            $item = array("id" => $i, "name" => $items[$i]['name']);
306
 
 
307
 
            if ($items[$i]['uid']) {
308
 
                $item['uid'] = $items[$i]['uid'];
309
 
            }
310
 
 
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";
316
 
                }
317
 
                elseif ($grp->GetGroupID() == "runs") {
318
 
                    $item["axis"] = 0;
319
 
                }
320
 
            }
321
 
 
322
 
            $res[] = $item;
323
 
        }
324
 
 
325
 
        return $res;
326
 
    }
327
 
 
328
 
    function GetMaskList(LOGGROUP $grp = NULL, $flags = 0)
329
 
    {
330
 
        //print "KATRINReader::GetMaskList";
331
 
 
332
 
        $grp = $this->CheckGroup($grp);
333
 
 
334
 
        $masks = array();
335
 
 
336
 
        if ($grp->GetGroupID() == "runs") {
337
 
        }
338
 
        else if ($grp->GetGroupID() == "countrates_uw" ||
339
 
                 $grp->GetGroupID() == "countrates_ipe3" ||
340
 
                 $grp->GetGroupID() == "countrates_ipe4") {
341
 
            $mask = array();
342
 
            $mask["id"] = "total";
343
 
            $mask["name"] = "Total";
344
 
            if ($flags & REQUEST::NEED_INFO) {
345
 
                $mask["mask"] = "0";
346
 
            }
347
 
            $masks[] = $mask;
348
 
 
349
 
            $mask = array();
350
 
            $mask["id"] = "ipe";
351
 
            $mask["name"] = "Pixels";
352
 
            if ($flags & REQUEST::NEED_INFO) {
353
 
                $items = array();
354
 
                for ($i = 1; $i < 65; $i++) {
355
 
                    $items[] = $i;
356
 
                }
357
 
                $mask["mask"] = implode(",", $items);
358
 
            }
359
 
            $masks[] = $mask;
360
 
        }
361
 
 
362
 
        return array_merge(parent::GetMaskList($grp, $flags), $masks);
363
 
    }
364
 
 
365
 
    function GetRawData(LOGGROUP $grp = NULL, $from = 0, $to = 0,
366
 
        DATAFilter $filter = NULL, &$filter_data = NULL)
367
 
    {
368
 
        $grp = $this->CheckGroup($grp);
369
 
 
370
 
        $ivl = $this->CreateInterval($grp);
371
 
        $ivl->Limit($from, $to);
372
 
 
373
 
        if ($filter) {
374
 
            $mask = $filter->GetItemMask();
375
 
            $resample = $filter->GetSamplingRate();
376
 
            $limit = $filter->GetVectorsLimit();
377
 
            if ($limit) $ivl->SetItemLimit($limit);
378
 
 
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;
383
 
            }
384
 
        }
385
 
        else {
386
 
            $mask = NULL;
387
 
            $resample = 0;
388
 
            $limit = 0;
389
 
        }
390
 
 
391
 
        $opts = $this->req->GetGroupOptions($grp);
392
 
 
393
 
        $items = $opts->Get('items', $this->items[$grp->gid]);
394
 
        if ($mask && is_array($ids = $mask->GetIDs())) {
395
 
            $tmp = array();
396
 
            foreach ($ids as $id) {
397
 
                if ($id >= sizeof($items)) {
398
 
                    $error =
399
 
                        translate("Invalid item mask is supplied. " .
400
 
                        "The ID:%d refers non-existing item.", $id);
401
 
                    throw new ADEIException($error);
402
 
                }
403
 
                array_push($tmp, $items[$id]);
404
 
            }
405
 
            $items = $tmp;
406
 
        }
407
 
 
408
 
        if ($grp->GetGroupID() == "countrates_uw") {
409
 
            return new KATRINCountrates($this->kdb,
410
 
                $this->req->GetGroupOptions($grp), $items, $ivl, kHardwareUw,
411
 
                $resample);
412
 
        }
413
 
        else if ($grp->GetGroupID() == "countrates_ipe3") {
414
 
            return new KATRINCountrates($this->kdb,
415
 
                $this->req->GetGroupOptions($grp), $items, $ivl, kHardwareIpe3,
416
 
                $resample);
417
 
        }
418
 
        else if ($grp->GetGroupID() == "countrates_ipe4") {
419
 
            return new KATRINCountrates($this->kdb,
420
 
                $this->req->GetGroupOptions($grp), $items, $ivl, kHardwareIpe4,
421
 
                $resample);
422
 
        }
423
 
        else if ($grp->GetGroupID() == "runs") {
424
 
            return new KATRINRuns($this->kdb, $this->req->GetGroupOptions($grp),
425
 
                $items, $ivl, $resample);
426
 
        }
427
 
        else {
428
 
            return NULL;
429
 
        }
430
 
    }
431
 
 
432
 
    function HaveData(LOGGROUP $grp = NULL, $from = 0, $to = 0)
433
 
    {
434
 
        if (is_null($grp) || $grp->GetGroupID() == "runs") {
435
 
            return $this->kdb->HaveRuns($from, $to);
436
 
        }
437
 
        else if ($grp->GetGroupID() == "countrates_uw" ||
438
 
                 $grp->GetGroupID() == "countrates_ipe3" ||
439
 
                 $grp->GetGroupID() == "countrates_ipe4") {
440
 
            return $this->kdb->HaveCountrates($from, $to);
441
 
        }
442
 
        else {
443
 
            return FALSE;
444
 
        }
445
 
    }
446
 
}
447
 
 
448
 
?>