source: trunk/MagicSoft/MarsOctober/mbase/MObjBuffer.cc@ 5795

Last change on this file since 5795 was 447, checked in by harald, 24 years ago
Bringing the sources for the octobertest under CVS controll. (november, 3rd, 2000)
  • Property svn:executable set to *
File size: 2.5 KB
Line 
1////////////////////////////////////////////////////////////////////////
2//
3// MObjBuffer
4//
5// This is a ring buffer for TObjects
6// It should be similar to TObjArray, but with different counting
7//
8////////////////////////////////////////////////////////////////////////
9#include "MObjBuffer.h"
10
11#include "MFileDescr.h"
12#include "MFile.h"
13
14ClassImp (MObjBuffer)
15
16MObjBuffer::MObjBuffer(MParContainer *o, Int_t nevts,
17 const char *name, const char *title) :
18 fIsInput(kFALSE), fIsOutput(kFALSE), fHasChanged(kFALSE),
19 nPos(0), nObjPos(0)
20{
21 fName = name ? name : o->GetName();
22 fTitle = title ? title : o->GetTitle();
23
24 //
25 // add the given object as first to the buffer
26 //
27 objs.Add(o);
28
29 //
30 // create nevts-1 new objects of the given object and add them to the buffer
31 //
32 for (Int_t i = 1; i<2*nevts+1; i++)
33 {
34 objs.Add(o->New());
35 }
36
37 nPreObjs = nPostObjs = nevts;
38 nEntries = nPreObjs+nPostObjs+1;
39}
40
41void MObjBuffer::SetAsInput(MFile *f, Bool_t i)
42{
43 fIsInput = i;
44
45 if (fIsInput)
46 pFileIn = f->OpenInput(fName, objs[0]->ClassName());
47 // else
48 // f->CloseInput();
49}
50
51void MObjBuffer::SetAsOutput(MFile *f, Bool_t o)
52{
53 fIsOutput = o;
54
55 if (fIsOutput)
56 pFileOut = f->OpenOutput(fName, objs[0]->ClassName(), (MParContainer**)&objs[0]);
57}
58
59Int_t MObjBuffer::GetNextEvent(Int_t time)
60{
61 //
62 // one step forward in the ring buffer
63 //
64 nObjPos++;
65 nObjPos %= nEntries;
66
67 //
68 // calculate the address of the object after the last one in the ring buffer
69 //
70 Int_t adr = (nObjPos+nPostObjs+nEntries+1)%nEntries;
71
72 //
73 // get the next entry (some event in the future) from file
74 //
75
76 pFileIn->SetAddress((MParContainer**)&objs[adr]);
77 pFileIn->GetEvent(nPos++);
78
79 //
80 // return number of actual event (present) in tree
81 //
82 return nPos-nPostObjs-1;
83}
84
85void MObjBuffer::PutEvent()
86{
87 //
88 // one step forward in the ring buffer
89 //
90 nObjPos++;
91 nObjPos %= nEntries;
92
93 //
94 // write actual (present) object to file
95 //
96 pFileOut->SetAddress((MParContainer**)&objs[nObjPos]);
97 pFileOut->Fill();
98}
99
100void MObjBuffer::Fill()
101{
102 //
103 // in the future this function has to handle the dynamic buffer
104 //
105 if (nPos)
106 return;
107
108 //
109 // fill PreBuffer (( objects in the future)
110 //
111 for (Int_t i=1; i<nPostObjs+2; i++)
112 {
113 pFileIn->SetAddress((MParContainer**)&objs[i]);
114 pFileIn->GetEvent(nPos++);
115 }
116 nObjPos = 0;
117}
118
Note: See TracBrowser for help on using the repository browser.