#include <RootDedxSimDataCnv.h>
Inheritance diagram for RootDedxSimDataCnv:
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 () |
ICalibRootSvc * | getCalibRootSvc () |
virtual StatusCode | initialize () |
const CLID & | objType () const |
destination * | operator (const source &) const |
destination * | operator (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 |
RootDedxSimDataCnv (ISvcLocator *svc) | |
virtual | ~RootDedxSimDataCnv () |
Static Public Member Functions | |
const CLID & | classID () |
const unsigned char | storageType () |
Protected Member Functions | |
StatusCode | closeRead () |
StatusCode | closeWrite () |
virtual destination * | convert (const source &) const =0 |
virtual destination * | convert (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 |
IInstrumentName * | m_instrSvc |
ICalibMetaCnvSvc * | m_metaSvc |
TFile * | m_outFile |
ICalibRootSvc * | m_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<RootDedxSimDataCnv> |
|
|
|
|
|
|
|
|
|
00034 : 00035 RootCalBaseCnv(svc, CLID_Dedx_Sim) { 00036 }
|
|
00026 {};
|
|
00043 {
00044 return CLID_Dedx_Sim;
00045 }
|
|
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 }
|
|
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 }
|
|
|
|
|
|
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 }
|
|
Create ROOT file corresponding to TDS object input. Default implementation is to return an error. Must be separately implemented for each calibration type.
Reimplemented from RootCalBaseCnv. 00102 { 00103 MsgStream log(msgSvc(), "RootDedxSimDataCnv"); 00104 00105 // Open the file, create the branch 00106 StatusCode sc = openWrite(fname); 00107 if(!sc) 00108 { log<<MSG::ERROR<<"unable to open files"<<endreq; 00109 } 00110 // write the Data in the TCDS to RootFile 00111 /* int i; 00112 int j; 00113 CalibData::TofCalibData* btof = dynamic_cast<CalibData::TofCalibData*>(pTDSObj); 00114 00115 // write btoftree---------------------------------------------------------------- 00116 double cnvP1[10]; 00117 double cnvP2[10]; 00118 double cnvW[4]; 00119 double cnvAtten[8]; 00120 double cnvQ; 00121 double cnvSpeed[2]; 00122 TTree *btoftree = new TTree("BarTofPar", "BarTofPar"); 00123 btoftree -> Branch("Atten0",&cnvAtten[0], "Atten0/D"); 00124 btoftree -> Branch("Atten1",&cnvAtten[1], "Atten1/D"); 00125 btoftree -> Branch("Atten2",&cnvAtten[2], "Atten2/D"); 00126 btoftree -> Branch("Atten3",&cnvAtten[3], "Atten3/D"); 00127 btoftree -> Branch("Atten4",&cnvAtten[4], "Atten4/D"); 00128 btoftree -> Branch("Atten5",&cnvAtten[5], "Atten5/D"); 00129 btoftree -> Branch("Atten6",&cnvAtten[6], "Atten6/D"); 00130 btoftree -> Branch("Atten7",&cnvAtten[7], "Atten7/D"); 00131 btoftree -> Branch("Q0",&cnvQ, "Q0/D"); 00132 btoftree -> Branch("Speed0",&cnvSpeed[0], "Speed0/D"); 00133 btoftree -> Branch("Speed1",&cnvSpeed[1], "Speed1/D"); 00134 btoftree -> Branch("P0",&cnvP1[0], "P0/D"); 00135 btoftree -> Branch("P1",&cnvP1[1], "P1/D"); 00136 btoftree -> Branch("P2",&cnvP1[2], "P2/D"); 00137 btoftree -> Branch("P3",&cnvP1[3], "P3/D"); 00138 btoftree -> Branch("P4",&cnvP1[4], "P4/D"); 00139 btoftree -> Branch("P5",&cnvP1[5], "P5/D"); 00140 btoftree -> Branch("P6",&cnvP1[6], "P6/D"); 00141 btoftree -> Branch("P7",&cnvP1[7], "P7/D"); 00142 btoftree -> Branch("P8",&cnvP1[8], "P8/D"); 00143 btoftree -> Branch("P9",&cnvP1[9], "P9/D"); 00144 btoftree -> Branch("P10",&cnvP2[0], "P10/D"); 00145 btoftree -> Branch("P11",&cnvP2[1], "P11/D"); 00146 btoftree -> Branch("P12",&cnvP2[2], "P12/D"); 00147 btoftree -> Branch("P13",&cnvP2[3], "P13/D"); 00148 btoftree -> Branch("P14",&cnvP2[4], "P14/D"); 00149 btoftree -> Branch("P15",&cnvP2[5], "P15/D"); 00150 btoftree -> Branch("P16",&cnvP2[6], "P16/D"); 00151 btoftree -> Branch("P17",&cnvP2[7], "P17/D"); 00152 btoftree -> Branch("P18",&cnvP2[8], "P17/D"); 00153 btoftree -> Branch("P19",&cnvP2[9], "P17/D"); 00154 btoftree -> Branch("W0",&cnvW[0], "W0/D"); 00155 btoftree -> Branch("W1",&cnvW[1], "W1/D"); 00156 btoftree -> Branch("W2",&cnvW[2], "W2/D"); 00157 btoftree -> Branch("W3",&cnvW[3], "W3/D"); 00158 00159 for(i=0; i<176; i++){ 00160 cnvAtten[0] = btof->getBTofAtten(i,0); 00161 cnvAtten[1] = btof->getBTofAtten(i,1); 00162 cnvAtten[2] = btof->getBTofAtten(i,2); 00163 cnvQ = btof->getBTofQ(i); 00164 cnvSpeed[0] = btof->getBTofSpeed(i,0); 00165 cnvSpeed[1] = btof->getBTofSpeed(i,1); 00166 for(j=0;j<10;j++){ 00167 cnvP1[j] = btof->getBTofPleft(i,j); 00168 cnvP2[j] = btof->getBTofPright(i,j); 00169 } 00170 for(j=0;j<4;j++){ 00171 cnvW[j]=btof->getBTofW(i,j); 00172 } 00173 btoftree -> Fill(); 00174 } 00175 00176 //write etoftree---------------------------------------------------------------- 00177 double ecnvP[8]; 00178 double ecnvAtten[5]; 00179 double ecnvSpeed[3]; 00180 TTree *etoftree = new TTree("EndTofPar", "EndTofPar"); 00181 etoftree -> Branch("Atten0",&ecnvAtten[0], "Atten0/D"); 00182 etoftree -> Branch("Atten1",&ecnvAtten[1], "Atten1/D"); 00183 etoftree -> Branch("Atten2",&ecnvAtten[2], "Atten2/D"); 00184 etoftree -> Branch("Atten3",&ecnvAtten[3], "Atten3/D"); 00185 etoftree -> Branch("Atten4",&ecnvAtten[4], "Atten4/D"); 00186 etoftree -> Branch("Speed0",&ecnvSpeed[0], "Speed0/D"); 00187 etoftree -> Branch("Speed1",&ecnvSpeed[1], "Speed1/D"); 00188 etoftree -> Branch("P0",&ecnvP[0], "P0/D"); 00189 etoftree -> Branch("P1",&ecnvP[1], "P1/D"); 00190 etoftree -> Branch("P2",&ecnvP[2], "P2/D"); 00191 etoftree -> Branch("P3",&ecnvP[3], "P3/D"); 00192 etoftree -> Branch("P4",&ecnvP[4], "P4/D"); 00193 etoftree -> Branch("P5",&ecnvP[5], "P5/D"); 00194 etoftree -> Branch("P6",&ecnvP[6], "P6/D"); 00195 etoftree -> Branch("P7",&ecnvP[7], "P7/D"); 00196 00197 for(i=0; i<96; i++){ 00198 ecnvAtten[0] = btof->getETofAtten(i,0); 00199 ecnvAtten[1] = btof->getETofAtten(i,1); 00200 ecnvAtten[2] = btof->getETofAtten(i,2); 00201 ecnvSpeed[0] = btof->getETofSpeed(i,0); 00202 ecnvSpeed[1] = btof->getETofSpeed(i,1); 00203 for(j=0;j<8;j++){ 00204 ecnvP[j] = btof->getETofP(i,j); 00205 } 00206 etoftree -> Fill(); 00207 } 00208 // write all the trees 00209 btoftree -> Write(); 00210 etoftree -> Write(); 00211 delete btoftree; 00212 delete etoftree; 00213 closeWrite(); 00214 log<<MSG::INFO<<"successfully create RootFile"<<endreq; 00215 */ 00216 return sc; 00217 00218 }
|
|
Given a pointer to a TDS object which can be cast to "our" type, fill in corresponding information in the corresponding root class
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 }
|
|
00079 {
00080 return Converter::finalize();
00081 }
|
|
00058 {
00059 return m_rootSvc;
00060 }
|
|
Read in object from specified branch. Don't need tree name; it's always Calib Reimplemented from RootCalBaseCnv. 00048 { 00049 00050 MsgStream log(msgSvc(), "RootDedxSimDataCnv"); 00051 log<<MSG::DEBUG<<"SetProperty"<<endreq; 00052 00053 CalibData::DedxSimData *tmpObject = new CalibData::DedxSimData ; 00054 00055 TH1F *h1=new TH1F(); 00056 // open the file 00057 StatusCode sc = openRead(fname); 00058 if(!sc) 00059 { 00060 log<<MSG::ERROR<<"unable to open files"<<endreq; 00061 } 00062 00063 std::vector<TH1F> hist; 00064 std::vector<double> hRange; 00065 // Read in the object 00066 int cnt; 00067 TTree *tree=(TTree*)m_inFile->Get("TH1F_Col"); 00068 tree->SetBranchAddress("TH1F_Col", &h1); 00069 int entries=tree->GetEntries(); 00070 for (cnt = 0; cnt < entries; cnt++) { 00071 tree -> GetEntry(cnt); 00072 gROOT->cd(); 00073 TH1F *h2=new TH1F(); 00074 h2=(TH1F*)h1->Clone(); 00075 hist.push_back(*h2); 00076 } 00077 // tmpObject->setHist(&hist); 00078 double betagamma[5000]; 00079 int totalNum; 00080 int bgNum; 00081 TTree* bin = (TTree*)m_inFile->Get("bin"); 00082 bin->SetBranchAddress("totalNum", &totalNum); 00083 bin->SetBranchAddress("betagamma", betagamma); 00084 bin->SetBranchAddress("betagammaBounds", &bgNum); 00085 bin->GetEntry(0); 00086 00087 //int tot=totalNum*2; 00088 for (cnt = 0; cnt < bgNum; cnt++) { 00089 hRange.push_back(betagamma[cnt]); 00090 } 00091 00092 tmpObject->setRangeNo(bgNum); 00093 tmpObject->setRange(&hRange); 00094 tmpObject->setHistNo(totalNum); 00095 tmpObject->setHist(&hist); 00096 refpObject = tmpObject; 00097 00098 return StatusCode::SUCCESS; 00099 }
|
|
In case there is additional work to do on the created object.
00320 {
00321 return StatusCode::SUCCESS;
00322 }
|
|
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 }
|
|
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.
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 }
|
|
00039 {
00040 return CLID_Dedx_Sim;
00041 }
|
|
Utility for "leaf" converters to call
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 }
|
|
Utility used by derived converters to start writing a ROOT file (open TFile, make a TTree, give it a 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 }
|
|
|
|
|
|
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 }
|
|
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 }
|
|
00031 {
00032 return CALIBROOT_StorageType;
00033 }
|
|
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 }
|
|
00062 {return CALIBROOT_StorageType;}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|