New class. Container of trigger crates from CRATE.TXT
authorivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 11 May 2006 14:58:08 +0000 (14:58 +0000)
committerivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 11 May 2006 14:58:08 +0000 (14:58 +0000)
(Laurent)

MUON/AliMUONTriggerCrateStore.cxx [new file with mode: 0644]
MUON/AliMUONTriggerCrateStore.h [new file with mode: 0644]

diff --git a/MUON/AliMUONTriggerCrateStore.cxx b/MUON/AliMUONTriggerCrateStore.cxx
new file mode 100644 (file)
index 0000000..156bae6
--- /dev/null
@@ -0,0 +1,329 @@
+/**************************************************************************
+* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+*                                                                        *
+* Author: The ALICE Off-line Project.                                    *
+* Contributors are mentioned in the code where appropriate.              *
+*                                                                        *
+* Permission to use, copy, modify and distribute this software and its   *
+* documentation strictly for non-commercial purposes is hereby granted   *
+* without fee, provided that the above copyright notice appears in all   *
+* copies and that both the copyright notice and this permission notice   *
+* appear in the supporting documentation. The authors make no claims     *
+* about the suitability of this software for any purpose. It is          *
+* provided "as is" without express or implied warranty.                  *
+**************************************************************************/
+
+// $Id$
+
+#include "AliMUONTriggerCrateStore.h"
+
+#include "AliMUONTriggerCrate.h"
+#include "AliMUONLocalTriggerBoard.h"
+#include "AliMUONRegionalTriggerBoard.h"
+#include "AliMpExMap.h"
+#include "TString.h"
+#include "TSystem.h"
+#include "AliLog.h"
+#include "Riostream.h"
+
+/// 
+/// \class AliMUONTriggerCrateStore
+/// 
+/// A container of trigger crate objects that offers iteration
+/// over both the crates themselves and the local boards they contain
+///
+/// \author Laurent Aphecetche
+
+ClassImp(AliMUONTriggerCrateStore)
+
+//_____________________________________________________________________________
+AliMUONTriggerCrateStore::AliMUONTriggerCrateStore()
+: TObject(),
+fCrates(0x0),
+fLocalBoards(0x0),
+fCrateIterator(0x0),
+fLBIterator(0x0),
+fCurrentCrate(0x0),
+fCurrentLocalBoard(-1)
+{
+  // ctor
+}
+
+//_____________________________________________________________________________
+AliMUONTriggerCrateStore::~AliMUONTriggerCrateStore()
+{
+    // dtor
+  delete fCrateIterator;
+  delete fLBIterator;
+  delete fCrates;
+  delete fLocalBoards;
+}
+
+//_____________________________________________________________________________
+void 
+AliMUONTriggerCrateStore::AddCrate(const char *name)
+{
+  /// create and add a crate to our map
+  if (!fCrates)
+  {
+    AliError("Object not properly initialized");
+    return;
+  }
+
+  AliDebug(1,Form("Adding crate %s",name));
+  TObject* there = fCrates->GetValue(name);
+  if (there)
+  {
+    AliError(Form("Cannot add crate %s because it's already there !",name));
+  }
+  else
+  {
+    fCrates->Add(name,new AliMUONTriggerCrate(name,17));
+  }
+}
+
+//_____________________________________________________________________________
+AliMUONLocalTriggerBoard* 
+AliMUONTriggerCrateStore::LocalBoard(Int_t boardNumber) const
+{
+  /// return a board by number
+  
+  if ( !fLocalBoards )
+  {
+    AliError("Object not properly initialized");
+    return 0x0;
+  }
+
+  return static_cast<AliMUONLocalTriggerBoard*>(fLocalBoards->GetValue(boardNumber));
+}
+
+//_____________________________________________________________________________
+AliMUONTriggerCrate* 
+AliMUONTriggerCrateStore::Crate(const char *name) const
+{
+  /// return a crate by name
+  if ( !fCrates )
+  {
+    AliError("Object not properly initialized");
+    return 0x0;
+  }
+  return static_cast<AliMUONTriggerCrate*>(fCrates->GetValue(name));
+}
+
+//_____________________________________________________________________________
+void
+AliMUONTriggerCrateStore::FirstCrate()
+{
+  /// initialize iteration
+  if ( !fCrates )
+  {
+    AliError("Object not properly initialized");
+    return;
+  }
+  if (!fCrateIterator)
+  {
+    fCrateIterator = new TExMapIter(fCrates->GetIterator());
+  }
+  fCrateIterator->Reset();
+}
+
+//_____________________________________________________________________________
+void
+AliMUONTriggerCrateStore::FirstLocalBoard()
+{
+  /// Initialize iterator on local boards.
+  /// Please note that we're not using directly the FirstCrate() and
+  /// NextCrate() methods here to avoid mix and match between crate iterator
+  /// and local board iterator
+  fCurrentCrate = 0x0;
+  fCurrentLocalBoard = 0;
+
+  if ( !fLBIterator ) 
+  {
+    fLBIterator = new TExMapIter(fCrates->GetIterator());
+  }
+  fLBIterator->Reset();
+  Long_t key, value;
+  Bool_t ok = fLBIterator->Next(key,value);
+  if ( ok )
+  {
+    fCurrentCrate = reinterpret_cast<AliMUONTriggerCrate*>(value);
+    fCurrentLocalBoard = 1;
+  }
+}
+
+//_____________________________________________________________________________
+AliMUONTriggerCrate*
+AliMUONTriggerCrateStore::NextCrate()
+{
+  /// Return the next crate in iteration, or 0 if iteration is ended.
+  if (!fCrateIterator) return 0x0;
+  
+  Long_t key, value;
+  Bool_t ok = fCrateIterator->Next(key,value);
+  if (ok)
+  {
+    return reinterpret_cast<AliMUONTriggerCrate*>(value);
+  }
+  else
+  {
+    return 0x0;
+  }
+}
+
+//_____________________________________________________________________________
+AliMUONLocalTriggerBoard*
+AliMUONTriggerCrateStore::NextLocalBoard()
+{  
+  /// Return the next local board in iteration, or 0 if iteration is ended.
+  if ( !fLBIterator ) return 0x0;
+
+  if ( fCurrentLocalBoard >= fCurrentCrate->Boards()->GetLast() +1)
+//  if ( fCurrentLocalBoard >= fCurrentCrate->Boards()->GetLast() )
+  {
+    // try to go to next crate, if some are left
+    Long_t key, value;
+    Bool_t ok = fLBIterator->Next(key,value);
+    if ( ok )
+    {
+      fCurrentCrate = reinterpret_cast<AliMUONTriggerCrate*>(value);
+      fCurrentLocalBoard = 1;
+    }
+    else
+    {
+      fCurrentLocalBoard = 0;
+      return 0x0;
+    }
+  }
+
+  AliMUONLocalTriggerBoard* lb = static_cast<AliMUONLocalTriggerBoard*>
+    (fCurrentCrate->Boards()->At(fCurrentLocalBoard));
+  
+  ++fCurrentLocalBoard;
+  
+  return lb;
+}
+
+//_____________________________________________________________________________
+Int_t
+AliMUONTriggerCrateStore::NumberOfCrates() const
+{
+  /// Number of crates we're holding
+  if ( fCrates ) return fCrates->GetSize();
+  return 0;
+}
+
+//_____________________________________________________________________________
+Int_t
+AliMUONTriggerCrateStore::NumberOfLocalBoards() const
+{
+  /// Number of local boards we're holding
+  if ( fLocalBoards ) return fLocalBoards->GetSize();
+  return 0;
+}
+
+//_____________________________________________________________________________
+void
+AliMUONTriggerCrateStore::ReadFromFile(const char* file)
+{
+  /// Read crate and local board information from file.
+  fCrates = new AliMpExMap(kTRUE);
+  fLocalBoards = new AliMpExMap(kFALSE);
+  
+  ifstream myInputFile(gSystem->ExpandPathName(file), ios::in);
+  
+  string sLine, sValue;
+  
+  if ( !myInputFile ) 
+  {
+    AliError("TRIGGER ELECTRONICS CONFIGURATION FILE COULD NOT BE OPENED");
+  }
+  else
+  {
+    while (getline(myInputFile,sLine))
+    {
+      if (sLine.empty()) continue; // Ignore empty lines
+      else
+      {
+        const Int_t kMaxfields = 15; char **fields = new char*[kMaxfields];
+        
+        char s[100]; 
+        
+        if (sLine.find("Board",0) != string::npos) 
+        {   
+          strcpy(s,sLine.c_str());
+          
+          Int_t numlines = 0;
+          
+          for (char *token = strtok(s, " ");
+               token != NULL;
+               token = strtok(NULL, " "))
+          {
+            fields[numlines] = new char[strlen(token)+1];
+            strcpy(fields[numlines++],token);
+          }
+          
+          char str[10]; strcpy(str, fields[6]); strcat(str, fields[7]);
+          
+          AliMUONTriggerCrate *crate = Crate(str); 
+          
+          if (!crate) 
+          {
+            AddCrate(str); crate = Crate(str);
+            
+            AliMUONRegionalTriggerBoard *rboard = new AliMUONRegionalTriggerBoard();
+            crate->AddBoard(rboard, 0);
+          }               
+          
+          //             CONVENTION: SLOT 0 HOLDS THE REGIONAL BOARD
+          Int_t sl = atoi(fields[10]);
+          
+//          AliMUONTriggerLut* lut = calibData->TriggerLut();
+          
+          AliMUONLocalTriggerBoard *board = 
+            new AliMUONLocalTriggerBoard(fields[4], sl, 0x0);
+          
+                                       if (strcmp(fields[1],"nn")) 
+                                       {
+                                               Int_t sboard = atoi(fields[1]);
+            
+                                               board->SetNumber(sboard);
+            fLocalBoards->Add(sboard,board);
+            
+//                                             fCrateMap[sboard-1] = new char[strlen(str)+1]; strcpy(fCrateMap[sboard-1], str);
+//                                             fBoardMap[sboard-1] = sl;
+                                       }
+          
+                                       board->SetCrate(str);
+          
+          crate->AddBoard(board, sl);
+          
+          while (getline(myInputFile,sLine)) if (sLine.find("transv",0) != string::npos) break;
+          
+          strcpy(s,sLine.c_str());
+          
+          for (char *token = strtok(s, " ");
+               token != NULL;
+               token = strtok(NULL, " ")) if (!strcmp(token,"NONE")) board->SetTC(kFALSE);
+          
+          while (getline(myInputFile,sLine)) if (sLine.find("Switch",0) != string::npos) break;
+          
+          while (getline(myInputFile,sLine)) if (!sLine.empty()) break;   
+          
+          strcpy(s,sLine.c_str());
+          
+          Int_t lines = 0;
+          
+          for (char *token = strtok(s, " ");
+               token != NULL;
+               token = strtok(NULL, " ")) board->SetSwitch(lines++, atoi(token));
+          
+          for (Int_t i = 0; i<numlines; i++) 
+            if (fields[i]) {delete [] fields[i]; fields[i] = 0;}
+              
+              delete [] fields; fields = 0;
+        }
+      }
+    }
+  }
+}
diff --git a/MUON/AliMUONTriggerCrateStore.h b/MUON/AliMUONTriggerCrateStore.h
new file mode 100644 (file)
index 0000000..eb128fd
--- /dev/null
@@ -0,0 +1,56 @@
+#ifndef ALIMUONTRIGGERCRATESTORE_H
+#define ALIMUONTRIGGERCRATESTORE_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+* See cxx source for full Copyright notice                               */
+
+// $Id$
+
+/// \ingroup sim
+/// \class AliMUONTriggerCrateStore
+/// \brief A container for AliMUONTriggerCrate objects.
+/// 
+/// \author Laurent Aphecetche
+
+#ifndef ROOT_TObject
+#  include "TObject.h"
+#endif
+
+class AliMUONLocalTriggerBoard;
+class AliMUONTriggerCrate;
+class AliMpExMap;
+class TExMapIter;
+
+class AliMUONTriggerCrateStore : public TObject
+{
+public:
+  AliMUONTriggerCrateStore();
+  virtual ~AliMUONTriggerCrateStore();
+  
+  Int_t NumberOfCrates() const;
+  void FirstCrate();
+  AliMUONTriggerCrate* NextCrate();
+  AliMUONTriggerCrate* Crate(const char* crateName) const;
+  
+  Int_t NumberOfLocalBoards() const;
+  void FirstLocalBoard();
+  AliMUONLocalTriggerBoard* NextLocalBoard();
+  AliMUONLocalTriggerBoard* LocalBoard(Int_t boardNumber) const;
+  
+  void ReadFromFile(const char* crateFile = "$ALICE_ROOT/MUON/data/CRATE.TXT");
+
+private:
+  void AddCrate(const char* crateName); 
+  
+private:
+  AliMpExMap* fCrates; // list of crates
+  AliMpExMap* fLocalBoards; // local boards (indexed by their number)
+  TExMapIter* fCrateIterator; //! iterator for the crate map above
+  TExMapIter* fLBIterator; //! iterator for boards (through crates)
+  AliMUONTriggerCrate* fCurrentCrate; //! used for iterating on local board
+  Int_t fCurrentLocalBoard; //! used for iterating on local board
+
+  ClassDef(AliMUONTriggerCrateStore,1) // Reader for CRATE.TXT file
+};
+
+#endif