BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
SubDetectorFragment.cxx
Go to the documentation of this file.
1// Dear emacs, this is -*- c++ -*-
2
3/**
4 * @file SubDetectorFragment.cxx
5 * @author <a href="mailto:Andre.dos.Anjos@cern.ch">Andre DOS ANJOS</a>
6 * $Author: zhangy $
7 * $Revision: 1.1.1.1 $
8 * $Date: 2009/06/19 07:35:41 $
9 *
10 * Implements the SubDetector fragment writing helper class
11 */
12
13#include "eformat/write/SubDetectorFragment.h"
14#include "eformat/HeaderMarker.h"
15#include "eformat/Status.h"
16#include "eformat/write/FullEventFragment.h"
17#include "ers/StreamFactory.h"
18
20 : m_parent( 0 ), m_child( 0 ), m_last( 0 ), m_next( 0 ), m_extra_count( 0 ) {
21 m_header[0] = eformat::SUB_DETECTOR; // marker
22 m_header[1] = 8; // this header size + status size
23 m_header[2] = 8; // this header size + status size
24 m_header[3] = eformat::DEFAULT_VERSION; // format version
25 m_header[4] = source_id;
26 m_header[5] = 1; // number of status
27 m_header[6] = 0; // number of fragment specific
28
29 // now initialize pages
30 set( m_node[0], m_header, 6, &m_node[1] );
31 set( m_node[1], &eformat::DEFAULT_STATUS, 1, &m_node[2] );
32 set( m_node[2], &m_header[6], 1, 0 );
33 ERS_DEBUG_3( "%s Source Id. = 0x%x.", "Built (write) subdetector from scratch, with",
35}
36
38 : m_parent( 0 ), m_child( 0 ), m_last( 0 ), m_next( 0 ), m_extra_count( 0 ) {
39 m_header[0] = eformat::SUB_DETECTOR; // marker
40 m_header[1] = 8; // this header size + status size
41 m_header[2] = 8; // this header size + status size
42 m_header[3] = eformat::DEFAULT_VERSION; // format version
43 m_header[4] = 0; // source identifier
44 m_header[5] = 1; // number of status
45 m_header[6] = 0; // number of fragment specific
46
47 // now initialize pages
48 set( m_node[0], m_header, 6, &m_node[1] );
49 set( m_node[1], &eformat::DEFAULT_STATUS, 1, &m_node[2] );
50 set( m_node[2], &m_header[6], 1, 0 );
51 ERS_DEBUG_3( "%s Source Id. = 0x%x.", "Built empty (write) subdetector from scratch, with",
53}
54
56 : m_parent( 0 ), m_child( 0 ), m_last( 0 ), m_next( 0 ), m_extra_count( 0 ) {
57 // now initialize pages
58 set( m_node[0], sd, 6, &m_node[1] );
59 set( m_node[1], &sd[6], sd[5], &m_node[2] );
60 set( m_node[2], &sd[6 + sd[5]], 1, &m_extra );
61 eformat::write::set( m_extra, &sd[7 + sd[5]], sd[1] - sd[2], 0 );
62 ++m_extra_count;
63 ERS_DEBUG_3( "%s Source Id. = 0x%x.",
64 "Built (write) subdetector from contiguous memory, with", source_id() );
65}
66
68 : m_parent( 0 ), m_child( 0 ), m_last( 0 ), m_next( 0 ), m_extra_count( 0 ) {
69 // now initialize pages
70 set( m_node[0], sd->base, 6, &m_node[1] );
71 set( m_node[1], &sd->base[6], sd->base[5], &m_node[2] );
72 set( m_node[2], &sd->base[6 + sd->base[5]], 1, &m_extra );
73 eformat::write::set( m_extra, &sd->base[7 + sd->base[5]], sd->size_word - sd->base[2],
74 sd->next );
75 m_extra_count += eformat::write::count( m_extra );
76 ERS_DEBUG_3( "%s Source Id. = 0x%x.", "Built (write) subdetector from paged memory, with",
77 source_id() );
78}
79
82 : m_parent( 0 ), m_child( 0 ), m_last( 0 ), m_next( 0 ), m_extra_count( 0 ) {
83 *this = other;
84 ERS_DEBUG_3( "%s Source Id. = 0x%x.", "Built (write) subdetector from copy, with",
85 source_id() );
86}
87
90 memcpy( reinterpret_cast<void*>( m_header ),
91 reinterpret_cast<const void*>( other.m_node[0].base ), 6 * sizeof( uint32_t ) );
92 m_header[6] = other.m_node[2].base[0];
93
94 // now initialize pages
95 set( m_node[0], m_header, 6, &m_node[1] );
96 set( m_node[1], other.m_node[1].base, other.m_node[1].size_word, &m_node[2] );
97 set( m_node[2], &m_header[6], 1, 0 );
98 ERS_DEBUG_3( "%s Source Id. = 0x%x.", "Copied (write) subdetector with",
100 return *this;
101}
102
103void eformat::write::SubDetectorFragment::status( uint32_t n, const uint32_t* status ) {
104 if ( m_parent )
105 m_parent->size_change( m_node[0].base[1], m_node[0].base[1] - m_node[0].base[5] + n );
106 m_node[0].base[1] -= m_node[0].base[5]; // remove count from previous status
107 m_node[0].base[2] -= m_node[0].base[5]; // remove count from previous status
108 m_node[1].size_word = m_node[0].base[5] = n; // set new values
109 m_node[0].base[1] += n;
110 m_node[0].base[2] += n;
111 m_node[1].base = const_cast<uint32_t*>( status );
112}
113
115 uint32_t old_size = m_node[0].base[1];
116 m_node[0].base[1] -= o;
117 m_node[0].base[1] += n;
118 if ( m_parent ) m_parent->size_change( old_size, m_node[0].base[1] );
119}
120
122 ERS_DEBUG_3( "%s Source Id. = 0x%x to subdetector with Source Id. = 0x%x",
123 "Appending ros fragment with", ros->source_id(), source_id() );
124 ros->parent( this );
125 uint32_t old_size = m_node[0].base[1];
126 m_node[0].base[1] += ros->size_word();
127
128 // adjust `m_last' and `m_child' to point to the new last ROB
129 if ( m_last ) m_last->next( ros );
130 else m_child = ros;
131 m_last = ros;
132
133 // propagate changes to my parent
134 if ( m_parent ) m_parent->size_change( old_size, m_node[0].base[1] );
135}
136
138 uint32_t retval = 3 + m_extra_count;
139 for ( const ROSFragment* curr = m_child; curr; curr = curr->next() )
140 retval += curr->page_count();
141 return retval;
142}
143
145 // the header is already concatenated by construction
146 eformat::write::node_t* last = &m_node[2];
147 if ( m_extra_count )
148 {
149 last = &m_extra;
150 while ( last->next ) last = last->next;
151 }
152 for ( ROSFragment* curr = m_child; curr; curr = const_cast<ROSFragment*>( curr->next() ) )
153 {
154 last->next = const_cast<eformat::write::node_t*>( curr->bind() );
155 while ( last->next ) last = last->next; // advance until end
156 }
157 return m_node;
158}
const Int_t n
#define ERS_DEBUG_3(...)
void size_change(uint32_t o, uint32_t n)
SubDetectorFragment & operator=(const SubDetectorFragment &other)
void status(uint32_t n, const uint32_t *status)
const eformat::write::node_t * bind(void)
void append(eformat::write::ROSFragment *ros)
void size_change(uint32_t o, uint32_t n)
uint32_t count(const node_t &list)
Definition node.cxx:38
void set(node_t &i, const uint32_t *b, size_t l, node_t *n=0)
Definition node.cxx:16
uint32_t * base
The base address for this page.
size_t size_word
The size, in 4-byte words for this page.