From 0772e1ad3817c10942e74a3dbdeaef8b0fc0b50c Mon Sep 17 00:00:00 2001
From: "Stephen A. Wood" <saw@jlab.org>
Date: Tue, 19 Mar 2013 15:33:37 -0400
Subject: [PATCH] Get Drift Chamber plane names from variable in hcana.param
 instead of hardwiring them.

---
 examples/PARAM/hcana.param |  3 +++
 src/THcDriftChamber.cxx    | 50 ++++++++++----------------------------
 2 files changed, 16 insertions(+), 37 deletions(-)

diff --git a/examples/PARAM/hcana.param b/examples/PARAM/hcana.param
index 1adc39f..e8fb336 100644
--- a/examples/PARAM/hcana.param
+++ b/examples/PARAM/hcana.param
@@ -8,3 +8,6 @@ hhodo_num_planes = 4
 hshower_num_layers = 4
 
 haero_num_pairs = 8
+
+# Names of planes so that parameter names can be constructed
+hdc_plane_names = "1x1 1y1 1u1 1v1 1y2 1x2 2x1 2y1 2u1 2v1 2y2 2x2"
diff --git a/src/THcDriftChamber.cxx b/src/THcDriftChamber.cxx
index ea45f06..c8fd9be 100644
--- a/src/THcDriftChamber.cxx
+++ b/src/THcDriftChamber.cxx
@@ -72,45 +72,21 @@ void THcDriftChamber::Setup(const char* name, const char* description)
 
   cout << "Drift Chambers: " <<  fNPlanes << " planes in " << fNChambers << " chambers" << endl;
 
+  // Can't put strings in DBRequest yet
+  string planelistvarname=" dc_plane_names";
+  planelistvarname[0] = prefix[0];
+  vector<string> plane_names = vsplit(gHcParms->GetString(planelistvarname));
+
+  if(plane_names.size() != (UInt_t) fNPlanes) {
+    cout << "ERROR: Number of planes " << fNPlanes << " doesn't agree with number of plane names " << plane_names.size() << endl;
+    // Should quit.  Is there an official way to quit?
+  }
   fPlaneNames = new char* [fNPlanes];
-  for(Int_t i=0;i<fNPlanes;i++) {fPlaneNames[i] = new char[4];}
-
-  // Big hack needed because the drift map parameters are in parameters with
-  // names like hwc1x1fract.  Need to do some kind of parameter name mapping
-  // or generate the names from the wire angle (alpha)
-  if(prefix[0] == 'h') {
-    strcpy(fPlaneNames[0],"1x1");
-    strcpy(fPlaneNames[1],"1y1");
-    strcpy(fPlaneNames[2],"1u1");
-    strcpy(fPlaneNames[3],"1v1");
-    strcpy(fPlaneNames[4],"1y2");
-    strcpy(fPlaneNames[5],"1x2");
-    strcpy(fPlaneNames[6],"2x1");
-    strcpy(fPlaneNames[7],"2y1");
-    strcpy(fPlaneNames[8],"2u1");
-    strcpy(fPlaneNames[9],"2v1");
-    strcpy(fPlaneNames[10],"2y2");
-    strcpy(fPlaneNames[11],"2x2");
-  } else if (prefix[0] == 's') {
-    strcpy(fPlaneNames[0],"1u1");
-    strcpy(fPlaneNames[1],"1u2");
-    strcpy(fPlaneNames[2],"1x1");
-    strcpy(fPlaneNames[3],"1x2");
-    strcpy(fPlaneNames[4],"1v1");
-    strcpy(fPlaneNames[5],"1v2");
-    strcpy(fPlaneNames[6],"2u1");
-    strcpy(fPlaneNames[7],"2u2");
-    strcpy(fPlaneNames[8],"2x1");
-    strcpy(fPlaneNames[9],"2x2");
-    strcpy(fPlaneNames[10],"2v1");
-    strcpy(fPlaneNames[11],"2v2");
-  } else {
-    cout << "Unknown Spectrometer Prefix '" << prefix << "' Guessing names" << endl;
-    for(Int_t i=0;i<fNPlanes;i++) {
-      sprintf(fPlaneNames[i],"%d",i+1);
-    }
+  for(Int_t i=0;i<fNPlanes;i++) {
+    fPlaneNames[i] = new char[plane_names[i].length()];
+    strcpy(fPlaneNames[i], plane_names[i].c_str());
   }
-    
+
   char *desc = new char[strlen(description)+100];
   fPlanes = new THcDriftChamberPlane* [fNPlanes];
 
-- 
GitLab