Logo ROOT   6.08/07
Reference Guide
TDsKey.cxx
Go to the documentation of this file.
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 
20 ////////////////////////////////////////////////////////////////////////////////
21 ///to be documented
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 }
28 ////////////////////////////////////////////////////////////////////////////////
29 ///to be documented
30 
31 TDsKey::TDsKey(const char *name,UInt_t uk) : fUrr(1)
32 {
33  if (name) SetName(name);
34  SetUrr(&uk,1);
35 }
36 ////////////////////////////////////////////////////////////////////////////////
37 ///to be documented
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 
46 ////////////////////////////////////////////////////////////////////////////////
47 ///to be documented
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 }
57 ////////////////////////////////////////////////////////////////////////////////
58 ///to be documented
59 
61 {
62  SetName(from.GetName());
63  fUrr = from.fUrr;
64  return *this;
65 }
66 ////////////////////////////////////////////////////////////////////////////////
67 ///to be documented
68 
70 {
71  SetUrr(&from,1);
72  return *this;
73 }
74 ////////////////////////////////////////////////////////////////////////////////
75 ///to be documented
76 
77 TDsKey &TDsKey::operator=( const char *from)
78 {
79  SetName(from);
80  return *this;
81 }
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Compare two keys
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 }
100 ////////////////////////////////////////////////////////////////////////////////
101 ///to be documented
102 
103 void TDsKey::Update( const TDsKey &from, const char *name)
104 {
105  fUrr = from.fUrr;
106  if (name) SetName(name);
107 }
108 ////////////////////////////////////////////////////////////////////////////////
109 ///to be documented
110 
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 }
123 ////////////////////////////////////////////////////////////////////////////////
124 ///to be documented
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 }
136 ////////////////////////////////////////////////////////////////////////////////
137 ///to be documented
138 
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
virtual Bool_t operator==(const TDsKey &from) const
Compare two keys.
Definition: TDsKey.cxx:85
virtual const char * GetName() const
Definition: TDsKey.h:40
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition: TString.h:625
TDsKey(const char *name=0, UInt_t *uk=0, int nk=1)
to be documented
Definition: TDsKey.cxx:23
void Set(Int_t n)
Set size of this array to n ints.
Definition: TArrayI.cxx:105
void AddAt(Int_t c, Int_t i)
Add Int_t c at position i. Check for out of bounds.
Definition: TArrayI.cxx:93
virtual void SetName(const char *name)
Definition: TDsKey.h:39
TArrayI fUrr
Definition: TDsKey.h:25
Int_t GetSize() const
Definition: TArray.h:49
unsigned int UInt_t
Definition: RtypesCore.h:42
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
TString fName
Definition: TDsKey.h:24
virtual TString GetKey() const
to be documented
Definition: TDsKey.cxx:111
#define snprintf
Definition: civetweb.c:822
Definition: TDsKey.h:21
const Bool_t kTRUE
Definition: Rtypes.h:91
const Int_t n
Definition: legend1.C:16
char name[80]
Definition: TGX11.cxx:109
virtual void SetKey(const char *key)
to be documented
Definition: TDsKey.cxx:126