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

RootInterface Class Reference

#include <RootInterface.h>

List of all members.

Public Member Functions

virtual StatusCode addInput (const std::string &treename, const std::string &file)
 add input tree to the list
virtual StatusCode addInput (const std::string &treename, const std::string &file)
 add input tree to the list
virtual StatusCode addOutput (const std::string &treename, const std::string &file, int splitx, int bufsize, int compression)
 add output tree to the list
virtual StatusCode addOutput (const std::string &treename, const std::string &file, int splitx, int bufsize, int compression)
 add output tree to the list
virtual bool checkEndOfTree ()
 check if all the files is over 2005-11-28
virtual bool checkEndOfTree ()
 check if all the files is over 2005-11-28
virtual StatusCode createBranch (const std::string &tree, const std::string &branch, const char *classname, void *addr, int &branchnr)
 create a branch in this tree
virtual StatusCode createBranch (const std::string &tree, const std::string &branch, const char *classname, void *addr, int &branchnr)
 create a branch in this tree
virtual StatusCode f_addOutput (const std::string &treename, const std::string &file, int splitx=1, int bufsize=64000, int compression=1)
virtual StatusCode f_addOutput (const std::string &treename, const std::string &file, int splitx=1, int bufsize=64000, int compression=1)
virtual StatusCode f_createBranch (const std::string &treename, const std::string &branchname, const char *classname, void *addr, int &branchnr)
virtual StatusCode f_createBranch (const std::string &treename, const std::string &branchname, const char *classname, void *addr, int &branchnr)
virtual StatusCode f_createTree (unsigned int treenr, const std::string treename)
virtual StatusCode f_createTree (unsigned int treenr, const std::string treename)
virtual StatusCode f_fillTrees ()
virtual StatusCode f_fillTrees ()
virtual StatusCode f_finalize ()
virtual StatusCode f_finalize ()
virtual StatusCode f_getTreeNr (const std::string treename, unsigned int &treenr, bool doAdd=false)
virtual StatusCode f_getTreeNr (const std::string treename, unsigned int &treenr, bool doAdd=false)
virtual StatusCode fillTrees ()
 fill in all trees
virtual StatusCode fillTrees ()
 fill in all trees
virtual StatusCode finalize ()
virtual StatusCode finalize ()
virtual StatusCode getBranchEntry (int nr, int entry, void *addr, int &nb)
 get entry from this branch with addr
virtual StatusCode getBranchEntry (int nr, int entry, int &nb)
 get entry from this branch
virtual StatusCode getBranchEntry (int nr, int entry, void *addr, int &nb)
 get entry from this branch with addr
virtual StatusCode getBranchEntry (int nr, int entry, int &nb)
 get entry from this branch
virtual std::string getCurrentFileName ()
virtual std::string getCurrentFileName ()
virtual std::string getDecayOptions ()
virtual std::string getDecayOptions ()
virtual bool getENDFILE ()
virtual bool getENDFILE ()
virtual Int_t getEntries ()
 get nr of entries
virtual Int_t getEntries ()
 get nr of entries
virtual bool getEOF ()
 get EOF flag
virtual bool getEOF ()
 get EOF flag
virtual std::string getJobOptions ()
virtual std::string getJobOptions ()
virtual std::vector< int > getTotEvtNo ()
virtual std::vector< int > getTotEvtNo ()
virtual void printJobInfo (TFile *file, int level)
virtual void printJobInfo (TFile *file, int level)
 RootInterface (MsgStream log)
 RootInterface (MsgStream log)
virtual StatusCode setBranchAddress (const std::string treename, const std::string branchname, void *addr, int &nb)
 set branch address
virtual StatusCode setBranchAddress (const std::string treename, const std::string branchname, void *addr, int &nb)
 set branch address
virtual ~RootInterface ()
virtual ~RootInterface ()

Static Public Member Functions

RootInterfaceInstance (MsgStream log)
 singleton behaviour
RootInterfaceInstance (MsgStream log)
 singleton behaviour

Private Member Functions

virtual StatusCode createTree (unsigned int treenr, const std::string treename)
 create this tree
virtual StatusCode createTree (unsigned int treenr, const std::string treename)
 create this tree
virtual TTree * getOtherTree (const std::string treename)
 get tree from other files 2005-11-28
virtual TTree * getOtherTree (const std::string treename)
 get tree from other files 2005-11-28
virtual TTree * getTree (const std::string treename)
 get tree
virtual TTree * getTree (const std::string treename)
 get tree
virtual StatusCode getTreeNr (const std::string treename, unsigned int &treenr, bool doAdd=false)
 get treenr from treename
virtual StatusCode getTreeNr (const std::string treename, unsigned int &treenr, bool doAdd=false)
 get treenr from treename

Private Attributes

std::vector< TFile * > inputFiles
 vector of input files
std::vector< TFile * > inputFiles
 vector of input files
MsgStream log
 instance of message stream transmitted at construction
std::string m_bossVer
TClonesArray * m_branches
 array of branch pointers for writing
TClonesArray * m_branches
 array of branch pointers for writing
TClonesArray * m_branchesRead
 array of branch pointers for reading
TClonesArray * m_branchesRead
 array of branch pointers for reading
std::vector< int > m_bufSizes
 vector of buffer sizes
std::vector< int > m_bufSizes
 vector of buffer sizes
std::vector< int > m_compressionLevels
 vector of compression levels
std::vector< int > m_compressionLevels
 vector of compression levels
std::string m_currentFileName
std::string m_decayOptions
bool m_ENDFILE
 signed the tree is end 2005-11-30
Int_t m_entries
 number of entries (<0 if not yet known)
bool m_EOF
 EOF flag.
std::vector< std::string > m_fileNames
 files 2005-11-28
std::vector< std::string > m_fileNames
 files 2005-11-28
int m_fileNum
 the number of the using files 2005-11-29
std::vector< std::string > m_inputFilenames
 vector of input filenames used
std::vector< std::string > m_inputFilenames
 vector of input filenames used
std::vector< TFile * > m_inputFiles
 vector of input files
std::vector< TFile * > m_inputFiles
 vector of input files
std::vector< TTree * > m_inputTrees
 vector of input trees
std::vector< TTree * > m_inputTrees
 vector of input trees
