From: ivana Date: Wed, 11 Jan 2006 09:00:08 +0000 (+0000) Subject: New class - iterator over valid detection element IDs. X-Git-Url: http://git.uio.no/git/?p=u%2Fmrichter%2FAliRoot.git;a=commitdiff_plain;h=732501823d4452985fbcf04e8d76604f6b374320 New class - iterator over valid detection element IDs. --- diff --git a/MUON/mapping/AliMpDEIterator.cxx b/MUON/mapping/AliMpDEIterator.cxx new file mode 100644 index 00000000000..5eeabd8982a --- /dev/null +++ b/MUON/mapping/AliMpDEIterator.cxx @@ -0,0 +1,221 @@ +/************************************************************************** + * 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 "AliMpDEIterator.h" +#include "AliMpDEManager.h" +#include "AliMpFiles.h" + +#include "AliLog.h" + +#include +#include + +ClassImp(AliMpDEIterator) + +const Int_t AliMpDEIterator::fgkMaxNofDetElements = 250; +TArrayI AliMpDEIterator::fgDetElemIds(fgkMaxNofDetElements); +Int_t AliMpDEIterator::fgNofDetElemIds = 0; + +// +// static private methods +// + +//______________________________________________________________________________ +Bool_t AliMpDEIterator::ReadDEIds(AliMpStationType station) +{ +/// Read det element ids from the file specified by name +/// and fill the map (the deNames are ignored) +/// Return true if the data were read ok + + // Open file + TString filePath = AliMpFiles::DENamesFilePath(station); + std::ifstream in(filePath); + if (!in.good()) { + AliErrorClassStream() << "Cannot open file " << filePath << endl;; + return false; + } + + // Skip plane types per cathods + empty lines + // + char line[80]; + in.getline(line, 80); + in.getline(line, 80); + in.getline(line, 80); + + // Read DE Ids + // + Int_t detElemId; + TString word; + in >> word; + while ( ! in.eof() ) { + if ( word[0] == '#' ) { + in.getline(line, 80); + } + else { + detElemId = word.Atoi(); + in.getline(line, 80); + AliDebugClassStream(1) + << "Adding " << fgNofDetElemIds << " " << detElemId << endl; + fgDetElemIds.AddAt(detElemId, fgNofDetElemIds++); + } + in >> word; + } + + // Close file + in.close(); + + return true; +} + +//______________________________________________________________________________ +void AliMpDEIterator::ReadData() +{ +/// Fill DE Ids array from DE names files +/// Return true if all data were read ok + + Bool_t result1 = ReadDEIds(kStation1); + Bool_t result2 = ReadDEIds(kStation2); + Bool_t result3 = ReadDEIds(kStation345); + Bool_t result4 = ReadDEIds(kStationTrigger); + + Bool_t result = result1 && result2 && result3 && result4; + if ( ! result ) { + AliErrorClassStream() << "Error in reading DE names files" << endl; + } +} + +// +// constructors, destructor +// + +//______________________________________________________________________________ +AliMpDEIterator::AliMpDEIterator() + : TObject(), + fIndex(-1), + fModuleId(-1) +{ +/// Standard and default constructor + + if (! fgNofDetElemIds ) ReadData(); +} + +//______________________________________________________________________________ +AliMpDEIterator::AliMpDEIterator(const AliMpDEIterator& rhs) + : TObject(rhs), + fIndex(rhs.fIndex), + fModuleId(rhs.fModuleId) +{ +/// Copy constructor +} + +//______________________________________________________________________________ + +AliMpDEIterator::~AliMpDEIterator() +{ +/// Destructor +} + +//______________________________________________________________________________ +AliMpDEIterator& AliMpDEIterator::operator=(const AliMpDEIterator& rhs) +{ +/// Assignement operator + + // check assignment to self + if (this == &rhs) return *this; + + // base class assignment + TObject::operator=(rhs); + + fIndex = rhs.fIndex; + fModuleId = rhs.fModuleId; + + return *this; +} + +// +// public methods +// + +//______________________________________________________________________________ +void AliMpDEIterator::First() +{ +/// Set iterator to the first DE Id defined + + fIndex = 0; + fModuleId = -1; +} + +//______________________________________________________________________________ +void AliMpDEIterator::First(Int_t moduleId) +{ + + fModuleId = -1; + fIndex = -1; + if ( ! AliMpDEManager::IsValidModuleId(moduleId) ) { + AliErrorStream() << "Invalid module Id " << moduleId << endl; + return; + } + + Int_t i=0; + while ( i < fgNofDetElemIds && fModuleId < 0 ) { + Int_t detElemId = fgDetElemIds.At(i); + if ( AliMpDEManager::GetModuleId(detElemId) == moduleId ) { + fModuleId = moduleId; + fIndex = i; + } + i++; + } + + if ( fModuleId < 0 ) { + AliErrorStream() + << "No DEs of Module Id " << moduleId << " found" << cout; + return; + } + +} + +//______________________________________________________________________________ +void AliMpDEIterator::Next() +{ + fIndex++; + + // Invalidate if at the end + if ( ( fIndex == fgNofDetElemIds ) || + ( fModuleId >= 0 && + AliMpDEManager::GetModuleId(CurrentDE()) != fModuleId ) ) { + fIndex = -1; + } +} + +//______________________________________________________________________________ +Bool_t AliMpDEIterator::IsDone() const +{ + return ( fIndex < 0 ); +} + +//______________________________________________________________________________ +Int_t AliMpDEIterator::CurrentDE() const +{ + if ( ! IsDone() ) + return fgDetElemIds.At(fIndex); + else { + AliErrorStream() + << "Not in valid position - returning invalid DE." << endl; + return 0; + } +} + diff --git a/MUON/mapping/AliMpDEIterator.h b/MUON/mapping/AliMpDEIterator.h new file mode 100644 index 00000000000..065d0c7505c --- /dev/null +++ b/MUON/mapping/AliMpDEIterator.h @@ -0,0 +1,78 @@ +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id$ */ + +/// \ingroup management +/// \class AliMpDEIterator +/// \brief The iterator over valid detection element IDs +/// +/// The valid detection element Ids are defined in the files denames*.dat. \n +/// It can iterate +/// - over all valid detection elements, if started with First() function; +/// - or over detection elements in a selected module, if started with +/// First(Int_t moduleId) function \n +/// +/// Author: Ivana Hrivnacova, IPN Orsay + +#ifndef ALI_MP_DE_ITERATOR_H +#define ALI_MP_DE_ITERATOR_H + +#include "AliMpStationType.h" + +#include +#include + +class TString; + +class AliMpDEIterator : public TObject { + + public: + AliMpDEIterator(); + AliMpDEIterator(const AliMpDEIterator& rhs); + virtual ~AliMpDEIterator(); + + // Operators + AliMpDEIterator& operator=(const AliMpDEIterator& rhs); + + // Methods for iterating over DE elements + // + void First(); + void First(Int_t moduleId); + void Next(); + Bool_t IsDone() const; + Int_t CurrentDE() const; + + private: + // static methods + static Bool_t ReadDEIds(AliMpStationType station); + static void ReadData(); + + // static data members + static const Int_t fgkMaxNofDetElements; // Maximum number of DEs + static TArrayI fgDetElemIds; // DE Ids + static Int_t fgNofDetElemIds; // Number of DE Ids + + // data members + Int_t fIndex; // Current DE index + Int_t fModuleId; // The iterated module + + ClassDef(AliMpDEIterator,0) // MUON Factory for Chambers and Segmentation +}; + +#endif //ALI_MP_DE_ITERATOR_H + + + + + + + + + + + + + + +