Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

RootMdcCalibDataCnv Class Reference

#include <RootMdcCalibDataCnv.h>

Inheritance diagram for RootMdcCalibDataCnv:

RootCalBaseCnv Converter< Ty1, Ty2 > List of all members.

Public Types

typedef Ty2 destination
typedef Ty2 destination
typedef Ty1 source
typedef Ty1 source

Public Member Functions

virtual StatusCode createObj (IOpaqueAddress *addr, DataObject *&refpObject)
virtual StatusCode createRoot (const std::string &fname, CalibData::CalibBase1 *pTDSObj)
virtual StatusCode finalize ()
ICalibRootSvcgetCalibRootSvc ()
virtual StatusCode initialize ()
const CLID & objType () const
destinationoperator (const source &) const
destinationoperator (const source &) const
virtual StatusCode readRootObj (TTree *tree, const std::string &branch, TObject *&pCalib, unsigned index=0)
virtual StatusCode readRootObj (const std::string &treename, const std::string &branch, TObject *&pCalib, unsigned index=0)
virtual long repSvcType () const
 RootMdcCalibDataCnv (ISvcLocator *svc)
virtual ~RootMdcCalibDataCnv ()

Static Public Member Functions

const CLID & classID ()
const unsigned char storageType ()

Protected Member Functions

StatusCode closeRead ()
StatusCode closeWrite ()
virtual destinationconvert (const source &) const =0
virtual destinationconvert (const source &) const =0
virtual StatusCode fillRoot (CalibData::CalibBase *pTDSObj, TObject *pRootObj)
virtual StatusCode i_createObj (const std::string &fname, DataObject *&refpObject)
virtual StatusCode i_processObj (DataObject *pObject, IOpaqueAddress *address)
 In case there is additional work to do on the created object.
virtual StatusCode internalCreateObj (const std::string &fname, DataObject *&refpObject, IOpaqueAddress *address)
StatusCode openRead (const std::string &fname)
virtual StatusCode openWrite (const std::string &fname)
void setBaseInfo (CalibData::CalibBase1 *pObj)
 Another utility for derived classes to use.

Protected Attributes

TFile * m_inFile
IInstrumentNamem_instrSvc
ICalibMetaCnvSvcm_metaSvc
TFile * m_outFile
ICalibRootSvcm_rootSvc
int m_runfrm
int m_runto
TDirectory * m_saveDir
int m_serNo
TTree * m_ttree
ITime * m_vend
ITime * m_vstart

Friends

class CnvFactory<RootMdcCalibDataCnv>

Detailed Description

Base class for CAL calibration converters from ROOT files to TCDS. All such converters need to do certain things, which are handled here. Methods common to *all* calibrations are in the base class RootCalBaseCnv

Author:
J. Bogart


Member Typedef Documentation

template<class Ty1, class Ty2>
typedef Ty2 Converter< Ty1, Ty2 >::destination [inherited]
 

template<class Ty1, class Ty2>
typedef Ty2 Converter< Ty1, Ty2 >::destination [inherited]
 

template<class Ty1, class Ty2>
typedef Ty1 Converter< Ty1, Ty2 >::source [inherited]
 

template<class Ty1, class Ty2>
typedef Ty1 Converter< Ty1, Ty2 >::source [inherited]
 


Constructor & Destructor Documentation

RootMdcCalibDataCnv::RootMdcCalibDataCnv ISvcLocator *  svc  ) 
 

00032                                                           :
00033   RootCalBaseCnv(svc, CLID_Calib_MdcCal) { 
00034 
00035 }

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

00030 {};


Member Function Documentation

const CLID & RootMdcCalibDataCnv::classID  )  [static]
 

00042                                          {
00043   return CLID_Calib_MdcCal;
00044 }

StatusCode RootCalBaseCnv::closeRead  )  [protected, inherited]
 

Clean up when we've finished reading in

00132                                      {
00133   m_inFile->Close();
00134 
00135   delete m_inFile;
00136   m_inFile = 0;
00137 
00138   if (m_saveDir) {
00139     m_saveDir->cd();
00140     m_saveDir = 0;
00141   }
00142   return StatusCode::SUCCESS;
00143 }