std::vector< std::string > m_jobOptions
std::vector< std::string > m_jobOptions
std::vector< TTree * > m_otherTrees
 parallel vectors vector of other trees created from others files 2005-11-28
std::vector< TTree * > m_otherTrees
 parallel vectors vector of other trees created from others files 2005-11-28
std::vector< std::string > m_outputFilenames
 vector of output filenames used
std::vector< std::string > m_outputFilenames
 vector of output filenames used
std::vector< TFile * > m_outputFiles
 vector of output files
std::vector< TFile * > m_outputFiles
 vector of output files
std::vector< TTree * > m_outputTrees
 vector of output trees
std::vector< TTree * > m_outputTrees
 vector of output trees
std::vector< int > m_single_bufSizes
std::vector< int > m_single_bufSizes
std::vector< int > m_single_compressionLevels
std::vector< int > m_single_compressionLevels
std::vector< std::string > m_single_outputFileNames
std::vector< std::string > m_single_outputFileNames
std::vector< TFile * > m_single_outputFiles
std::vector< TFile * > m_single_outputFiles
std::vector< TTree * > m_single_outputTrees
std::vector< TTree * > m_single_outputTrees
std::vector< int > m_single_splitModes
std::vector< int > m_single_splitModes
std::vector< std::string > m_single_treenames
std::vector< std::string > m_single_treenames
std::vector< int > m_splitModes
 vector of splitmodes
std::vector< int > m_splitModes
 vector of splitmodes
std::vector< int > m_totEvtNo
std::vector< int > m_totEvtNo
std::vector< std::string > m_treenames
 vector of treenames used
std::vector< std::string > m_treenames
 vector of treenames used

Static Private Attributes

RootInterfacem_rootInterface
 static singleton pointer
RootInterfacem_rootInterface = 0
 static singleton pointer


Constructor & Destructor Documentation

RootInterface::RootInterface MsgStream  log  ) 
 

00031                                           : log(str)
00032 { 
00033   
00034   m_branches= new TClonesArray("TBranch",1); 
00035   m_branchesRead= new TClonesArray("TBranch",1);
00036   m_entries=-1;
00037   m_EOF=false;
00038   m_ENDFILE = false ;
00039   m_fileNum = 0; //-1
00040  }

RootInterface::~RootInterface  )  [virtual]
 

00044 { 
00045 }

RootInterface::RootInterface MsgStream  log  ) 
 

virtual RootInterface::~RootInterface  )  [virtual]
 


Member Function Documentation

virtual StatusCode RootInterface::addInput const std::string &  treename,
const std::string &  file
[virtual]
 

add input tree to the list

StatusCode RootInterface::addInput const std::string &  treename,
const std::string &  file
[virtual]
 

add input tree to the list

00163                                                                                   {
00164   log << MSG::DEBUG << "addInput  for Tree "<<treename<<endreq;
00165   StatusCode sc=StatusCode::SUCCESS;
00166   m_fileNames.push_back(file); //input files 2005-11-28
00167   m_otherTrees.push_back(NULL);
00168   inputFiles.push_back(NULL);
00169   unsigned int treenr;
00170   sc=getTreeNr(treename,treenr,true);
00171   m_inputFilenames[treenr]=file; // the last one file is setted 
00172   m_inputFiles[treenr]=NULL;
00173   m_inputTrees[treenr]=NULL;
00174 
00175   return sc;
00176 }

virtual StatusCode RootInterface::addOutput const std::string &  treename,
const std::string &  file,
int  splitx,
int  bufsize,
int  compression
[virtual]
 

add output tree to the list

StatusCode RootInterface::addOutput const std::string &  treename,
const std::string &  file,
int  splitx,
int  bufsize,
int  compression
[virtual]
 

add output tree to the list

00178                                                                                                                            {
00179   static int i =0;
00180   i ++;
00181   log << MSG::DEBUG << "addOutput  for Tree "<<treename<<endreq;
00182   StatusCode sc=StatusCode::SUCCESS;
00183   unsigned int treenr;
00184   sc=getTreeNr(treename,treenr,true);
00185   m_outputFilenames[treenr]=file;
00186   m_outputFiles[treenr]=NULL;
00187   m_outputTrees[treenr]=NULL;
00188   m_splitModes[treenr]=split;
00189   m_bufSizes[treenr]=bufsize;
00190   m_compressionLevels[treenr]=compression;
00191 
00192   return sc;
00193 }

virtual bool RootInterface::checkEndOfTree  )  [virtual]
 

check if all the files is over 2005-11-28

bool RootInterface::checkEndOfTree  )  [virtual]
 

check if all the files is over 2005-11-28

00425                                   {
00426 
00427   if ( m_fileNum >= int(m_fileNames.size())-1 ){
00428     if(m_inputFiles[0]){ 
00429       delete m_inputFiles[0];   
00430       m_inputFiles[0] = NULL;   
00431     }   
00432     return true;
00433   }
00434   
00435   (*m_branchesRead).Clear();
00436   unsigned int treenr;
00437   getTreeNr("Event",treenr);
00438   if(m_inputFiles[treenr]){ 
00439     delete m_inputFiles[treenr];
00440     m_inputFiles[treenr] = NULL;
00441   }
00442   if(m_inputTrees[treenr]){
00443     //delete m_inputTrees[treenr];
00444     m_inputTrees[treenr] = NULL;
00445   }
00446   if(m_otherTrees[m_fileNum]) delete m_otherTrees[m_fileNum];
00447   if(inputFiles[m_fileNum])   delete inputFiles[m_fileNum];
00448 
00449   m_ENDFILE = true;
00450   m_fileNum++;
00451   
00452   m_entries=-1;
00453   m_EOF = false;
00454   return false;
00455 }

virtual StatusCode RootInterface::createBranch const std::string &  tree,
const std::string &  branch,
const char *  classname,
void *  addr,
int &  branchnr
[virtual]
 

create a branch in this tree

StatusCode RootInterface::createBranch const std::string &  tree,
const std::string &  branch,
const char *  classname,
void *  addr,
int &  branchnr
[virtual]
 

create a branch in this tree

