]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Implementing a clever Print method which allow to select which part of the store...
authorivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 6 Feb 2007 17:18:48 +0000 (17:18 +0000)
committerivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 6 Feb 2007 17:18:48 +0000 (17:18 +0000)
MUON/AliMUONV2DStore.cxx
MUON/AliMUONV2DStore.h

index 4ba004a5ac9895b891c1a7b0c041bbbd5eeef95b..7d9a2cdefa9c9511168dc3c394366a28c19d7ca6 100644 (file)
 ClassImp(AliMUONV2DStore)
 /// \endcond
 
+#include "AliMpIntPair.h"
+#include "AliMUONObjectPair.h"
+#include "AliMUONVDataIterator.h"
+#include "Riostream.h"
+#include "TMap.h"
+#include "TObjArray.h"
+#include "TObjString.h"
+#include "TString.h"
+
 //_____________________________________________________________________________
 AliMUONV2DStore::AliMUONV2DStore()
 {
@@ -43,6 +52,86 @@ AliMUONV2DStore::~AliMUONV2DStore()
 /// Destructor
 }
 
+TMap* Decode(const TString& s)
+{
+  TString ss(s);
+  ss.ToUpper();
+  
+  TMap* m = new TMap;
+  m->SetOwner(true);
+  
+  TObjArray* a = ss.Tokenize(";");
+  TIter next(a);
+  TObjString* o;
+  
+  while ( ( o = static_cast<TObjString*>(next()) ) )
+  {
+    TString& os(o->String());
+    TObjArray* b = os.Tokenize("=");
+    if (b->GetEntries()==2)
+    {
+      m->Add(b->At(0),b->At(1));
+    }
+  }
+  return m;
+}
 
+Bool_t Decode(const TMap& m, const TString& key, TString& value)
+{
+  TString skey(key);
+  skey.ToUpper();
+  value = "";
+  TPair* p = static_cast<TPair*>(m.FindObject(skey));
+  if (p) 
+  {
+    value = (static_cast<TObjString*>(p->Value()))->String();
+    return kTRUE;
+  }
+  return kFALSE;
+}
+
+//_____________________________________________________________________________
+void
+AliMUONV2DStore::Print(Option_t* opt) const
+{
+  /// Printout
+  /// opt is used to filter which (i,j) couple you want to see
+  /// e.g opt="I=12;J=1;opt=Full" to see complete values, but only for the 
+  /// (12,1) pair.
+  /// Warning : decoding of opt format is not really bullet-proof (yet?)
+  
+  AliMUONVDataIterator* it = this->Iterator();
+  
+  AliMUONObjectPair* pair;
+  
+  TMap* m = Decode(opt);
+  
+  TString si;  
+  Bool_t selectI = Decode(*m,"i",si);
+  TString sj;
+  Bool_t selectJ = Decode(*m,"j",sj);
+  TString sopt;
+  Decode(*m,"opt",sopt);
+  
+  m->DeleteAll();
+  delete m;
+  
+  while ( ( pair = static_cast<AliMUONObjectPair*>(it->Next() ) ) )
+  {
+    AliMpIntPair* ip = static_cast<AliMpIntPair*>(pair->First());
+    Int_t i = ip->GetFirst();
+    Int_t j = ip->GetSecond();
+    if ( selectI && i != si.Atoi() ) continue;
+    if ( selectJ && j != sj.Atoi() ) continue;
+    cout << Form("[%d,%d]",i,j) << endl;
+    TObject* o = pair->Second();
+    if (o) 
+    {
+      o->Print(sopt.Data());
+    }
+  }
+  
+  delete it;
+}
 
 
index 1fb3b575dbdae92834dbfcefa3d21706e8ed9d66..4cce53c43559795019e049727fc323e51f68054e 100644 (file)
@@ -40,6 +40,8 @@ public:
   /// Whether or not this container is the owner of its contents.
   virtual Bool_t IsOwner() const = 0;
   
+  virtual void Print(Option_t* opt="") const;
+  
 private:  
   ClassDef(AliMUONV2DStore,0) // Generic container indexed by a pair of integers
 };