AlcapDAQ
1
Main Page
Related Pages
Modules
Namespaces
Data Structures
Files
File List
Globals
analyzer
src
FADC
MOctalFADCPacketLoss.cpp
Go to the documentation of this file.
1
/********************************************************************\
2
3
Name: MOctalFADCPacketLoss
4
Created by: Andrew Edmonds
5
6
Contents: Module to plot the average number of lost packets per FADC board
7
8
\********************************************************************/
9
10
/* Standard includes */
11
#include <stdio.h>
12
#include <stdlib.h>
13
#include <string>
14
#include <map>
15
#include <utility>
16
17
/* MIDAS includes */
18
#include "midas.h"
19
20
/* ROOT includes */
21
#include <TH2.h>
22
23
/* AlCap includes */
24
#include "
TOctalFADCIsland.h
"
25
#include "
TOctalFADCBankReader.h
"
26
#include "
TGlobalData.h
"
27
#include "
TSetupData.h
"
28
29
using
std::string;
30
using
std::map;
31
using
std::vector;
32
using
std::pair;
33
34
/*-- Module declaration --------------------------------------------*/
35
INT
MOctalFADCPacketLoss_init
(
void
);
36
INT
MOctalFADCPacketLoss_BOR
(INT
run_number
);
37
INT
MOctalFADCPacketLoss
(EVENT_HEADER*,
void
*);
38
39
extern
HNDLE
hDB
;
40
extern
TGlobalData
*
gData
;
41
extern
TSetupData
*
gSetup
;
42
43
static
TH1*
hNOctalFADCAvgPacketLoss
;
44
static
TH1*
hNOctalFADCEventsWithPacketLoss
;
45
static
TH1*
hNOctalFADCEventsWithPacketLossPercent
;
46
static
int
midas_events
;
47
48
49
ANA_MODULE
MOctalFADCPacketLoss_module
=
50
{
51
"MOctalFADCPacketLoss"
,
/* module name */
52
"Andrew Edmonds"
,
/* author */
53
MOctalFADCPacketLoss
,
/* event routine */
54
MOctalFADCPacketLoss_BOR
,
/* BOR routine */
55
NULL,
/* EOR routine */
56
MOctalFADCPacketLoss_init
,
/* init routine */
57
NULL,
/* exit routine */
58
NULL,
/* parameter structure */
59
0,
/* structure size */
60
NULL,
/* initial parameters */
61
};
62
65
INT
MOctalFADCPacketLoss_init
()
66
{
67
// This histogram has the bank names labeled on the X-axis, and the midas
68
// block number on the Y-axis.
69
// This uses the TH1::kCanRebin mechanism to expand automatically to the
70
// number of FADC banks.
71
hNOctalFADCAvgPacketLoss
=
new
TH1F(
72
"hNOctalFADCAvgPacketLoss"
,
73
"Number of FADC packets lost per board"
,
74
4,128, 132);
75
hNOctalFADCAvgPacketLoss
->SetBit(TH1::kCanRebin);
76
hNOctalFADCAvgPacketLoss
->GetXaxis()->SetTitle(
"FADC Board Number"
);
77
hNOctalFADCAvgPacketLoss
->GetYaxis()->SetTitle(
"Number of Packets Lost"
);
78
79
hNOctalFADCEventsWithPacketLoss
=
new
TH1F(
80
"hNOctalFADCEventsWithPacketLoss"
,
81
"Number of MIDAS Events with FADC packet loss per board"
,
82
4,128, 132);
83
hNOctalFADCEventsWithPacketLoss
->SetBit(TH1::kCanRebin);
84
hNOctalFADCEventsWithPacketLoss
->GetXaxis()->SetTitle(
"FADC Board Number"
);
85
hNOctalFADCEventsWithPacketLoss
->GetYaxis()->SetTitle(
"Number of Events with lost packets"
);
86
87
hNOctalFADCEventsWithPacketLossPercent
=
new
TH1F(
88
"hNOctalFADCEventsWithPacketLossPercent"
,
89
"Percentage of MIDAS Events with FADC packet loss per board"
,
90
4,128, 132);
91
hNOctalFADCEventsWithPacketLossPercent
->SetBit(TH1::kCanRebin);
92
hNOctalFADCEventsWithPacketLossPercent
->GetXaxis()->SetTitle(
"FADC Board Number"
);
93
hNOctalFADCEventsWithPacketLossPercent
->GetYaxis()->SetTitle(
"Average Number of Events with lost packets"
);
94
95
return
SUCCESS
;
96
}
97
101
INT
MOctalFADCPacketLoss_BOR
(INT
run_number
)
102
{
103
midas_events
= 1;
104
105
return
SUCCESS
;
106
}
107
111
INT
MOctalFADCPacketLoss
(EVENT_HEADER *pheader,
void
*pevent)
112
{
113
// Get the event number
114
int
midas_event_number = pheader->serial_number;
115
116
// Want the average and since I'll scale by 1/midas_event_number at the end, I should undo it now before I add the new data
117
//if (midas_event_number > 1)
118
// hNOctalFADCAvgPacketLoss->Scale(midas_event_number-1);
119
120
unsigned
int
* raw;
// Points at the raw data
121
int
bankSize = bk_locate(pevent,
"NLSS"
,&raw);
122
123
int
board_number = 0;
124
int
packet_lost = 0;
125
int
n_packets_lost = 0;
126
127
bool
Boards[256];
// We can have maximally 256 FADC boards due to the address space
128
for
(
int
i
=0;
i
<256; ++
i
) Boards[
i
] =
false
;
129
130
for
(
int
i
= 0;
i
< bankSize;
i
+=2) {
131
board_number = *(raw+
i
);
132
packet_lost = *(raw+
i
+1);
133
134
if
(*(raw+
i
) >= 0 && *(raw+
i
) < 255) Boards[
i
] =
true
;
135
136
n_packets_lost++;
137
// printf("Event #%d: Board %d lost packet #%d\n", midas_event_number, board_number, packet_lost);
138
139
// Fill Diagnostic histogram
140
hNOctalFADCAvgPacketLoss
->Fill(board_number, 1);
141
}
142
143
for
(
int
i
=0;
i
<256; ++
i
){
144
if
(Boards[
i
] ==
true
){
145
int
bin =
hNOctalFADCEventsWithPacketLoss
->FindBin(
i
+1);
146
hNOctalFADCEventsWithPacketLoss
->Fill(bin);
147
hNOctalFADCEventsWithPacketLossPercent
->SetBinContent(bin,
hNOctalFADCEventsWithPacketLoss
->GetBinContent(bin) /
midas_events
);
148
}
149
}
150
151
++
midas_events
;
152
153
// Scale down for the average, the final midas event should leave this correct
154
//hNOctalFADCAvgPacketLoss->Scale(1.0 / midas_event_number);
155
156
return
SUCCESS
;
157
}
Generated by
1.8.4