00195                                                                                                                                             {
00196 
00197   log << MSG::DEBUG << "CreateBranch, Tree "<<treename<<" branch "<<branchname<<endreq;
00198 
00199   TBranch *branch;
00200   unsigned int treenr;
00201   StatusCode sc=getTreeNr(treename,treenr);
00202   if (!sc.isSuccess()) return sc;
00203 
00204   if ( m_outputFilenames[treenr].empty() ) {
00205      log << MSG::DEBUG << "No corresponding output file specified, ignore createBranch: "<<branchname<<endreq;
00206      return StatusCode::SUCCESS;
00207   }
00208 
00209   if(!m_outputTrees[treenr])  sc=this->createTree(treenr,treename);
00210   if (!sc.isSuccess()) return sc;
00211   TTree *  tree=m_outputTrees[treenr];
00212   tree->SetUniqueID(treenr);
00213 
00214   branch = tree->Branch(branchname.c_str(),classname,addr,m_bufSizes[treenr],m_splitModes[treenr]);
00215   branch->SetUniqueID(treenr);
00216   branchnr=m_branches->GetEntriesFast()+1;
00217   m_branches->Expand(branchnr);
00218   TClonesArray &a = *m_branches;
00219   a[branchnr-1]=branch;
00220   tree->SetBasketSize(branchname.c_str(),m_bufSizes[treenr]); //some problem with above method to set buffersize, so we set it here.
00221   return StatusCode::SUCCESS;
00222 }

virtual StatusCode RootInterface::createTree unsigned int  treenr,
const std::string  treename
[private, virtual]
 

create this tree

StatusCode RootInterface::createTree unsigned int  treenr,
const std::string  treename
[private, virtual]
 

create this tree

00226 {
00227   // opens file and creates TTree on it
00228  
00229   TDirectory *saveDir = gDirectory;   
00230 
00231   // Create the new ROOT file
00232   m_outputFiles[treenr] =new TFile(m_outputFilenames[treenr].c_str(), "RECREATE");
00233   if(m_outputFiles[treenr]->IsZombie()){ 
00234         std::cout<<"RootInterface ERROR::Can't not open file"<<m_outputFilenames[treenr].c_str()<<std::endl; 
00235         exit(1); 
00236     } 
00237   if (!m_outputFiles[treenr]->IsOpen()) {
00238     log << MSG::FATAL << "ROOT file " << m_outputFilenames[treenr] 
00239         << " could not be opened for writing." << endreq;
00240     exit(1);
00241     return StatusCode::FAILURE;
00242   }
00243   log << MSG::INFO << "RootInterface::opened file for output:" << m_outputFilenames[treenr].c_str() <<endreq;
00244  
00245   m_outputFiles[treenr]->cd();
00246   m_outputFiles[treenr]->SetCompressionLevel(m_compressionLevels[treenr]);
00247   std::string title=treename+" from conversion";
00248   m_outputTrees[treenr]= new TTree(treename.c_str(), title.c_str());
00249   TTree::SetMaxTreeSize(20000000000LL);
00250 
00251   saveDir->cd();
00252 
00253   return StatusCode::SUCCESS;
00254 }

virtual StatusCode RootInterface::f_addOutput const std::string &  treename,
const std::string &  file,
int  splitx = 1,
int  bufsize = 64000,
int  compression = 1
[virtual]
 

StatusCode RootInterface::f_addOutput const std::string &  treename,
const std::string &  file,
int  splitx = 1,
int  bufsize = 64000,
int  compression = 1
[virtual]
 

00626                                                                                {
00627     log << MSG::INFO << "addOutput to single event" << endreq;
00628     StatusCode status = StatusCode::FAILURE;
00629     unsigned int treenr;
00630 
00631     status = f_getTreeNr(treename, treenr, true);
00632     m_single_compressionLevels[treenr]  =       compression;
00633     m_single_outputFileNames[treenr]    =       file;
00634     m_single_outputFiles[treenr]        =       NULL;
00635     m_single_outputTrees[treenr]        =       NULL;
00636     m_single_splitModes[treenr] =       splitx;
00637     m_single_bufSizes[treenr]   =       bufsize;
00638 
00639     std::cout << "finish f_addOutput to single event" << std::endl;
00640     return status;
00641 }

virtual StatusCode RootInterface::f_createBranch const std::string &  treename,
const std::string &  branchname,
const char *  classname,
void *  addr,
int &  branchnr
[virtual]
 

StatusCode RootInterface::f_createBranch const std::string &  treename,
const std::string &  branchname,
const char *  classname,
void *  addr,
int &  branchnr
[virtual]
 

00674                                    {
00675     log << MSG::INFO << "f_craeteBranch() create branch, tree name:"
00676     << treename << ", branch name:" << branchname << endreq;
00677 
00678     TBranch *branch;
00679     unsigned int treenr;
00680     StatusCode status = f_getTreeNr(treename, treenr);
00681     if ( !status.isSuccess()) return status;
00682 
00683     if ( !m_single_outputTrees[treenr])
00684         status = this->f_createTree(treenr, treename);
00685     if ( !status.isSuccess()) return status;
00686 
00687     TTree*      tree = m_single_outputTrees[treenr];
00688     tree->SetUniqueID(treenr);
00689 
00690     branch = tree->Branch(branchname.c_str(),
00691                           classname,
00692                           addr,
00693                           m_single_bufSizes[treenr],
00694                           m_single_splitModes[treenr]);
00695 
00696 }

virtual StatusCode RootInterface::f_createTree unsigned int  treenr,
const std::string  treename
[virtual]
 

StatusCode RootInterface::f_createTree unsigned int  treenr,
const std::string  treename
[virtual]
 

00644                                                                 {
00645     log << MSG::INFO << "f_createTree()" << endreq;
00646 
00647     TDirectory *saveDir = gDirectory;
00648 
00649     m_single_outputFiles[treenr] =
00650         new TFile(m_single_outputFileNames[treenr].c_str(), "RECREATE");
00651     if ( !m_single_outputFiles[treenr]->IsOpen()){
00652         log << MSG::ERROR << "ROOT share file: "
00653         << m_single_outputFileNames[treenr]
00654         << " could not be opened for writing"
00655         << endreq;
00656         return StatusCode::FAILURE;
00657     }
00658     log << MSG::INFO << "f_createTree()::open share file for writing: "
00659     << m_single_outputFileNames[treenr] << endreq;
00660 
00661     m_single_outputFiles[treenr]->cd();
00662     m_single_outputFiles[treenr]->SetCompressionLevel(m_single_compressionLevels[treenr]);
00663 
00664     std::string title = treename + " for share";
00665     m_single_outputTrees[treenr] = new TTree(treename.c_str(), title.c_str());
00666     saveDir->cd();
00667 
00668     return StatusCode::SUCCESS;
00669 }

