]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONV2DStore.cxx
Various fixes in order to compile the DA source code
[u/mrichter/AliRoot.git] / MUON / AliMUONV2DStore.cxx
CommitLineData
6cc447df 1/**************************************************************************
2* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3* *
4* Author: The ALICE Off-line Project. *
5* Contributors are mentioned in the code where appropriate. *
6* *
7* Permission to use, copy, modify and distribute this software and its *
8* documentation strictly for non-commercial purposes is hereby granted *
9* without fee, provided that the above copyright notice appears in all *
10* copies and that both the copyright notice and this permission notice *
11* appear in the supporting documentation. The authors make no claims *
12* about the suitability of this software for any purpose. It is *
13* provided "as is" without express or implied warranty. *
14**************************************************************************/
15
16// $Id$
17
18#include "AliMUONV2DStore.h"
19
5398f946 20/// \class AliMUONV2DStore
9d5f6a64 21/// Defines an interface equivalent to a 2D array of TObject, indexed
22/// by a pair of integers (somehow a matrix,
23/// except that indices are not necessarily sequential).
24///
25/// It's extremely simple and hopefully allow many implementations.
26/// It also makes the object ownership self-evident.
27///
5398f946 28/// \author Laurent Aphecetche
9d5f6a64 29
5398f946 30/// \cond CLASSIMP
6cc447df 31ClassImp(AliMUONV2DStore)
5398f946 32/// \endcond
6cc447df 33
f056a0c0 34#include "AliLog.h"
1b9f295e 35#include "AliMUONObjectPair.h"
36#include "AliMUONVDataIterator.h"
f056a0c0 37#include "AliMpIntPair.h"
38#include <TMap.h>
39#include <TString.h>
40#include <TObjString.h>
41#include <TObjArray.h>
42#include <Riostream.h>
43
44namespace
45{
46 //_____________________________________________________________________________
47 void Decode(TMap& m, const TString& s, const char* sep)
48{
49 /// Fills the map m with (key,value) extracted from s
50 /// where s is of the form :
51 /// key1=value1;key2=value2;key3=value3
52
53 TString ss(s);
54 ss.ToUpper();
55
56 m.SetOwner(true);
57
58 TObjArray* a = ss.Tokenize(sep);
59 TIter next(a);
60 TObjString* o;
61
62 while ( ( o = static_cast<TObjString*>(next()) ) )
63 {
64 TString& os(o->String());
65 TObjArray* b = os.Tokenize("=");
66 if (b->GetEntries()==2)
67 {
68 m.Add(b->At(0),b->At(1));
69 }
70 }
71}
72
73//_____________________________________________________________________________
74Bool_t FindValue(const TMap& m, const TString& key, TString& value)
75{
76 /// Find value corresponding to key in map m.
77 /// Return false if key not found.
78
79 TString skey(key);
80 skey.ToUpper();
81 value = "";
82 TPair* p = static_cast<TPair*>(m.FindObject(skey));
83 if (p)
84 {
85 value = (static_cast<TObjString*>(p->Value()))->String();
86 return kTRUE;
87 }
88 return kFALSE;
89}
90
91}
1b9f295e 92
9d5f6a64 93//_____________________________________________________________________________
94AliMUONV2DStore::AliMUONV2DStore()
95{
5398f946 96/// Default constructor
9d5f6a64 97}
98
6cc447df 99//_____________________________________________________________________________
100AliMUONV2DStore::~AliMUONV2DStore()
101{
5398f946 102/// Destructor
6cc447df 103}
104
f056a0c0 105
1b9f295e 106//_____________________________________________________________________________
107void
108AliMUONV2DStore::Print(Option_t* opt) const
109{
110 /// Printout
111 /// opt is used to filter which (i,j) couple you want to see
112 /// e.g opt="I=12;J=1;opt=Full" to see complete values, but only for the
113 /// (12,1) pair.
114 /// Warning : decoding of opt format is not really bullet-proof (yet?)
f056a0c0 115
1b9f295e 116 AliMUONVDataIterator* it = this->Iterator();
117
118 AliMUONObjectPair* pair;
119
f056a0c0 120 TMap m;
121 Decode(m,opt,";");
1b9f295e 122
123 TString si;
f056a0c0 124 Bool_t selectI = FindValue(m,"i",si);
1b9f295e 125 TString sj;
f056a0c0 126 Bool_t selectJ = FindValue(m,"j",sj);
1b9f295e 127 TString sopt;
f056a0c0 128 FindValue(m,"opt",sopt);
1b9f295e 129
130 while ( ( pair = static_cast<AliMUONObjectPair*>(it->Next() ) ) )
131 {
132 AliMpIntPair* ip = static_cast<AliMpIntPair*>(pair->First());
133 Int_t i = ip->GetFirst();
134 Int_t j = ip->GetSecond();
135 if ( selectI && i != si.Atoi() ) continue;
136 if ( selectJ && j != sj.Atoi() ) continue;
137 cout << Form("[%d,%d]",i,j) << endl;
138 TObject* o = pair->Second();
139 if (o)
140 {
141 o->Print(sopt.Data());
142 }
f056a0c0 143 if ( it->IsOwner() ) delete pair;
1b9f295e 144 }
1b9f295e 145 delete it;
f056a0c0 146}
6cc447df 147
148