StatusCode RootCalBaseCnv::closeWrite  )  [protected, inherited]
 

Finish up writing file opened with openWrite: fill the tree write the file close the file Delete TFile (causes associated Tree to be deleted)

00179                                       {
00180 
00181   MsgStream log(msgSvc(), "RootCalBaseCnv");
00182 
00183   StatusCode ret = StatusCode::SUCCESS;
00184 
00185   m_outFile->cd();
00186   m_outFile->Close();
00187   delete m_outFile;
00188   m_outFile = 0;
00189   if (m_saveDir) m_saveDir->cd();
00190   m_saveDir = 0;
00191   return ret;
00192 }

template<class Ty1, class Ty2>
virtual destination* Converter< Ty1, Ty2 >::convert const source  )  const [protected, pure virtual, inherited]
 

template<class Ty1, class Ty2>
virtual destination* Converter< Ty1, Ty2 >::convert const source  )  const [protected, pure virtual, inherited]
 

StatusCode RootCalBaseCnv::createObj IOpaqueAddress *  addr,
DataObject *&  refpObject
[virtual, inherited]
 

Create the transient representation of an object, given an opaque address. This and the following update method comprise the core functionality of calibration converters.

00250                                                            {
00251   //  StatusCode ret;
00252 
00253   // first do the things we always need:
00254   //   First string parameter of opaque address is file ident
00255   MsgStream log(msgSvc(), "RootCalBaseCnv");
00256    log << MSG::DEBUG<<"RootCalBaseCnv::createObj( starting ...."<<endreq;
00257    const std::string* par = addr->par();
00258 
00259   std::string par0 = par[0];
00260    
00261   return internalCreateObj(par0, refpObject, addr);
00262 
00263 }

StatusCode RootMdcCalibDataCnv::createRoot const std::string &  fname,
CalibData::CalibBase1 pTDSObj
[virtual]
 

Create ROOT file corresponding to TDS object input. Default implementation is to return an error. Must be separately implemented for each calibration type.

Parameters:
fname Filename for output file
pTDSObj Pointer to tds object to be converted

Reimplemented from RootCalBaseCnv.

00115                                                                       {
00116  
00117   MsgStream log(msgSvc(), "RootMdcCalibDataCnv");
00118  // Open the file, create the branch
00119    StatusCode sc = openWrite(fname);
00120   if(!sc)
00121     { log<<MSG::ERROR<<"unable to open files"<<endreq;
00122     }
00123   // write the Data in the TCDS to RootFile
00124   CalibData::MdcCalibData* tmpObject = dynamic_cast<CalibData::MdcCalibData*>(pTDSObj);
00125      int tmpNo;
00126      int key;
00127      double xtpar;
00128      double t0;
00129      double delt0;
00130      double qtpar[2];
00131      double sdpar;
00132      int i;
00133   
00134      //xttree------------------------------------------------------------------
00135      TTree *xttree = new TTree("XtTree", "XtTree");
00136      xttree -> Branch("xtkey", &key, "key/I");
00137      xttree -> Branch("xtpar", &xtpar, "xtpar/D");
00138      tmpObject -> setXtBegin();
00139      while( tmpObject -> getNextXtpar(key, xtpar) ){
00140           xttree -> Fill();
00141              }
00142     
00143      //t0tree-------------------------------------------------------------------
00144      TTree *t0tree = new TTree("T0Tree", "T0Tree");
00145      t0tree -> Branch("t0", &t0, "t0/D");
00146      t0tree -> Branch("delt0", &delt0, "delt0/D");
00147      tmpNo = tmpObject -> gett0No();
00148      for(i=0; i<tmpNo; i++){
00149           t0 = tmpObject -> getT0(i);
00150           delt0 = tmpObject -> getDelT0(i);
00151           t0tree -> Fill();
00152      }
00153 
00154      //qttree--------------------------------------------------------------------
00155      TTree *qttree = new TTree("QtTree", "QtTree");
00156      qttree -> Branch("qtpar0", &(qtpar[0]), "qtpar0/D");
00157      qttree -> Branch("qtpar1", &(qtpar[1]), "qtpar1/D");
00158      tmpNo = tmpObject -> getqtparNo();
00159      for(i=0; i<tmpNo; i++){
00160           qtpar[0] =  tmpObject -> getQtpar0(i);
00161           qtpar[1] =  tmpObject -> getQtpar1(i);
00162           qttree -> Fill();
00163      }
00164      
00165      //sdtree--------------------------------------------------------------------
00166      TTree *sdtree = new TTree("SdTree", "SdTree");
00167      sdtree -> Branch("sdkey", &key, "key/I");
00168      sdtree -> Branch("sdpar", &sdpar, "sdpar/D");
00169      tmpObject -> setSdBegin();
00170      while( tmpObject -> getNextSdpar(key, sdpar) ){
00171                sdtree -> Fill();
00172       }
00173      
00174      xttree -> Write();
00175      t0tree -> Write();
00176      qttree -> Write();
00177      sdtree -> Write();
00178    
00179      delete xttree;
00180      delete t0tree;
00181      delete qttree;
00182      delete sdtree;
00183   
00184      closeWrite();
00185      log<<MSG::INFO<<"successfully create RootFile"<<endreq;
00186      return sc;
00187 }

