GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
TGo4MbsSubEvent.cxx
Go to the documentation of this file.
1// $Id$
2//-----------------------------------------------------------------------
3// The GSI Online Offline Object Oriented (Go4) Project
4// Experiment Data Processing at EE department, GSI
5//-----------------------------------------------------------------------
6// Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7// Planckstr. 1, 64291 Darmstadt, Germany
8// Contact: http://go4.gsi.de
9//-----------------------------------------------------------------------
10// This software can be used under the license agreements as stated
11// in Go4License.txt file which is part of the distribution.
12//-----------------------------------------------------------------------
13
14#include "TGo4MbsSubEvent.h"
15
16#include "TGo4Log.h"
17#include "TGo4MbsSource.h"
18
21 fbIsFilled(kFALSE),
22 fbIsDataOwner(kTRUE),
23 fxHeader(),
24 fiAllocLen(0),
25 fiData(nullptr)
26{
27 GO4TRACE((12,"TGo4MbstSubEvent::TGo4MbsSubEvent()",__LINE__, __FILE__));
28 //TGo4Log::Info( "MBS SubEvent default ctor.");
29}
30
33 fbIsFilled(kFALSE),
34 fbIsDataOwner(kTRUE),
35 fxHeader(),
36 fiAllocLen(0),
37 fiData(nullptr)
38{
39 GO4TRACE((12,"TGo4MbsSubEvent::TGo4MbsSubEvent(UInt_t)",__LINE__, __FILE__));
40 //TGo4Log::Info( "MBS SubEvent normal ctor.");
41 if(fbIsDataOwner) {
42 fiData = new Int_t[datasize];
43 fiAllocLen = datasize;
44 for (Int_t t = 0; t < datasize; t++)
45 fiData[t] = 0;
46 }
47}
48
50{
51 GO4TRACE((12,"TGo4MbsSubEvent::~TGo4MbsSubEvent()",__LINE__, __FILE__));
52 // check if Clear with only the used field elements worked correctly
53 //TGo4Log::Info( "MBS SubEvent dtor...");
54 Clear();
55 if (fbIsDataOwner && fiData) {
56 for (Int_t t = 0; t < GetAllocatedLength(); t++)
57 if (fiData[t] != 0)
58 TGo4Log::Debug(" MBS SubEvent dtor WARNING: Data(%d) not zero after Clear !!! ", t);
59 delete[] fiData;
60 // TGo4Log::Info( "MBS SubEvent dtor deleted data field");
61 }
62}
63
65{
66 GO4TRACE((11,"TGo4MbsSubEvent::PrintEvent()",__LINE__, __FILE__));
67
69 /* Bool_t printhexa=kFALSE;
70 Int_t *pData = (Int_t *) GetDataField();
71 std::cout << " Mbs Subevent t/s "
72 << dec << std::setw(4) << (Int_t)GetType()
73 << " " << std::setw(4) << (Int_t)GetSubtype()
74 << " len " << std::setw(8) << (Int_t)GetDlen()
75 << " procid " << std::setw(4) << (Int_t)GetProcid()
76 << " ctrl " << std::setw(4) << (Int_t)GetControl()
77 << " cr " << std::setw(4) << (Int_t)GetSubcrate()
78 << std::endl;
79 if(printhexa) std::cout << hex; else std::cout << dec;
80 for(Int_t i = 0; i < GetDlen()/2-1; i++) {
81 std::cout << std::setw(12) << *pData << " ";
82 if((i-3) % 4 == 0) std::cout << std::endl;
83 pData++;
84 }
85 std::cout << std::endl;
86 */
87
88 // very new style just using printf
90}
91
92
93void TGo4MbsSubEvent::PrintMbsSubevent(Bool_t longw, Bool_t hexw, Bool_t dataw)
94{
95 // print header
96 printf(" SubEv ID %6d Type/Subtype %5d %5d Length %5d[w] Control %2d Subcrate %2d\n",
98
99 if(!dataw) return;
100 // print data
101
102 Int_t *pl_data = GetDataField();
103 Int_t ll = GetIntLen();
104
105 if(longw) {
106 /* In this case we assume data as one longword per channel */
107 for (Int_t l = 0; l < ll; l++) {
108 if (l % 8 == 0)
109 printf(" ");
110 if (hexw)
111 printf("%04x.%04x ", (unsigned)((*pl_data >> 16) & 0xffff), (unsigned)(*pl_data & 0xffff));
112 else
113 printf("%8u ", (unsigned)*pl_data);
114 pl_data++;
115 if (l % 8 == 7)
116 printf("\n");
117 }
118
119 if (ll%8 != 0) printf("\n");
120 } else {
121 /* In this case we assume data as two words per channel */
122 for (Int_t l = 0; l < ll; l++) {
123 if (l % 4 == 0)
124 printf(" ");
125 if (hexw)
126 printf("%6x%6x", (unsigned)(*pl_data & 0xffff), (unsigned)((*pl_data >> 16) & 0xffff));
127 else
128 printf("%8u%8u", (unsigned)(*pl_data & 0xffff), (unsigned)((*pl_data >> 16) & 0xffff));
129 pl_data++;
130 if (l % 4 == 3)
131 printf("\n");
132 }
133 if (ll % 4 != 0)
134 printf("\n");
135 }
136}
137
138void TGo4MbsSubEvent::Set(Int_t dlen,
139 Short_t type,
140 Short_t subtype,
141 Short_t procid,
142 Char_t subcrate,
143 Char_t ctrl)
144{
145 SetDlen(dlen);
146 SetType(type);
147 SetSubtype(subtype);
148 //SetProcid(procid); do not change procid and identifiers!!
149 //SetSubcrate(subcrate);
150 //SetControl(ctrl);
151}
152
154{
155 GO4TRACE((11,"TGo4MbsSubEvent::Clear()",__LINE__, __FILE__));
156 fbIsFilled = kFALSE;
157 if(fbIsDataOwner && fiData) {
158 // clear array of data
159 Int_t dleng = GetDlen();
160 if(dleng == 0) dleng = 2; // default value for dleng is not zero!!
161 // only clear regions which were used by the previous fill...
162 Int_t fieldlength = (dleng-2) / TGo4MbsSource::fguLONGBYSHORT ; // field is Int_t
163 if(fieldlength>fiAllocLen)
164 fieldlength = fiAllocLen;
165
166 if(fieldlength == 0)
167 fiData[0] = 0; // clear in case of zero subevents!
168
169 for (Int_t i = 0; i < fieldlength; ++i)
170 fiData[i] = 0;
171 fxHeader.Clear();
172 Set(dleng); // set to default values, but remember last datalength
173 }//if(fbIsDataOwner)
174}
175
177{
178 GO4TRACE((11,"TGo4MbsSubEvent::ReAllocate(UInt_t)",__LINE__, __FILE__));
179 if(!fbIsDataOwner) return;
180 if( newsize <= fiAllocLen ) {
181 // newsize is smaller, we do not reallocate
182 } else {
183 delete [] fiData;
184 fiData = new Int_t[newsize];
185 TGo4Log::Debug(" MbsSubEvent: Reallocating Data field from %d to %d longwords ",fiAllocLen,newsize);
186 fiAllocLen = newsize;
187 Clear();
188 }
189}
#define GO4TRACE(X)
Definition TGo4Log.h:25
static void Debug(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 0.
Definition TGo4Log.cxx:281
static const UInt_t fguLONGBYSHORT
ratio sizeof(long) by sizeof(short).
Bool_t fbIsFilled
True if this subevent has already been filled in this event cycle.
Int_t * GetDataField() const
Direct access to the fiData field pointer.
TGo4SubEventHeader10 fxHeader
aggregationByValue
Int_t * fiData
Pointer to external integer field containing the subevent data.
void PrintEvent() override
Print event with default arguments.
void Set(Int_t dlen, Short_t type=10, Short_t subtype=1, Short_t procid=0, Char_t subcrate=0, Char_t ctrl=0)
virtual ~TGo4MbsSubEvent()
Short_t GetSubtype() const
Int_t GetAllocatedLength() const
Return length of allocated memory for data field.
Char_t GetSubcrate() const
void SetSubtype(Short_t subtype)
void Clear(Option_t *opt="") override
Int_t GetIntLen() const
Return raw data length in int (4-bytes)
void SetDlen(Int_t dlen)
void ReAllocate(Int_t newsize)
Allocate the data field with newsize.
Char_t GetControl() const
Short_t GetProcid() const
Bool_t fbIsDataOwner
True if subevent owns data field.
Int_t fiAllocLen
Length of the allocated data field.
Int_t GetDlen() const
void SetType(Short_t type)
void PrintMbsSubevent(Bool_t longw=kTRUE, Bool_t hexw=kTRUE, Bool_t dataw=kTRUE)
Print MBS subevent.
Short_t GetType() const
int l