CMS 3D CMS Logo

TFileAdaptor.cc
Go to the documentation of this file.
1 #include "TFileAdaptor.h"
2 
12 
13 #include <TROOT.h>
14 #include <TFile.h>
15 #include <TPluginManager.h>
16 
17 #include <memory>
18 
19 #include <algorithm>
20 #include <sstream>
21 
22 // Driver for configuring ROOT plug-in manager to use TStorageFactoryFile.
23 
38 void TFileAdaptor::addType(TPluginManager* mgr, char const* type, int altType /*=0*/) {
39  // HACK:
40  // The ROOT plug-in manager does not understand loading plugins with different
41  // signatures. So, because TXNetSystem is registered with a different constructor
42  // than all the other plugins, we must match its interface in order to override
43  // it.
44  if (altType == 0) {
45  mgr->AddHandler("TFile",
46  type,
47  "TStorageFactoryFile",
48  "IOPoolTFileAdaptor",
49  "TStorageFactoryFile(char const*,Option_t*,char const*,Int_t)");
50 
51  mgr->AddHandler("TSystem", type, "TStorageFactorySystem", "IOPoolTFileAdaptor", "TStorageFactorySystem()");
52  } else if (altType == 1) {
53  mgr->AddHandler("TFile",
54  type,
55  "TStorageFactoryFile",
56  "IOPoolTFileAdaptor",
57  "TStorageFactoryFile(char const*,Option_t*,char const*,Int_t, Int_t, Bool_t)");
58 
59  mgr->AddHandler(
60  "TSystem", type, "TStorageFactorySystem", "IOPoolTFileAdaptor", "TStorageFactorySystem(const char *,Bool_t)");
61  }
62 }
63 
64 bool TFileAdaptor::native(char const* proto) const {
65  return std::find(native_.begin(), native_.end(), "all") != native_.end() ||
66  std::find(native_.begin(), native_.end(), proto) != native_.end();
67 }
68 
70  : enabled_(true),
71  doStats_(true),
72  enablePrefetching_(false),
73  cacheHint_("auto-detect"),
74  readHint_("auto-detect"),
75  tempDir_(),
76  minFree_(0),
77  timeout_(0U),
78  debugLevel_(0U),
79  native_() {
80  if (!(enabled_ = pset.getUntrackedParameter<bool>("enable", enabled_)))
81  return;
82 
84  doStats_ = pset.getUntrackedParameter<bool>("stats", doStats_);
85 
86  // values set in the site local config or in SiteLocalConfigService override
87  // any values set here for this service.
88  // These parameters here are needed only for backward compatibility
89  // for WMDM tools until we switch to only using the site local config for this info.
90  cacheHint_ = pset.getUntrackedParameter<std::string>("cacheHint", cacheHint_);
91  readHint_ = pset.getUntrackedParameter<std::string>("readHint", readHint_);
92  tempDir_ = pset.getUntrackedParameter<std::string>("tempDir", f->tempPath());
93  minFree_ = pset.getUntrackedParameter<double>("tempMinFree", f->tempMinFree());
94  native_ = pset.getUntrackedParameter<std::vector<std::string> >("native", native_);
95 
97 
98  // Retrieve values from SiteLocalConfigService.
99  // Any such values will override values set above.
101  if (pSLC.isAvailable()) {
102  if (std::string const* p = pSLC->sourceCacheTempDir()) {
103  tempDir_ = *p;
104  }
105  if (double const* p = pSLC->sourceCacheMinFree()) {
106  minFree_ = *p;
107  }
108  if (std::string const* p = pSLC->sourceCacheHint()) {
109  cacheHint_ = *p;
110  }
111  if (std::string const* p = pSLC->sourceReadHint()) {
112  readHint_ = *p;
113  }
114  if (unsigned int const* p = pSLC->sourceTimeout()) {
115  timeout_ = *p;
116  }
117  if (std::vector<std::string> const* p = pSLC->sourceNativeProtocols()) {
118  native_ = *p;
119  }
120  debugLevel_ = pSLC->debugLevel();
122  }
123 
124  // Prefetching does not work with storage-only; forcibly disable it.
125  if ((enablePrefetching_) && ((cacheHint_ == "storage-only") || (cacheHint_ == "auto-detect")))
126  cacheHint_ = "application-only";
127 
128  // tell factory how clients should access files
129  if (cacheHint_ == "application-only")
131  else if (cacheHint_ == "storage-only")
132  f->setCacheHint(StorageFactory::CACHE_HINT_STORAGE);
133  else if (cacheHint_ == "lazy-download")
135  else if (cacheHint_ == "auto-detect")
137  else
138  throw cms::Exception("TFileAdaptor") << "Unrecognised 'cacheHint' value '" << cacheHint_
139  << "', recognised values are 'application-only',"
140  << " 'storage-only', 'lazy-download', 'auto-detect'";
141 
142  if (readHint_ == "direct-unbuffered")
144  else if (readHint_ == "read-ahead-buffered")
146  else if (readHint_ == "auto-detect")
147  f->setReadHint(StorageFactory::READ_HINT_AUTO);
148  else
149  throw cms::Exception("TFileAdaptor") << "Unrecognised 'readHint' value '" << readHint_
150  << "', recognised values are 'direct-unbuffered',"
151  << " 'read-ahead-buffered', 'auto-detect'";
152 
153  f->setTimeout(timeout_);
154  f->setDebugLevel(debugLevel_);
155 
156  // enable file access stats accounting if requested
157  f->enableAccounting(doStats_);
158 
159  // tell where to save files.
160  f->setTempDir(tempDir_, minFree_);
161 
162  // set our own root plugins
163  TPluginManager* mgr = gROOT->GetPluginManager();
164 
165  // Make sure ROOT parses system directories first.
166  mgr->LoadHandlersFromPluginDirs("TFile");
167  mgr->LoadHandlersFromPluginDirs("TSystem");
168 
169  if (!native("file"))
170  addType(mgr, "^file:");
171  if (!native("http"))
172  addType(mgr, "^http:");
173  if (!native("http"))
174  addType(mgr, "^http[s]?:");
175  if (!native("ftp"))
176  addType(mgr, "^ftp:");
177  /* always */ addType(mgr, "^web:");
178  /* always */ addType(mgr, "^gsiftp:");
179  /* always */ addType(mgr, "^sfn:");
180  if (!native("rfio"))
181  addType(mgr, "^rfio:");
182  if (!native("dcache"))
183  addType(mgr, "^dcache:");
184  if (!native("dcap"))
185  addType(mgr, "^dcap:");
186  if (!native("gsidcap"))
187  addType(mgr, "^gsidcap:");
188  if (!native("storm"))
189  addType(mgr, "^storm:");
190  if (!native("storm-lcg"))
191  addType(mgr, "^storm-lcg:");
192  if (!native("lstore"))
193  addType(mgr, "^lstore:");
194  if (!native("root"))
195  addType(mgr, "^root:", 1); // See comments in addType
196  if (!native("root"))
197  addType(mgr, "^[x]?root:", 1); // See comments in addType
198 }
199 
202  desc.addOptionalUntracked<bool>("enable");
203  desc.addOptionalUntracked<bool>("stats");
204  desc.addOptionalUntracked<std::string>("cacheHint");
205  desc.addOptionalUntracked<std::string>("readHint");
206  desc.addOptionalUntracked<std::string>("tempDir");
207  desc.addOptionalUntracked<double>("tempMinFree");
208  desc.addOptionalUntracked<std::vector<std::string> >("native");
209  descriptions.add("AdaptorConfig", desc);
210 }
211 
212 // Write current Storage statistics on a ostream
213 void TFileAdaptor::termination(void) const {
214  std::map<std::string, std::string> data;
215  statsXML(data);
216  if (!data.empty()) {
218  reportSvc->reportPerformanceSummary("StorageStatistics", data);
219  }
220 }
221 
222 void TFileAdaptor::stats(std::ostream& o) const {
223  if (!doStats_) {
224  return;
225  }
226  float const oneMeg = 1048576.0;
227  o << "Storage parameters: adaptor: true"
228  << " Stats:" << (doStats_ ? "true" : "false") << '\n'
229  << " Prefetching:" << (enablePrefetching_ ? "true" : "false") << '\n'
230  << " Cache hint:" << cacheHint_ << '\n'
231  << " Read hint:" << readHint_ << '\n'
232  << "Storage statistics: " << StorageAccount::summaryText() << "; tfile/read=?/?/"
233  << (TFile::GetFileBytesRead() / oneMeg) << "MB/?ms/?ms/?ms"
234  << "; tfile/write=?/?/" << (TFile::GetFileBytesWritten() / oneMeg) << "MB/?ms/?ms/?ms";
235 }
236 
237 void TFileAdaptor::statsXML(std::map<std::string, std::string>& data) const {
238  if (!doStats_) {
239  return;
240  }
241  float const oneMeg = 1048576.0;
242  data.insert(std::make_pair("Parameter-untracked-bool-enabled", "true"));
243  data.insert(std::make_pair("Parameter-untracked-bool-stats", (doStats_ ? "true" : "false")));
244  data.insert(std::make_pair("Parameter-untracked-bool-prefetching", (enablePrefetching_ ? "true" : "false")));
245  data.insert(std::make_pair("Parameter-untracked-string-cacheHint", cacheHint_));
246  data.insert(std::make_pair("Parameter-untracked-string-readHint", readHint_));
248  std::ostringstream r;
249  std::ostringstream w;
250  r << (TFile::GetFileBytesRead() / oneMeg);
251  w << (TFile::GetFileBytesWritten() / oneMeg);
252  data.insert(std::make_pair("ROOT-tfile-read-totalMegabytes", r.str()));
253  data.insert(std::make_pair("ROOT-tfile-write-totalMegabytes", w.str()));
254 }
255 
256 #include <iostream>
257 
260  const edm::ParameterSet param;
261  me = std::make_shared<TFileAdaptor>(param, ar); // propagate_const<T> has no reset() function
262 }
263 
265 
266 void TFileAdaptorUI::stats() const {
267  me->stats(std::cout);
268  std::cout << std::endl;
269 }
ConfigurationDescriptions.h
TFileAdaptorUI::me
edm::propagate_const< std::shared_ptr< TFileAdaptor > > me
Definition: TFileAdaptor.h:74
TFileAdaptor.h
funct::false
false
Definition: Factorize.h:29
TFileAdaptor::termination
void termination(void) const
Definition: TFileAdaptor.cc:213
TFileAdaptor::native_
std::vector< std::string > native_
Definition: TFileAdaptor.h:49
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
edm::SiteLocalConfig::sourceNativeProtocols
virtual std::vector< std::string > const * sourceNativeProtocols() const =0
StorageFactory::READ_HINT_UNBUFFERED
Definition: StorageFactory.h:17
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
TFileAdaptor::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: TFileAdaptor.cc:200
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:42
StorageFactory::getToModify
static StorageFactory * getToModify(void)
Definition: StorageFactory.cc:30
StorageFactory::READ_HINT_READAHEAD
Definition: StorageFactory.h:17
EDMException.h
TFileAdaptorUI::~TFileAdaptorUI
~TFileAdaptorUI()
Definition: TFileAdaptor.cc:264
edm::ActivityRegistry::watchPostEndJob
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
Definition: ActivityRegistry.h:170
StorageFactory::CACHE_HINT_LAZY_DOWNLOAD
Definition: StorageFactory.h:15
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
TFileAdaptor::stats
void stats(std::ostream &o) const
Definition: TFileAdaptor.cc:222
edm::SiteLocalConfig::sourceCacheTempDir
virtual std::string const * sourceCacheTempDir() const =0
Service.h
w
const double w
Definition: UKUtility.cc:23
edm::ActivityRegistry
Definition: ActivityRegistry.h:134
StorageAccount.h
edm::SiteLocalConfig::sourceReadHint
virtual std::string const * sourceReadHint() const =0
ParameterSetDescription.h
edm::SiteLocalConfig::enablePrefetching
virtual bool enablePrefetching() const =0
StorageFactory::READ_HINT_AUTO
Definition: StorageFactory.h:17
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
funct::true
true
Definition: Factorize.h:173
TFileAdaptor::minFree_
double minFree_
Definition: TFileAdaptor.h:46
edm::ParameterSet
Definition: ParameterSet.h:47
TFileAdaptor::tempDir_
std::string tempDir_
Definition: TFileAdaptor.h:45
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
TFileAdaptor::TFileAdaptor
TFileAdaptor(edm::ParameterSet const &pset, edm::ActivityRegistry &ar)
Definition: TFileAdaptor.cc:69
type
type
Definition: SiPixelVCal_PayloadInspector.cc:39
TFileAdaptor::debugLevel_
unsigned int debugLevel_
Definition: TFileAdaptor.h:48
TFileAdaptor::native
bool native(char const *proto) const
Definition: TFileAdaptor.cc:64
StorageFactory.h
edm::Service
Definition: Service.h:30
TFileAdaptor::cacheHint_
std::string cacheHint_
Definition: TFileAdaptor.h:43
edm::SiteLocalConfig::sourceCacheMinFree
virtual double const * sourceCacheMinFree() const =0
TFileAdaptor::timeout_
unsigned int timeout_
Definition: TFileAdaptor.h:47
StorageFactory::CACHE_HINT_AUTO_DETECT
Definition: StorageFactory.h:15
TFileAdaptorUI::stats
void stats() const
Definition: TFileAdaptor.cc:266
TFileAdaptor::statsXML
void statsXML(std::map< std::string, std::string > &data) const
Definition: TFileAdaptor.cc:237
StorageFactory
Definition: StorageFactory.h:13
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
alignCSCRings.r
r
Definition: alignCSCRings.py:93
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
edm::SiteLocalConfig::debugLevel
virtual unsigned int debugLevel() const =0
StorageFactory::CACHE_HINT_APPLICATION
Definition: StorageFactory.h:15
TFileAdaptor::readHint_
std::string readHint_
Definition: TFileAdaptor.h:44
StorageAccount::summaryText
static std::string summaryText(bool banner=false)
Definition: StorageAccount.cc:59
Exception
Definition: hltDiff.cc:245
edm::SiteLocalConfig::sourceTimeout
virtual unsigned int const * sourceTimeout() const =0
TFileAdaptorUI::TFileAdaptorUI
TFileAdaptorUI()
Definition: TFileAdaptor.cc:258
edm::SiteLocalConfig::sourceCacheHint
virtual std::string const * sourceCacheHint() const =0
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
StorageFactory::CACHE_HINT_STORAGE
Definition: StorageFactory.h:15
edm::JobReport::reportPerformanceSummary
void reportPerformanceSummary(std::string const &metricClass, std::map< std::string, std::string > const &metrics)
Definition: JobReport.cc:652
TFileAdaptor::addType
static void addType(TPluginManager *mgr, char const *type, int altType=0)
Definition: TFileAdaptor.cc:38
TFileAdaptor::enabled_
bool enabled_
Definition: TFileAdaptor.h:40
JobReport.h
ParameterSet.h
StorageAccount::fillSummary
static void fillSummary(std::map< std::string, std::string > &summary)
Definition: StorageAccount.cc:76
TFileAdaptor::enablePrefetching_
bool enablePrefetching_
Definition: TFileAdaptor.h:42
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
SiteLocalConfig.h
TFileAdaptor::doStats_
bool doStats_
Definition: TFileAdaptor.h:41