#include <digiRootReaderAlg.h>
Public Member Functions | |
digiRootReaderAlg (const std::string &name, ISvcLocator *pSvcLocator) | |
StatusCode | initialize () |
Handles setup by opening ROOT file in read mode and creating a new TTree. | |
StatusCode | execute () |
Orchastrates reading from ROOT file and storing the data on the TDS for each event. | |
StatusCode | finalize () |
Closes the ROOT file and cleans up. | |
Private Member Functions | |
StatusCode | readDigiEvent () |
Reads top-level DigiEvent. | |
StatusCode | readMdcDigi () |
Reads TKR digi data from ROOT and puts it on the TDS. | |
void | close () |
Closes the ROOT file. | |
Private Attributes | |
TFile * | m_digiFile |
ROOT file pointer. | |
TChain * | m_digiTree |
ROOT tree pointer. | |
DigiEvent * | m_digiEvt |
Top-level Monte Carlo ROOT object. | |
std::string | m_fileName |
name of the input ROOT file | |
StringArrayProperty | m_fileList |
Array of input file names. | |
std::string | m_treeName |
name of the Monte Carlo TTree stored in the ROOT file | |
int | m_numEvents |
Stores number of events available in the input ROOT TTree. | |
IRootIoSvc * | m_rootIoSvc |
Definition at line 34 of file digiRootReaderAlg.h.
digiRootReaderAlg::digiRootReaderAlg | ( | const std::string & | name, | |
ISvcLocator * | pSvcLocator | |||
) |
Definition at line 85 of file digiRootReaderAlg.h.
References m_fileList, m_fileName, and m_treeName.
00085 : 00086 Algorithm(name, pSvcLocator) 00087 { 00088 // Input pararmeters that may be set via the jobOptions file 00089 // Input ROOT file name 00090 declareProperty("digiRootFile",m_fileName=""); 00091 StringArrayProperty initList; 00092 std::vector<std::string> initVec; 00093 initVec.push_back("digicopy.root"); 00094 initList.setValue(initVec); 00095 declareProperty("digiRootFileList",m_fileList=initList); 00096 // Input TTree name 00097 initVec.clear(); 00098 declareProperty("digiTreeName", m_treeName="Rec");// wensp midify for test 2005/05/14 00099 00100 }
void digiRootReaderAlg::close | ( | ) | [private] |
Closes the ROOT file.
Definition at line 297 of file digiRootReaderAlg.h.
References m_digiTree.
Referenced by finalize().
00298 { 00299 // Purpose and Method: Writes the ROOT file at the end of the run. 00300 // The TObject::kOverWrite parameter is used in the Write method 00301 // since ROOT will periodically write to the ROOT file when the bufSize 00302 // is filled. Writing would create 2 copies of the same tree to be 00303 // stored in the ROOT file, if we did not specify kOverwrite. 00304 00305 if (m_digiTree) delete m_digiTree; 00306 }
StatusCode digiRootReaderAlg::execute | ( | ) |
Orchastrates reading from ROOT file and storing the data on the TDS for each event.
Definition at line 175 of file digiRootReaderAlg.h.
References calibUtil::ERROR, IRootIoSvc::index(), m_digiEvt, m_digiTree, m_numEvents, m_rootIoSvc, msgSvc(), readDigiEvent(), readMdcDigi(), IRootIoSvc::runEventPair(), and Bes_Common::WARNING.
00176 { 00177 // Purpose and Method: Called once per event. This method calls 00178 // the appropriate methods to read data from the ROOT file and store 00179 // data on the TDS. 00180 00181 MsgStream log(msgSvc(), name()); 00182 00183 StatusCode sc = StatusCode::SUCCESS; 00184 00185 if (m_digiEvt) m_digiEvt->Clear(); 00186 00187 static Int_t evtId = 0; 00188 int readInd, numBytes; 00189 std::pair<int,int> runEventPair = (m_rootIoSvc) ? m_rootIoSvc->runEventPair() : std::pair<int,int>(-1,-1); 00190 00191 if ((m_rootIoSvc) && (m_rootIoSvc->index() >= 0)) { 00192 readInd = m_rootIoSvc->index(); 00193 } else if ((m_rootIoSvc) && (runEventPair.first != -1) && (runEventPair.second != -1)) { 00194 int run = runEventPair.first; 00195 int evt = runEventPair.second; 00196 readInd = m_digiTree->GetEntryNumberWithIndex(run, evt); 00197 } else { 00198 readInd = evtId; 00199 } 00200 00201 if (readInd >= m_numEvents) { 00202 log << MSG::WARNING << "Requested index is out of bounds - no digi data loaded" << endreq; 00203 return StatusCode::SUCCESS; 00204 } 00205 00206 numBytes = m_digiTree->GetEvent(readInd); 00207 00208 if ((numBytes <= 0) || (!m_digiEvt)) { 00209 log << MSG::WARNING << "Failed to load digi event" << endreq; 00210 return StatusCode::SUCCESS; 00211 } 00212 00213 00214 sc = readDigiEvent(); 00215 if (sc.isFailure()) { 00216 log << MSG::ERROR << "Failed to read top level DigiEvent" << endreq; 00217 return sc; 00218 } 00219 00220 sc = readMdcDigi(); 00221 if (sc.isFailure()) { 00222 log << MSG::ERROR << "Failed to load MdcDigi" << endreq; 00223 return sc; 00224 } 00225 00226 evtId = readInd+1; 00227 return sc; 00228 }
StatusCode digiRootReaderAlg::finalize | ( | ) |
Closes the ROOT file and cleans up.
Definition at line 308 of file digiRootReaderAlg.h.
References close().
00309 { 00310 close(); 00311 00312 StatusCode sc = StatusCode::SUCCESS; 00313 return sc; 00314 }
StatusCode digiRootReaderAlg::initialize | ( | ) |
Handles setup by opening ROOT file in read mode and creating a new TTree.
Definition at line 102 of file digiRootReaderAlg.h.
References calibUtil::ERROR, gen_rBB_filelist::fileList, Bes_Common::INFO, m_digiEvt, m_digiTree, m_fileList, m_fileName, m_numEvents, m_rootIoSvc, m_treeName, msgSvc(), IRootIoSvc::registerRootTree(), IRootIoSvc::setRootEvtMax(), and deljobs::string.
00103 { 00104 // Purpose and Method: Called once before the run begins. This method 00105 // opens a new ROOT file and prepares for reading. 00106 00107 StatusCode sc = StatusCode::SUCCESS; 00108 MsgStream log(msgSvc(), name()); 00109 00110 // Use the Job options service to set the Algorithm's parameters 00111 // This will retrieve parameters set in the job options file 00112 setProperties(); 00113 00114 if ( service("RootIoSvc", m_rootIoSvc, true).isFailure() ){ 00115 log << MSG::INFO << "Couldn't find the RootIoSvc!" << endreq; 00116 log << MSG::INFO << "Event loop will not terminate gracefully" << endreq; 00117 m_rootIoSvc = 0; 00118 //return StatusCode::FAILURE; 00119 } 00120 00121 facilities::Util::expandEnvVar(&m_fileName); 00122 00123 // Save the current directory for the ntuple writer service 00124 TDirectory *saveDir = gDirectory; 00125 00126 m_digiTree = new TChain(m_treeName.c_str()); 00127 00128 std::string emptyStr(""); 00129 if (m_fileName.compare(emptyStr) != 0) { 00130 TFile f(m_fileName.c_str()); 00131 if (!f.IsOpen()) { 00132 log << MSG::ERROR << "ROOT file " << m_fileName.c_str() 00133 << " could not be opened for reading." << endreq; 00134 return StatusCode::FAILURE; 00135 } 00136 f.Close(); 00137 m_digiTree->Add(m_fileName.c_str()); 00138 log << MSG::INFO << "Opened file: " << m_fileName.c_str() << endreq; 00139 } else { 00140 const std::vector<std::string> fileList = m_fileList.value( ); 00141 std::vector<std::string>::const_iterator it; 00142 std::vector<std::string>::const_iterator itend = fileList.end( ); 00143 for (it = fileList.begin(); it != itend; it++) { 00144 std::string theFile = (*it); 00145 TFile f(theFile.c_str()); 00146 if (!f.IsOpen()) { 00147 log << MSG::ERROR << "ROOT file " << theFile.c_str() 00148 << " could not be opened for reading." << endreq; 00149 return StatusCode::FAILURE; 00150 } 00151 f.Close(); 00152 m_digiTree->Add(theFile.c_str()); 00153 log << MSG::INFO << "Opened file: " << theFile.c_str() << endreq; 00154 } 00155 } 00156 00157 00158 m_digiEvt = 0; 00159 m_digiTree->SetBranchAddress("DigiEvent", &m_digiEvt); 00160 //m_common.m_digiEvt = m_digiEvt; 00161 m_numEvents = m_digiTree->GetEntries(); 00162 00163 if (m_rootIoSvc) { 00164 m_rootIoSvc->setRootEvtMax(m_numEvents); 00165 if (!m_digiTree->GetIndex()) m_digiTree->BuildIndex("m_runId", "m_eventId"); 00166 m_rootIoSvc->registerRootTree(m_digiTree); 00167 } 00168 00169 00170 saveDir->cd(); 00171 return sc; 00172 00173 }
StatusCode digiRootReaderAlg::readDigiEvent | ( | ) | [private] |
Reads top-level DigiEvent.
Definition at line 231 of file digiRootReaderAlg.h.
References calibUtil::ERROR, EventModel::Digi::Event, EventModel::EventHeader, DigiEvent::initialize(), m_digiEvt, and msgSvc().
Referenced by execute().
00231 { 00232 00233 MsgStream log(msgSvc(), name()); 00234 00235 StatusCode sc = StatusCode::SUCCESS; 00236 00237 // Retrieve the Event data for this event 00238 SmartDataPtr<Event::EventHeader> evt(eventSvc(), EventModel::EventHeader); 00239 if (!evt) { 00240 log << MSG::ERROR << "Failed to retrieve Event" << endreq; 00241 return StatusCode::FAILURE; 00242 } 00243 00244 unsigned int eventIdTds = evt->eventNumber(); 00245 unsigned int runIdTds = evt->runNumber(); 00246 00247 unsigned int eventIdRoot = m_digiEvt->getEventId(); 00248 unsigned int runIdRoot = m_digiEvt->getRunId(); 00249 00250 // Check to see if the event and run ids have already been set. 00251 if (eventIdTds != eventIdRoot) evt->setEventNumber(eventIdRoot); 00252 if (runIdTds != runIdRoot) evt->setRunNumber(runIdRoot); 00253 00254 00255 Event::DigiEvent* digiEventTds = 00256 SmartDataPtr<Event::DigiEvent>(eventSvc(), EventModel::Digi::Event); 00257 if (!digiEventTds) { 00258 sc = eventSvc()->registerObject(EventModel::Digi::Event /*"/Event/Digi"*/,new DataObject); 00259 if( sc.isFailure() ) { 00260 log << MSG::ERROR << "could not register " << EventModel::Digi::Event /*<< /Event/Digi "*/ << endreq; 00261 return sc; 00262 } 00263 } else { 00264 bool fromMc = m_digiEvt->getFromMc(); 00265 digiEventTds->initialize(fromMc); 00266 } 00267 return sc; 00268 }
StatusCode digiRootReaderAlg::readMdcDigi | ( | ) | [private] |
Reads TKR digi data from ROOT and puts it on the TDS.
Definition at line 271 of file digiRootReaderAlg.h.
References m_digiEvt, EventModel::Digi::MdcDigiCol, msgSvc(), and TRawData::Print().
Referenced by execute().
00271 { 00272 MsgStream log(msgSvc(), name()); 00273 00274 StatusCode sc = StatusCode::SUCCESS; 00275 const TObjArray *mdcDigiRootCol = m_digiEvt->getMdcDigiCol(); 00276 if (!mdcDigiRootCol) return sc; 00277 TIter mdcDigiIter(mdcDigiRootCol); 00278 00279 // create the TDS location for the EmcDigi Collection 00280 MdcDigiCol* mdcDigiTdsCol = new MdcDigiCol; 00281 sc = eventSvc()->registerObject(EventModel::Digi::MdcDigiCol, mdcDigiTdsCol); 00282 if (sc.isFailure()) { 00283 log << "Failed to register MdcDigi Collection" << endreq; 00284 return StatusCode::FAILURE; 00285 } 00286 00287 00288 00289 TMdcDigi *mdcDigiRoot = 0; 00290 while ((mdcDigiRoot = (TMdcDigi*)mdcDigiIter.Next())!=0) { 00291 mdcDigiRoot->Print(); 00292 } 00293 00294 return sc; 00295 }
DigiEvent* digiRootReaderAlg::m_digiEvt [private] |
Top-level Monte Carlo ROOT object.
Definition at line 66 of file digiRootReaderAlg.h.
Referenced by execute(), initialize(), readDigiEvent(), and readMdcDigi().
TFile* digiRootReaderAlg::m_digiFile [private] |
TChain* digiRootReaderAlg::m_digiTree [private] |
ROOT tree pointer.
Definition at line 64 of file digiRootReaderAlg.h.
Referenced by close(), execute(), and initialize().
StringArrayProperty digiRootReaderAlg::m_fileList [private] |
Array of input file names.
Definition at line 70 of file digiRootReaderAlg.h.
Referenced by digiRootReaderAlg(), and initialize().
std::string digiRootReaderAlg::m_fileName [private] |
name of the input ROOT file
Definition at line 68 of file digiRootReaderAlg.h.
Referenced by digiRootReaderAlg(), and initialize().
int digiRootReaderAlg::m_numEvents [private] |
Stores number of events available in the input ROOT TTree.
Definition at line 74 of file digiRootReaderAlg.h.
Referenced by execute(), and initialize().
IRootIoSvc* digiRootReaderAlg::m_rootIoSvc [private] |
std::string digiRootReaderAlg::m_treeName [private] |
name of the Monte Carlo TTree stored in the ROOT file
Definition at line 72 of file digiRootReaderAlg.h.
Referenced by digiRootReaderAlg(), and initialize().