StatusCode RootCalBaseCnv::fillRoot CalibData::CalibBase pTDSObj,
TObject *  pRootObj
[protected, virtual, inherited]
 

Given a pointer to a TDS object which can be cast to "our" type, fill in corresponding information in the corresponding root class

Parameters:
pTDSObj Pointer to tds object to be converted
pRootObj Pointer to destination root object
...maybe don't need pRootObj argument; keep this as the (protected) data member m_rootObj. Or else this routine could set the protected member to this passed-in value
00239                                                           {
00240 
00241   // Get instrument name from InstrumentName service  Now handled by 
00242   // RootCalBaseCnv
00243   //  TString instr = TString((m_instrSvc->getInstrumentName()).c_str());
00244   //  pRootObj->setInstrument(instr);
00245   return StatusCode::SUCCESS;
00246 }

StatusCode RootCalBaseCnv::finalize  )  [virtual, inherited]
 

00079                                     {
00080   return Converter::finalize();
00081 }

ICalibRootSvc* RootCalBaseCnv::getCalibRootSvc  )  [inline, inherited]
 

00058                                    {
00059     return m_rootSvc;
00060   }

StatusCode RootMdcCalibDataCnv::i_createObj const std::string &  fname,
DataObject *&  refpObject
[protected, virtual]
 

This creates the transient representation of an object from the corresponding ROOT object. This actually does the "new" operation and deals with the attributes of the node. This base class implementation does nothing; it should not normally be called because it doesn't correspond to any TCDS class. Instead, i_createObj of some derived class will be called.

Parameters:
fname The ROOT file to be read in to be used to builds the object
refpObject the object to be built
Returns:
status depending on the completion of the call

Reimplemented from RootCalBaseCnv.

