File indexing completed on 2024-04-06 12:11:41
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
0026
0027
0028
0029
0030 bool FWLiteJobMetadataManager::doUpdate(FWJobMetadataUpdateRequest* request) {
0031 FWLiteJobMetadataUpdateRequest* liteRequest = dynamic_cast<FWLiteJobMetadataUpdateRequest*>(request);
0032
0033
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
0051
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
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
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100 purposes.clear();
0101 for (size_t ii = 0, ei = infos.size(); ii != ei; ++ii) {
0102
0103
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
0116
0117
0118
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
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 }