Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members | File Members

CalibItemMgr Class Reference

abstract class for handling a single Cal calibration data type. More...

#include <CalibItemMgr.h>

Inheritance diagram for CalibItemMgr:

Inheritance graph
[legend]
Collaboration diagram for CalibItemMgr:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 CalibItemMgr (const ICalibPathSvc::CalibItem calibItem, const CalCalibShared &ccsShared, const size_t indexSize, const size_t nSplineTypes=0)
virtual ~CalibItemMgr ()
virtual StatusCode initialize (const std::string &flavor)
 initialization code which must be done during Gaudi init() period

void invalidate ()
 data should be invalidated at beginning of each event.

int getSerNo ()
 return serial # for current calib data return calibration data serial number from CalibSvc, or SERNO_IDEAL, SERNO_NODATA


Protected Member Functions

virtual StatusCode updateCalib ()
 check calib validity period, (re)build local store if necessary

virtual StatusCode loadIdealVals ()=0
 load ideal (fake) calibration vals for my calib_type if db is down

virtual StatusCode genLocalStore ()=0
 generate full set of spline f()'s or other local data (if applicable for calib_type)

StatusCode evalSpline (const int calibType, const CalUtil::LATWideIndex idx, const float x, float &y)
 generic spline evaluation f() works for any calib_type

StatusCode genSpline (const int calibType, const CalUtil::LATWideIndex idx, const std::string &name, const std::vector< float > &x, const std::vector< float > &y)
 generate new spline from 2 STL vecs & insert into appropriate splineList

const CalibData::RangeBase * getRangeBase (const idents::CalXtalId xtalId)
 retrieve spec'd rangeBase object, update if necessary


Protected Attributes

const ICalibPathSvc::CalibItem m_calibItem
 used for generate calib path

std::string m_calibPath
 TDS path to calib data for my calib_type and path.

CalibData::CalCalibBase * m_calibBase
 TDS location for root of my calib_type and path.

const CalCalibSharedm_ccsShared
 ref to data shared by all classes used by CalibDataSvc

bool m_idealMode
 boolean if we're in ideal 'fake' mode

std::vector< CalUtil::CalVec<
CalUtil::LATWideIndex, TSpline3 * > > 
m_splineLists
 2d vector of all (optional) splines in local data store

std::vector< CalUtil::CalVec<
CalUtil::LATWideIndex, float > > 
m_splineXMin
 min X val for each (optional) spline in local data store

std::vector< CalUtil::CalVec<
CalUtil::LATWideIndex, float > > 
m_splineXMax
 max X val for each (optional) spline in local data store

std::vector< CalUtil::CalVec<
CalUtil::LATWideIndex, float > > 
m_splineYMin
 min Y val for each (optional) spline in local data store

std::vector< CalUtil::CalVec<
CalUtil::LATWideIndex, float > > 
m_splineYMax
 max Y val for each (optional) spline in local data store

CalUtil::CalVec< CalUtil::LATWideIndex,
const CalibData::RangeBase * > 
m_rngBases
 pointers to each data member for my calib_type


Static Protected Attributes

const int SERNO_NODATA = -1
 m_serNo has this value when data has not yet been loaded

const int SERNO_IDEAL = 1
 m_serNo has this value when ideal mode data has been loaded


Private Member Functions

void clearLocalStore ()
 wipe out locally stored data (e.g. splines)


Private Attributes

std::string m_flavor
 calib flavor

bool m_isValid
 validity state of CalibItemMgr data

int m_serNo
 serial # for current calibration source may be set to SERNO_IDEAL, or SERNO_NODATA


Detailed Description

abstract class for handling a single Cal calibration data type.

Author:
Z.Fewtrell
provides the following services:

Definition at line 38 of file CalibItemMgr.h.


Constructor & Destructor Documentation

CalibItemMgr::CalibItemMgr const ICalibPathSvc::CalibItem  calibItem,
const CalCalibShared ccsShared,
const size_t  indexSize,
const size_t  nSplineTypes = 0
[inline]
 

