Go to the documentation of this file.00001 #include "Validation/RecoTau/plugins/DQMFileLoader.h"
00002
00003 #include "Validation/RecoTau/plugins/dqmAuxFunctions.h"
00004
00005
00006 #include "FWCore/Framework/interface/Frameworkfwd.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008
00009
00010 #include "DQMServices/Core/interface/DQMStore.h"
00011 #include "FWCore/ServiceRegistry/interface/Service.h"
00012 #include "DQMServices/Core/interface/MonitorElement.h"
00013
00014 #include <TFile.h>
00015 #include <TList.h>
00016 #include <TKey.h>
00017 #include <TH1.h>
00018
00019 #include <iostream>
00020
00021 const std::string dqmRootDirectory_inTFile = "DQMData";
00022
00023 const double defaultScaleFactor = 1.;
00024
00025 const int verbosity = 0;
00026
00027 void mapSubDirectoryStructure(TDirectory* directory, std::string directoryName, std::set<std::string>& subDirectories)
00028 {
00029
00030
00031
00032 TList* subDirectoryNames = directory->GetListOfKeys();
00033 if ( !subDirectoryNames ) return;
00034
00035 TIter next(subDirectoryNames);
00036 while ( TKey* key = dynamic_cast<TKey*>(next()) ) {
00037
00038 TObject* obj = directory->Get(key->GetName());
00039
00040 if ( TDirectory* subDirectory = dynamic_cast<TDirectory*>(obj) ) {
00041 std::string subDirectoryName = dqmDirectoryName(directoryName).append(key->GetName());
00042
00043
00044 subDirectories.insert(subDirectoryName);
00045
00046 mapSubDirectoryStructure(subDirectory, subDirectoryName, subDirectories);
00047 }
00048 }
00049 }
00050
00051
00052
00053
00054
00055 TauDQMFileLoader::cfgEntryFileSet::cfgEntryFileSet(const std::string& name, const edm::ParameterSet& cfg)
00056 {
00057
00058
00059 name_ = name;
00060
00061 vstring inputFileList = cfg.getParameter<vstring>("inputFileNames");
00062 for ( vstring::const_iterator inputFile = inputFileList.begin();
00063 inputFile != inputFileList.end(); ++inputFile ) {
00064 if ( inputFile->find(rangeKeyword) != std::string::npos ) {
00065 size_t posRangeStart = inputFile->find(rangeKeyword) + rangeKeyword.length();
00066 size_t posRangeEnd = inputFile->find('#', posRangeStart);
00067
00068 size_t posRangeSeparator = inputFile->find('-', posRangeStart);
00069
00070 if ( (posRangeEnd == std::string::npos) ||
00071 (posRangeSeparator >= posRangeEnd) ) {
00072 edm::LogError ("TauDQMFileLoader::cfgEntryFileSet") << " Invalid range specification in inputFile = " << (*inputFile) << " !!";
00073 continue;
00074 }
00075
00076 std::string firstFile = std::string(*inputFile, posRangeStart, posRangeSeparator - posRangeStart);
00077
00078 std::string lastFile = std::string(*inputFile, posRangeSeparator + 1, posRangeEnd - (posRangeSeparator + 1));
00079
00080
00081 if ( firstFile.length() != lastFile.length() ) {
00082 edm::LogError ("TauDQMFileLoader::cfgEntryFileSet") << " Invalid range specification in inputFile = " << (*inputFile) << " !!";
00083 continue;
00084 }
00085
00086 int numFirstFile = atoi(firstFile.data());
00087 int numLastFile = atoi(lastFile.data());
00088 for ( int iFile = numFirstFile; iFile <= numLastFile; ++iFile ) {
00089 std::ostringstream fileName;
00090 fileName << std::string(*inputFile, 0, inputFile->find(rangeKeyword));
00091 fileName << std::setfill('0') << std::setw(firstFile.length()) << iFile;
00092 fileName << std::string(*inputFile, posRangeEnd + 1);
00093
00094 inputFileNames_.push_back(fileName.str());
00095 }
00096 } else {
00097 inputFileNames_.push_back(*inputFile);
00098 }
00099 }
00100
00101 scaleFactor_ = ( cfg.exists("scaleFactor") ) ? cfg.getParameter<double>("scaleFactor") : defaultScaleFactor;
00102
00103
00104 dqmDirectory_store_ = ( cfg.exists("dqmDirectory_store") ) ? cfg.getParameter<std::string>("dqmDirectory_store") : "";
00105
00106 if ( verbosity ) print();
00107 }
00108
00109 void TauDQMFileLoader::cfgEntryFileSet::print() const
00110 {
00111 std::cout << "<cfgEntryFileSet::print>:" << std::endl;
00112 std::cout << " name = " << name_ << std::endl;
00113 std::cout << " inputFileNames = " << format_vstring(inputFileNames_) << std::endl;
00114 std::cout << " scaleFactor = " << scaleFactor_ << std::endl;
00115 std::cout << " dqmDirectory_store = " << dqmDirectory_store_ << std::endl;
00116 }
00117
00118
00119
00120
00121
00122 TauDQMFileLoader::TauDQMFileLoader(const edm::ParameterSet& cfg)
00123 {
00124 std::cout << "<TauDQMFileLoader::TauDQMFileLoader>:" << std::endl;
00125
00126 cfgError_ = 0;
00127
00128
00129
00130 readCfgParameter<cfgEntryFileSet>(cfg, fileSets_);
00131
00132
00133
00134
00135
00136 for ( std::map<std::string, cfgEntryFileSet>::const_iterator fileSet = fileSets_.begin();
00137 fileSet != fileSets_.end(); ++fileSet ) {
00138 if ( fileSet->second.dqmDirectory_store_ == "" && fileSets_.size() > 1 ) {
00139 edm::LogError ("TauDQMFileLoader") << " dqmDirectory_store undefined for fileSet = " << fileSet->second.name_ << " !!";
00140 cfgError_ = 1;
00141 break;
00142 }
00143 }
00144
00145 std::cout << "done." << std::endl;
00146 }
00147
00148 TauDQMFileLoader::~TauDQMFileLoader()
00149 {
00150
00151 }
00152
00153 void TauDQMFileLoader::analyze(const edm::Event&, const edm::EventSetup&)
00154 {
00155
00156 }
00157
00158 void TauDQMFileLoader::endRun(const edm::Run& r, const edm::EventSetup& c)
00159 {
00160 std::cout << "<TauDQMFileLoader::endJob>:" << std::endl;
00161
00162
00163 if ( cfgError_ ) {
00164 edm::LogError ("endJob") << " Error in Configuration ParameterSet"
00165 << " --> histograms will NOT be loaded !!";
00166 return;
00167 }
00168
00169
00170 if ( !edm::Service<DQMStore>().isAvailable() ) {
00171 edm::LogError ("endJob") << " Failed to access dqmStore"
00172 << " --> histograms will NOT be loaded !!";
00173 return;
00174 }
00175
00176
00177
00178
00179
00180
00181
00182
00183 for ( std::map<std::string, cfgEntryFileSet>::const_iterator fileSet = fileSets_.begin();
00184 fileSet != fileSets_.end(); ++fileSet ) {
00185 for ( vstring::const_iterator inputFileName = fileSet->second.inputFileNames_.begin();
00186 inputFileName != fileSet->second.inputFileNames_.end(); ++inputFileName ) {
00187
00188 TFile inputFile(inputFileName->data());
00189 if ( inputFile.IsZombie() ) {
00190 edm::LogError ("endJob") << " Failed to open inputFile = " << (*inputFileName)
00191 << "--> histograms will NOT be loaded !!";
00192 return;
00193 }
00194
00195 TObject* obj = inputFile.Get(dqmRootDirectory_inTFile.data());
00196
00197 if ( TDirectory* directory = dynamic_cast<TDirectory*>(obj) ) {
00198 mapSubDirectoryStructure(directory, dqmRootDirectory, subDirectoryMap_[*inputFileName]);
00199 } else {
00200 edm::LogError ("endJob") << " Failed to access " << dqmRootDirectory_inTFile << " in inputFile = " << (*inputFileName)
00201 << "--> histograms will NOT be loaded !!";
00202 return;
00203 }
00204
00205 inputFile.Close();
00206 }
00207 }
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 DQMStore& dqmStore = (*edm::Service<DQMStore>());
00221 for ( std::map<std::string, cfgEntryFileSet>::const_iterator fileSet = fileSets_.begin();
00222 fileSet != fileSets_.end(); ++fileSet ) {
00223 for ( vstring::const_iterator inputFileName = fileSet->second.inputFileNames_.begin();
00224 inputFileName != fileSet->second.inputFileNames_.end(); ++inputFileName ) {
00225 if ( verbosity ) std::cout << " opening inputFile = " << (*inputFileName) << std::endl;
00226 dqmStore.open(*inputFileName, true);
00227
00228
00229
00230
00231
00232
00233
00234 if ( fileSet->second.dqmDirectory_store_ != "" ) {
00235 std::string inputDirectory = dqmRootDirectory;
00236
00237 std::string outputDirectory = dqmDirectoryName(std::string(inputDirectory)).append(fileSet->second.dqmDirectory_store_);
00238
00239
00240 dqmStore.setCurrentFolder(inputDirectory);
00241 std::vector<std::string> dirNames = dqmStore.getSubdirs();
00242 for ( std::vector<std::string>::const_iterator dirName = dirNames.begin();
00243 dirName != dirNames.end(); ++dirName ) {
00244 std::string subDirName = dqmSubDirectoryName_merged(inputDirectory, *dirName);
00245
00246
00247 const sstring& subDirectories = subDirectoryMap_[*inputFileName];
00248 if ( subDirectories.find(subDirName) != subDirectories.end() ) {
00249 std::string inputDirName_full = dqmDirectoryName(inputDirectory).append(subDirName);
00250
00251
00252 std::string outputDirName_full = dqmDirectoryName(outputDirectory).append(subDirName);
00253
00254
00255
00256
00257
00258
00259 int mode = ( inputFileName == fileSet->second.inputFileNames_.begin() ) ? 1 : 3;
00260 dqmCopyRecursively(dqmStore, inputDirName_full, outputDirName_full, fileSet->second.scaleFactor_, mode, true);
00261 }
00262 }
00263 }
00264 }
00265 }
00266
00267 std::cout << "done." << std::endl;
00268 if ( verbosity ) dqmStore.showDirStructure();
00269 }
00270
00271 #include "FWCore/Framework/interface/MakerMacros.h"
00272
00273 DEFINE_FWK_MODULE(TauDQMFileLoader);