00047                                                                 {
00048 
00049   MsgStream log(msgSvc(), "RootMdcCalibDataCnv");
00050   log<<MSG::DEBUG<<"SetProperty"<<endreq;
00051  
00052   StatusCode sc = openRead(fname);
00053   if(!sc)
00054     { log<<MSG::ERROR<<"unable to open files"<<endreq;
00055     }
00056  
00057   CalibData::MdcCalibData *tmpObject = new CalibData::MdcCalibData ;
00058   // Read in our object
00059   int i;
00060   int nentries;
00061   // read xttree ------------------------------------------------------------
00062      double xtpar;
00063      int  xtkey;
00064      TTree *xttree = (TTree*)m_inFile -> Get("XtTree");
00065      xttree -> SetBranchAddress("xtpar", &xtpar);
00066      xttree -> SetBranchAddress("xtkey", &xtkey);
00067      nentries = xttree -> GetEntries();
00068      for(i=0; i<nentries; i++){
00069            xttree -> GetEntry(i);
00070            tmpObject -> setXtpar(xtkey,xtpar);
00071      }
00072 // read t0tree ------------------------------------------------------------
00073      double t0;
00074      double delt0;
00075      TTree *t0tree = (TTree*)m_inFile -> Get("T0Tree");
00076      t0tree -> SetBranchAddress("t0", &t0);
00077      t0tree -> SetBranchAddress("delt0", &delt0);
00078      nentries = t0tree -> GetEntries();
00079      for(i=0; i<nentries; i++){
00080            t0tree -> GetEntry(i);
00081            tmpObject -> setT0(t0);
00082            tmpObject -> setDelT0(delt0);
00083      }
00084 // read qttree ------------------------------------------------------------
00085      double qtpar0;
00086      double qtpar1;
00087      TTree *qttree = (TTree*)m_inFile -> Get("QtTree");
00088      qttree -> SetBranchAddress("qtpar0", &qtpar0);
00089      qttree -> SetBranchAddress("qtpar1", &qtpar1);
00090      nentries = qttree -> GetEntries();
00091      for(i=0; i<nentries; i++){
00092           qttree -> GetEntry(i);
00093           tmpObject -> setQtpar0(qtpar0);
00094           tmpObject -> setQtpar1(qtpar1);
00095       }
00096  
00097 // read Sdtree ---------------------------------------------------------
00098      double sdpar;
00099      int  sdkey;
00100      TTree *sdtree = (TTree*)m_inFile -> Get("SdTree");
00101      sdtree -> SetBranchAddress("sdpar", &sdpar);
00102      sdtree -> SetBranchAddress("sdkey", &sdkey);
00103      nentries = sdtree -> GetEntries();
00104 
00105      for(i=0; i<nentries; i++){
00106            sdtree -> GetEntry(i);
00107            tmpObject -> setSdpar(sdkey,sdpar);
00108      }
00109 
00110     refpObject=tmpObject;
00111   return StatusCode::SUCCESS;
00112 }

StatusCode RootCalBaseCnv::i_processObj DataObject *  pObject,
IOpaqueAddress *  address
[protected, virtual, inherited]
 

In case there is additional work to do on the created object.

00320                                                                       {
00321   return StatusCode::SUCCESS;
00322 }

StatusCode RootCalBaseCnv::initialize  )  [virtual, inherited]
 

00046                                       {
00047   StatusCode status = Converter::initialize();
00048 
00049   IDataProviderSvc* dp;
00050 
00051   // I guess the service names are assigned in jobOptions?
00052 
00053   serviceLocator()->getService ("CalibDataSvc",
00054                                 IID_IDataProviderSvc,
00055                                 (IInterface*&)dp);
00056   setDataProvider(dp);
00057   
00058   // Locate the Root Conversion Service
00059   serviceLocator()->getService ("CalibRootCnvSvc",
00060                                 IID_ICalibRootSvc,
00061                                 (IInterface*&) m_rootSvc);
00062 
00063   // Locate meta conversion service
00064   // Will anything need to be changed here to accommodate possibility
00065   // of two concrete implementations of ICalibMetaCnvSvc?  Would
00066   // have different storage types.  Could specify type desired
00067   // as job option.  Ditto for name of class?
00068   serviceLocator()->getService("CalibMySQLCnvSvc", 
00069                                IID_ICalibMetaCnvSvc,
00070                                 (IInterface*&)m_metaSvc);
00071 
00072   serviceLocator()->getService ("CalibDataSvc",
00073                                 IID_IInstrumentName,
00074                                 (IInterface*&)m_instrSvc);
00075 
00076   return status;
00077 }

StatusCode RootCalBaseCnv::internalCreateObj const std::string &  fname,
DataObject *&  refpObject,
IOpaqueAddress *  address
[protected, virtual, inherited]
 

This creates the transient representation of an object from the corresponding ROOT object it, then fills it and process it. This implementation actually only calls the i_* methods of the "right" converter to do the job; so the very first thing it does is get a pointer to the appropriate derived converter. Converters typically don't need to override this method but only to override/implement some of the i_* methods.

