#include <digiRootWriterAlg.h>
Public Member Functions | |
digiRootWriterAlg (const std::string &name, ISvcLocator *pSvcLocator) | |
StatusCode | initialize () |
Handles setup by opening ROOT file in write mode and creating a new TTree. | |
StatusCode | execute () |
Orchastrates reading from TDS and writing to ROOT for each event. | |
StatusCode | finalize () |
Closes the ROOT file and cleans up. | |
Private Member Functions | |
StatusCode | writeDigiEvent () |
Retrieves event Id and run Id from TDS and fills the McEvent ROOT object. | |
StatusCode | writeMdcDigi () |
void | writeEvent () |
Calls TTree::Fill for each event and clears m_digiEvt. | |
void | close () |
Performs the final write to the ROOT file and closes. | |
Private Attributes | |
TFile * | m_digiFile |
ROOT file pointer. | |
TTree * | m_digiTree |
ROOT tree pointer. | |
DigiEvent * | m_digiEvt |
Top-level Monte Carlo ROOT object. | |
std::string | m_fileName |
name of the output ROOT file | |
std::string | m_treeName |
name of the TTree in the ROOT file | |
int | m_splitMode |
ROOT split mode. | |
int | m_bufSize |
Buffer Size for the ROOT file. | |
int | m_compressionLevel |
Compression level for the ROOT file. | |
int | m_autoSaveEvents |
auto save every events | |
commonData | m_common |
IRootIoSvc * | m_rootIoSvc |
Definition at line 31 of file digiRootWriterAlg.h.
digiRootWriterAlg::digiRootWriterAlg | ( | const std::string & | name, | |
ISvcLocator * | pSvcLocator | |||
) |
Definition at line 88 of file digiRootWriterAlg.h.
References m_autoSaveEvents, m_bufSize, m_compressionLevel, m_fileName, m_splitMode, and m_treeName.
00089 : 00090 Algorithm(name, pSvcLocator) 00091 { 00092 // Input parameters available to be set via the jobOptions file 00093 declareProperty("digiRootFile",m_fileName="digi.root"); 00094 declareProperty("splitMode", m_splitMode=1); 00095 declareProperty("bufferSize", m_bufSize=64000); 00096 declareProperty("compressionLevel", m_compressionLevel=1); 00097 //declareProperty("treeName", m_treeName="Digi"); 00098 declareProperty("treeName", m_treeName="Rec"); //wensp modified on 20050515 for test 00099 declareProperty("autoSave", m_autoSaveEvents=1000); 00100 00101 }
void digiRootWriterAlg::close | ( | ) | [private] |
Performs the final write to the ROOT file and closes.
Definition at line 247 of file digiRootWriterAlg.h.
References m_digiTree.
Referenced by finalize().
00248 { 00249 // Purpose and Method: Writes the ROOT file at the end of the run. 00250 // The TObject::kWriteDelete parameter is used in the Write method 00251 // replacing TObject::kOverwrite - supposed to be safer 00252 // since ROOT will periodically write to the ROOT file when the bufSize 00253 // is filled. Writing would create 2 copies of the same tree to be 00254 // stored in the ROOT file, if we did not specify kOverwrite. 00255 00256 TDirectory *saveDir = gDirectory; 00257 TFile *f = m_digiTree->GetCurrentFile(); 00258 //m_digiFile->cd(); 00259 f->cd(); 00260 m_digiTree->BuildIndex("m_runId", "m_eventId"); 00261 f->Write(0, TObject::kWriteDelete); 00262 f->Close(); 00263 saveDir->cd(); 00264 return; 00265 }
StatusCode digiRootWriterAlg::execute | ( | ) |
Orchastrates reading from TDS and writing to ROOT for each event.
Definition at line 143 of file digiRootWriterAlg.h.
References calibUtil::ERROR, m_digiEvt, m_digiFile, m_fileName, msgSvc(), writeDigiEvent(), writeEvent(), and writeMdcDigi().
00144 { 00145 // Purpose and Method: Called once per event. This method calls 00146 // the appropriate methods to read data from the TDS and write data 00147 // to the ROOT file. 00148 00149 MsgStream log(msgSvc(), name()); 00150 00151 StatusCode sc = StatusCode::SUCCESS; 00152 00153 if (!m_digiFile->IsOpen()) { 00154 log << MSG::ERROR << "ROOT file " << m_fileName 00155 << " could not be opened for writing." << endreq; 00156 return StatusCode::FAILURE; 00157 } 00158 00159 m_digiEvt->Clear(); 00160 00161 sc = writeDigiEvent(); 00162 if (sc.isFailure()) { 00163 log << MSG::ERROR << "Failed to write DigiEvent" << endreq; 00164 return sc; 00165 } 00166 00167 00168 sc = writeMdcDigi(); 00169 if (sc.isFailure()) { 00170 log << MSG::ERROR << "Failed to write Tkr Digi Collection" << endreq; 00171 return sc; 00172 } 00173 00174 writeEvent(); 00175 return sc; 00176 }
StatusCode digiRootWriterAlg::finalize | ( | ) |
Closes the ROOT file and cleans up.
Definition at line 267 of file digiRootWriterAlg.h.
References close().
00268 { 00269 close(); 00270 00271 StatusCode sc = StatusCode::SUCCESS; 00272 return sc; 00273 }
StatusCode digiRootWriterAlg::initialize | ( | ) |
Handles setup by opening ROOT file in write mode and creating a new TTree.
Definition at line 103 of file digiRootWriterAlg.h.
References calibUtil::ERROR, Bes_Common::INFO, m_bufSize, m_common, m_compressionLevel, m_digiEvt, m_digiFile, m_digiTree, m_fileName, m_rootIoSvc, m_splitMode, m_treeName, and msgSvc().
00104 { 00105 // Purpose and Method: Called once before the run begins. This method 00106 // opens a new ROOT file and prepares for writing. 00107 00108 StatusCode sc = StatusCode::SUCCESS; 00109 MsgStream log(msgSvc(), name()); 00110 00111 // Use the Job options service to set the Algorithm's parameters 00112 // This will retrieve parameters set in the job options file 00113 setProperties(); 00114 00115 if ( service("RootIoSvc", m_rootIoSvc, true).isFailure() ){ 00116 log << MSG::INFO << "Couldn't find the RootIoSvc!" << endreq; 00117 log << MSG::INFO << "No Auto Saving" << endreq; 00118 m_rootIoSvc = 0; 00119 } 00120 00121 facilities::Util::expandEnvVar(&m_fileName); 00122 00123 // Save the current directory for the ntuple writer service 00124 TDirectory *saveDir = gDirectory; 00125 // Create the new ROOT file 00126 m_digiFile = new TFile(m_fileName.c_str(), "RECREATE"); 00127 if (!m_digiFile->IsOpen()) { 00128 log << MSG::ERROR << "ROOT file " << m_fileName 00129 << " could not be opened for writing." << endreq; 00130 return StatusCode::FAILURE; 00131 } 00132 m_digiFile->cd(); 00133 m_digiFile->SetCompressionLevel(m_compressionLevel); 00134 m_digiTree = new TTree(m_treeName.c_str(), "Bes Digitization Data"); 00135 m_digiEvt = new DigiEvent(); 00136 m_common.m_digiEvt = m_digiEvt; 00137 m_digiTree->Branch("DigiEvent","DigiEvent", &m_digiEvt, m_bufSize, m_splitMode); 00138 saveDir->cd(); 00139 return sc; 00140 00141 }
StatusCode digiRootWriterAlg::writeDigiEvent | ( | ) | [private] |
Retrieves event Id and run Id from TDS and fills the McEvent ROOT object.
Definition at line 179 of file digiRootWriterAlg.h.
References DigiEvent::initialize(), m_digiEvt, and msgSvc().
Referenced by execute().
00179 { 00180 // Purpose and Method: Retrieve the Event object from the TDS and set the 00181 // event and run numbers in the DigiEvent ROOT object 00182 00183 MsgStream log(msgSvc(), name()); 00184 StatusCode sc = StatusCode::SUCCESS; 00185 00186 // Retrieve the Event data for this event 00187 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event"); 00188 if (!eventHeader) return sc; 00189 00190 Short_t runId = eventHeader->runNumber(); 00191 Short_t evtId = eventHeader->eventNumber(); 00192 Bool_t fromMc = true; 00193 00194 00195 m_digiEvt->initialize(evtId, runId, fromMc); 00196 // m_digiEvt->Print(); 00197 00198 return sc; 00199 }
void digiRootWriterAlg::writeEvent | ( | ) | [private] |
Calls TTree::Fill for each event and clears m_digiEvt.
Definition at line 229 of file digiRootWriterAlg.h.
References IRootIoSvc::getAutoSaveInterval(), m_digiTree, and m_rootIoSvc.
Referenced by execute().
00230 { 00231 // Purpose and Method: Stores the DigiEvent data for this event in the ROOT 00232 // tree. The m_digiEvt object is cleared for the next event. 00233 static int eventCounter = 0; 00234 TDirectory *saveDir = gDirectory; 00235 m_digiTree->GetCurrentFile()->cd(); 00236 //m_digiFile->cd(); 00237 m_digiTree->Fill(); 00238 //m_digiEvt->Clear(); 00239 saveDir->cd(); 00240 ++eventCounter; 00241 if (m_rootIoSvc) 00242 if (eventCounter % m_rootIoSvc->getAutoSaveInterval() == 0) m_digiTree->AutoSave(); 00243 00244 return; 00245 }
StatusCode digiRootWriterAlg::writeMdcDigi | ( | ) | [private] |
Retrieves TKR digitization data from the TDS and fills the TkrDigi ROOT collection
Definition at line 201 of file digiRootWriterAlg.h.
References TRawData::initialize(), m_common, m_digiEvt, commonData::m_mdcDigiMap, EventModel::Digi::MdcDigiCol, msgSvc(), and TMdcDigi::setOverflow().
Referenced by execute().
00201 { 00202 // Purpose and Method: Retrieve the TkrDigi collection from the TDS and set the 00203 // TkrDigi ROOT collection 00204 00205 MsgStream log(msgSvc(), name()); 00206 StatusCode sc = StatusCode::SUCCESS; 00207 00208 SmartDataPtr<MdcDigiCol> mdcDigiColTds(eventSvc(), EventModel::Digi::MdcDigiCol); 00209 if (!mdcDigiColTds) return sc; 00210 MdcDigiCol::const_iterator mdcDigiTds; 00211 00212 for (mdcDigiTds = mdcDigiColTds->begin(); mdcDigiTds != mdcDigiColTds->end(); mdcDigiTds++) { 00213 UInt_t overflow = (*mdcDigiTds)->getOverflow(); 00214 UInt_t time = (*mdcDigiTds)->getTimeChannel(); 00215 UInt_t charge = (*mdcDigiTds)->getChargeChannel(); 00216 UInt_t id = (*mdcDigiTds)->getIntId(); 00217 TMdcDigi *mdcDigiRoot = new TMdcDigi(); 00218 m_common.m_mdcDigiMap[(*mdcDigiTds)] = mdcDigiRoot; 00219 00220 mdcDigiRoot->initialize(id, time ,charge); 00221 mdcDigiRoot->setOverflow(overflow); 00222 m_digiEvt->addMdcDigi(mdcDigiRoot); 00223 // mdcDigiRoot->Print(); 00224 } 00225 00226 return sc; 00227 }
int digiRootWriterAlg::m_autoSaveEvents [private] |
auto save every events
Definition at line 78 of file digiRootWriterAlg.h.
Referenced by digiRootWriterAlg().
int digiRootWriterAlg::m_bufSize [private] |
Buffer Size for the ROOT file.
Definition at line 74 of file digiRootWriterAlg.h.
Referenced by digiRootWriterAlg(), and initialize().
commonData digiRootWriterAlg::m_common [private] |
int digiRootWriterAlg::m_compressionLevel [private] |
Compression level for the ROOT file.
Definition at line 76 of file digiRootWriterAlg.h.
Referenced by digiRootWriterAlg(), and initialize().
DigiEvent* digiRootWriterAlg::m_digiEvt [private] |
Top-level Monte Carlo ROOT object.
Definition at line 66 of file digiRootWriterAlg.h.
Referenced by execute(), initialize(), writeDigiEvent(), and writeMdcDigi().
TFile* digiRootWriterAlg::m_digiFile [private] |
ROOT file pointer.
Definition at line 62 of file digiRootWriterAlg.h.
Referenced by execute(), and initialize().
TTree* digiRootWriterAlg::m_digiTree [private] |
ROOT tree pointer.
Definition at line 64 of file digiRootWriterAlg.h.
Referenced by close(), initialize(), and writeEvent().
std::string digiRootWriterAlg::m_fileName [private] |
name of the output ROOT file
Definition at line 68 of file digiRootWriterAlg.h.
Referenced by digiRootWriterAlg(), execute(), and initialize().
IRootIoSvc* digiRootWriterAlg::m_rootIoSvc [private] |
int digiRootWriterAlg::m_splitMode [private] |
ROOT split mode.
Definition at line 72 of file digiRootWriterAlg.h.
Referenced by digiRootWriterAlg(), and initialize().
std::string digiRootWriterAlg::m_treeName [private] |
name of the TTree in the ROOT file
Definition at line 70 of file digiRootWriterAlg.h.
Referenced by digiRootWriterAlg(), and initialize().