Parameters:
calibItem TDS path to calibration data to be managed
ccsShared CalCalibSvc shared resources
indexSize number of channels to manage (array size)
nSplineTypes number of splines per channel

Definition at line 44 of file CalibItemMgr.h.

References m_calibBase, m_calibItem, m_ccsShared, m_idealMode, m_isValid, m_rngBases, m_serNo, m_splineLists, m_splineXMax, m_splineXMin, m_splineYMax, m_splineYMin, and SERNO_NODATA.

00047                                             : 
00048     m_calibItem(calibItem),
00049     m_calibBase(0),
00050     m_ccsShared(ccsShared),
00051     m_idealMode(false),
00053     m_splineLists(nSplineTypes,CalUtil::CalVec<CalUtil::LATWideIndex, TSpline3*>(indexSize)), 
00054     m_splineXMin(nSplineTypes,CalUtil::CalVec<CalUtil::LATWideIndex, float>(indexSize)),
00055     m_splineXMax(nSplineTypes,CalUtil::CalVec<CalUtil::LATWideIndex, float>(indexSize)),
00056     m_splineYMin(nSplineTypes,CalUtil::CalVec<CalUtil::LATWideIndex, float>(indexSize)),
00057     m_splineYMax(nSplineTypes,CalUtil::CalVec<CalUtil::LATWideIndex, float>(indexSize)),
00058     m_rngBases(indexSize),
00059     m_isValid(false),
00060     m_serNo(SERNO_NODATA)
00061   {}

virtual CalibItemMgr::~CalibItemMgr  )  [inline, virtual]
 

Definition at line 63 of file CalibItemMgr.h.

00063 {};


Member Function Documentation

void CalibItemMgr::clearLocalStore  )  [private]
 

wipe out locally stored data (e.g. splines)

Definition at line 259 of file CalibItemMgr.cxx.

References del_all_ptrs(), m_rngBases, m_splineLists, m_splineXMax, m_splineXMin, m_splineYMax, and m_splineYMin.

Referenced by updateCalib().

00259                                    {   
00260   fill(m_rngBases.begin(), m_rngBases.end(), static_cast<CalibData::RangeBase*>(0));
00261 
00262   // m_splineLists is the 'owner' of the splines, so i need to delete
00263   // the objects themselves as well as the pointers.
00264   for (unsigned i = 0; i < m_splineLists.size(); i++) {
00265     del_all_ptrs(m_splineLists[i]);
00266     fill_zero(m_splineXMin[i]);
00267     fill_zero(m_splineXMax[i]);
00268     fill_zero(m_splineYMin[i]);
00269     fill_zero(m_splineYMax[i]);
00270   }
00271 }

StatusCode CalibItemMgr::evalSpline const int  calibType,
const CalUtil::LATWideIndex  idx,
const float  x,
float &  y
[protected]
 

generic spline evaluation f() works for any calib_type

Definition at line 138 of file CalibItemMgr.cxx.

References m_calibPath, m_ccsShared, CalCalibShared::m_service, m_splineLists, m_splineXMax, m_splineXMin, and updateCalib().

Referenced by IntNonlinMgr::evalADC(), AsymMgr::evalAsym(), IntNonlinMgr::evalCIDAC(), and AsymMgr::evalPos().