virtual StatusCode RootInterface::f_fillTrees  )  [virtual]
 

StatusCode RootInterface::f_fillTrees  )  [virtual]
 

00728                                      {
00729     StatusCode status = StatusCode::FAILURE;
00730     int byte;
00731 
00732     std::vector<TTree *>::const_iterator tree;
00733     for ( tree = m_single_outputTrees.begin(); tree < m_single_outputTrees.end(); tree++){
00734         if ( (*tree) == NULL) continue;
00735         byte = (*tree)->Fill();
00736         (*tree)->Print();
00737         log << MSG::INFO << "f_fillTrees() filled tree " << (*tree)->GetName()
00738         << " with " << byte << " bytes!" << endreq;
00739         status = StatusCode::SUCCESS;
00740     }
00741 
00742     return status;
00743 }

virtual StatusCode RootInterface::f_finalize  )  [virtual]
 

StatusCode RootInterface::f_finalize  )  [virtual]
 

00745                                     {
00746     log << MSG::INFO << "f_finalize() in RootInterface" << endreq;
00747 
00748     std::vector<TTree *>::const_iterator        tree;
00749     for ( tree = m_single_outputTrees.begin(); tree < m_single_outputTrees.end(); tree++){
00750         if ( *tree){
00751             unsigned int treenr = (*tree)->GetUniqueID();
00752             log << MSG::INFO << "tree id: " << treenr << endreq;
00753             if ( m_single_outputFiles[treenr] ){
00754                 if ( !m_single_outputFiles[treenr]->IsOpen()){
00755                     log << MSG::ERROR << "f_finalize could not open share file for writing"
00756                     << endreq;
00757                     return StatusCode::FAILURE;
00758                 }
00759                 else {
00760                     log << MSG::INFO << "Closing file:" << treenr
00761                     << ", tree:" << (*tree)->GetName() << endreq;
00762 
00763                     TDirectory *saveDir = gDirectory;
00764                     m_single_outputFiles[treenr]->cd();
00765                     log <<MSG::INFO << "WREITE TO FILE BYTES: " 
00766                             << m_single_outputFiles[treenr]->Write()
00767                             << endreq;
00768                     m_single_outputFiles[treenr]->Close();
00769                     saveDir->cd();
00770                 }
00771             }
00772         }
00773     }
00774     return StatusCode::SUCCESS;
00775 }

virtual StatusCode RootInterface::f_getTreeNr const std::string  treename,
unsigned int &  treenr,
bool  doAdd = false
[virtual]
 

StatusCode RootInterface::f_getTreeNr const std::string  treename,
unsigned int &  treenr,
bool  doAdd = false
[virtual]
 

00699                                                                       {
00700 
00701     std::vector<std::string>::iterator where =
00702         std::find(m_single_treenames.begin(), m_single_treenames.end(), treename);
00703 
00704     if ( where == m_single_treenames.end()){
00705         if ( doAdd){
00706             treenr = m_single_treenames.size();
00707             m_single_treenames.push_back(treename);
00708 
00709             m_single_outputFileNames.push_back("");
00710             m_single_outputFiles.push_back(NULL);
00711             m_single_outputTrees.push_back(NULL);
00712             m_single_splitModes.push_back(0);
00713             m_single_bufSizes.push_back(0);
00714             m_single_compressionLevels.push_back(0);
00715 
00716             return StatusCode::SUCCESS;
00717         }
00718         else {
00719             log << MSG::ERROR << "Invalid share tree name: "
00720             << treename << endreq;
00721             return StatusCode::FAILURE;
00722         }
00723     }
00724     treenr = where - m_single_treenames.begin();
00725     return StatusCode::SUCCESS;
00726 }

virtual StatusCode RootInterface::fillTrees  )  [virtual]
 

fill in all trees

StatusCode RootInterface::fillTrees  )  [virtual]
 

fill in all trees

00596                                     {
00597   // loop over all trees and fill them
00598   StatusCode sc=StatusCode::FAILURE;
00599   int nb;
00600   std::vector<TTree *>::const_iterator trees;
00601   for (trees=m_outputTrees.begin();trees<m_outputTrees.end();trees++) {
00602       if ((*trees)==NULL) continue;
00603       int treenr=(*trees)->GetUniqueID();
00604      if(m_outputFiles[treenr]->IsZombie()||(!m_outputFiles[treenr]->IsOpen())){
00605             std::cout<<"RootInterface ERROR::The ROOT File:"<<m_outputFilenames[treenr].c_str()<<"status is false"<<std::endl;
00606             exit(1);
00607          }
00608       nb=(*trees)->Fill();
00609       m_outputFiles[treenr] = (*trees)->GetCurrentFile();
00610       log << MSG::DEBUG << "filled tree "<<(* trees)->GetName() <<" with "<<nb<<" bytes"<< endreq;
00611       if(nb==-1){
00612          log << MSG::FATAL << "Error in filling tree "<<(* trees)->GetName() <<" with "<<nb<<" bytes"<< endreq; 
00613     exit(1);
00614         }
00615       sc=StatusCode::SUCCESS;
00616   }
00617   return sc;
00618 }

virtual StatusCode RootInterface::finalize  )  [virtual]
 

StatusCode RootInterface::finalize  )  [virtual]
 

