GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AgataDataFrame.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004 by Olivier Stezowski *
3  * stezow(AT)ipnl.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
23 #ifndef ADF_AgataDataFrame
24 #define ADF_AgataDataFrame
25 
26 #ifndef ADF_GenericFrame
27 #include "GenericFrame.h"
28 #endif
29 
30 namespace ADF
31 {
32 
33 class AgataFrameFactory;
34 
36 
38 template <typename Data_T>
39 class AgataDataFrame : public ConcreteDataFrame< Data_T >
40 {
41  friend class AgataFrameFactory;
42 
43 protected:
45  ConcreteDataFrame< Data_T >(key) {;}
46 
48  virtual UInt_t ReadImp() = 0;
50  virtual UInt_t WriteImp() = 0;
51 
52 public:
53  virtual ~AgataDataFrame()
54  {;}
55 
57  virtual void DataReset() = 0;
58 
59  virtual UInt_t Read()
60  {
61  // to know the expected length of the frame
62  UInt_t length_from_key
64 
65  // test on 64 bits ??
66 
67  // the buffer is ready to be read
68  AgataDataFrame< Data_T >::fBuffer->SetEffectiveSize(length_from_key);
71 
72  UInt_t size_read = ReadImp();
73 
74  // check if everything is all right and synchronize Global items
76  && size_read <= length_from_key ) {
77  AgataDataFrame< Data_T >::Data()->Global()->GetItems();
78  } else { // something goes wrong
79  size_read = 0u;
80  }
81  return size_read;
82  }
83  virtual UInt_t Write()
84  {
85  // first, synchronize external items into local ones
86  AgataDataFrame< Data_T >::Data()->Global()->SetItems();
87 
88  // set current offset to 0
91 
92  UInt_t size_written = WriteImp();
93 
94  if ( size_written > 0u && AgataDataFrame< Data_T >::fBuffer->IsStatus(BaseBuffer::kGood) )
95  {
96  // to align an AgataFrame on 32 bits ... REQUIRED by ADA
97  const UInt_t align = 4u;
98  UInt_t offset
99  = (size_written + AgataDataFrame< Data_T >::GetKey()->GetKeyLength()) % align;
100 
101  if ( offset > 0u ) {
102  AgataDataFrame< Data_T >::fBuffer->Reserve(align);
103  UInt_t toadd = align - offset;
104  AgataDataFrame< Data_T >::fBuffer->FillWith(0,toadd);
105  }
106  // end to align
107 
108  // check if everything is all right and update the Key part
110  if ( ok ) {
111  AgataDataFrame< Data_T >::GetKey()->SetDataLength
113  } else { // something goes wrong
114  AgataDataFrame< Data_T >::GetKey()->SetDataLength(0u);
115  }
116  }
118  }
119  virtual void Reset()
121 };
122 
123 
124 } // namespace ADF
125 #endif
126 
virtual Data_T * Data()
Definition: GenericFrame.h:51
Base class for a Key.
Definition: Key.h:56
virtual UInt_t ReadImp()=0
to get from the frame the data content
General interface for a AgataDataFrame.
virtual ~AgataDataFrame()
virtual void DataReset()=0
to reset the data content
virtual Key * GetKey()
To get the Key associated to this frame.
Definition: Frame.h:344
virtual UInt_t GetDataLength() const
Definition: Key.h:134
AgataDataFrame(Key *key)
ConcreteDataFrame : a RawFrame with a data interface.
Definition: GenericFrame.h:39
virtual UInt_t GetKeyLength() const
Unique number corresponding to a type of Key.
Definition: Key.h:210
AgataFrameFactory, implements agata's like Frame Factory.
virtual void Reset()
copy the sub-frame #i to the Frame given in the second argument
virtual UInt_t Read()
It just returns the current size of the buffer.
virtual UInt_t WriteImp()=0
to set from the frame the data content
virtual UInt_t Write()
It just set the size of the frame from the current position in the buffer.
virtual void FastReset()
FastReset the current frame, means the data part keep the previous values.
Definition: Frame.h:526