00001 #include <stdio.h>
00002 #include <string.h>
00003 #include <stdlib.h>
00004 #include <assert.h>
00005 #include "StFileI.h"
00006
00007 ClassImp(StFileI)
00008
00009 StUKey::StUKey(const char *name,UInt_t *uk,int nk)
00010 {
00011 if (name) SetName(name);
00012 SetUrr(uk,nk);
00013 }
00014
00015 StUKey::StUKey(const char *name,UInt_t uk)
00016 {
00017 if (name) SetName(name);
00018 SetUrr(&uk,1);
00019 }
00020
00021 StUKey::StUKey(UInt_t uRun,UInt_t uEvent)
00022 {
00023 UInt_t u[2]; u[0]=uRun; u[1]=uEvent;
00024 int n = 1; if (u[1]) n=2;
00025 SetUrr(u,n);
00026 }
00027
00028 void StUKey::SetUrr(const UInt_t *uk,int nk)
00029 {
00030 int n;
00031 fNUrr = 1;
00032 fUrr[0] = 0;
00033 if (!uk) return;
00034 for (n=1;n<nk && uk[n]; n++){}
00035 fNUrr = n;
00036 memcpy(fUrr,uk,nk*sizeof(UInt_t));
00037 }
00038
00039 StUKey &StUKey::operator=( const StUKey &from)
00040 {
00041 SetName(from.GetName());
00042 SetUrr(from.fUrr,from.fNUrr);
00043 return *this;
00044 }
00045
00046 StUKey &StUKey::operator=( UInt_t from)
00047 {
00048 SetUrr(&from,1);
00049 return *this;
00050 }
00051
00052 StUKey &StUKey::operator=( const char *from)
00053 {
00054 SetName(from);
00055 return *this;
00056 }
00057
00058 void StUKey::Update( const StUKey &from, const char *name)
00059 {
00060 SetUrr(from.fUrr,from.fNUrr);
00061 if (name) SetName(name);
00062 }
00063
00064 TString StUKey::GetKey() const
00065 {
00066 char ubuf[12];
00067 TString tk(fName);
00068 for (int i=0;i<fNUrr;i++){
00069 tk +=".";
00070 sprintf(ubuf,"%010u",fUrr[i]);
00071 tk +=ubuf;}
00072 return tk;
00073 }
00074
00075 void StUKey::SetKey(const char *key)
00076 {
00077 const char *cc;
00078 int n = strchr(key,'.') - key;
00079 assert(n>0 && n<100);
00080 fName.Replace(0,999,key,n);
00081 for (fNUrr = 0,cc=key+n;*cc=='.'; cc+=11)
00082 fUrr[fNUrr++] = strtoul(cc+1,0,10);
00083 }
00084
00085 UInt_t StUKey::GetSum() const
00086 {
00087 UInt_t s = fUrr[0];
00088 for (int i=1;i<fNUrr;i++) s^=fUrr[i];
00089 return s;
00090 }
00091
00092 StUKey StFileI::GetNextEvent()
00093 {
00094 UInt_t u[9] = {0,0,0,0,0,0,0,0,0};
00095 int ret = GetNextEvent(u);
00096 if (ret) u[0]=kUMAX;
00097 StUKey uk(0,u,9);
00098 return uk;
00099 }
00100