Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DLorentzMapCalibDB.cc
Go to the documentation of this file.
1 #include "DLorentzMapCalibDB.h"
2 #include "DLorentzDeflections.h"
3 #include <map>
4 #include <vector>
5 using namespace std;
6 
7 
8 //---------------------------------
9 // DLorentzMapCalibDB (Constructor)
10 //---------------------------------
11 DLorentzMapCalibDB::DLorentzMapCalibDB(JApplication *japp, unsigned int run_number)
12 {
13  jcalib = japp->GetJCalibration(run_number);
14 
15  int Npoints = GetLorentzDeflections();
16  if(Npoints==0){
17  _DBG_<<"Error getting JCalibration object for Lorentz corrections!"<<
18  endl;
19  japp->Quit();
20  }
21 }
22 
23 //---------------------------------
24 // DLorentzMapCalibDB (Constructor)
25 //---------------------------------
27 {
28  this->jcalib = jcalib;
29  if(GetLorentzDeflections()==0){
30  _DBG_<<"Error getting JCalibration object for Lorentz corrections!"<<
31  endl;
32  exit(1);
33  }
34 }
35 
36 
37 
39  /// Routine for accessing calibration constants adapted from code written by
40  /// David Lawrence.
41  /// The values specified by "namepath" will be read into the array
42  /// "vals". The "vals" array should have enough memory allocated
43  /// to hold *Nvals elements. If not, only the first *Nvals elements
44  /// will be copied and a non-zero value returned. If the number
45  /// of values in the database are less than *Nvals, then all values
46  /// are copied, *Nvals is updated to reflect the number of valid
47  /// elements in "vals", and a value of 0 is returned.
48 
49  // Make sure jcalib is set
50  if(!jcalib){
51  _DBG_<<"ERROR - GetLorentzDefelections() called when jcalib not set!"<<endl;
52  _DBG_<<"ERROR - Exiting ..."<<endl;
53  return 0;
54  }
55 
56  // Get constants and do basic check on number of elements
57  vector< map<string, float> > tvals;
58  jcalib->Get("FDC/lorentz_deflections", tvals);
59  if(tvals.size() != LORENTZ_X_POINTS*LORENTZ_Z_POINTS){
60  _DBG_<<"ERROR - GetLorentzDefelections() number of elements in calib DB"<<endl;
61  _DBG_<<"ERROR - not the same as expected. DB="<<tvals.size()<<" expected"<<LORENTZ_X_POINTS*LORENTZ_Z_POINTS<<endl;
62  _DBG_<<"ERROR - Exiting ..."<<endl;
63  return 0;
64  }
65 
66  // Notify user
67  jout<<"Read "<<tvals.size()<<" values from FDC/lorentz_deflections in calibDB"<<endl;
68  jout<<" lorentz_deflections columns (alphabetical): ";
69  map<string,float>::iterator iter;
70  for(iter=tvals[0].begin(); iter!=tvals[0].end(); iter++)jout<<iter->first<<" ";
71  jout<<endl;
72 
73  // Copy values into tables. We preserve the order since that is how it was
74  // originally done in hitFDC.c
75  for(unsigned int i=0; i<tvals.size(); i++){
76  map<string, float> &row = tvals[i];
77  unsigned int xindex = i/LORENTZ_Z_POINTS;
78  unsigned int zindex = i%LORENTZ_Z_POINTS;
79  lorentz_x[xindex] = row["x"];
80  lorentz_z[zindex] = row["z"];
81  lorentz_nx[xindex][zindex] = row["nx"];
82  lorentz_nz[xindex][zindex] = row["nz"];
83  }
84  return tvals.size();
85 }
DLorentzMapCalibDB(JApplication *japp, unsigned int run_number=1)
#define LORENTZ_X_POINTS
#define LORENTZ_Z_POINTS
JApplication * japp
#define _DBG_
Definition: HDEVIO.h:12
unsigned int GetLorentzDeflections(void)