MIDAS
Loading...
Searching...
No Matches
scaler_module.cxx
Go to the documentation of this file.
1/********************************************************************\
2
3 Name: scaler.c
4 Created by: Stefan Ritt
5
6 Contents: Example scaler analyzer module. This module looks
7 for a SCLR banks and accumulates scalers into an
8 ACUM bank.
9
10 $Id:$
11
12\********************************************************************/
13
14#if 0
15/*-- Include files -------------------------------------------------*/
16
17/* standard includes */
18#include <stdio.h>
19#include <string.h>
20#include <time.h>
21
22/* midas includes */
23#include "midas.h"
24#include "experim.h"
25#include "analyzer.h"
26
27/*-- Module declaration --------------------------------------------*/
28
32
34 "Scaler accumulation", /* module name */
35 "Stefan Ritt", /* author */
36 scaler_accum, /* event routine */
37 scaler_clear, /* BOR routine */
38 scaler_eor, /* EOR routine */
39 NULL, /* init routine */
40 NULL, /* exit routine */
41 NULL, /* parameter structure */
42 0, /* structure size */
43 NULL, /* initial parameters */
44};
45
46/*-- accumulated scalers -------------------------------------------*/
47
48double scaler[32];
49
50/*-- BOR routine ---------------------------------------------------*/
51
53{
54 memset(scaler, 0, sizeof(scaler));
55 return SUCCESS;
56}
57
58/*-- EOR routine ---------------------------------------------------*/
59
61{
62 return SUCCESS;
63}
64
65/*-- event routine -------------------------------------------------*/
66
67INT scaler_accum(EVENT_HEADER * pheader, void *pevent)
68{
69 INT n, i;
70 DWORD *psclr;
71 double *pacum;
72
73 /* look for SCLR bank */
74 n = bk_locate(pevent, "SCLR", &psclr);
75 if (n == 0)
76 return 1;
77
78 /* create acummulated scaler bank */
79 bk_create(pevent, "ACUM", TID_DOUBLE, (void**)&pacum);
80
81 /* accumulate scalers */
82 for (i = 0; i < n; i++) {
83 scaler[i] += psclr[i];
84 pacum[i] = scaler[i];
85 }
86
87 /* close bank */
88 bk_close(pevent, pacum + n);
89
90 return SUCCESS;
91}
92#endif
93
94//
95// MIDAS analyzer example 2: ROOT analyzer
96//
97// K.Olchanski
98//
99
100#include <stdio.h>
101
102#include "manalyzer.h"
103#include "midasio.h"
104
105struct Scaler: public TARunObject
106{
107 double fScaler[32];
108
110 : TARunObject(runinfo)
111 {
112 printf("Scaler::ctor!\n");
113
114 memset(fScaler, 0, sizeof(fScaler));
115 }
116
118 {
119 printf("Scaler::dtor!\n");
120 }
121
123 {
124 printf("BeginRun, run %d, file %s\n", runinfo->fRunNo, runinfo->fFileName.c_str());
125
126 memset(fScaler, 0, sizeof(fScaler));
127 }
128
130 {
131 printf("EndRun, run %d\n", runinfo->fRunNo);
132 }
133
135 {
136 printf("Analyze, run %d, event serno %d, id 0x%04x, data size %d\n", runinfo->fRunNo, event->serial_number, (int)event->event_id, event->data_size);
137
138 TMBank* bsclr = event->FindBank("SCLR");
139 if (!bsclr)
140 return flow;
141
142 uint32_t* psclr = (uint32_t*)event->GetBankData(bsclr);
143 if (!psclr)
144 return flow;
145
146 int n = bsclr->data_size / sizeof(uint32_t);
147 if (n == 0)
148 return flow;
149
150 assert(n == 32); // original scaler.cxx has a bug, there is no check for correct size of SCLR bank. K.O.
151
152 double acum[32];
153
154 /* accumulate scalers */
155 for (int i = 0; i < n; i++) {
156 fScaler[i] += psclr[i];
157 acum[i] = fScaler[i];
158 }
159
160 /* create acummulated scaler bank */
161 event->AddBank("ACUM", TID_DOUBLE, (char*)&acum, sizeof(acum));
162
163 return flow;
164 }
165};
166
167class ScalerFactory: public TAFactory
168{
169public:
170 void Init(const std::vector<std::string> &args)
171 {
172 printf("Init!\n");
173 }
174
175 void Finish()
176 {
177 printf("Finish!\n");
178 }
179
181 {
182 printf("NewRunObject, run %d, file %s\n", runinfo->fRunNo, runinfo->fFileName.c_str());
183 return new Scaler(runinfo);
184 }
185};
186
188
189/* emacs
190 * Local Variables:
191 * tab-width: 8
192 * c-basic-offset: 3
193 * indent-tabs-mode: nil
194 * End:
195 */
RUNINFO runinfo
Definition analyzer.cxx:49
ANA_MODULE scaler_accum_module
Definition scaler.cxx:32
void Init(const std::vector< std::string > &args)
TARunObject * NewRunObject(TARunInfo *runinfo)
INT bk_close(void *event, void *pdata)
Definition midas.cxx:16780
INT bk_locate(const void *event, const char *name, void *pdata)
Definition midas.cxx:16889
void bk_create(void *event, const char *name, WORD type, void **pdata)
Definition midas.cxx:16561
unsigned int DWORD
Definition mcstd.h:51
#define SUCCESS
Definition mcstd.h:54
#define TID_DOUBLE
Definition midas.h:343
INT run_number[2]
Definition mana.cxx:246
DWORD n[4]
Definition mana.cxx:247
INT i
Definition mdump.cxx:32
int INT
Definition midas.h:129
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
INT scaler_clear(INT run_number)
Definition scaler.cxx:51
double scaler[32]
Definition scaler.cxx:47
INT scaler_accum(EVENT_HEADER *, void *)
Definition scaler.cxx:66
INT scaler_eor(INT run_number)
Definition scaler.cxx:59
static TARegister tar(new ScalerFactory)
TAFlowEvent * Analyze(TARunInfo *runinfo, TMEvent *event, TAFlags *flags, TAFlowEvent *flow)
void BeginRun(TARunInfo *runinfo)
double fScaler[32]
Scaler(TARunInfo *runinfo)
void EndRun(TARunInfo *runinfo)