Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:16

0001 #include "Fireworks/Core/interface/FWLiteJobMetadataManager.h"
0002 #include "Fireworks/Core/interface/FWLiteJobMetadataUpdateRequest.h"
0003 #include "Fireworks/Core/interface/fwLog.h"
0004 #include "Fireworks/Core/interface/FWItemAccessorFactory.h"
0005 #include "DataFormats/Provenance/interface/BranchDescription.h"
0006 #include "DataFormats/FWLite/interface/Event.h"
0007 
0008 #include "TFile.h"
0009 #include "TTree.h"
0010 #include <set>
0011 
0012 FWLiteJobMetadataManager::FWLiteJobMetadataManager(void) : FWJobMetadataManager(), m_event(nullptr) {}
0013 
0014 bool FWLiteJobMetadataManager::hasModuleLabel(std::string& moduleLabel) {
0015   if (m_event) {
0016     for (auto bit = m_event->getBranchDescriptions().begin(); bit != m_event->getBranchDescriptions().end(); ++bit) {
0017       if (bit->moduleLabel() == moduleLabel) {
0018         return true;
0019       }
0020     }
0021   }
0022   return false;
0023 }
0024 
0025 /** This method inspects the currently opened TFile and for each branch 
0026     containing products for which we can either build a TCollectionProxy or 
0027     for which we have a specialized accessor, it registers it as a viewable 
0028     item.
0029  */
0030 bool FWLiteJobMetadataManager::doUpdate(FWJobMetadataUpdateRequest* request) {
0031   FWLiteJobMetadataUpdateRequest* liteRequest = dynamic_cast<FWLiteJobMetadataUpdateRequest*>(request);
0032   // There is no way we are going to get a non-FWLite updated request for
0033   // this class.
0034   assert(liteRequest);
0035   if (m_event == liteRequest->event_)
0036     return false;
0037 
0038   m_event = liteRequest->event_;
0039   const TFile* file = liteRequest->file_;
0040 
0041   assert(file);
0042 
0043   usableData().clear();
0044 
0045   if (!m_event)
0046     return true;
0047 
0048   const std::vector<std::string>& history = m_event->getProcessHistory();
0049 
0050   // Turns out, in the online system we do sometimes gets files without any
0051   // history, this really should be investigated
0052   if (history.empty())
0053     std::cout << "WARNING: the file '" << file->GetName()
0054               << "' contains no processing history"
0055                  " and therefore should have no accessible data.\n";
0056 
0057   std::copy(history.rbegin(), history.rend(), std::back_inserter(processNamesInJob()));
0058 
0059   static const std::string s_blank;
0060   const std::vector<edm::BranchDescription>& descriptions = m_event->getBranchDescriptions();
0061 
0062   Data d;
0063 
0064   //I'm not going to modify TFile but I need to see what it is holding
0065   TTree* eventsTree = dynamic_cast<TTree*>(const_cast<TFile*>(file)->Get("Events"));
0066   assert(eventsTree);
0067 
0068   std::set<std::string> branchNamesInFile;
0069   TIter nextBranch(eventsTree->GetListOfBranches());
0070   while (TBranch* branch = static_cast<TBranch*>(nextBranch()))
0071     branchNamesInFile.insert(branch->GetName());
0072 
0073   typedef std::set<std::string> Purposes;
0074   Purposes purposes;
0075   std::string classType;
0076 
0077   for (size_t bi = 0, be = descriptions.size(); bi != be; ++bi) {
0078     const edm::BranchDescription& desc = descriptions[bi];
0079 
0080     if (!desc.present() || branchNamesInFile.end() == branchNamesInFile.find(desc.branchName()))
0081       continue;
0082 
0083     const std::vector<FWRepresentationInfo>& infos = m_typeAndReps->representationsForType(desc.fullClassName());
0084 
0085     /*
0086       //std::cout <<"try to find match "<<itBranch->fullClassName()<<std::endl;
0087       //For each view we need to find the non-sub-part builder whose proximity is smallest and 
0088       // then register only that purpose
0089       //NOTE: for now, we will ignore the view and only look for the closest proximity
0090       unsigned int minProx = ~(0U);
0091       for (size_t ii = 0, ei = infos.size(); ii != ei; ++ii) {
0092       if (!infos[ii].representsSubPart() && minProx > infos[ii].proximity()) {
0093       minProx = infos[ii].proximity();
0094       }
0095       }
0096       */
0097 
0098     //the infos list can contain multiple items with the same purpose so we will just find
0099     // the unique ones
0100     purposes.clear();
0101     for (size_t ii = 0, ei = infos.size(); ii != ei; ++ii) {
0102       /* if(!infos[ii].representsSubPart() && minProx != infos[ii].proximity()) {
0103             continue;
0104             } */
0105       if (infos[ii].requiresFF() == false) {
0106         purposes.insert(infos[ii].purpose());
0107       }
0108     }
0109 
0110     if (purposes.empty())
0111       purposes.insert("Table");
0112 
0113     for (Purposes::const_iterator itPurpose = purposes.begin(), itEnd = purposes.end(); itPurpose != itEnd;
0114          ++itPurpose) {
0115       // Determine whether or not the class can be iterated
0116       // either by using a TVirtualCollectionProxy (of the class
0117       // itself or on one of its members), or by using a
0118       // FWItemAccessor plugin.
0119       TClass* theClass = TClass::GetClass(desc.fullClassName().c_str());
0120 
0121       if (!theClass)
0122         continue;
0123 
0124       if (!theClass->GetTypeInfo())
0125         continue;
0126 
0127       const static bool debug = false;
0128       // This is pretty much the same thing that happens
0129       if (!FWItemAccessorFactory::classAccessedAsCollection(theClass)) {
0130         if (debug) {
0131           fwLog(fwlog::kDebug) << theClass->GetName() << " will not be displayed in table." << std::endl;
0132         }
0133         continue;
0134       }
0135       d.type_ = desc.fullClassName();
0136       d.purpose_ = *itPurpose;
0137       d.moduleLabel_ = desc.moduleLabel();
0138       d.productInstanceLabel_ = desc.productInstanceName();
0139       d.processName_ = desc.processName();
0140       usableData().push_back(d);
0141       if (debug) {
0142         fwLog(fwlog::kDebug) << "Add collection will display " << d.type_ << " " << d.moduleLabel_ << " "
0143                              << d.productInstanceLabel_ << " " << d.processName_ << std::endl;
0144       }
0145     }
0146   }
0147   return true;
0148 }