00139                                                        {
00140   StatusCode sc;
00141 
00142   // make sure we have valid calib data for this event.
00143   sc = updateCalib();
00144   if (sc.isFailure()) return sc;
00145 
00146   // check that we have a spline for this particular xtal
00147   // (i.e. when LAT is not fully populated)
00148   TSpline3 const*const spline = m_splineLists[calibType][idx];
00149   if (!spline) {
00150     ostringstream msg;
00151     MsgStream msglog(m_ccsShared.m_service->msgSvc(), m_ccsShared.m_service->name()); 
00152     msglog << MSG::VERBOSE 
00153            << "No spline data found for " << m_calibPath 
00154            << " xtal=" << idx.val()
00155            << endreq;
00156 
00157     return StatusCode::FAILURE;
00158   }
00159 
00160   // bounds check input to spline function to avoid
00161   // weird behavior
00162   x = max<float>(m_splineXMin[calibType][idx],x);
00163   x = min<float>(m_splineXMax[calibType][idx],x);
00164 
00165   y = spline->Eval(x);
00166 
00167 #if 0
00168   //-- USEFUL FOR DEBUGGING SPLINE BEHAVIOR --//
00169   // create MsgStream only when needed (for performance)
00170   if (spline->GetName()[0] != 'a') {
00171 
00172     MsgStream msglog(m_ccsShared.m_service->msgSvc(), m_ccsShared.m_service->name()); 
00173     msglog << MSG::VERBOSE << "Evaluating spline: "
00174            << spline->GetName()
00175            << " idx=" << idx.val()
00176            << " X=" << x
00177            << " Y=" << y;
00178     if (y != 0)
00179       msglog << " x/y=" << x/y;
00180     msglog << endreq;
00181     const unsigned nKnots = spline->GetNp();
00182     for (unsigned nPt = 0 ; nPt < nKnots; nPt++) {
00184       double x,y,b,c,d;
00185       spline->GetCoeff(nPt,x,y,b,c,d);
00186       msglog << MSG::VERBOSE
00187              << "spline coeff x=" << x
00188              << " y=" << y
00189              << " b=" << b
00190              << " c=" << c
00191              << " d=" << d
00192              << endreq;
00193     }
00194   }
00195 #endif
00196 
00197   
00198   return StatusCode::SUCCESS;
00199 }

virtual StatusCode CalibItemMgr::genLocalStore  )  [protected, pure virtual]
 

generate full set of spline f()'s or other local data (if applicable for calib_type)

Implemented in AsymMgr, IntNonlinMgr, MPDMgr, PedMgr, and TholdCIMgr.

Referenced by initialize(), and updateCalib().

StatusCode CalibItemMgr::genSpline const int  calibType,
const CalUtil::LATWideIndex  idx,
const std::string &  name,
const std::vector< float > &  x,
const std::vector< float > &  y
[protected]
 

generate new spline from 2 STL vecs & insert into appropriate splineList

Definition at line 201 of file CalibItemMgr.cxx.

References m_ccsShared, CalCalibShared::m_service, m_splineLists, m_splineXMax, m_splineXMin, m_splineYMax, and m_splineYMin.

Referenced by IntNonlinMgr::genLocalStore(), and AsymMgr::genLocalStore().

00202                                                                                    {
00203 
00204   int n = min(x.size(),y.size());
00205 
00206   // create tmp arrays for TSpline ctor
00207   double *const xp = new double[n];
00208   double *const yp = new double[n];
00209 
00210   // copy vector data into temp arrays
00211   copy(x.begin(),x.begin()+n,xp);
00212   copy(y.begin(),y.begin()+n,yp);
00213 
00214 
00215   auto_ptr<TSpline3> mySpline(new TSpline3(name.c_str(),
00216                                            xp,yp,n));
00217   mySpline->SetName(name.c_str());
00218 
00219 #if 0
00220   //-- USEFUL FOR DEBUGGING SPLINE BEHAVIOR --//
00221   // create MsgStream only when needed (for performance)
00222   MsgStream msglog(m_ccsShared.m_service->msgSvc(), m_ccsShared.m_service->name()); 
00223   msglog << MSG::VERBOSE << "Generating spline: "
00224          << mySpline->GetName()
00225          << " " << mySpline.get()
00226          << " idx=" << idx.val();
00227   for (int i = 0; i < n; i++) {
00228     msglog << "\tX=" << xp[i]
00229            << " Y=" << yp[i];
00230     if (xp[i] != 0)                                                          
00231       msglog << "\t" << yp[i] / xp[i];
00232   }
00233   msglog << endreq;
00234 #endif
00235 
00236   
00237   // put spline in list
00238   m_splineLists[calibType][idx] = mySpline.release();
00239   // populate x-axis boundaries
00240   m_splineXMin[calibType][idx] = xp[0];
00241   m_splineXMax[calibType][idx] = xp[n-1];
00242   // populate y-axis boundaries
00243   m_splineYMin[calibType][idx] = yp[0];
00244   m_splineYMax[calibType][idx] = yp[n-1];
00245 
00246 
00247   // clear heap variables
00248   delete [] xp;
00249   delete [] yp;
00250   
00251   return StatusCode::SUCCESS;
00252 }