Parameters:
pRootObj pointer to the ROOT object
refpObject the object to be built
address the opaque address for this object
Returns:
status depending on the completion of the call
00267                                                                    {
00268   MsgStream log(msgSvc(), "RootCalBaseCnv");
00269    log << MSG::DEBUG<<"RootCalBaseCnv::internalCreateObj( starting ..... "<<endreq;
00270    RootCalBaseCnv* converter = this;
00271   CLID classId = address->clID();
00272 
00273   IConverter* conv = this->conversionSvc()->converter(classId);
00274   if (0 == conv) {
00275     log << MSG::WARNING
00276         << "No proper converter found for classID " << classId
00277             << ", the default converter"
00278             << " will be used. " << endreq;
00279   } else {
00280     converter = dynamic_cast <RootCalBaseCnv*> (conv);
00281     if (0 == converter) {
00282       log << MSG::ERROR
00283           << "The converter found for classID " << classId
00284               << " was not a descendent of RootCalBaseCnv as it should be "
00285               << "( was of type " << typeid (*converter).name() << "). "
00286               << "The default converter will be used" << endreq;
00287       converter = this;
00288     }
00289   }
00290 
00291     m_runfrm =*( address->ipar());
00292     m_runto =*( address->ipar()+1);
00293    // creates an object for the node found
00294    StatusCode sc = converter->i_createObj(fname, refpObject);
00295      if (sc.isFailure()) {
00296     return sc;
00297   } 
00298      CalibData::CalibBase1* tmpObject =  dynamic_cast <CalibData::CalibBase1*> (refpObject);
00299      setBaseInfo(tmpObject);
00300   // ends up the object construction
00301   sc = converter->i_processObj(refpObject, address);
00302   if (sc.isSuccess()) {
00303     log << MSG::DEBUG << "Successfully created calib. object " << endreq;
00304   }
00305   closeRead();
00306   return sc;
00307 }

const CLID & RootMdcCalibDataCnv::objType  )  const
 

00038                                                {
00039   return CLID_Calib_MdcCal;
00040 }

StatusCode RootCalBaseCnv::openRead const std::string &  fname  )  [protected, inherited]
 

Utility for "leaf" converters to call

Parameters:
Root file to open for read
Name of branch to be read in
ref. to pCalib pointer which will be set to address of read-in object
00095                                                           { 
00096 
00097   MsgStream log(msgSvc(), "RootCalBaseCnv");
00098 
00099   // Check fname isn't empty
00100   if (fname == std::string("")) return StatusCode::FAILURE;
00101 
00102   if (doClean() ) {
00103     log << MSG::WARNING << "Previous operation didn't clean up! " << endreq;
00104   }
00105   m_saveDir = gDirectory;
00106 
00107   std::string ourName(fname);
00108   facilities::Util::expandEnvVar(&ourName);
00109 
00110   m_inFile = new TFile(ourName.c_str());
00111   
00112   if (!m_inFile->IsOpen() ) {
00113     log << MSG::ERROR << "ROOT file " << ourName 
00114         << "could not be opened for reading " << endreq;
00115     delete m_inFile;
00116     m_inFile = 0;
00117     return StatusCode::FAILURE;
00118   }
00119   else {
00120     log << MSG::INFO
00121         << "Successfully opened ROOT file " << fname << " aka " << ourName
00122         << " for reading " << endreq;
00123   }
00124 
00125 
00126   m_inFile->cd();             //    Maybe will need this
00127 
00128 
00129   return StatusCode::SUCCESS;
00130 }

StatusCode RootCalBaseCnv::openWrite const std::string &  fname  )  [protected, virtual, inherited]
 

Utility used by derived converters to start writing a ROOT file (open TFile, make a TTree, give it a branch)

