**************************************************************************/
// $Id$
-// $MpId: AliMpDEManager.cxx,v 1.1 2006/01/11 10:24:44 ivana Exp $
+// $MpId: AliMpDEManager.cxx,v 1.4 2006/05/24 13:58:34 ivana Exp $
// Category: management
-//
+
+//-----------------------------------------------------------------------------
// Class AliMpDEManager
// --------------------
// The manager class for definition of detection element types
// Authors: Ivana Hrivnacova, IPN Orsay
// Laurent Aphecetche, SUBATECH Nantes
+//-----------------------------------------------------------------------------
#include "AliMpDEManager.h"
+#include "AliMpDEStore.h"
+#include "AliMpDetElement.h"
#include "AliMpConstants.h"
-#include "AliMpFiles.h"
+#include "AliMpCathodType.h"
+#include "AliMpEncodePair.h"
#include "AliLog.h"
#include <Riostream.h>
-#include <TSystem.h>
-#include <TObjString.h>
-#include <TMap.h>
+#include <TClass.h>
+/// \cond CLASSIMP
ClassImp(AliMpDEManager)
+/// \endcond
-const char AliMpDEManager::fgkNameSeparator = '_';
-const char AliMpDEManager::fgkCommentPrefix = '#';
const Int_t AliMpDEManager::fgkCoefficient = 100;
-AliMpExMap AliMpDEManager::fgDENamesMap = AliMpExMap(true);
-
-//______________________________________________________________________________
-AliMpDEManager::AliMpDEManager()
- : TObject()
-{
-/// Protected default/standard constructor
-}
-
-//______________________________________________________________________________
-AliMpDEManager::AliMpDEManager(const AliMpDEManager& rhs)
- : TObject(rhs)
-{
-/// Protected copy constructor
-
- AliFatal("Not implemented.");
-}
+TArrayI AliMpDEManager::fgNofDEPerChamber;
//______________________________________________________________________________
/// Destructor
}
-//______________________________________________________________________________
-AliMpDEManager& AliMpDEManager::operator=(const AliMpDEManager& rhs)
-{
-/// Protected assignement operator
-
- if (this == &rhs) return *this;
-
- AliFatal("Not implemented.");
-
- return *this;
-}
-
//
// static private methods
//
//______________________________________________________________________________
-Bool_t AliMpDEManager::IsPlaneType(const TString& planeTypeName)
+AliMpDetElement* AliMpDEManager::GetDetElement(Int_t detElemId, Bool_t warn)
{
-/// Return true if the planeTypeName corresponds to a valid plane type
-
- if ( planeTypeName == PlaneTypeName(kBendingPlane) ||
- planeTypeName == PlaneTypeName(kNonBendingPlane) )
- return true;
+/// Return det element for given detElemId
- return false;
-}
-
-//______________________________________________________________________________
-AliMpPlaneType AliMpDEManager::PlaneType(const TString& planeTypeName)
-{
-/// Return plane type for the given planeTypeName \n
-/// Fatal error if planeTypeName is wrong
-
- if ( planeTypeName == PlaneTypeName(kBendingPlane) )
- return kBendingPlane;
-
- if ( planeTypeName == PlaneTypeName(kNonBendingPlane) )
- return kNonBendingPlane;
-
- // Should never reach this line
- AliFatalClass(Form("No plane type defined for %s", planeTypeName.Data()));
- return kBendingPlane;
-}
-
-//______________________________________________________________________________
-AliMpStationType AliMpDEManager::StationType(const TString& stationTypeName)
-{
-/// Return station type for the given stationTypeName \n
-/// Fatal error if stationTypeName is wrong
-
- if ( stationTypeName == StationTypeName(kStation1) )
- return kStation1;
-
- if ( stationTypeName == StationTypeName(kStation2) )
- return kStation2;
-
- if ( stationTypeName == StationTypeName(kStation345) )
- return kStation345;
-
- if ( stationTypeName == StationTypeName(kStationTrigger) )
- return kStationTrigger;
-
- // Should never reach this line
- AliFatalClass(Form("No station type defined for ", stationTypeName.Data()));
- return kStation1;
-}
-
-//______________________________________________________________________________
-Bool_t
-AliMpDEManager::ReadDENames(AliMpStationType station)
-{
-/// Read det element names for cath = 0 from the file specified by name
-/// and fill the map
-
- // Open file
- TString filePath = AliMpFiles::DENamesFilePath(station);
- std::ifstream in(filePath);
- if (!in.good()) {
- AliErrorClassStream() << "Cannot open file " << filePath << endl;;
- return false;
- }
-
- // Read plane types per cathods
- //
- char line[80];
- TString word;
- TString cathName1, cathName2;
- in >> word;
- while ( ! in.eof() && cathName1.Length() == 0 ) {
- if ( word[0] == '#' )
- in.getline(line, 80);
- else {
- cathName1 = word;
- in >> cathName2;
- }
- in >> word;
- }
-
- Bool_t isCathNameDefined = false;
- if ( IsPlaneType(cathName1) && IsPlaneType(cathName2) )
- isCathNameDefined = true;
-
- // Read DE names
- //
- Int_t detElemId;
- TString name1, name2;
- while ( ! in.eof() ) {
- if ( word[0] == '#' )
- in.getline(line, 80);
- else {
- detElemId = word.Atoi();
- in >> name1;
- if ( ! isCathNameDefined )
- in >> name2;
- else {
- name1 += fgkNameSeparator;
- name2 = name1;
- name1 += cathName1;
- name2 += cathName2;
- }
-
- if ( ! fgDENamesMap.GetValue(detElemId) ) {
- AliDebugClassStream(1)
- << "Adding " << detElemId << " " << name1 << " " << name2 << endl;
- fgDENamesMap.Add(detElemId,
- new TPair(new TObjString(name1), new TObjString(name2)));
- }
- }
- in >> word;
- }
-
- // Close file
- in.close();
-
- return true;
-}
+ return AliMpDEStore::Instance()->GetDetElement(detElemId, warn);
+}
//______________________________________________________________________________
-void AliMpDEManager::FillDENames()
+AliMpDetElement* AliMpDEManager::GetDetElement(const TString& deName, Bool_t warn)
{
-/// Fill DE names from files
+/// Return det element for given deName
- Bool_t result1 = ReadDENames(kStation1);
- Bool_t result2 = ReadDENames(kStation2);
- Bool_t result3 = ReadDENames(kStation345);
- Bool_t result4 = ReadDENames(kStationTrigger);
-
- Bool_t result = result1 && result2 && result3 && result4;
- if ( ! result ) {
- AliErrorClassStream() << "Error in reading DE names files" << endl;
- }
-}
+ return AliMpDEStore::Instance()->GetDetElement(deName, warn);
+}
//
// static public methods
Bool_t AliMpDEManager::IsValidDetElemId(Int_t detElemId, Bool_t warn)
{
/// Return true if detElemId is valid
-/// (is present in the DE names files)
-
- if ( fgDENamesMap.GetSize() == 0 ) FillDENames();
+/// (is present in the DE map)
- if ( fgDENamesMap.GetValue(detElemId) ) return true;
+ if ( GetDetElement(detElemId, warn) ) return true;
- if (warn) {
- AliErrorClassStream()
- << "Detection element " << detElemId << " not defined." << endl;
- }
return false;
}
//______________________________________________________________________________
-Bool_t AliMpDEManager::IsValidCathod(Int_t cath, Bool_t warn)
+Bool_t AliMpDEManager::IsValidChamberId(Int_t chamberId, Bool_t warn)
{
-/// Return true if cath is 0 or 1
-/// (Better solution would be to use systematically enum)
-
- if (cath == 0 || cath == 1 ) return true;
+/// Return true if chamberId is valid
- if (warn)
- AliErrorClassStream() << "Wrong cathod number " << cath << endl;
-
+ if ( chamberId >= 0 && chamberId < AliMpConstants::NofChambers() )
+ return true;
+
+ if (warn)
+ AliErrorClassStream() << "Wrong chamber Id " << chamberId << endl;
+
return false;
}
-
-//______________________________________________________________________________
-Bool_t AliMpDEManager::IsValid(Int_t detElemId, Int_t cath, Bool_t warn)
-{
-/// Return true if both detElemId and cathod number are valid
-
- return ( IsValidDetElemId(detElemId, warn) && IsValidCathod(cath, warn) );
-}
-
//______________________________________________________________________________
-Bool_t AliMpDEManager::IsValidModuleId(Int_t moduleId, Bool_t warn)
+Bool_t AliMpDEManager::IsValidGeomModuleId(Int_t moduleId, Bool_t warn)
{
/// Return true if moduleId is valid
- if ( moduleId >= 0 && moduleId < AliMpConstants::NCh() )
+ if ( moduleId >= 0 && moduleId < AliMpConstants::NofGeomModules() )
return true;
if (warn)
}
//______________________________________________________________________________
-TString AliMpDEManager::GetDEName(Int_t detElemId, Int_t cath, Bool_t warn)
+Int_t AliMpDEManager::GetChamberId(Int_t detElemId, Bool_t warn)
{
-/// Return det element type name
+/// Return chamber Id for given detElemId
- if ( ! IsValid(detElemId, cath, warn) ) return "undefined";
-
- TPair* namePair = (TPair*)fgDENamesMap.GetValue(detElemId);
-
- if (cath == 0) return ((TObjString*)namePair->Key())->GetString();
- if (cath == 1) return ((TObjString*)namePair->Value())->GetString();
-
- return "undefined";
-}
-
-//______________________________________________________________________________
-TString AliMpDEManager::GetDETypeName(Int_t detElemId, Int_t cath, Bool_t warn)
-{
-/// Return det element type name
-
- TString fullName = GetDEName(detElemId, cath, warn);
+ if ( ! IsValidDetElemId(detElemId, warn) ) return -1;
- // cut plane type extension
- Ssiz_t pos = fullName.First(fgkNameSeparator);
- return fullName(0,pos);
-}
+ return detElemId/fgkCoefficient - 1;
+}
//______________________________________________________________________________
-Int_t AliMpDEManager::GetModuleId(Int_t detElemId, Bool_t warn)
+Int_t AliMpDEManager::GetGeomModuleId(Int_t detElemId, Bool_t warn)
{
-/// Return module Id for given detElemId
+/// <pre>
+/// Get module Id from detection element Id
+/// !!! moduleId != chamberId
+/// Station 1: Chamber: 1 Module: 0 Det elements: 100-103
+/// Chamber: 2 Module: 1 Det elements: 200-203
+/// Station 2: Chamber: 3 Module: 2 Det elements: 300-303
+/// Chamber: 4 Module: 3 Det elements: 400-403
+/// Station 3: Chamber: 5 Module: 4 Det elements: 500-504, 514-517
+/// Module: 5 Det elements: 505-513,
+/// Chamber: 6 Module: 6 Det elements: 600-604, 614-617
+/// Module: 7 Det elements: 605-613
+/// Station 4: Chamber: 7 Module: 8 Det elements: 700-706, 720-725
+/// Module: 9 Det elements: 707-719
+/// Chamber: 8 Module: 10 Det elements: 800-806, 820-825
+/// Module: 11 Det elements: 807-819
+/// Station 5: Chamber: 9 Module: 12 Det elements: 900-906, 920-925
+/// Module: 13 Det elements: 907-919
+/// Chamber: 10 Module: 14 Det elements: 1000-1006,1020-1025
+/// Module: 15 Det elements: 1007-1019
+/// Station 6: Chamber: 11 Module: 16 Det elements: 1100-1117
+/// Chamber: 12 Module: 17 Det elements: 1200-1217
+/// Station 7: Chamber: 13 Module: 18 Det elements: 1300-1317
+/// Chamber: 14 Module: 19 Det elements: 1400-1417
+/// </pre>
if ( ! IsValidDetElemId(detElemId, warn) ) return -1;
- return detElemId/fgkCoefficient - 1;
+ return detElemId/fgkCoefficient
+ + ((detElemId >= 505 && detElemId <= 513) || detElemId >= 600 )
+ + ((detElemId >= 605 && detElemId <= 613) || detElemId >= 700 )
+ + ((detElemId >= 707 && detElemId <= 719) || detElemId >= 800 )
+ + ((detElemId >= 807 && detElemId <= 819) || detElemId >= 900 )
+ + ((detElemId >= 907 && detElemId <= 919) || detElemId >= 1000 )
+ + ((detElemId >= 1007 && detElemId <= 1019) || detElemId >= 1100 ) - 1;
}
//______________________________________________________________________________
-AliMpPlaneType AliMpDEManager::GetPlaneType(Int_t detElemId, Int_t cath)
+AliMp::PlaneType AliMpDEManager::GetPlaneType(Int_t detElemId, AliMp::CathodType cath)
{
/// Return plane type \n
-/// Failure causes Fatal error - as AliMpPlaneType has no possibility
+/// Failure causes Fatal error - as AliMp::PlaneType has no possibility
/// to return undefined value
- if ( ! IsValid(detElemId, cath, true) ) {
- AliFatalClass("Cannot return AliMpPlaneType value.");
- return kBendingPlane;
+ if ( ! IsValidDetElemId(detElemId, true) ) {
+ AliFatalClass("Cannot return AliMp::PlaneType value.");
+ return AliMp::kBendingPlane;
}
- TPair* namePair = (TPair*)fgDENamesMap.GetValue(detElemId);
-
- TString fullName;
- if (cath == 0) fullName = ((TObjString*)namePair->Key())->GetString();
- if (cath == 1) fullName = ((TObjString*)namePair->Value())->GetString();
-
- // Get plane type name
- Ssiz_t pos = fullName.First(fgkNameSeparator);
- TString planeTypeName = fullName(pos+1,fullName.Length()-pos);
-
- return PlaneType(planeTypeName);
+ return GetDetElement(detElemId)->GetPlaneType(cath);
}
//______________________________________________________________________________
-AliMpStationType AliMpDEManager::GetStationType(Int_t detElemId)
+AliMp::StationType AliMpDEManager::GetStationType(Int_t detElemId)
{
/// Return station type \n
-/// Failure causes Fatal error - as AliMpStationType has no possibility
+/// Failure causes Fatal error - as AliMp::StationType has no possibility
/// to return undefined value
if ( ! IsValidDetElemId(detElemId, true) ) {
- AliFatalClass("Cannot return AliMpStationType value.");
- return kStation1;
+ AliFatalClass("Cannot return AliMp::StationType value.");
+ return AliMp::kStation12;
}
- Int_t moduleId = GetModuleId(detElemId, false);
- if ( ! IsValidModuleId(moduleId, true) ) {
- AliFatalClass("Cannot return AliMpStationType value.");
- return kStation1;
+ return GetDetElement(detElemId)->GetStationType();
+}
+
+//______________________________________________________________________________
+AliMq::Station12Type AliMpDEManager::GetStation12Type(Int_t detElemId)
+{
+/// Return station12 type \n
+/// Failure causes Fatal error - as AliMp::StationNumber has no possibility
+/// to return undefined value
+
+ if ( ! IsValidDetElemId(detElemId, true) ) {
+ AliFatalClass("Cannot return AliMp::Station12Type value.");
+ return AliMq::kNotSt12;
}
- if ( moduleId == 0 || moduleId == 1 ) return kStation1;
- if ( moduleId == 2 || moduleId == 3 ) return kStation2;
- if ( moduleId >= 4 && moduleId <= 9 ) return kStation345;
- if ( moduleId >= 10 && moduleId <= 13 ) return kStationTrigger;
-
- // Should never get to this line
- AliFatalClass("Cannot return AliMpStationType value.");
- return kStation1;
+ return GetDetElement(detElemId)->GetStation12Type();
+}
+
+//______________________________________________________________________________
+AliMp::CathodType
+AliMpDEManager::GetCathod(Int_t detElemId, AliMp::PlaneType planeType)
+{
+/// Return cathod number for given detElemId and planeType
+
+ if ( ! IsValidDetElemId(detElemId, true) ) {
+ AliFatalClass("Cannot return AliMp::CathodType value.");
+ return AliMp::kCath0;
+ }
+
+ return GetDetElement(detElemId)->GetCathodType(planeType);
+}
+
+//______________________________________________________________________________
+Int_t AliMpDEManager::GetNofDEInChamber(Int_t chamberId, Bool_t warn)
+{
+/// Return the number of detection elements in the chamber with the given
+/// chamberId
+
+ if ( ! IsValidChamberId(chamberId,warn) ) return 0;
+
+ // Fill array if it is empty
+ if ( ! fgNofDEPerChamber.GetSize() ) {
+ fgNofDEPerChamber.Set(AliMpConstants::NofChambers());
+ AliMpDEIterator it;
+ for ( Int_t i=0; i<AliMpConstants::NofChambers(); i++ ) {
+ Int_t counter = 0;
+ for ( it.First(i); ! it.IsDone(); it.Next() ) ++counter;
+ fgNofDEPerChamber[i] = counter;
+ }
+ }
+
+ return fgNofDEPerChamber[chamberId];
+
+}
+
+//______________________________________________________________________________
+MpPair_t AliMpDEManager::GetDetElemIdRange(Int_t chamberId)
+{
+/// Return the detection element Id range for given chamberId
+/// es encoded pair
+
+ if ( ! IsValidChamberId(chamberId) ) return 0;
+
+ return AliMp::Pair(
+ (chamberId+1)*fgkCoefficient,
+ (chamberId+1)*fgkCoefficient + GetNofDEInChamber(chamberId) - 1);
+
}