StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TDsKey.cxx
1 // @(#)root/table:$Id$
2 // Author: Victor Perevoztchikov (fine@bnl.gov) 01/03/2001
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2001, Rene Brun and Fons Rademakers. *
6  * Copyright (C) 2001 [BNL] Brookhaven National Laboratory. *
7  * All rights reserved. *
8  * *
9  * For the licensing terms see $ROOTSYS/LICENSE. *
10  * For the list of contributors see $ROOTSYS/README/CREDITS. *
11  *************************************************************************/
12 
13 #include <stdio.h>
14 #include <string.h>
15 #include <stdlib.h>
16 #include <assert.h>
17 #include "TDsKey.h"
18 
19 
22 
23 TDsKey::TDsKey(const char *name,UInt_t *uk,int nk) : fUrr(nk)
24 {
25  if (name) SetName(name);
26  SetUrr(uk,nk);
27 }
30 
31 TDsKey::TDsKey(const char *name,UInt_t uk) : fUrr(1)
32 {
33  if (name) SetName(name);
34  SetUrr(&uk,1);
35 }
38 
39 TDsKey::TDsKey(UInt_t uRun,UInt_t uEvent) :fUrr(2)
40 {
41  UInt_t u[2]; u[0]=uRun; u[1]=uEvent;
42  int n = 1; if (u[1]) n=2;
43  SetUrr(u,n);
44 }
45 
48 
49 void TDsKey::SetUrr(const UInt_t *uk,int nk)
50 {
51  int n;
52  fUrr[0] = 0;
53  if (!uk) return;
54  for (n=1;n<nk && uk[n]; n++){}
55  fUrr.Set(n,(Int_t *)uk);
56 }
59 
61 {
62  SetName(from.GetName());
63  fUrr = from.fUrr;
64  return *this;
65 }
68 
69 TDsKey &TDsKey::operator=( UInt_t from)
70 {
71  SetUrr(&from,1);
72  return *this;
73 }
76 
77 TDsKey &TDsKey::operator=( const char *from)
78 {
79  SetName(from);
80  return *this;
81 }
84 
85 Bool_t TDsKey::operator==(const TDsKey &from) const
86 {
87  Bool_t res = ( fName == from.fName )
88  && ( fUrr.GetSize() == from.fUrr.GetSize() ) ;
89 
90  Bool_t numMatch = kTRUE;
91  int i = 0;
92  for (; i < fUrr.GetSize(); i++) {
93  if ( fUrr[i] != from.fUrr[i] ) {
94  numMatch =kFALSE;
95  break;
96  }
97  }
98  return ( res && numMatch ) ;
99 }
102 
103 void TDsKey::Update( const TDsKey &from, const char *name)
104 {
105  fUrr = from.fUrr;
106  if (name) SetName(name);
107 }
110 
111 TString TDsKey::GetKey() const
112 {
113  char ubuf[12];
114  TString tk(fName);
115  Int_t lUrr = fUrr.GetSize();
116  for (int i=0;i<lUrr;i++){
117  tk +=".";
118  snprintf(ubuf,12,"%010u",fUrr[i]);
119  tk +=ubuf;
120  }
121  return tk;
122 }
125 
126 void TDsKey::SetKey(const char *key)
127 {
128  const char *cc;
129  int n = strchr(key,'.') - key;
130  assert(n>0 && n<100);
131  fName.Replace(0,999,key,n);
132  Int_t i = 0;
133  for (cc=key+n;*cc=='.'; cc+=11,i++)
134  fUrr.AddAt(strtoul(cc+1,0,10),i);
135 }
138 
139 UInt_t TDsKey::GetSum() const
140 {
141  UInt_t s = fUrr[0];
142  for (int i=1;i<fUrr.GetSize();i++) s^=fUrr[i];
143  return s;
144 }
145 
146 
virtual void Update(const TDsKey &from, const char *name=0)
to be documented
Definition: TDsKey.cxx:103
TDsKey(const char *name=0, UInt_t *uk=0, int nk=1)
to be documented
Definition: TDsKey.cxx:23
virtual TString GetKey() const
to be documented
Definition: TDsKey.cxx:111
virtual void SetUrr(const UInt_t *key, int nk)
to be documented
Definition: TDsKey.cxx:49
virtual TDsKey & operator=(const TDsKey &from)
to be documented
Definition: TDsKey.cxx:60
virtual UInt_t GetSum() const
to be documented
Definition: TDsKey.cxx:139
virtual Bool_t operator==(const TDsKey &from) const
Compare two keys.
Definition: TDsKey.cxx:85
Definition: TDsKey.h:21
virtual void SetKey(const char *key)
to be documented
Definition: TDsKey.cxx:126