/[PAMELA software]/gp2root/pBlockPointer.cpp
ViewVC logotype

Contents of /gp2root/pBlockPointer.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Sun Oct 22 08:26:37 2006 UTC (18 years, 1 month ago) by cafagna
Branch: MAIN
CVS Tags: v0r9, v0r10, HEAD
Changes since 1.1: +8 -7 lines
Stable version, lot of changes, ROOT support included, persistency not yet activated

1 #include <string>
2 #include <iostream>
3 #include <vector>
4
5 #include "pBlockPointer.h"
6
7 #define VAR_SIZE 4
8
9 using std::cout;
10 using std::endl;
11 using std::string;
12
13 // Returns the address of the block named sin the buffer _pbuf
14 char* pBlockPointer::BlockAddress(const std::string& s){
15 return _pbuf+BlockInd(s);
16 }
17 char* pBlockPointer::BlockAddressR(const std::string& s){
18 return _pbr+BlockInd(s);
19 }
20
21
22 // Returns the pointer to the buffer to be passed to HBOOK routines
23 char* pBlockPointer::CreatePbuf() {
24 if(!(_pbuf==0)) {
25 cout<< " pBlockPointer::CreatePbuf: deleting _pbuf" << endl;
26 delete [] _pbuf;
27 }
28 if(!(_pbr==0)) {
29 cout<< " pBlockPointer::CreatePbuf: deleting _pbr" << endl;
30 delete [] _pbr;
31 }
32 _pbuf=new char[TotBufSize()];
33 _pbr=new char[TotBufSize()];
34 return _pbuf;
35 }
36
37 // Returns the size, in Byte, of the buffer
38 int pBlockPointer::TotBufSize(){
39 int temp=0;
40 for (unsigned int i=0; i< _pblockmap.size(); temp+=_pblockmap[i++].nbyte);
41 return temp;
42 }
43
44 // Does count the number of bytes associated with the block s
45 int& pBlockPointer::CountByte(const std::string& s)
46 {
47 for (unsigned int i=0; i< _pblockmap.size(); i++)
48 if( s== _pblockmap[i].name) return _pblockmap[i].nbyte;
49
50 pBlockDesc p(s, 0, 0);
51 _pblockmap.push_back(p);
52
53 return _pblockmap[_pblockmap.size()-1].nbyte;
54 }
55
56 // Does count the number of bytes associated with the block s
57 int& pBlockPointer::CountVar(const std::string& s)
58 {
59 for (unsigned int i=0; i< _pblockmap.size(); i++)
60 if( s== _pblockmap[i].name) return _pblockmap[i].nvar;
61
62 pBlockDesc p(s, 0, 0);
63 _pblockmap.push_back(p);
64
65 return _pblockmap[_pblockmap.size()-1].nvar;
66 }
67 // Does count the number of bytes associated with the block s
68 int& pBlockPointer::SetMult(const std::string& s)
69 {
70 for (unsigned int i=0; i< _pblockmap.size(); i++)
71 if( s== _pblockmap[i].name) return _pblockmap[i].nmult;
72
73 pBlockDesc p(s, 0, 0);
74 _pblockmap.push_back(p);
75
76 return _pblockmap[_pblockmap.size()-1].nmult;
77 }
78
79 // Return the index in the buffer corresponding to the block
80 int pBlockPointer::BlockInd(const std::string& s)
81 {
82 int temp=0;
83 for (unsigned int i=0; i< _pblockmap.size(); ++i) {
84 if( s== _pblockmap[i].name) {
85 break;
86 } else {
87 temp+=_pblockmap[i].nbyte;
88 }
89 }
90 return temp;
91 }
92
93 pBlockDesc* pBlockPointer::GetBlockDesc(const std::string& s)
94 {
95 for (unsigned int i=0; i< _pblockmap.size(); ++i) {
96 if( s== _pblockmap[i].name) {
97 return &_pblockmap[i];
98 }
99 }
100 return new pBlockDesc("NULL",0,0);
101
102 }
103
104 void pBlockPointer::Print(){
105
106 cout << " Blocks found : " << _pblockmap.size() << endl;
107 cout << "| B Name | B Size(Byte) | B Nvar | B Mult |"
108 << endl;
109 cout << "------------------------------------------------------------"
110 << endl;
111 for (pBlockMap::const_iterator p=_pblockmap.begin(); p!=_pblockmap.end(); ++p)
112 {
113 cout << p->name << " | " << p->nbyte << " | " << p->nvar << " | " <<
114 p->nmult << endl;
115 }
116 }
117
118 char * pBlockPointer::BuffReorder(){
119 char* temp=_pbuf;
120 char* tempr=_pbr;
121 char* junk;
122 // for (pBlockMap::const_iterator p=_pblockmap.begin();
123 // p!=_pblockmap.end(); ++p)
124 for (unsigned int i=0; i<_pblockmap.size(); ++i)
125 {
126 if(_pblockmap[i].nmult==1){
127 for(int j=0;j<_pblockmap[i].nbyte;++j) *tempr++=*temp++;
128 } else {
129 for(int j=0;j<VAR_SIZE;++j) *tempr++=*temp++;
130 // char **tt=new char*[p->nvar-1];
131 char *tt[_pblockmap[i].nvar-1];
132 cout << " Det: " << _pblockmap[i].name << ", " <<
133 _pblockmap[i].nvar << endl;
134 for(int j=0;j<(_pblockmap[i].nvar-1);++j){
135 tt[j]=temp+VAR_SIZE*j*_pblockmap[i].nmult;
136 cout << " tt: " << std::hex << (long int) tt[j] <<
137 ", val:" << (long int)(temp+VAR_SIZE*j*_pblockmap[i].nmult) << ", " <<
138 (long int)_pbuf <<
139 ", " << (long int ) temp <<
140 ", " << j << ", " << _pblockmap[i].nmult << std::dec << endl;
141 }
142 for(int j=0;j<(_pblockmap[i].nmult);++j) {
143 for(int k=0;k<(_pblockmap[i].nvar-1);++k){
144 junk=tt[k];
145 for(int b=0; b<VAR_SIZE; ++b) *tempr++=*junk++;
146 tt[k]=junk;
147 }
148 }
149 temp+=(_pblockmap[i].nbyte-VAR_SIZE);
150 }
151 }
152 return _pbr;
153 }
154

  ViewVC Help
Powered by ViewVC 1.1.23