GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FrameBlock.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_FrameBlock
24 #define ADF_FrameBlock
25 
26 #ifndef ADF_ConfAgent
27 #include "ConfAgent.h"
28 #endif
29 #ifndef ADF_Frame
30 #include "Frame.h"
31 #endif
32 
33 namespace ADF
34 {
35 
36  class Key;
37 
39 
43  class FrameBlock
44  {
45  private:
47  ConfAgent::EMode fMode;
48  private:
50 
54  Bool_t fEoB;
55  private:
57  // std::string fName;
58  private:
60  void *fOwner;
61 
62  protected:
64 
66  virtual Bool_t Expand(UInt_t) = 0;
67 
68  public:
70  fMode(mode),
71  fEoB(false),
72  /* fName("AFrameBlock"), */
73  fOwner(0x0)
74  {;}
75  virtual ~FrameBlock()
76  {;}
77 
80  { return fMode; }
81  virtual void SetModeIO(ConfAgent::EMode mode)
82  { fMode = mode; }
83  Bool_t IsMode(ConfAgent::EMode mode) const
84  { return fMode == mode; }
85 
86  Bool_t IsEoB() const
87  { return fEoB; }
88 
89  void SetEoB(Bool_t b)
90  { fEoB = b; }
91 
93  /*
94  virtual void SetName(std::string name)
95  {
96  fName = name;
97  }
98  virtual std::string GetName() const
99  {
100  return fName;
101  }
102  */
104  virtual void *SetOwner(void * owner = 0x0)
105  {
106  void *current = fOwner; fOwner = owner; return current;
107  }
108  virtual Bool_t IsOwner(void * owner = 0x0) const
109  {
110  return fOwner == owner;
111  }
112 
114  virtual BufferIO *GetBufferIO(UInt_t which = 0u) = 0;
115  // virtual const BufferIO *GetBufferIO(UInt_t which = 0u) = 0;
116 
118 
120  virtual Bool_t NextFrame(Key *) = 0;
121 
123 
126  virtual BufferIO &GetFrame(UInt_t which = 0u) = 0;
127 
129 
137  virtual Bool_t Reserve(UInt_t, Bool_t /*switch_eob*/ = false, UInt_t /*which*/ = 0u)
138  { return false; }
139 
141  virtual Long64_t GetSize(UInt_t = 0u) const
142  { return 0; }
144  virtual Long64_t GetMaxSize(UInt_t = 0u) const
145  { return 0; }
147  virtual Long64_t GetOffset(UInt_t = 0u) const
148  { return 0; }
149 
151 
154  virtual Bool_t AddFrame(const BufferIO &, UInt_t = 0u)
155  { return false; }
156 
157  virtual Bool_t AddFrame(const Frame &, UInt_t = 0u)
158  { return false; }
159 
161 
168  virtual void Rewind(ConfAgent::EMode mode = ConfAgent::kRead) = 0;
169 
171  virtual void Snapshot()
172  {;}
174  virtual void BackToSnapshot()
175  {;}
176 
177  virtual UInt_t NumberOfChannels() const = 0;
178 
180 
194  virtual Bool_t SetBlock(Char_t * /*buf */ = 0x0, UInt_t /*size*/ = 0u, char /*opt_rewind*/ = 'r', char /*opt_link_or_copy*/ = 'l', UInt_t /*which*/ = 0u) = 0;
195 
197  //virtual Bool_t MoveBlock( FrameBlock &, char /*opt_rewind*/ = 'r', char /*opt_link_or_copy*/ = 'l', UInt_t /*which*/ = 0u)
198  // { return false; }
199 
200  };
201 
203 
206  class OneBlock : public FrameBlock
207  {
208  protected:
210 
212 
220 
221  protected:
223 
225  virtual Bool_t Expand(UInt_t)
226  { return false ; }
227 
228  public:
230  {;}
231  virtual ~OneBlock()
232  {;}
233 
234  virtual Long64_t GetSize(UInt_t = 0u) const
235  {
236  if (GetModeIO()==ConfAgent::kRead) {
237  return fBuffer.Size();
238  }
239  else return fBuffer.Offset();
240  }
241  virtual Long64_t GetMaxSize(UInt_t = 0u) const
242  {
243  return fBuffer.Size();
244  }
245 
247  virtual Long64_t GetOffset(UInt_t = 0u) const
248  {
249  return fBuffer.Offset();
250  }
251 
252  virtual BufferIO *GetBufferIO(UInt_t /*which*/ = 0u)
253  { return &fBuffer; }
254 
256 
258  virtual Bool_t NextFrame(Key *);
259 
261 
263  virtual BufferIO &GetFrame(UInt_t = 0u)
264  { return fFrame; }
265 
267  virtual Bool_t Reserve(UInt_t, Bool_t /*switch_eob*/ = false, UInt_t /*which*/ = 0u);
268 
270  virtual void Snapshot()
271  { fLastSnapshot = fBuffer.Offset(); }
273  virtual void BackToSnapshot()
275 
277 
279  virtual Bool_t AddFrame(const BufferIO &, UInt_t i = 0u);
280  virtual Bool_t AddFrame(const Frame &, UInt_t i = 0u);
281 
283 
285  virtual void Rewind(ConfAgent::EMode mode = ConfAgent::kRead);
286 
287  virtual UInt_t NumberOfChannels() const
288  { return 1u; }
289 
291 
293  virtual Bool_t SetBlock(Char_t * /*buf*/ = 0x0, UInt_t /*size*/ = 0u, char /*opt_rewind*/ = 'r', char /*opt_link_or_copy*/ = 'l', UInt_t /*which*/ = 0u);
294 
296  // virtual Bool_t MoveBlock( FrameBlock &, char /*opt_rewind*/ = 'r', char /*opt_link_or_copy*/ = 'l', UInt_t /*which*/ = 0u);
297  //
298  /*
299  virtual void View()
300  {
301  UInt_t off;
302 
303  fBuffer.Offset();
304  fBuffer.SetOffset();
305 
306  UInt_t length, message;
307  fBuffer >> length >> message;
308  std::cout << std::dec
309  << length
310  << " 0x"
311  << std::hex
312  << message << std::dec << std::endl;
313 
314  fBuffer.SetOffset(off);
315  }
316  */
317  };
318 
320 
323  class NullBlock : public OneBlock
324  {
325  protected:
326  virtual Bool_t Expand(UInt_t)
327  { return true ; }
328 
329  public:
331  { ; }
332  virtual ~NullBlock() {;}
333 
334  virtual Bool_t NextFrame(Key *)
335  { return false; }
336  virtual BufferIO &GetFrame(UInt_t = 0u)
337  { fFrame.SetEffectiveSize(0u); return fFrame; }
338 
339  virtual Bool_t Reserve(UInt_t, Bool_t /*switch_eob*/ = false, UInt_t /*which*/ = 0u)
340  { return true; }
341 
342  virtual Bool_t AddFrame(const BufferIO &, UInt_t = 0u)
343  { return true; }
344  virtual Bool_t AddFrame(const Frame &, UInt_t = 0u)
345  { return true; }
346  };
347 
349 
351  class ExpandableBlock : public OneBlock
352  {
353  protected:
355  virtual Bool_t Expand(UInt_t);
356 
357  public:
359  {;}
360  virtual ~ExpandableBlock()
361  {;}
362  };
363 
365 
367  class FileBlock : public OneBlock
368  {
369  private:
370  Long64_t fCurrentSize;
371  Long64_t fMaxSize;
372 
373  Long64_t fFileSnapshot;
374 
375  private:
376  FILE *fFile;
377 
378  protected:
379  void Reset();
380 
381  public:
383  virtual ~FileBlock()
384  {;}
385 
386  virtual Long64_t GetSize(UInt_t = 0u) const
387  {
388  if (GetModeIO()==ConfAgent::kRead) {
389  return fMaxSize;
390  }
391  else return fCurrentSize;
392 
393  }
394  virtual Long64_t GetMaxSize(UInt_t = 0u) const
395  {
396  return fMaxSize;
397  }
398 
400  virtual Long64_t GetOffset(UInt_t = 0u) const
401  {
402  return fCurrentSize;
403  }
404 
405  virtual void SetFile(FILE *file, Long64_t max_size = kMaxUInt_t)
406  {
407  Reset();
408  if (GetModeIO()==ConfAgent::kRead) { // reading mode, take the value from the file
409 #if !defined(_MSC_VER)
410  // keep current position
411  Long64_t c = ::ftell(file);
412  // now get the end of file
413  ::fseek(file, 0L, SEEK_END);
414  fMaxSize = ::ftell(file);
415  // back to current position
416  ::fseek(file, c, SEEK_SET);
417 #else
418  // WINDOWS, where the use of 64 bits is not automatic as in LINUX
419  // keep current position
420  Long64_t c = _ftelli64(file);
421  // now get the end of file
422  _fseeki64(file, __int64(0), SEEK_END);
423  fMaxSize = _ftelli64(file);
424  // back to current position
425  _fseeki64(file, c, SEEK_SET);
426 #endif
427  }
428  else fMaxSize = max_size;
429  fFile = file;
430  }
431 
432  virtual Bool_t Reserve(UInt_t, Bool_t /*switch_eob*/ = false, UInt_t /*which*/ = 0u);
433 
435 
438  virtual Bool_t NextFrame(Key *);
439 
441  virtual void Snapshot()
442  {
443  fFileSnapshot = fCurrentSize;
444  }
446  virtual void BackToSnapshot()
447  {
448  if ( fFile )
449 #if !defined(_MSC_VER)
450  ::fseek(fFile,fFileSnapshot,SEEK_SET);
451 #else
452  _fseeki64(fFile,fFileSnapshot,SEEK_SET);
453 #endif
454  fCurrentSize = fFileSnapshot;
455  }
456 
458  {
459  fCurrentSize = 0u;
460  if ( fFile )
461  ::fseek(fFile,0u,SEEK_SET);
462  }
463 
464  virtual Bool_t SetBlock(Char_t * /*buf*/= 0x0, UInt_t/*size*/= 0u, char /*opt_rewind*/ = 'r', char /*opt_link_or_copy*/ = 'l', UInt_t/*which*/ = 0u)
465  { return false; }
466 
467  virtual Bool_t AddFrame(const BufferIO &, UInt_t i = 0u);
468  virtual Bool_t AddFrame(const Frame &, UInt_t i = 0u);
469  };
470 
471 } // namespace ADF
472 #endif
473 
474 
virtual BufferIO & GetFrame(UInt_t which=0u)=0
the new frame is wrapped in a BufferIO object for transportation between the different classes ...
TBrowser * b
virtual void * SetOwner(void *owner=0x0)
Name of the block ... used to distinguish several blocks in a topology.
Definition: FrameBlock.h:104
virtual Bool_t Expand(UInt_t)=0
return true if the output is expandable
virtual Bool_t NextFrame(Key *)
return true if there is a new frame available (in reading mode)
Definition: FrameBlock.cpp:32
virtual BufferIO & GetFrame(UInt_t=0u)
Return a buffer that is linked with the part of the buffer that corresponds to the next frame...
Definition: FrameBlock.h:263
virtual Long64_t GetSize(UInt_t=0u) const
size of the current block
Definition: FrameBlock.h:141
Base class for a Key.
Definition: Key.h:56
virtual void BackToSnapshot()
back to the last position
Definition: FrameBlock.h:273
virtual void Rewind(ConfAgent::EMode mode=ConfAgent::kRead)
Rewind to be ready to be used again.
Definition: FrameBlock.cpp:130
virtual Bool_t SetBlock(Char_t *=0x0, UInt_t=0u, char= 'r', char= 'l', UInt_t=0u)
Attach a external block to this.
Definition: FrameBlock.cpp:51
virtual UInt_t NumberOfChannels() const =0
virtual ~NullBlock()
Definition: FrameBlock.h:332
Base class for a Frame.
Definition: Frame.h:73
virtual Bool_t Reserve(UInt_t, Bool_t=false, UInt_t=0u)
check if enough place to write something (writing mode)
Definition: FrameBlock.cpp:93
virtual Long64_t GetMaxSize(UInt_t=0u) const
max size of the block
Definition: FrameBlock.h:144
virtual ~ExpandableBlock()
Definition: FrameBlock.h:360
Bool_t IsMode(ConfAgent::EMode mode) const
Definition: FrameBlock.h:83
It implements an expandable block of Frame.
Definition: FrameBlock.h:351
A Block of Frames.
Definition: FrameBlock.h:43
FileBlock(UInt_t size=aMByte, ConfAgent::EMode mode=ConfAgent::kRead)
Definition: FrameBlock.cpp:153
EMode
Operating mode for frame IO.
Definition: ConfAgent.h:67
void SetEoB(Bool_t b)
Definition: FrameBlock.h:89
NullBlock(ConfAgent::EMode mode=ConfAgent::kRead)
Definition: FrameBlock.h:330
virtual Bool_t Expand(UInt_t)
This kind of Block is not expandable.
Definition: FrameBlock.h:326
ConfAgent::EMode GetModeIO() const
Return the operating mode.
Definition: FrameBlock.h:79
const UInt_t kMaxUInt_t
Definition: ADFConfig.h:100
virtual void SetModeIO(ConfAgent::EMode mode)
Definition: FrameBlock.h:81
virtual Bool_t AddFrame(const BufferIO &, UInt_t i=0u)
Add a Frame to the block.
Definition: FrameBlock.cpp:210
virtual Bool_t AddFrame(const Frame &, UInt_t=0u)
Definition: FrameBlock.h:344
virtual void BackToSnapshot()
back to the last position
Definition: FrameBlock.h:446
virtual Long64_t GetOffset(UInt_t=0u) const
Current position.
Definition: FrameBlock.h:400
UInt_t Offset() const
it returns the current position in the buffer
Definition: BufferIO.h:240
UInt_t Size() const
it returns the maximum number of bytes in this buffer
Definition: BufferIO.h:220
UInt_t fLastSnapshot
Definition: FrameBlock.h:209
const UInt_t aMByte
Definition: BaseBuffer.h:36
virtual Bool_t AddFrame(const BufferIO &, UInt_t=0u)
Add a Frame to the block.
Definition: FrameBlock.h:342
ExpandableBlock(UInt_t size=aMByte, ConfAgent::EMode mode=ConfAgent::kRead)
Definition: FrameBlock.h:358
Frames are extracted/added directly, one by one from/to a file.
Definition: FrameBlock.h:367
header file for Frame.cpp
virtual Long64_t GetMaxSize(UInt_t=0u) const
max size of the block
Definition: FrameBlock.h:241
virtual void Snapshot()
keep the position
Definition: FrameBlock.h:270
Bool_t IsEoB() const
Definition: FrameBlock.h:86
virtual Bool_t AddFrame(const BufferIO &, UInt_t i=0u)
Add a Frame to the block.
Definition: FrameBlock.cpp:112
virtual UInt_t NumberOfChannels() const
Definition: FrameBlock.h:287
virtual Long64_t GetMaxSize(UInt_t=0u) const
max size of the block
Definition: FrameBlock.h:394
virtual void Snapshot()
keep the position
Definition: FrameBlock.h:441
virtual void BackToSnapshot()
back to the last position
Definition: FrameBlock.h:174
virtual Long64_t GetOffset(UInt_t=0u) const
Current position.
Definition: FrameBlock.h:147
It implements a black hole for Frames.
Definition: FrameBlock.h:323
virtual BufferIO * GetBufferIO(UInt_t which=0u)=0
To get the address of the underlying buffer.
virtual BufferIO * GetBufferIO(UInt_t=0u)
To get the address of the underlying buffer.
Definition: FrameBlock.h:252
virtual Bool_t IsOwner(void *owner=0x0) const
Definition: FrameBlock.h:108
OneBlock(UInt_t size=aMByte, ConfAgent::EMode mode=ConfAgent::kRead)
Definition: FrameBlock.h:229
virtual Bool_t NextFrame(Key *)=0
true if there is a new frame available in the block
virtual Bool_t AddFrame(const BufferIO &, UInt_t=0u)
Add a Frame to the block.
Definition: FrameBlock.h:154
const UInt_t aByte
Definition: BaseBuffer.h:34
BufferIO fBuffer
The buffer to look for Frames.
Definition: FrameBlock.h:217
virtual Bool_t NextFrame(Key *)
Read next frame from file.
Definition: FrameBlock.cpp:168
virtual Long64_t GetSize(UInt_t=0u) const
size of the current block
Definition: FrameBlock.h:234
virtual Bool_t Reserve(UInt_t, Bool_t=false, UInt_t=0u)
check if enough place to write something (writing mode)
Definition: FrameBlock.h:339
BufferIO fFrame
to wrap the current Frame
Definition: FrameBlock.h:219
virtual Bool_t SetBlock(Char_t *=0x0, UInt_t=0u, char= 'r', char= 'l', UInt_t=0u)=0
Attach a external block to this.
UInt_t SetEffectiveSize(UInt_t size=kMaxUInt_t)
in case the buffer is partly filled and you would like to read it again
Definition: BufferIO.cpp:152
virtual void Rewind(ConfAgent::EMode=ConfAgent::kRead)
Rewind to be ready to be used again.
Definition: FrameBlock.h:457
virtual ~FileBlock()
Definition: FrameBlock.h:383
virtual ~FrameBlock()
Definition: FrameBlock.h:75
header file for ConfAgent.cpp
virtual BufferIO & GetFrame(UInt_t=0u)
Return a buffer that is linked with the part of the buffer that corresponds to the next frame...
Definition: FrameBlock.h:336
virtual void SetFile(FILE *file, Long64_t max_size=kMaxUInt_t)
Definition: FrameBlock.h:405
virtual Bool_t Reserve(UInt_t, Bool_t=false, UInt_t=0u)
Reserve the given size for writing.
Definition: FrameBlock.h:137
FrameBlock(ConfAgent::EMode mode=ConfAgent::kRead)
Definition: FrameBlock.h:69
virtual Bool_t Expand(UInt_t)
implements Expand method
Definition: FrameBlock.cpp:144
virtual Long64_t GetOffset(UInt_t=0u) const
Current position.
Definition: FrameBlock.h:247
virtual Bool_t NextFrame(Key *)
return true if there is a new frame available (in reading mode)
Definition: FrameBlock.h:334
virtual Long64_t GetSize(UInt_t=0u) const
size of the current block
Definition: FrameBlock.h:386
virtual void Rewind(ConfAgent::EMode mode=ConfAgent::kRead)=0
Rewind to be ready to be used again.
const Int_t size
Definition: BenchIO.C:24
virtual Bool_t Expand(UInt_t)
This kind of Block is not expandable.
Definition: FrameBlock.h:225
virtual void Snapshot()
keep the current position
Definition: FrameBlock.h:171
It implements an in-memory block of Frames.
Definition: FrameBlock.h:206
virtual Bool_t AddFrame(const Frame &, UInt_t=0u)
Definition: FrameBlock.h:157
virtual Bool_t SetBlock(Char_t *=0x0, UInt_t=0u, char= 'r', char= 'l', UInt_t=0u)
Attach a external block to this.
Definition: FrameBlock.h:464
virtual ~OneBlock()
Definition: FrameBlock.h:231
virtual Bool_t Reserve(UInt_t, Bool_t=false, UInt_t=0u)
check if enough place to write something (writing mode)
Definition: FrameBlock.cpp:235
UInt_t SetOffset(UInt_t off=0u) const
change the current position.
Definition: BufferIO.cpp:122