CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Fireworks/Core/src/FWLiteJobMetadataManager.cc

Go to the documentation of this file.
00001 #include "Fireworks/Core/interface/FWLiteJobMetadataManager.h"
00002 #include "Fireworks/Core/interface/FWLiteJobMetadataUpdateRequest.h"
00003 #include "Fireworks/Core/interface/fwLog.h"
00004 #include "Fireworks/Core/interface/FWItemAccessorFactory.h"
00005 #include "DataFormats/Provenance/interface/BranchDescription.h"
00006 #include "DataFormats/FWLite/interface/Event.h"
00007 
00008 #include "TFile.h"
00009 #include "TTree.h"
00010 #include <set>
00011 
00012 FWLiteJobMetadataManager::FWLiteJobMetadataManager(void)
00013    : FWJobMetadataManager(),
00014      m_event(0)
00015 {}
00016 
00022 bool
00023 FWLiteJobMetadataManager::doUpdate(FWJobMetadataUpdateRequest *request)
00024 {
00025    FWLiteJobMetadataUpdateRequest *liteRequest 
00026       = dynamic_cast<FWLiteJobMetadataUpdateRequest *>(request);
00027    // There is no way we are going to get a non-FWLite updated request for
00028    // this class.
00029    assert(liteRequest);
00030    if (m_event == liteRequest->event_) 
00031       return false;
00032 
00033    m_event = liteRequest->event_;
00034    const TFile *file = liteRequest->file_;
00035 
00036    assert(file);
00037    
00038    usableData().clear();
00039    
00040    if (!m_event)
00041       return true;
00042    
00043    const std::vector<std::string>& history = m_event->getProcessHistory();
00044    
00045    // Turns out, in the online system we do sometimes gets files without any  
00046    // history, this really should be investigated
00047    if (history.empty())
00048       fwLog(fwlog::kWarning) << "WARNING: the file '"
00049          << file->GetName() << "' contains no processing history"
00050             " and therefore should have no accessible data";
00051    
00052    std::copy(history.rbegin(),history.rend(),
00053              std::back_inserter(processNamesInJob()));
00054    
00055    static const std::string s_blank;
00056    const std::vector<edm::BranchDescription>& descriptions =
00057       m_event->getBranchDescriptions();
00058 
00059    Data d;
00060    
00061    //I'm not going to modify TFile but I need to see what it is holding
00062    TTree* eventsTree = dynamic_cast<TTree*>(const_cast<TFile*>(file)->Get("Events"));
00063    assert(eventsTree);
00064    
00065    std::set<std::string> branchNamesInFile;
00066    TIter nextBranch(eventsTree->GetListOfBranches());
00067    while(TBranch* branch = static_cast<TBranch*>(nextBranch()))
00068       branchNamesInFile.insert(branch->GetName());
00069    
00070    typedef std::set<std::string> Purposes;
00071    Purposes purposes;
00072    std::string classType;
00073    
00074    for(size_t bi = 0, be = descriptions.size(); bi != be; ++bi) 
00075    {
00076       const edm::BranchDescription &desc = descriptions[bi];
00077       
00078       if (!desc.present() 
00079           || branchNamesInFile.end() == branchNamesInFile.find(desc.branchName()))
00080          continue;
00081       
00082       const std::vector<FWRepresentationInfo>& infos 
00083          = m_typeAndReps->representationsForType(desc.fullClassName());
00084       
00085       /*
00086       //std::cout <<"try to find match "<<itBranch->fullClassName()<<std::endl;
00087       //For each view we need to find the non-sub-part builder whose proximity is smallest and 
00088       // then register only that purpose
00089       //NOTE: for now, we will ignore the view and only look for the closest proximity
00090       unsigned int minProx = ~(0U);
00091       for (size_t ii = 0, ei = infos.size(); ii != ei; ++ii) {
00092       if (!infos[ii].representsSubPart() && minProx > infos[ii].proximity()) {
00093       minProx = infos[ii].proximity();
00094       }
00095       }
00096       */
00097       
00098       //the infos list can contain multiple items with the same purpose so we will just find
00099       // the unique ones
00100       purposes.clear();
00101       for (size_t ii = 0, ei = infos.size(); ii != ei; ++ii) {
00102          /* if(!infos[ii].representsSubPart() && minProx != infos[ii].proximity()) {
00103             continue;
00104             } */
00105          purposes.insert(infos[ii].purpose());
00106       }
00107       
00108       if (purposes.empty())
00109          purposes.insert("Table");
00110       
00111       for (Purposes::const_iterator itPurpose = purposes.begin(),
00112               itEnd = purposes.end();
00113            itPurpose != itEnd;
00114            ++itPurpose) 
00115       {
00116          // Determine whether or not the class can be iterated
00117          // either by using a TVirtualCollectionProxy (of the class 
00118          // itself or on one of its members), or by using a 
00119          // FWItemAccessor plugin.
00120          TClass* theClass = TClass::GetClass(desc.fullClassName().c_str());
00121          
00122          if (!theClass)
00123             continue;
00124       
00125          if (!theClass->GetTypeInfo())
00126             continue;
00127          
00128          const static bool debug = false;
00129          // This is pretty much the same thing that happens 
00130          if (!FWItemAccessorFactory::classAccessedAsCollection(theClass) )
00131          {
00132             if (debug) {
00133                fwLog(fwlog::kDebug) << theClass->GetName() 
00134                                     << " will not be displayed in table." << std::endl;
00135             }
00136             continue;
00137          }
00138          d.type_ = desc.fullClassName();
00139          d.purpose_ = *itPurpose;
00140          d.moduleLabel_ = desc.moduleLabel();
00141          d.productInstanceLabel_ = desc.productInstanceName();
00142          d.processName_ = desc.processName();
00143          usableData().push_back(d);
00144          if (debug)
00145          {
00146             fwLog(fwlog::kDebug) << "Add collection will display " << d.type_ 
00147                                  << " " << d.moduleLabel_ 
00148                                  << " " << d.productInstanceLabel_
00149                                  << " " << d.processName_ << std::endl;
00150          }
00151       }
00152    }
00153    return true;
00154 }