// $Id$
// $MpId: AliMpDEStore.cxx,v 1.4 2006/05/24 13:58:34 ivana Exp $
// Category: management
-//
+
+//-----------------------------------------------------------------------------
// Class AliMpDEStore
// --------------------
// The container class for detection element objects
// Authors: Ivana Hrivnacova, IPN Orsay
// Laurent Aphecetche, Christian Finck, SUBATECH Nantes
+//-----------------------------------------------------------------------------
+#include <cstdlib>
#include "AliMpDEStore.h"
#include "AliMpDEManager.h"
#include "AliMpDetElement.h"
#include "AliMpConstants.h"
#include "AliMpFiles.h"
+#include "AliMpDataStreams.h"
#include "AliMpHelper.h"
-#include "AliMpIntPair.h"
#include "AliMpConstants.h"
+#include "AliMpExMapIterator.h"
#include "AliLog.h"
#include <Riostream.h>
+#include <TClass.h>
#include <TSystem.h>
#include <TObjString.h>
+#include <TObjArray.h>
#include <TMap.h>
/// \cond CLASSIMP
//
//______________________________________________________________________________
-AliMpDEStore* AliMpDEStore::Instance()
+AliMpDEStore* AliMpDEStore::Instance(Bool_t warn)
{
/// Create the DE store if it does not yet exist
/// and return its instance
- if ( ! fgInstance )
- fgInstance = new AliMpDEStore();
-
+ if ( ! fgInstance && warn ) {
+ AliWarningClass("DE Store has not been loaded");
+ }
+
+ return fgInstance;
+}
+
+//______________________________________________________________________________
+AliMpDEStore* AliMpDEStore::ReadData(const AliMpDataStreams& dataStreams,
+ Bool_t warn)
+{
+/// Load the DE store data from ASCII data files
+/// and return its instance
+
+ if ( fgInstance ) {
+ if ( warn )
+ AliWarningClass("DE Store has been already loaded");
+ return fgInstance;
+ }
+
+ if ( dataStreams.GetReadFromFiles() )
+ AliInfoClass("Reading DE Store from ASCII files.");
+
+ fgInstance = new AliMpDEStore(dataStreams);
return fgInstance;
}
//
//______________________________________________________________________________
-AliMpDEStore::AliMpDEStore()
+AliMpDEStore::AliMpDEStore(const AliMpDataStreams& dataStreams)
: TObject(),
- fDetElements(true)
+ fkDataStreams(dataStreams),
+ fDetElements()
{
/// Standard constructor
}
//______________________________________________________________________________
-AliMpDEStore::AliMpDEStore(TRootIOCtor* /*ioCtor*/)
+AliMpDEStore::AliMpDEStore(TRootIOCtor* ioCtor)
: TObject(),
- fDetElements()
+ fkDataStreams(ioCtor),
+ fDetElements(ioCtor)
{
/// Constructor for IO
return false;
}
-//______________________________________________________________________________
-AliMp::PlaneType AliMpDEStore::PlaneType(const TString& planeTypeName)
-{
-/// Return plane type for the given planeTypeName \n
-/// Fatal error if planeTypeName is wrong
-
- if ( planeTypeName == PlaneTypeName(AliMp::kBendingPlane) )
- return AliMp::kBendingPlane;
-
- if ( planeTypeName == PlaneTypeName(AliMp::kNonBendingPlane) )
- return AliMp::kNonBendingPlane;
-
- // Should never reach this line
- AliFatalClass(Form("No plane type defined for %s", planeTypeName.Data()));
- return AliMp::kBendingPlane;
-}
-
-//______________________________________________________________________________
-AliMp::StationType AliMpDEStore::StationType(const TString& stationTypeName)
-{
-/// Return station type for the given stationTypeName \n
-/// Fatal error if stationTypeName is wrong
-
- if ( stationTypeName == StationTypeName(AliMp::kStation1) )
- return AliMp::kStation1;
-
- if ( stationTypeName == StationTypeName(AliMp::kStation2) )
- return AliMp::kStation2;
-
- if ( stationTypeName == StationTypeName(AliMp::kStation345) )
- return AliMp::kStation345;
-
- if ( stationTypeName == StationTypeName(AliMp::kStationTrigger) )
- return AliMp::kStationTrigger;
-
- // Should never reach this line
- AliFatalClass(Form("No station type defined for ", stationTypeName.Data()));
- return AliMp::kStation1;
-}
-
-//______________________________________________________________________________
-Bool_t AliMpDEStore::ReadManuToSerialNbs(AliMpDetElement* detElement,
- AliMp::StationType stationType)
-{
-/// Read manu serial numbers for the given detection element
-
- TString deName = detElement->GetDEName();
-
- TString infile = AliMpFiles::ManuToSerialPath(deName, stationType);
- ifstream in(infile, ios::in);
-
- // Change to Error when all files available
- //if ( !in.is_open() && stationType == AliMp::kStation345 ) {
- // AliWarningStream() << "File " << infile << " not found." << endl;
- // return false;
- //}
-
- char line[80];
-
- while ( in.getline(line,80) ) {
-
- if ( line[0] == '#' ) continue;
-
- TString tmp(AliMpHelper::Normalize(line));
-
- Int_t blankPos = tmp.First(' ');
-
- TString sManuId(tmp(0, blankPos));
-
- Int_t manuId = atoi(sManuId.Data());
-
- TString sManuSerial(tmp(blankPos + 1, tmp.Length()-blankPos));
-
- Int_t manuSerial = atoi(sManuSerial.Data());
-
- // filling manuId <> manuSerial
- detElement->AddManuSerial(manuId, manuSerial);
- }
-
- in.close();
- return true;
-}
-
//______________________________________________________________________________
Bool_t
-AliMpDEStore::ReadDENames(AliMp::StationType station)
+AliMpDEStore::ReadDENames(AliMp::StationType station,
+ AliMq::Station12Type station12)
{
/// 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;
- }
+ // Open stream
+ istream& in
+ = fkDataStreams.
+ CreateDataStream(AliMpFiles::DENamesFilePath(station, station12));
// Read plane types per cathods
//
" of DetElemId %d",detElemId));
}
- AliMpDetElement* detElement
- = new AliMpDetElement(detElemId, name, name0, planeForCathode[0]);
+ AliMpDetElement* detElement = new AliMpDetElement(detElemId, name, name0, planeForCathode[0]);
+
if ( ! fDetElements.GetValue(detElemId) )
{
AliDebugClassStream(3)
<< "Adding DE name " << detElemId << " " << name << endl;
fDetElements.Add(detElemId, detElement);
-
- // Read manu serial numbers for this det element
- ReadManuToSerialNbs(detElement, station);
}
else
{
}
in >> word;
}
-
- // Close file
- in.close();
+ delete ∈
+
return true;
}
{
/// Fill DE names from files
AliDebugClass(2,"");
- Bool_t result1 = ReadDENames(AliMp::kStation1);
- Bool_t result2 = ReadDENames(AliMp::kStation2);
+ Bool_t result1 = ReadDENames(AliMp::kStation12, AliMq::kStation1);
+ Bool_t result2 = ReadDENames(AliMp::kStation12, AliMq::kStation2);
Bool_t result3 = ReadDENames(AliMp::kStation345);
Bool_t result4 = ReadDENames(AliMp::kStationTrigger);
if ( ! result ) {
AliErrorClassStream() << "Error in reading DE names files" << endl;
}
+ AliDebug(1,Form("%d detection elements were read in",fDetElements.GetSize()));
}
//
}
//______________________________________________________________________________
-AliMpIntPair AliMpDEStore::GetDetElemIdManu(Int_t manuSerial) const
+AliMpDetElement* AliMpDEStore::GetDetElement(const TString& deName, Bool_t warn) const
{
-/// Return the detElemId and manuId for given serial manu number
+/// Return det element for given deName
- for ( Int_t i = 0; i < fDetElements.GetSize(); i++ ) {
-
- AliMpDetElement* detElement
- = (AliMpDetElement*)fDetElements.GetObject(i);
-
- Int_t manuId = detElement->GetManuIdFromSerial(manuSerial);
- if ( manuId ) return AliMpIntPair(detElement->GetId(), manuId);
- }
+ TIter next(fDetElements.CreateIterator());
+ AliMpDetElement* detElement;
+
+ while ( ( detElement = static_cast<AliMpDetElement*>(next()) ) )
+ {
+
+ if (deName.CompareTo(detElement->GetDEName()) == 0)
- // manu with this serial number does not exist
- return AliMpIntPair::Invalid();
-}
+ return detElement;
+ }
+
+ if (warn) {
+ AliErrorClassStream()
+ << "Detection element with name" << deName.Data() << " not defined." << endl;
+ }
+
+ return 0x0;
+
+}