const CalibData::RangeBase* CalibItemMgr::getRangeBase const idents::CalXtalId  xtalId  )  [inline, protected]
 

retrieve spec'd rangeBase object, update if necessary

Returns:
NULL if there is no data

Definition at line 139 of file CalibItemMgr.h.

References m_calibBase.

Referenced by TholdCIMgr::genLocalStore(), PedMgr::genLocalStore(), MPDMgr::genLocalStore(), IntNonlinMgr::genLocalStore(), and AsymMgr::genLocalStore().

00139                                                                        {
00140     return m_calibBase->getRange(xtalId);
00141   }

int CalibItemMgr::getSerNo  )  [inline]
 

return serial # for current calib data return calibration data serial number from CalibSvc, or SERNO_IDEAL, SERNO_NODATA

Definition at line 76 of file CalibItemMgr.h.

References m_serNo.

Referenced by CalCalibSvc::getSerNoAsym(), CalCalibSvc::getSerNoINL(), CalCalibSvc::getSerNoMPD(), CalCalibSvc::getSerNoPed(), and CalCalibSvc::getSerNoTholdCI().

00076 {return m_serNo;}

StatusCode CalibItemMgr::initialize const std::string &  flavor  )  [virtual]
 

initialization code which must be done during Gaudi init() period

some data is not available at construction time

Definition at line 52 of file CalibItemMgr.cxx.

References genLocalStore(), loadIdealVals(), m_calibItem, m_calibPath, CalCalibShared::m_calibPathSvc, m_ccsShared, m_flavor, m_idealMode, m_serNo, CalCalibShared::m_service, and SERNO_IDEAL.

Referenced by CalCalibSvc::initialize(), and AsymMgr::initialize().

00052                                                         {
00053   StatusCode sc;
00054 
00055   m_flavor = flavor;
00056 
00057   m_calibPath = m_ccsShared.m_calibPathSvc->getCalibPath(m_calibItem, flavor);
00058   
00059   sc = loadIdealVals();
00060   if (sc.isFailure()) return sc;
00061 
00062   //-- IDEAL MODE --//
00063   if (m_flavor == "ideal") {
00064     m_idealMode = true;
00065 
00066     // localstore will not be automatically 
00067     // generated by standard code b/c we are circumventing it.
00068     // so we have to call this ourselves.
00069     // it's a hack, but so be it.
00070     sc = genLocalStore();
00071     if (sc.isFailure()) return sc;
00072 
00073     // create MsgStream only when needed (for performance)
00074     MsgStream msglog(m_ccsShared.m_service->msgSvc(), m_ccsShared.m_service->name()); 
00075     msglog << MSG::INFO << m_calibPath << " Overriding CalibSvc with ideal calibrations." << endreq;
00076 
00077     m_serNo = SERNO_IDEAL;
00078   }
00079 
00080   return StatusCode::SUCCESS;
00081 }

void CalibItemMgr::invalidate  )  [inline]
 

data should be invalidated at beginning of each event.

just in case there is a change in validity period

Definition at line 72 of file CalibItemMgr.h.

References m_isValid.

Referenced by CalCalibSvc::handle().

00072 {m_isValid = false;} 

virtual StatusCode CalibItemMgr::loadIdealVals  )  [protected, pure virtual]
 

load ideal (fake) calibration vals for my calib_type if db is down

Implemented in AsymMgr, IntNonlinMgr, MPDMgr, PedMgr, and TholdCIMgr.

Referenced by initialize().

StatusCode CalibItemMgr::updateCalib  )  [protected, virtual]
 

check calib validity period, (re)build local store if necessary

needs to be called once per event (_before_ processing calibration data ;). Subsequent calls in same event will return immediately.

Definition at line 83 of file CalibItemMgr.cxx.

References clearLocalStore(), genLocalStore(), m_calibBase, m_calibPath, m_ccsShared, CalCalibShared::m_dataProviderSvc, m_idealMode, m_isValid, m_serNo, and CalCalibShared::m_service.