00107                                    {
00108 
00109   //  Get the messaging service, print where you are
00110   log << MSG::INFO << "finalize() in RootInterface" << endreq;
00111 
00112   // close file (FIXME for several output files)
00113   std::vector<TTree *>::const_iterator trees;
00114   for (trees=m_outputTrees.begin();trees<m_outputTrees.end();trees++)
00115    if (*trees) {
00116     int treenr=(*trees)->GetUniqueID();
00117     if (m_outputFiles[treenr]) {
00118       if (!m_outputFiles[treenr]->IsOpen()) {
00119         log << MSG::ERROR << "Could not open file for writing" << endreq;
00120         return StatusCode::FAILURE;
00121       } else {
00122         log << MSG::DEBUG<<" Closing file "<<treenr<<", tree "<<(*trees)->GetName()<<endreq;
00123         TDirectory *saveDir = gDirectory;
00124         m_outputFiles[treenr]->cd();
00125 
00126   TJobInfo* jobInfo = new TJobInfo;
00127   TTree* m_jobInfoTree = new TTree("JobInfoTree","Job info");
00128   m_jobInfoTree->Branch("JobInfo",&jobInfo);
00129   
00130   m_bossVer = getenv("BES_RELEASE");
00131   log << MSG::INFO << "fill boss version: "<<m_bossVer << endreq;
00132 
00133   string tmpJobOptions = getJobOptions();
00134   m_jobOptions.push_back( tmpJobOptions );
00135 
00136   if(m_decayOptions.size()==0)
00137     m_decayOptions = getDecayOptions();
00138  
00139   m_totEvtNo = getTotEvtNo(); 
00140   jobInfo->setBossVer(m_bossVer);
00141   jobInfo->setJobOptions(m_jobOptions);
00142   jobInfo->setDecayOptions(m_decayOptions); 
00143   jobInfo->setTotEvtNo(m_totEvtNo); 
00144   m_jobInfoTree->Fill();
00145 
00146         //?    m_mcFile->Write(0, TObject::kOverwrite);
00147         int st =1;
00148         st = m_outputFiles[treenr]->Write();
00149         if(st==0){
00150            log << MSG::FATAL<<" can not write the file "<< m_outputFilenames[treenr].c_str()<<endreq;
00151            exit(1);
00152         }
00153  
00154         m_outputFiles[treenr]->Close();
00155         saveDir->cd();
00156       }
00157     }
00158    }
00159   if(m_outputTrees.size()>0) m_outputTrees.clear();
00160   return StatusCode::SUCCESS;
00161 }

virtual StatusCode RootInterface::getBranchEntry int  nr,
int  entry,
void *  addr,
int &  nb
[virtual]
 

get entry from this branch with addr

virtual StatusCode RootInterface::getBranchEntry int  nr,
int  entry,
int &  nb
[virtual]
 

get entry from this branch

StatusCode RootInterface::getBranchEntry int  nr,
int  entry,
void *  addr,
int &  nb
[virtual]
 

get entry from this branch with addr

00528 {
00529   log << MSG::DEBUG <<"RootInterface::getBranchEntry: "<<", branch nr "<<nr  <<", entry "<<entry <<endreq;
00530 
00531   if (nr <0) return StatusCode::FAILURE;
00532   TBranch *branch=(TBranch *)m_branchesRead->At(nr);
00533   if (!branch) {
00534     log << MSG::ERROR << "Could not find branch " << nr <<endreq;
00535     return StatusCode::FAILURE;
00536   }
00537 
00538   branch->SetAddress(addr);
00539   nb=branch->GetEntry(entry);
00540 
00541   if (nb<=0){
00542     m_EOF=true;
00543 
00544   }
00545   return StatusCode::SUCCESS;
00546 }

StatusCode RootInterface::getBranchEntry int  nr,
int  entry,
int &  nb
[virtual]
 

get entry from this branch

00550 {
00551   log << MSG::DEBUG <<"RootInterface::getBranchEntry: "<<", branch nr "<<nr  <<", entry "<<entry <<endreq;
00552 
00553   if (nr <0) return StatusCode::FAILURE;
00554   TBranch *branch=(TBranch *)m_branchesRead->At(nr);
00555   if (!branch) {
00556     log << MSG::ERROR << "Could not find branch " << nr <<endreq;
00557     return StatusCode::FAILURE;
00558   }
00559   nb=branch->GetEntry(entry);
00560   
00561   if (nb<=0){
00562     m_EOF=true;
00563     
00564   }
00565   
00566   return StatusCode::SUCCESS;
00567 }

virtual std::string RootInterface::getCurrentFileName  )  [inline, virtual]
 

00055 { return m_currentFileName;}  

virtual std::string RootInterface::getCurrentFileName  )  [inline, virtual]
 

00055 { return m_currentFileName;}  

virtual std::string RootInterface::getDecayOptions  )  [virtual]
 

std::string RootInterface::getDecayOptions  )  [virtual]
 

00071 { 
00072   ISvcLocator* svcLocator = Gaudi::svcLocator();
00073   IDataInfoSvc *tmpInfoSvc;
00074   DataInfoSvc* jobInfoSvc;
00075   string decayOptions;
00076   StatusCode status = svcLocator->service("DataInfoSvc",tmpInfoSvc);
00077   if (status.isSuccess()) {
00078     log << MSG::INFO << "get the DataInfoSvc" << endreq;
00079     jobInfoSvc=dynamic_cast<DataInfoSvc *>(tmpInfoSvc);
00080     decayOptions = jobInfoSvc->getDecayOptions();
00081     log << MSG::INFO << "get decay options" << endreq
00082         << decayOptions << endreq;
00083   }else {
00084     log << MSG::WARNING << "could not get the DataInfoSvc. Ignore it." << endreq;
00085   }
00086   return decayOptions;
00087 }

virtual bool RootInterface::getENDFILE  )  [inline, virtual]
 

00031 { return m_ENDFILE;}

virtual bool RootInterface::getENDFILE  )  [inline, virtual]
 

00031 { return m_ENDFILE;}

virtual Int_t RootInterface::getEntries  )  [inline, virtual]
 

get nr of entries

00051 { return m_entries;}

virtual Int_t RootInterface::getEntries  )  [inline, virtual]
 

get nr of entries

00051 { return m_entries;}

virtual bool RootInterface::getEOF  )  [inline, virtual]
 

get EOF flag

00049 { return m_EOF;}

virtual bool RootInterface::getEOF  )  [inline, virtual]
 

get EOF flag

00049 { return m_EOF;}

virtual std::string RootInterface::getJobOptions  )  [virtual]
 

std::string RootInterface::getJobOptions  )  [virtual]
 

