00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "TLeafO.h"
00019 #include "TBranch.h"
00020 #include "TClonesArray.h"
00021 #include "Riostream.h"
00022
00023 ClassImp(TLeafO)
00024
00025
00026 TLeafO::TLeafO(): TLeaf()
00027 {
00028
00029
00030
00031 fValue = 0;
00032 fPointer = 0;
00033 fMinimum = 0;
00034 fMaximum = 0;
00035 fLenType = sizeof(bool);
00036 }
00037
00038
00039 TLeafO::TLeafO(TBranch *parent, const char *name, const char *type)
00040 : TLeaf(parent,name,type)
00041 {
00042
00043
00044
00045
00046 fLenType = sizeof(bool);
00047 fMinimum = 0;
00048 fMaximum = 0;
00049 fValue = 0;
00050 fPointer = 0;
00051 }
00052
00053
00054 TLeafO::~TLeafO()
00055 {
00056
00057
00058
00059 if (ResetAddress(0,kTRUE)) delete [] fValue;
00060 }
00061
00062
00063
00064 void TLeafO::Export(TClonesArray *list, Int_t n)
00065 {
00066
00067
00068
00069 Int_t j = 0;
00070 for (Int_t i=0;i<n;i++) {
00071 memcpy((char*)list->UncheckedAt(i) + fOffset,&fValue[j], fLen);
00072 j += fLen;
00073 }
00074 }
00075
00076
00077
00078 void TLeafO::FillBasket(TBuffer &b)
00079 {
00080
00081
00082
00083 Int_t len = GetLen();
00084 if (fPointer) fValue = *fPointer;
00085 b.WriteFastArray(fValue,len);
00086 }
00087
00088
00089 const char *TLeafO::GetTypeName() const
00090 {
00091
00092
00093
00094 return "Bool_t";
00095 }
00096
00097
00098
00099 void TLeafO::Import(TClonesArray *list, Int_t n)
00100 {
00101
00102
00103
00104 Int_t j = 0;
00105 for (Int_t i=0;i<n;i++) {
00106 memcpy(&fValue[j],(char*)list->UncheckedAt(i) + fOffset, fLen);
00107 j += fLen;
00108 }
00109 }
00110
00111
00112 void TLeafO::PrintValue(Int_t l) const
00113 {
00114
00115
00116 char *value = (char*)GetValuePointer();
00117 printf("%d",(Int_t)value[l]);
00118 }
00119
00120
00121
00122 void TLeafO::ReadBasket(TBuffer &b)
00123 {
00124
00125
00126
00127 if (!fLeafCount && fNdata == 1) {
00128 b >> fValue[0];
00129 }else {
00130 if (fLeafCount) {
00131 Long64_t entry = fBranch->GetReadEntry();
00132 if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
00133 fLeafCount->GetBranch()->GetEntry(entry);
00134 }
00135 Int_t len = Int_t(fLeafCount->GetValue());
00136 if (len > fLeafCount->GetMaximum()) {
00137 printf("ERROR leaf:%s, len=%d and max=%d\n",GetName(),len,fLeafCount->GetMaximum());
00138 len = fLeafCount->GetMaximum();
00139 }
00140 fNdata = len*fLen;
00141 b.ReadFastArray(fValue,len*fLen);
00142 } else {
00143 b.ReadFastArray(fValue,fLen);
00144 }
00145 }
00146 }
00147
00148
00149 void TLeafO::ReadBasketExport(TBuffer &b, TClonesArray *list, Int_t n)
00150 {
00151
00152
00153
00154 b.ReadFastArray(fValue,n*fLen);
00155
00156 Int_t j = 0;
00157 for (Int_t i=0;i<n;i++) {
00158 memcpy((char*)list->UncheckedAt(i) + fOffset,&fValue[j], fLen);
00159 j += fLen;
00160 }
00161 }
00162
00163
00164 void TLeafO::ReadValue(istream &s)
00165 {
00166
00167 char *value = (char*)GetValuePointer();
00168 s >> value;
00169 }
00170
00171
00172 void TLeafO::SetAddress(void *add)
00173 {
00174
00175
00176
00177 if (ResetAddress(add)) {
00178 delete [] fValue;
00179 }
00180 if (add) {
00181 if (TestBit(kIndirectAddress)) {
00182 fPointer = (Bool_t**) add;
00183 Int_t ncountmax = fLen;
00184 if (fLeafCount) ncountmax = fLen*(fLeafCount->GetMaximum() + 1);
00185 if ((fLeafCount && ncountmax > Int_t(fLeafCount->GetValue())) ||
00186 ncountmax > fNdata || *fPointer == 0) {
00187 if (*fPointer) delete [] *fPointer;
00188 if (ncountmax > fNdata) fNdata = ncountmax;
00189 *fPointer = new Bool_t[fNdata];
00190 }
00191 fValue = *fPointer;
00192 } else {
00193 fValue = (bool*)add;
00194 }
00195 } else {
00196 fValue = new bool[fNdata];
00197 fValue[0] = 0;
00198 }
00199 }