CMS 3D CMS Logo

CollUtil.cc

Go to the documentation of this file.
00001 #include "IOPool/Common/bin/CollUtil.h"
00002 
00003 #include "DataFormats/Provenance/interface/BranchType.h"
00004 #include "DataFormats/Provenance/interface/FileID.h"
00005 #include "DataFormats/Provenance/interface/FileFormatVersion.h"
00006 #include "DataFormats/Provenance/interface/FileIndex.h"
00007 
00008 #include <iostream>
00009 
00010 #include "TFile.h" 
00011 #include "TList.h"
00012 #include "TIterator.h"
00013 #include "TKey.h"
00014 #include "TTree.h"
00015 #include "TObject.h"
00016 #include "TBranch.h"
00017 
00018 namespace edm {
00019 
00020   // Get a file handler
00021   TFile* openFileHdl(const std::string& fname) {
00022     
00023     TFile *hdl= TFile::Open(fname.c_str(),"read");
00024 
00025     if ( 0== hdl ) {
00026       std::cout << "ERR Could not open file " << fname.c_str() << std::endl;
00027       exit(1);
00028     }
00029     return hdl;
00030   }
00031 
00032   // Print every tree in a file
00033   void printTrees(TFile *hdl) {
00034 
00035     hdl->ls();
00036     TList *keylist= hdl->GetListOfKeys();
00037     TIterator *iter= keylist->MakeIterator();
00038     TKey *key;
00039     while ( (key= (TKey*)iter->Next()) ) {
00040       TObject *obj= hdl->Get(key->GetName());
00041       if ( obj->IsA() == TTree::Class() ) {
00042         obj->Print();
00043       }
00044     }
00045     return;
00046   }
00047 
00048   // number of entries in a tree
00049   Long64_t numEntries(TFile *hdl, const std::string& trname) {
00050 
00051     TTree *tree= (TTree*)hdl->Get(trname.c_str());
00052     if ( tree ) {
00053       return tree->GetEntries();
00054     } else {
00055       std::cout << "ERR cannot find a TTree named \"" << trname << "\"" 
00056                 << std::endl;
00057       return -1;
00058     }
00059   }
00060 
00061 
00062   void printBranchNames( TTree *tree) {
00063 
00064     if ( tree != 0 ) {
00065       Long64_t nB=tree->GetListOfBranches()->GetEntries();
00066       for ( Long64_t i=0; i<nB; ++i) {
00067         TBranch *btemp = (TBranch *)tree->GetListOfBranches()->At(i);
00068         std::cout << "Branch " << i <<" of " << tree->GetName() <<" tree: " << btemp->GetName() << " Total size = " << btemp->GetTotalSize() << std::endl;
00069       }
00070     }
00071     else{
00072       std::cout << "Missing Events tree?\n";
00073     }
00074 
00075   }
00076 
00077   void longBranchPrint( TTree *tr) {
00078 
00079     if ( tr != 0 ) {
00080       Long64_t nB=tr->GetListOfBranches()->GetEntries();
00081       for ( Long64_t i=0; i<nB; ++i) {    
00082         tr->GetListOfBranches()->At(i)->Print();
00083       }
00084     }
00085     else{
00086       std::cout << "Missing Events tree?\n";
00087     }
00088     
00089   }
00090 
00091   void printUuids(TTree *uuidTree) {
00092     FileID fid;
00093     FileID *fidPtr = &fid;
00094     uuidTree->SetBranchAddress(poolNames::fileIdentifierBranchName().c_str(), &fidPtr);
00095     uuidTree->GetEntry(0);
00096 
00097     std::cout << "UUID: " << fid.fid() << std::endl;
00098   }
00099 
00100   void printEventLists(TFile *tfl) {
00101 
00102     FileFormatVersion fileFormatVersion;
00103     FileFormatVersion *fftPtr = &fileFormatVersion;
00104 
00105     FileIndex fileIndex;
00106     FileIndex *findexPtr = &fileIndex;
00107 
00108     TTree *metaDataTree = dynamic_cast<TTree *>(tfl->Get(poolNames::metaDataTreeName().c_str()));
00109     metaDataTree->SetBranchAddress(poolNames::fileFormatVersionBranchName().c_str(), &fftPtr);
00110     if (metaDataTree->FindBranch(poolNames::fileIndexBranchName().c_str()) != 0) {
00111       metaDataTree->SetBranchAddress(poolNames::fileIndexBranchName().c_str(), &findexPtr);
00112     }
00113     else {
00114       std::cout << "FileIndex not found.  If this input file was created with release 1_8_0 or later\n"
00115                    "this indicates a problem with the file.  This condition should be expected with\n"
00116         "files created with earlier releases and printout of the event list will fail.\n";
00117       return;
00118     }
00119     metaDataTree->GetEntry(0);
00120 
00121     std::cout << "\n" << fileIndex;
00122 
00123     std::cout << "\nFileFormatVersion = " << fileFormatVersion << ".  ";
00124     if (fileFormatVersion.fastCopyPossible()) std::cout << "This version supports fast copy\n";
00125     else std::cout << "This version does not support fast copy\n";
00126 
00127     if (fileIndex.allEventsInEntryOrder()) {
00128       std::cout << "Events are sorted such that fast copy is possible in the default mode\n";
00129     }
00130     else {
00131       std::cout << "Events are sorted such that fast copy is NOT possible in the default mode\n";
00132     }
00133 
00134     fileIndex.sortBy_Run_Lumi_EventEntry();
00135     if (fileIndex.allEventsInEntryOrder()) {
00136       std::cout << "Events are sorted such that fast copy is possible in the \"noEventSort\" mode\n";
00137     }
00138     else {
00139       std::cout << "Events are sorted such that fast copy is NOT possible in the \"noEventSort\" mode\n";
00140     }
00141     std::cout << "(Note that other factors can prevent fast copy from occurring)\n\n";
00142   }
00143 }

Generated on Tue Jun 9 17:39:09 2009 for CMSSW by  doxygen 1.5.4