00048 {
00049   IInterface* iface = Gaudi::createApplicationMgr();
00050   SmartIF<IProperty> propMgr ( IID_IProperty, iface );
00051   std::string path;
00052   propMgr->getProperty( "JobOptionsPath", path);
00053   log << MSG::INFO << "JobOptions file for current job: " <<path << endreq;
00054   ifstream fin(path.c_str());
00055   string jobOptions;
00056   string tempString;
00057   while(getline(fin,tempString))
00058   {
00059     if( tempString.size()>0 && tempString.find("//")>tempString.size() )
00060     { 
00061       jobOptions += tempString;
00062       jobOptions += "\n";
00063     }
00064   }
00065   log << MSG::INFO << "JobOptions: " << endreq
00066       << jobOptions << endreq;
00067   return jobOptions;
00068 }

virtual TTree* RootInterface::getOtherTree const std::string  treename  )  [private, virtual]
 

get tree from other files 2005-11-28

TTree * RootInterface::getOtherTree const std::string  treename  )  [private, virtual]
 

get tree from other files 2005-11-28

00381                                                            {
00382   //get other TTree for input
00383   log<<MSG::INFO<<"RootInterface:;getOtherTree"<<endreq;
00384   m_ENDFILE = false ;
00385   if(m_otherTrees[m_fileNum]) return m_otherTrees[m_fileNum];
00386   // TFile* inputFile = new TFile(m_fileNames[m_fileNum].c_str(),"READ");
00387   inputFiles[m_fileNum] =  TFile::Open(m_fileNames[m_fileNum].c_str(),"READ");
00388    
00389   if(!inputFiles[m_fileNum]->IsOpen()){
00390     log<<MSG::ERROR<<"ROOT File" <<inputFiles[m_fileNum]->GetName()<<"Coult not be opened for reading."<<endreq;
00391     delete inputFiles[m_fileNum];
00392     inputFiles[m_fileNum] = NULL;
00393     return NULL; // The Root can not be opened
00394   }
00395   m_EOF = false;
00396   log<<MSG::INFO<<"RootIntrFace:;Opened File for input:"<<m_fileNames[m_fileNum].c_str()<<endreq;
00397   m_currentFileName = m_fileNames[m_fileNum].c_str(); //liangyt 2008-11-19
00398 
00399   TTree* tree =(TTree*)inputFiles[m_fileNum]->Get(treename.c_str());//the same tree name;
00400   if(!tree){
00401     log << MSG::ERROR << "ROOT file " << inputFiles[m_fileNum]->GetName()
00402         << " does not contain requested TTree: " << treename <<endreq;
00403     return NULL;
00404   }
00405 
00406   if(tree->GetEntries()<=0)
00407   {
00408     log << MSG::ERROR << "ROOT file "<< m_fileNames[m_fileNum].c_str()<< " entries <= 0" << endreq;
00409     exit(1);
00410   }
00411   
00412   m_otherTrees[m_fileNum] = tree;
00413   if (m_entries<=0){
00414     m_entries=(Int_t)tree->GetEntries();
00415     log<<MSG::INFO<<"m_entries  =  "<<m_entries<<endreq;
00416   }
00417 
00418   printJobInfo(inputFiles[m_fileNum],0);
00419 
00420   //delete inputFile;
00421   // inputFile= NULL;
00422   return tree; 
00423 }

virtual std::vector<int> RootInterface::getTotEvtNo  )  [virtual]
 

std::vector< int > RootInterface::getTotEvtNo  )  [virtual]
 

00090 {
00091   ISvcLocator* svcLocator = Gaudi::svcLocator();
00092   IDataInfoSvc *tmpInfoSvc;
00093   DataInfoSvc* jobInfoSvc;
00094   std::vector<int> totEvtNo;
00095   StatusCode status = svcLocator->service("DataInfoSvc",tmpInfoSvc);
00096   if (status.isSuccess()) {
00097     log << MSG::INFO << "get the DataInfoSvc" << endreq;
00098     jobInfoSvc=dynamic_cast<DataInfoSvc *>(tmpInfoSvc);
00099     totEvtNo = jobInfoSvc->getTotEvtNo();
00100     log << MSG::INFO << "get total event number for each run" << endreq;
00101   }else {
00102     log << MSG::WARNING << "could not get the DataInfoSvc. Ignore it." << endreq;
00103   }
00104   return totEvtNo;
00105 }

virtual TTree* RootInterface::getTree const std::string  treename  )  [private, virtual]
 

get tree

TTree * RootInterface::getTree const std::string  treename  )  [private, virtual]
 

get tree

00257 {
00258 
00259   // get TTree for input
00260   log<<MSG::INFO<<"RootInterface:;getTree"<<endreq; 
00261   unsigned int treenr;
00262   getTreeNr(treename,treenr);
00263  
00264   if (m_inputTrees[treenr]) return m_inputTrees[treenr];
00265   if (!m_inputFiles[treenr] ) {
00266    m_inputFiles[treenr] = TFile::Open(m_fileNames[treenr].c_str(), "READ");
00267    if (!m_inputFiles[treenr]->IsOpen()) {
00268      log << MSG::ERROR << "ROOT file " << m_inputFiles[treenr]->GetName()
00269          << " could not be opened for reading." << endreq;
00270      delete m_inputFiles[treenr];
00271      m_inputFiles[treenr]=NULL;
00272      m_EOF=true;
00273      return NULL;
00274    }
00275   }
00276   log << MSG::INFO << "RootInterface::opened file for input:" << m_fileNames[treenr].c_str() <<endreq;
00277   m_currentFileName = m_fileNames[treenr].c_str();  //liangyt 2008-11-19
00278   TTree *tree= (TTree *)m_inputFiles[treenr]->Get(treename.c_str());
00279   if (!tree) {
00280     log << MSG::ERROR << "ROOT file " << m_inputFiles[treenr]->GetName()
00281         << " does not contain requested TTree: " << treename <<endreq;
00282     return NULL;
00283   }
00284   if (tree->GetEntries()<=0)
00285   {
00286     log << MSG::ERROR << "ROOT file "<< m_inputFiles[treenr]->GetName()<< " entries <= 0" << endreq;
00287     exit(1);
00288   }
00289 
00290   m_inputTrees[treenr]=tree;
00291   if (m_entries<=0 ) {
00292     m_entries=(Int_t)tree->GetEntries();
00293   }
00294 
00295   printJobInfo( m_inputFiles[treenr],1);
00296   
00297   return tree;
00298 }

