CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/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       std::cout << "WARNING: the file '"
00049          << file->GetName() << "' contains no processing history"
00050             " and therefore should have no accessible data.\n";
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           // AMT: this is a simple workaround to hide FF proxybuilder
00106           //      the proper solution is implemented in CMSSW_7_0_X
00107           if (infos[ii].purpose() != "TracksFF")
00108              purposes.insert(infos[ii].purpose());
00109       }
00110       
00111       if (purposes.empty())
00112          purposes.insert("Table");
00113       
00114       for (Purposes::const_iterator itPurpose = purposes.begin(),
00115               itEnd = purposes.end();
00116            itPurpose != itEnd;
00117            ++itPurpose) 
00118       {
00119          // Determine whether or not the class can be iterated
00120          // either by using a TVirtualCollectionProxy (of the class 
00121          // itself or on one of its members), or by using a 
00122          // FWItemAccessor plugin.
00123          TClass* theClass = TClass::GetClass(desc.fullClassName().c_str());
00124          
00125          if (!theClass)
00126             continue;
00127       
00128          if (!theClass->GetTypeInfo())
00129             continue;
00130          
00131          const static bool debug = false;
00132          // This is pretty much the same thing that happens 
00133          if (!FWItemAccessorFactory::classAccessedAsCollection(theClass) )
00134          {
00135             if (debug) {
00136                fwLog(fwlog::kDebug) << theClass->GetName() 
00137                                     << " will not be displayed in table." << std::endl;
00138             }
00139             continue;
00140          }
00141          d.type_ = desc.fullClassName();
00142          d.purpose_ = *itPurpose;
00143          d.moduleLabel_ = desc.moduleLabel();
00144          d.productInstanceLabel_ = desc.productInstanceName();
00145          d.processName_ = desc.processName();
00146          usableData().push_back(d);
00147          if (debug)
00148          {
00149             fwLog(fwlog::kDebug) << "Add collection will display " << d.type_ 
00150                                  << " " << d.moduleLabel_ 
00151                                  << " " << d.productInstanceLabel_
00152                                  << " " << d.processName_ << std::endl;
00153          }
00154       }
00155    }
00156    return true;
00157 }