Referenced by evalSpline(), AsymMgr::getAsym(), AsymMgr::getAsymCtr(), IntNonlinMgr::getInlAdc(), IntNonlinMgr::getInlCIDAC(), MPDMgr::getMPD(), PedMgr::getPed(), TholdCIMgr::getTholdCI(), and AsymMgr::getXpos().

00083                                      {
00084   StatusCode sc;
00085 
00086   // ideal mode never requires update, is never invalid
00087   if (m_idealMode) return StatusCode::SUCCESS;
00088   
00089   // if event is already validated return quickly
00090   if (m_isValid) return StatusCode::SUCCESS;
00091 
00093   //-- CHECK TDS DATA VALIDITY --//
00095 
00096   // Get pointer to Gain tree from TDS
00097   // usually this f() should return immediately
00098   // if it fails then we have no valid calib data
00099   // for the current event.
00100   DataObject *pObject;
00101   sc = m_ccsShared.m_dataProviderSvc->retrieveObject(m_calibPath, pObject);
00102   if (!sc.isFailure())
00103     m_calibBase = (CalibData::CalCalibBase *)(pObject);
00104   else {
00105     // create MsgStream only when needed (for performance)
00106     MsgStream msglog(m_ccsShared.m_service->msgSvc(), m_ccsShared.m_service->name()); 
00107     
00108     // else return error (can't find calib)
00109     msglog << MSG::ERROR << "can't get " 
00110            << m_calibPath << " from calib db" << endreq;
00111     return sc;  
00112   }
00113 
00115   //-- CHECK IF TDS DATA HAS CHANGED --//
00117 
00118   // check serial # to see if we're still valid.
00119   int curSerNo = m_calibBase->getSerNo();
00120   if (curSerNo != m_serNo) {
00121     // create MsgStream only when needed (for performance)
00122     MsgStream msglog(m_ccsShared.m_service->msgSvc(), m_ccsShared.m_service->name()); 
00123     msglog << MSG::INFO << "Updating " << m_calibPath << endreq;
00124     m_serNo = curSerNo;
00125     clearLocalStore();
00126         
00127     // generate local data (e.g. splines) if needed
00128     sc = genLocalStore();
00129     if (sc.isFailure()) return sc;
00130   }
00131 
00132   // reset 'in update' flag
00133   m_isValid = true;
00134 
00135   return StatusCode::SUCCESS;
00136 }


Member Data Documentation

CalibData::CalCalibBase* CalibItemMgr::m_calibBase [protected]
 

TDS location for root of my calib_type and path.

Definition at line 114 of file CalibItemMgr.h.

Referenced by CalibItemMgr(), IntNonlinMgr::genLocalStore(), getRangeBase(), AsymMgr::getXpos(), and updateCalib().

const ICalibPathSvc::CalibItem CalibItemMgr::m_calibItem [protected]
 

used for generate calib path

Definition at line 108 of file CalibItemMgr.h.

Referenced by CalibItemMgr(), and initialize().

std::string CalibItemMgr::m_calibPath [protected]
 

TDS path to calib data for my calib_type and path.

Definition at line 111 of file CalibItemMgr.h.

Referenced by evalSpline(), initialize(), updateCalib(), TholdCIMgr::validateRangeBase(), and AsymMgr::validateRangeBase().

const CalCalibShared& CalibItemMgr::m_ccsShared [protected]
 

ref to data shared by all classes used by CalibDataSvc

Definition at line 117 of file CalibItemMgr.h.

Referenced by CalibItemMgr(), evalSpline(), IntNonlinMgr::genLocalStore(), genSpline(), initialize(), AsymMgr::initialize(), TholdCIMgr::loadIdealVals(), PedMgr::loadIdealVals(), MPDMgr::loadIdealVals(), IntNonlinMgr::loadIdealVals(), AsymMgr::loadIdealVals(), updateCalib(), TholdCIMgr::validateRangeBase(), and AsymMgr::validateRangeBase().

std::string CalibItemMgr::m_flavor [private]
 