virtual StatusCode RootInterface::getTreeNr const std::string  treename,
unsigned int &  treenr,
bool  doAdd = false
[private, virtual]
 

get treenr from treename

StatusCode RootInterface::getTreeNr const std::string  treename,
unsigned int &  treenr,
bool  doAdd = false
[private, virtual]
 

get treenr from treename

00569                                                                                             {
00570   // look whether this tree has already got a number
00571   // if not, add it
00572   std::vector<std::string>::iterator where=std::find(m_treenames.begin(),m_treenames.end(),treename);
00573   if (where == m_treenames.end()) {
00574     if (doAdd) {
00575      treenr=m_treenames.size();
00576      m_treenames.push_back(treename);
00577      m_inputFilenames.push_back("");
00578      m_inputFiles.push_back(NULL);
00579      m_inputTrees.push_back(NULL);
00580      m_outputFilenames.push_back("");
00581      m_outputFiles.push_back(NULL);
00582      m_outputTrees.push_back(NULL);
00583      m_splitModes.push_back(0);
00584      m_bufSizes.push_back(0);
00585      m_compressionLevels.push_back(0);
00586      return StatusCode::SUCCESS;
00587     }else {
00588       log << MSG::ERROR << "Invalid tree name: " <<treename<< endreq;
00589       return StatusCode::FAILURE;
00590     }
00591   }
00592   treenr=where-m_treenames.begin();
00593   return StatusCode::SUCCESS;
00594 }

RootInterface* RootInterface::Instance MsgStream  log  )  [static]
 

singleton behaviour

RootInterface * RootInterface::Instance MsgStream  log  )  [static]
 

singleton behaviour

00025                                                     {
00026   if (m_rootInterface) return m_rootInterface;
00027   m_rootInterface=new RootInterface(log);
00028   return m_rootInterface;
00029 }

virtual void RootInterface::printJobInfo TFile *  file,
int  level
[virtual]
 

void RootInterface::printJobInfo TFile *  file,
int  level
[virtual]
 

00301 {
00302   TTree* tree2  = (TTree *)file->Get("JobInfoTree");
00303   if(!tree2)
00304   {
00305     std::cout<<"no JobInfoTree for file "<<file->GetName()<<std::endl;
00306     exit(1);
00307   }
00308   else
00309   {
00310     log << MSG::INFO << "get JobInfoTree" << endreq;
00311     TBranch* branch = tree2->GetBranch("JobInfo");
00312     if(!branch)
00313     { 
00314       std::cout<<"ERROR! No branch in JobInfoTree"<<std::endl;
00315       exit(1);
00316     }
00317     else
00318     {
00319       TJobInfo* jobInfo= new TJobInfo;
00320       branch->SetAddress(&jobInfo);
00321       branch->GetEntry(0);
00322       m_bossVer = jobInfo->getBossVer() ;
00323       std::cout<<std::endl
00324              << "**************************************************" << std::endl
00325              <<"Print JobInfo for data file: "<< file->GetName()<<std::endl
00326              << "          BOSS version: "<< m_bossVer << std::endl
00327              << "**************************************************" << std::endl
00328              << std::endl;
00329 
00330       m_decayOptions = jobInfo->getDecayOptions();
00331       if(m_decayOptions.size()>0)
00332       {
00333         std::cout<< std::endl
00334                  <<"**************************************************" << std::endl
00335                  <<"          Decay Options: "<<std::endl
00336                  <<m_decayOptions << std::endl
00337                  <<"**************************************************" << std::endl
00338                  << std::endl;
00339       }
00340 
00341       ISvcLocator* svcLocator = Gaudi::svcLocator();
00342       IDataInfoSvc *tmpInfoSvc;
00343       DataInfoSvc* jobInfoSvc;
00344       StatusCode status = svcLocator->service("DataInfoSvc",tmpInfoSvc);
00345       if (status.isSuccess()) {
00346       log << MSG::INFO << "get the DataInfoSvc" << endreq;
00347       jobInfoSvc=dynamic_cast<DataInfoSvc *>(tmpInfoSvc);
00348       }else {
00349        log << MSG::WARNING << "could not get the DataInfoSvc." << endreq;
00350       }
00351  
00352       m_totEvtNo = jobInfo->getTotEvtNo();
00353       jobInfoSvc->setTotEvtNo(m_totEvtNo);
00354 
00355       if(level>0)
00356       {    
00357         std::cout<<std::endl
00358                  <<"**************************************************" << std::endl
00359                  <<"          JobOptions for this data file: " << std::endl
00360                  << std::endl;
00361       
00362                
00363         m_jobOptions = jobInfo->getJobOptions();
00364         vector<std::string> vs = m_jobOptions;
00365         int nv = vs.size();
00366         if(nv>0)
00367         {
00368           for(int i=0;i<nv;i++)
00369           {
00370             std::cout<<vs[i]<<std::endl;
00371             std::cout<<"          end of the jobOptions file " << std::endl; 
00372             std::cout<<"**************************************************" << std::endl
00373                      <<std::endl;
00374           }
00375         }
00376       }
00377     }
00378   } 
00379 }

virtual StatusCode RootInterface::setBranchAddress const std::string  treename,
const std::string  branchname,
void *  addr,
int &  nb
[virtual]
 

set branch address

StatusCode RootInterface::setBranchAddress const std::string  treename,
const std::string  branchname,
void *  addr,
int &  nb
[virtual]
 

set branch address

