Belle II Software  release-08-01-10
SendHeader.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include "daq/dataobjects/SendHeader.h"
10 
11 using namespace std;
12 using namespace Belle2;
13 
14 //ClassImp(SendHeader);
15 
16 SendHeader::SendHeader()
17 {
18  Initialize();
19  // cout << "SendHeader NULL constructor" << endl;
20 }
21 
22 SendHeader::SendHeader(int* buffer)
23 {
24  // cout << "SendHeader constructor with buffer" << endl;
25  memcpy(m_buffer, buffer, SENDHDR_NWORDS * sizeof(int));
26 }
27 
28 SendHeader::~SendHeader()
29 {
30 }
31 
32 int* SendHeader::GetBuffer()
33 {
34  return m_buffer;
35 }
36 
37 void SendHeader::SetBuffer(int* bufin)
38 {
39  memcpy(m_buffer, bufin, SENDHDR_NWORDS * sizeof(int));
40 }
41 
42 void SendHeader::Initialize()
43 {
44  memset(m_buffer, 0, sizeof(int)* SENDHDR_NWORDS);
45  m_buffer[ POS_HDR_NWORDS ] = SENDHDR_NWORDS;
46 }
47 
48 
49 // Set Values
50 
51 void SendHeader::SetNwords(int total_data_nwords)
52 {
53  m_buffer[ POS_NWORDS ] = total_data_nwords;
54 }
55 
56 void SendHeader::SetExpRunWord(unsigned int exp_run)
57 {
58  m_buffer[ POS_EXP_RUN_NUM ] = exp_run;
59 }
60 
61 void SendHeader::SetNumEventsinPacket(int num_events)
62 {
63  m_buffer[ POS_NUM_EVE_NUM_NODES ] =
64  (m_buffer[ POS_NUM_EVE_NUM_NODES ] & 0x0000FFFF) |
65  ((num_events << 16) & 0xFFFF0000);
66 }
67 
68 void SendHeader::SetNumNodesinPacket(int num_nodes)
69 {
70  m_buffer[ POS_NUM_EVE_NUM_NODES ] =
71  (m_buffer[ POS_NUM_EVE_NUM_NODES ] & 0xFFFF0000) |
72  (num_nodes & 0x0000FFFF);
73 }
74 
75 
76 void SendHeader::SetEventNumber(int eve_num)
77 {
78  m_buffer[ POS_EVE_NUM ] = eve_num;
79 }
80 
81 
82 void SendHeader::SetNodeID(int node_id)
83 {
84  m_buffer[ POS_NODE_ID ] = node_id;
85 }
86 
87 
88 void SendHeader::SetRunNum(int run_num)
89 {
90 
91  unsigned int inv_mask = ~((unsigned int)(RUNNO_MASK));
92  m_buffer[ POS_EXP_RUN_NUM ] =
93  ((unsigned int)m_buffer[ POS_EXP_RUN_NUM ] & inv_mask) |
94  (((unsigned int)run_num << RUNNO_SHIFT) & RUNNO_MASK);
95 
96  return;
97 }
98 
99 void SendHeader::SetSubRunNum(int subrun_num)
100 {
101 
102  unsigned int inv_mask = ~((unsigned int)(SUBRUNNO_MASK));
103  m_buffer[ POS_EXP_RUN_NUM ] =
104  ((unsigned int)m_buffer[ POS_EXP_RUN_NUM ] & inv_mask) | ((unsigned int)subrun_num & SUBRUNNO_MASK);
105  return;
106 }
107 
108 void SendHeader::SetExpNum(int exp_num)
109 {
110 
111  unsigned int inv_mask = ~((unsigned int)(EXP_MASK));
112  m_buffer[ POS_EXP_RUN_NUM ] =
113  ((unsigned int)m_buffer[ POS_EXP_RUN_NUM ] & inv_mask) |
114  (((unsigned int)exp_num << EXP_SHIFT) & EXP_MASK);
115 
116  return;
117 }
118 
119 
120 
121 // Get Values
122 
123 int SendHeader::GetTotalNwords() { return m_buffer[ POS_NWORDS ];}
124 int SendHeader::GetHdrNwords() { return SENDHDR_NWORDS; }
125 int SendHeader::GetNumEventsinPacket()
126 {
127  return
128  ((m_buffer[ POS_NUM_EVE_NUM_NODES ] & 0xFFFF0000) >> 16) & 0x0000FFFF;
129 
130 }
131 int SendHeader::GetNumNodesinPacket() { return m_buffer[ POS_NUM_EVE_NUM_NODES ] & 0x0000FFFF; }
132 
133 int SendHeader::GetEventNumber() { return m_buffer[ POS_EVE_NUM ]; }
134 
135 int SendHeader::GetNodeID() { return m_buffer[ POS_NODE_ID ]; }
136 
137 int SendHeader::GetRunNum()
138 {
139  return (((unsigned int)(m_buffer[ POS_EXP_RUN_NUM ]) & RUNNO_MASK) >> RUNNO_SHIFT);
140 }
141 
142 int SendHeader::GetSubRunNum()
143 {
144  return ((unsigned int)(m_buffer[ POS_EXP_RUN_NUM ]) & SUBRUNNO_MASK);
145 }
146 
147 int SendHeader::GetRunNumSubRunNum()
148 {
149 
150  return ((unsigned int)(m_buffer[ POS_EXP_RUN_NUM ]) &
151  (RUNNO_MASK | SUBRUNNO_MASK));
152 }
153 
154 
155 int SendHeader::GetExpNum()
156 {
157 
158  return (((unsigned int)(m_buffer[ POS_EXP_RUN_NUM ]) & EXP_MASK) >> EXP_SHIFT);
159 }
160 
161 
Abstract base class for different kinds of events.