calib flavor

Definition at line 153 of file CalibItemMgr.h.

Referenced by initialize().

bool CalibItemMgr::m_idealMode [protected]
 

boolean if we're in ideal 'fake' mode

Definition at line 120 of file CalibItemMgr.h.

Referenced by CalibItemMgr(), TholdCIMgr::genLocalStore(), PedMgr::genLocalStore(), MPDMgr::genLocalStore(), IntNonlinMgr::genLocalStore(), AsymMgr::genLocalStore(), AsymMgr::getXpos(), initialize(), and updateCalib().

bool CalibItemMgr::m_isValid [private]
 

validity state of CalibItemMgr data

Definition at line 155 of file CalibItemMgr.h.

Referenced by CalibItemMgr(), invalidate(), and updateCalib().

CalUtil::CalVec<CalUtil::LATWideIndex, const CalibData::RangeBase* > CalibItemMgr::m_rngBases [protected]
 

pointers to each data member for my calib_type

Definition at line 134 of file CalibItemMgr.h.

Referenced by CalibItemMgr(), clearLocalStore(), TholdCIMgr::genLocalStore(), PedMgr::genLocalStore(), MPDMgr::genLocalStore(), IntNonlinMgr::genLocalStore(), AsymMgr::genLocalStore(), AsymMgr::getAsym(), AsymMgr::getAsymCtr(), IntNonlinMgr::getInlAdc(), MPDMgr::getMPD(), PedMgr::getPed(), and TholdCIMgr::getTholdCI().

int CalibItemMgr::m_serNo [private]
 

serial # for current calibration source may be set to SERNO_IDEAL, or SERNO_NODATA

Definition at line 159 of file CalibItemMgr.h.

Referenced by CalibItemMgr(), getSerNo(), initialize(), and updateCalib().

std::vector<CalUtil::CalVec<CalUtil::LATWideIndex, TSpline3* > > CalibItemMgr::m_splineLists [protected]
 

2d vector of all (optional) splines in local data store

Definition at line 123 of file CalibItemMgr.h.

Referenced by CalibItemMgr(), clearLocalStore(), evalSpline(), and genSpline().

std::vector<CalUtil::CalVec<CalUtil::LATWideIndex, float> > CalibItemMgr::m_splineXMax [protected]
 

max X val for each (optional) spline in local data store

Definition at line 127 of file CalibItemMgr.h.

Referenced by CalibItemMgr(), clearLocalStore(), evalSpline(), and genSpline().

std::vector<CalUtil::CalVec<CalUtil::LATWideIndex, float> > CalibItemMgr::m_splineXMin [protected]
 

min X val for each (optional) spline in local data store

Definition at line 125 of file CalibItemMgr.h.

Referenced by CalibItemMgr(), clearLocalStore(), evalSpline(), and genSpline().

std::vector<CalUtil::CalVec<CalUtil::LATWideIndex, float> > CalibItemMgr::m_splineYMax [protected]
 

max Y val for each (optional) spline in local data store

Definition at line 131 of file CalibItemMgr.h.

Referenced by CalibItemMgr(), clearLocalStore(), IntNonlinMgr::evalADC(), IntNonlinMgr::evalCIDAC(), and genSpline().

std::vector<CalUtil::CalVec<CalUtil::LATWideIndex, float> > CalibItemMgr::m_splineYMin [protected]
 

min Y val for each (optional) spline in local data store

Definition at line 129 of file CalibItemMgr.h.

Referenced by CalibItemMgr(), clearLocalStore(), and genSpline().

const int CalibItemMgr::SERNO_IDEAL = 1 [static, protected]
 

m_serNo has this value when ideal mode data has been loaded

Definition at line 146 of file CalibItemMgr.h.

Referenced by initialize().

const int CalibItemMgr::SERNO_NODATA = -1 [static, protected]
 

m_serNo has this value when data has not yet been loaded

Definition at line 144 of file CalibItemMgr.h.

Referenced by CalibItemMgr().


The documentation for this class was generated from the following files:
Generated on Wed Nov 26 20:29:23 2008 by doxygen 1.3.3