00485 {
00486   log << MSG::DEBUG <<"RootInterface::setbranch address, treename: "<<treename <<", branch "<<branchname <<endreq;
00487 
00488   branchnr=-1;
00489   
00490   TTree * tree;
00491   
00492   if(m_fileNum != 0){
00493    
00494     tree = getOtherTree(treename);
00495   }else{
00496     tree = getTree(treename);
00497   } 
00498     
00499   //TTree * tree = getTree("Dst");
00500   if (!tree) {
00501     log << MSG::ERROR << "Could not find tree " << treename <<endreq;
00502     log << MSG::ERROR << "terminate the process handly"<<endreq;
00503     exit(1);
00504     return StatusCode::FAILURE;
00505   }
00506   tree->SetMakeClass(1);  // necessary for separate branch reading (segv otherwise)!
00507 
00508   //   log << MSG::INFO <<"ok!!!!!!!!!!!!!11"<<endreq; 
00509   TBranch *b = tree->GetBranch(branchname.c_str());
00510   if (!b) {
00511     //tree->Print();
00512     log << MSG::DEBUG << "Could not find branch xx" << branchname <<"xx"<<endreq;
00513     return StatusCode::FAILURE;
00514   }
00515   // log << MSG::INFO <<"ok!!!!!!!!!!!!!22"<<endreq;
00516   // log << MSG::INFO <<"ok!!!!!!!!!!!!!22"<<(*addr)<<endreq; 
00517   b->SetAddress(addr);  
00518   // log << MSG::INFO <<"ok!!!!!!!!!!!!!33"<<endreq;  
00519   branchnr=m_branchesRead->GetEntries();
00520   // log << MSG::INFO <<"ok!!!!!!!!!!!!!44"<<endreq;
00521   TClonesArray &a = *m_branchesRead;
00522   m_branchesRead->Expand(branchnr+1);
00523   a[branchnr]=b;
00524   return StatusCode::SUCCESS;
00525 }


Member Data Documentation

std::vector<TFile *> RootInterface::inputFiles [private]
 

vector of input files

std::vector<TFile *> RootInterface::inputFiles [private]
 

vector of input files

MsgStream RootInterface::log [private]
 

instance of message stream transmitted at construction

std::string RootInterface::m_bossVer [private]
 

TClonesArray* RootInterface::m_branches [private]
 

array of branch pointers for writing

TClonesArray* RootInterface::m_branches [private]
 

array of branch pointers for writing

TClonesArray* RootInterface::m_branchesRead [private]
 

array of branch pointers for reading

TClonesArray* RootInterface::m_branchesRead [private]
 

array of branch pointers for reading

std::vector<int> RootInterface::m_bufSizes [private]
 

vector of buffer sizes

std::vector<int> RootInterface::m_bufSizes [private]
 

vector of buffer sizes

std::vector<int> RootInterface::m_compressionLevels [private]
 

vector of compression levels

std::vector<int> RootInterface::m_compressionLevels [private]
 

vector of compression levels

std::string RootInterface::m_currentFileName [private]
 

std::string RootInterface::m_decayOptions [private]
 

bool RootInterface::m_ENDFILE [private]
 

signed the tree is end 2005-11-30

Int_t RootInterface::m_entries [private]
 

number of entries (<0 if not yet known)

bool RootInterface::m_EOF [private]
 

EOF flag.

std::vector<std::string> RootInterface::m_fileNames [private]
 

files 2005-11-28

std::vector<std::string> RootInterface::m_fileNames [private]
 

files 2005-11-28

int RootInterface::m_fileNum [private]
 

the number of the using files 2005-11-29

std::vector<std::string> RootInterface::m_inputFilenames [private]
 

vector of input filenames used

std::vector<std::string> RootInterface::m_inputFilenames [private]
 

vector of input filenames used

std::vector<TFile *> RootInterface::m_inputFiles [private]
 

vector of input files

std::vector<TFile *> RootInterface::m_inputFiles [private]
 

vector of input files

std::vector<TTree *> RootInterface::m_inputTrees [private]
 

vector of input trees

std::vector<TTree *> RootInterface::m_inputTrees [private]
 

vector of input trees

std::vector<std::string> RootInterface::m_jobOptions [private]
 

std::vector<std::string> RootInterface::m_jobOptions [private]
 

std::vector<TTree *> RootInterface::m_otherTrees [private]
 

parallel vectors vector of other trees created from others files 2005-11-28

std::vector<TTree *> RootInterface::m_otherTrees [private]
 

parallel vectors vector of other trees created from others files 2005-11-28

std::vector<std::string> RootInterface::m_outputFilenames [private]
 

vector of output filenames used

std::vector<std::string> RootInterface::m_outputFilenames [private]
 

vector of output filenames used

std::vector<TFile *> RootInterface::m_outputFiles [private]
 

vector of output files

std::vector<TFile *> RootInterface::m_outputFiles [private]
 

vector of output files

std::vector<TTree *> RootInterface::m_outputTrees [private]
 

vector of output trees

std::vector<TTree *> RootInterface::m_outputTrees [private]
 

vector of output trees

RootInterface* RootInterface::m_rootInterface [static, private]
 

static singleton pointer

RootInterface * RootInterface::m_rootInterface = 0 [static, private]
 

static singleton pointer

std::vector<int> RootInterface::m_single_bufSizes [private]
 

std::vector<int> RootInterface::m_single_bufSizes [private]
 

std::vector<int> RootInterface::m_single_compressionLevels [private]
 

std::vector<int> RootInterface::m_single_compressionLevels [private]
 

std::vector<std::string> RootInterface::m_single_outputFileNames [private]
 

std::vector<std::string> RootInterface::m_single_outputFileNames [private]
 

std::vector<TFile *> RootInterface::m_single_outputFiles [private]
 

std::vector<TFile *> RootInterface::m_single_outputFiles [private]
 

std::vector<TTree *> RootInterface::m_single_outputTrees [private]
 

std::vector<TTree *> RootInterface::m_single_outputTrees [private]
 

std::vector<int> RootInterface::m_single_splitModes [private]
 

std::vector<int> RootInterface::m_single_splitModes [private]
 

std::vector<std::string> RootInterface::m_single_treenames [private]
 

std::vector<std::string> RootInterface::m_single_treenames [private]
 

std::vector<int> RootInterface::m_splitModes [private]
 

vector of splitmodes

std::vector<int> RootInterface::m_splitModes [private]
 

vector of splitmodes

std::vector<int> RootInterface::m_totEvtNo [private]
 

std::vector<int> RootInterface::m_totEvtNo [private]
 

std::vector<std::string> RootInterface::m_treenames [private]
 

vector of treenames used

std::vector<std::string> RootInterface::m_treenames [private]
 

vector of treenames used


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