00001 #include <assert.h>
00002 #include <stdlib.h>
00003 #include "StArray.h"
00004 #include "TDatime.h"
00005 #include "TBrowser.h"
00006 #include "StMkDeb.h"
00007
00008 enum {kBelongs = BIT(22)};
00009
00010 ClassImp(StObjLink)
00011
00012 void StObjLink::Browse(TBrowser* b) {b->Add(fLink);}
00013
00014 void StObjLink::Streamer(TBuffer &R__b)
00015 {
00016
00017 if (R__b.IsReading()) {
00018 fLink = 0;
00019 UInt_t ubj;
00020 R__b >> ubj ;
00021 if (!ubj) return;
00022 StProxyUrr *urr = new StProxyUrr(&fLink);
00023 urr->push_back(ubj);
00024 StXRefManager::fgManager->AddColl(urr);
00025
00026 } else {
00027
00028 if (!fLink || fLink->IsZombie()) R__b << UInt_t(0);
00029 else fLink->Ztreamer(R__b);
00030 }
00031 }
00032
00033
00034
00035 ClassImp(StObjArray)
00036
00037 Int_t StObjArray::getEntries() const
00038 {
00039 int sz = size();
00040 int en = 0;
00041 for (int i=0;i<sz;i++)
00042 {
00043 TObject *to = fV[i];
00044 if (!to) continue;
00045 if (to->IsZombie()) continue;
00046 en++;
00047 }
00048 return en;
00049 }
00050
00051 TObject** StObjArray::Erase(TObject** it,int del)
00052 {
00053 int i = it-&fV[0];
00054 if (del) {delete fV[i]; fV[i]=0;}
00055 return &(*(fV.erase(fV.begin()+i)));
00056 }
00057
00058 TObject** StObjArray::Erase(TObject** fst,TObject** lst,int del)
00059 {
00060 int ifst = fst-&fV[0];
00061 int ilst = lst-&fV[0];
00062 if (del) {for (int i=ifst;i<ilst;i++) {delete fV[i];fV[i]=0;}}
00063 return &(*(fV.erase(fV.begin()+ifst,fV.begin()+ilst)));
00064 }
00065
00066 TObject* StObjArray::find(const char *name) const
00067 {
00068 int n = fV.size();
00069 for (int i=0;i<n;i++) {
00070 if (!fV[i]) continue;
00071 if (!strcmp(name,fV[i]->GetName())) return (TObject*)fV[i];
00072 }
00073 return 0;
00074 }
00075
00076 void StObjArray::Streamer(TBuffer &b)
00077 {
00078
00079
00080
00081 Int_t nobjects;
00082 if (b.IsReading()) {
00083 Version_t v = b.ReadVersion(); if (v){}
00084 clear();
00085 b >> nobjects;
00086 if (!nobjects) return;
00087 resize(nobjects);
00088 TObject *obj;
00089 for (Int_t i = 0; i < nobjects; i++) {
00090 b >> obj; fV[i] =(obj);}
00091 } else {
00092 b.WriteVersion(Class());
00093 nobjects = getEntries();
00094 b << nobjects;
00095
00096 for (Int_t i = 0; nobjects; i++) {
00097 TObject *to = at(i);
00098 if (to && !to->IsZombie()) {b << to; nobjects--;}
00099 }
00100 }
00101 }
00102
00103
00104
00105
00106 void StObjArray::Browse(TBrowser *b)
00107 {
00108 enum { maxBrowsable = 5000};
00109
00110
00111
00112
00113
00114 if (!b) return;
00115 TObject *obj=0;
00116
00117 Int_t counter = 0;
00118 Int_t totalSize = size();
00119 for (int i=0; i<totalSize && ++counter < maxBrowsable ; i++) {
00120 obj = at(i); if (!obj || ((ULong_t)obj)&1) continue;
00121 TString browseName(obj->GetName());
00122 if (browseName.IsNull()) browseName = obj->ClassName();
00123 char buffer[100];
00124 sprintf(buffer,"_%d(%d)",counter,totalSize);
00125 browseName += buffer;
00126 b->Add(obj,browseName.Data());
00127 }
00128 }
00129
00130 Bool_t StObjArray::IsFolder() const
00131 { return size();}
00132
00133
00134 void StObjArray::random_shuffle(int start,int end)
00135 {
00136
00137 int lst = size();
00138 if (start >= lst) return;
00139 if (end > lst) end = lst;
00140 ::random_shuffle(begin()+start,begin()+end);
00141
00142 }
00143
00144 void StObjArray::ls(const char *tit) const
00145 {
00146 if (!tit) tit ="";
00147 int n = fV.size();
00148 Info("ls","%s(%s)[%d]",ClassName(),tit,n);
00149 for (int i=0;i<n;i++) {
00150 TObject *to = fV[i]; if (!to) continue;
00151 printf("%4d - %p %s(%s)\n",i, (void*)to,to->ClassName(),to->GetName());
00152 }
00153 }
00154
00155
00156 ClassImp(StRefArray)
00157 StRefArray::StRefArray(Int_t sz):StObjArray(sz){};
00158 StRefArray::StRefArray(const StRefArray &from):StObjArray(from){};
00159
00160
00161 void StRefArray::Streamer(TBuffer &R__b)
00162 {
00163
00164
00165
00166 Int_t nobjects;
00167 if (R__b.IsReading()) {
00168 Version_t v = R__b.ReadVersion(); if (v){}
00169 clear();
00170 R__b >> nobjects;
00171 if (!nobjects) return;
00172 if (v <=2 || nobjects>0) {
00173 TObject *obj;
00174 for (Int_t i = 0; i < nobjects; i++) {
00175 R__b >> obj; push_back(obj);}
00176 } else {
00177 UInt_t ubj;
00178 nobjects = -nobjects;
00179 StProxyUrr *urr = new StProxyUrr(this);
00180 for (Int_t i = 0; i < nobjects; i++) {
00181 R__b >> ubj ; urr->push_back(ubj);
00182 }
00183 StXRefManager::fgManager->AddColl(urr);
00184 }
00185
00186 } else {
00187 R__b.WriteVersion(Class());
00188 int nobjs = nobjects = getEntries();
00189 if (StObject::fgTally) nobjs=-nobjs;
00190 R__b << nobjs;
00191 if (!nobjects) return;
00192 TObject *to;
00193 for (Int_t i = 0; nobjects; i++) {
00194 to = at(i);
00195 if (!to) continue;
00196 if (to->IsZombie()) continue;
00197 nobjects--;
00198 if (nobjs<0) {((StObject*)to)->Ztreamer(R__b);}
00199 else { R__b << to; }
00200 }
00201 }
00202 }
00203
00204
00205 ClassImp(StStrArray)
00206
00207 StStrArray::StStrArray(Int_t sz):StObjArray(sz){}
00208
00209 void StStrArray::operator=(const StStrArray &a)
00210 {
00211 int n,i; TObject *sto;
00212
00213 clear();
00214 n = a.size();
00215 resize(n);
00216 for (i=0; i<n; i++)
00217 {
00218 sto = a[i];
00219 if (sto) sto = ((StObject*)sto)->clone();
00220 sto->ResetBit(kBelongs);
00221 put_at(sto,i);
00222 }
00223 }
00224
00225 StStrArray::StStrArray(const StStrArray &from){ *this = from;}
00226
00227 void StStrArray::clear()
00228 {
00229 assert(!fV.size() || !fV[0] || ((TObject*)fV[0])->TestBit(TObject::kNotDeleted));
00230 int n,i;
00231
00232 n = fV.size();
00233 for (i=0; i<n; i++){
00234 TObject *to = fV[i];
00235 if (!to) continue;
00236 if (to->TObject::TestBit(TObject::kNotDeleted)) {
00237 delete fV[i];
00238 } else {
00239 Warning("clear","Object[%d]=%p(%d) is already deleted",i,(void*)to,to);
00240 #if 0
00241 const char *mk=0;
00242 mk = StMkDeb::GetName(StMkDeb::GetCurrent());
00243 if (mk && *mk) printf("*** Now we are in %s ***\n",mk);
00244 mk = StMkDeb::GetUser(to);
00245 if (mk && *mk) printf("*** It was deleted in maker %s ***\n",mk);
00246 #endif
00247
00248 }
00249 fV[i]=0;
00250 }
00251 fV.clear();
00252 }
00253 StStrArray::~StStrArray()
00254 {
00255 clear();
00256 }
00257
00258 void StStrArray::put_at(TObject *obj,int i)
00259 {
00260 assert(i>=0 && i<int(size()));
00261 if (obj) {
00262 if (fV[i]==obj) return;
00263 assert(!obj->TestBit(kBelongs) && obj->TestBit(TObject::kNotDeleted));
00264 obj->SetBit(kBelongs);
00265 }
00266 fV[i]=obj;}
00267
00268 void StStrArray::push_back(const TObject * const to)
00269 {
00270 TObject* obj = (TObject*)to;
00271 if (obj) {
00272 assert(!obj->TestBit(kBelongs) && obj->TestBit(TObject::kNotDeleted));
00273 obj->SetBit(kBelongs);
00274 }
00275
00276 fV.push_back(obj);
00277 }
00278
00279
00280 void StStrArray::Streamer(TBuffer &R__b)
00281 {
00282
00283 if (R__b.IsReading()) {
00284 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
00285 StObjArray::Streamer(R__b);
00286 if (R__v >=3)
00287 StXRefManager::fgManager->AddColl(this);
00288 } else {
00289 R__b.WriteVersion(Class());
00290 StObjArray::Streamer(R__b);
00291 }
00292
00293 }
00294
00295 void StStrArray::makeZombie(int flg)
00296 {
00297 StObject::makeZombie(flg);
00298 int n = size();
00299 for (int i=0;i<n;i++)
00300 { StObject *o = (StObject*)at(i); if (o) o->makeZombie(flg);}
00301 }
00302
00303
00304
00305
00306