Segmentation can be stored/retreaved from file (in Config.C...)
authorshahoian <shahoian@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 6 Aug 2012 22:50:01 +0000 (22:50 +0000)
committershahoian <shahoian@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 6 Aug 2012 22:50:01 +0000 (22:50 +0000)
ITS/UPGRADE/AliITSsegmentationPixUpg.cxx
ITS/UPGRADE/AliITSsegmentationPixUpg.h
ITS/UPGRADE/CMakelibITSUpgradeBase.pkg
ITS/UPGRADE/ITSUpgradeBaseLinkDef.h

index 71f2265..d7b163a 100644 (file)
 #include <TGeoManager.h>
 #include <TGeoVolume.h>
 #include <TGeoBBox.h>
+#include <TObjArray.h>
+#include <TString.h>
+#include <TSystem.h>
+#include <TFile.h>
 #include "AliITSsegmentationPixUpg.h"
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
 ClassImp(AliITSsegmentationPixUpg)
 
+const char* AliITSsegmentationPixUpg::fgkSegmListName = "ITSUpgradeSegmentations";
+
 //_____________________________________________________________________________RS
 AliITSsegmentationPixUpg::AliITSsegmentationPixUpg(int nchips,int ncol,int nrow,
                                                   double pitchX,double pitchZ,
-                                                  double pitchLftC,double pitchRgtC,
                                                   double thickness,
+                                                  double pitchLftC,double pitchRgtC,
                                                   double edgL,double edgR,double edgT,double edgB)
 : AliITSsegmentation()
   ,fGuardLft(edgL)
@@ -370,3 +376,70 @@ void AliITSsegmentationPixUpg::Init()
 {
   // init settings
 }
+
+//______________________________________________________________________
+Bool_t AliITSsegmentationPixUpg::StoreWithID(UInt_t id, const char* outf)
+{
+  // store in the special list under given ID
+  TString fns = outf;
+  gSystem->ExpandPathName(fns);
+  if (fns.IsNull()) {AliFatal("No file name provided"); return kFALSE;}
+  TFile* fout = TFile::Open(fns.Data(),"update");
+  if (!fout) {AliFatal(Form("Failed to open output file %s",outf)); return kFALSE;}
+  TObjArray* arr = (TObjArray*)fout->Get(fgkSegmListName);
+  if (!arr) arr = new TObjArray();
+  else {
+    int nent = arr->GetEntriesFast();
+    for (int i=nent;i--;) {
+      AliITSsegmentationPixUpg* segm = dynamic_cast<AliITSsegmentationPixUpg*>(arr->At(i));
+      if (segm && segm->GetUniqueID()==id) {
+       AliFatal(Form("Segmenation %d already exists in file %s",id,outf)); 
+       return kFALSE;
+      }
+    }
+  }
+  //
+  this->SetUniqueID(id);  
+  arr->AddLast(this);
+  arr->SetOwner(kTRUE);
+  fout->WriteObject(arr,fgkSegmListName,"kSingleKey");
+  fout->Close();
+  delete fout;
+  arr->Remove(this);
+  delete arr;
+  AliInfo(Form("Stored segmentation %d in %s",id,outf));
+  return kTRUE;
+  //
+}
+
+//______________________________________________________________________
+AliITSsegmentationPixUpg* AliITSsegmentationPixUpg::LoadWithID(UInt_t id, const char* inpf)
+{
+  // store in the special list under given ID
+  TString fns = inpf;
+  gSystem->ExpandPathName(fns);
+  if (fns.IsNull()) {AliFatalGeneral("LoadWithID","No file name provided"); return 0;}
+  TFile* finp = TFile::Open(fns.Data());
+  if (!finp) {AliFatalGeneral("LoadWithID",Form("Failed to open file %s",inpf)); return 0;}
+  TObjArray* arr = (TObjArray*)finp->Get(fgkSegmListName);
+  if (!arr) {
+    AliFatalGeneral("LoadWithID",Form("Failed to find segmenation array %s in %s",fgkSegmListName,inpf)); 
+    return 0;
+  }
+  AliITSsegmentationPixUpg* segm = 0;
+  int nent = arr->GetEntriesFast();
+  for (int i=nent;i--;) {
+    segm = dynamic_cast<AliITSsegmentationPixUpg*>(arr->At(i));
+    if (segm && segm->GetUniqueID()==id) {arr->RemoveAt(i); break;}
+    segm = 0;
+  }
+  //
+  if (!segm) {AliFatalGeneral("LoadWithID",Form("Failed to find segmenation %d in %s",id,inpf)); return 0;}
+  //
+  arr->SetOwner(kTRUE); // to not leave in memory other segmenations
+  finp->Close();
+  delete finp;
+  delete arr;
+  //
+  return segm;
+}
index 36451a4..030be26 100644 (file)
@@ -13,8 +13,8 @@ public AliITSsegmentation {
   enum {kCM2MC=10000};
   AliITSsegmentationPixUpg(int nchips=0,int ncol=0,int nrow=0,
                           double pitchX=0,double pitchZ=0,
-                          double pitchLftC=-1,double pitchRgtC=-1,
                           double thickness=0,
+                          double pitchLftC=-1,double pitchRgtC=-1,
                           double edgL=0,double edgR=0,double edgT=0,double edgB=0);
   
   //  AliITSsegmentationPixUpg(Option_t *opt="" );
@@ -56,6 +56,9 @@ public AliITSsegmentation {
   //
   virtual void PrintDefaultParameters() const {AliWarning("No def. parameters defined as const static data members");}
   //
+  Bool_t                           StoreWithID(UInt_t id, const char* outf);
+  static AliITSsegmentationPixUpg* LoadWithID(UInt_t id, const char* inpf);
+  //
  protected:
   Float_t Z2Col(Float_t z) const;
   Float_t Col2Z(Int_t col) const;
@@ -75,7 +78,8 @@ public AliITSsegmentation {
     Int_t    fNRow;            // number of rows
     Int_t    fNCol;            // number of columns (total)
     //
-
+    static const char* fgkSegmListName; // pattern for segmentations list name
+    //
   ClassDef(AliITSsegmentationPixUpg,1) //Segmentation class upgrade pixels 
 
 };
index a13bbd6..97b7286 100644 (file)
@@ -34,6 +34,7 @@ AliITSInitGeometryUpg.cxx
 AliITSLoaderUpg.cxx 
 AliITSgeomTGeoUpg.cxx
 AliITSCalibrationPixUpg.cxx
+AliITSsegmentationPixUpg.cxx
 )
 
 string ( REPLACE ".cxx" ".h" HDRS "${SRCS}" )
index 0e1420e..83c136d 100644 (file)
@@ -19,4 +19,5 @@
 #pragma link C++ class  AliITSLoaderUpg+;
 #pragma link C++ class  AliITSgeomTGeoUpg+;
 #pragma link C++ class  AliITSCalibrationPixUpg+;
+#pragma link C++ class  AliITSsegmentationPixUpg+;
 #endif