Parameters:
fname Name for new file
className Name of class for object specified in next parameter; used to name branch as well)
pCalib pointer to object used to create the branch
00145                                                            {
00146 
00147   MsgStream log(msgSvc(), "RootCalBaseCnv");
00148 
00149   // Check fname isn't empty
00150   if (fname == std::string("")) return StatusCode::FAILURE;
00151 
00152   std::string ourName(fname);
00153   facilities::Util::expandEnvVar(&ourName);
00154 
00155   if (doClean() ) {
00156     log << MSG::WARNING << "Previous operation didn't clean up! " << endreq;
00157   }
00158 
00159   m_saveDir = gDirectory;
00160 
00161  
00162   m_outFile = new TFile(ourName.c_str(), "RECREATE");
00163   if (!m_outFile->IsOpen()) {
00164     log << MSG::ERROR << "ROOT file " << fname << " aka " << ourName 
00165         << " could not be opened for writing" << endreq;
00166     delete m_outFile;
00167     m_outFile = 0;
00168     return StatusCode::FAILURE;
00169   }
00170   else {
00171     log << MSG::INFO
00172         << "Successfully opened ROOT file " << fname << " aka " << ourName
00173         << " for writing " << endreq;
00174   }
00175    m_outFile->cd();
00176   return StatusCode::SUCCESS;
00177 }

template<class Ty1, class Ty2>
destination* Converter< Ty1, Ty2 >::operator const source  )  const [inline, inherited]
 

template<class Ty1, class Ty2>
destination* Converter< Ty1, Ty2 >::operator const source  )  const [inline, inherited]
 

StatusCode RootCalBaseCnv::readRootObj TTree *  tree,
const std::string &  branch,
TObject *&  pCalib,
unsigned  index = 0
[virtual, inherited]
 

00205                                                                 {
00206   TBranch* pBranch=pTree->GetBranch(branch.c_str());
00207   pBranch->SetAddress(&pObj);
00208   int nBytes = pBranch->GetEntry(ix);
00209   return (nBytes > 0) ? StatusCode::SUCCESS : StatusCode::FAILURE;
00210  }

StatusCode RootCalBaseCnv::readRootObj const std::string &  treename,
const std::string &  branch,
TObject *&  pCalib,
unsigned  index = 0
[virtual, inherited]
 

Read in object (by default the first) from specified branch.

00197                                                                 {
00198   TTree* pTree = (TTree*)m_inFile->Get(treename.c_str());
00199 
00200   return readRootObj(pTree, branch, pObj, ix);
00201  }

virtual long RootMdcCalibDataCnv::repSvcType  )  const [inline, virtual]
 

00035                                   { 
00036           return CALIBROOT_StorageType; 
00037       } 

void RootCalBaseCnv::setBaseInfo CalibData::CalibBase1 pObj  )  [protected, inherited]
 

Another utility for derived classes to use.

Another convenience for derived classes: sets information belonging to the calibration base class, namely validity interval and serial number.

00325                                                           {
00326    MsgStream log(msgSvc(), "RootCalBaseCnv");
00327    log << MSG::DEBUG<<"set the runfrm and runto Numbers in the converter"<<endreq;
00328   pObj->setrunfrm(m_runfrm);
00329   pObj->setrunto(m_runto);
00330 }

const unsigned char RootCalBaseCnv::storageType  )  [inline, static, inherited]
 

00062 {return CALIBROOT_StorageType;}


Friends And Related Function Documentation

friend class CnvFactory<RootMdcCalibDataCnv> [friend]
 


Member Data Documentation

TFile* RootCalBaseCnv::m_inFile [protected, inherited]
 

IInstrumentName* RootCalBaseCnv::m_instrSvc [protected, inherited]
 

ICalibMetaCnvSvc* RootCalBaseCnv::m_metaSvc [protected, inherited]
 

TFile* RootCalBaseCnv::m_outFile [protected, inherited]
 

ICalibRootSvc* RootCalBaseCnv::m_rootSvc [protected, inherited]
 

int RootCalBaseCnv::m_runfrm [protected, inherited]
 

int RootCalBaseCnv::m_runto [protected, inherited]
 

TDirectory* RootCalBaseCnv::m_saveDir [protected, inherited]
 

int RootCalBaseCnv::m_serNo [protected, inherited]
 

TTree* RootCalBaseCnv::m_ttree [protected, inherited]
 

ITime* RootCalBaseCnv::m_vend [protected, inherited]
 

ITime* RootCalBaseCnv::m_vstart [protected, inherited]
 


The documentation for this class was generated from the following files:
Generated on Wed Feb 2 18:48:57 2011 for BOSS6.5.5 by  doxygen 1.3.9.1