CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends
TFileAdaptor Class Reference

#include <TFileAdaptor.h>

Public Member Functions

 TFileAdaptor (edm::ParameterSet const &pset, edm::ActivityRegistry &ar)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Member Functions

bool native (char const *proto) const
 
void stats (std::ostream &o) const
 
void statsXML (std::map< std::string, std::string > &data) const
 
void termination (void) const
 

Static Private Member Functions

static void addType (TPluginManager *mgr, char const *type, int altType=0)
 

Private Attributes

std::string cacheHint_
 
unsigned int debugLevel_
 
bool doStats_
 
bool enabled_
 
bool enablePrefetching_
 
double minFree_
 
std::vector< std::string > native_
 
std::string readHint_
 
std::string tempDir_
 
unsigned int timeout_
 

Friends

class TFileAdaptorUI
 

Detailed Description

Definition at line 20 of file TFileAdaptor.h.

Constructor & Destructor Documentation

◆ TFileAdaptor()

TFileAdaptor::TFileAdaptor ( edm::ParameterSet const &  pset,
edm::ActivityRegistry ar 
)

Definition at line 70 of file TFileAdaptor.cc.

References addType(), cacheHint_, haddnano::cl, edm::SiteLocalConfig::debugLevel(), debugLevel_, doStats_, enabled_, edm::SiteLocalConfig::enablePrefetching(), enablePrefetching_, Exception, f, edm::Service< T >::isAvailable(), minFree_, native(), native_, AlCaHLTBitMon_ParallelJobs::p, muonDTDigis_cfi::pset, readHint_, edm::SiteLocalConfig::sourceCacheHint(), edm::SiteLocalConfig::sourceCacheMinFree(), edm::SiteLocalConfig::sourceCacheTempDir(), edm::SiteLocalConfig::sourceNativeProtocols(), edm::SiteLocalConfig::sourceReadHint(), edm::SiteLocalConfig::sourceTimeout(), AlCaHLTBitMon_QueryRunRegistry::string, tempDir_, termination(), timeout_, and edm::ActivityRegistry::watchPostEndJob().

71  : enabled_(true),
72  doStats_(true),
73  enablePrefetching_(false),
74  cacheHint_("auto-detect"),
75  readHint_("auto-detect"),
76  tempDir_(),
77  minFree_(0),
78  timeout_(0U),
79  debugLevel_(0U),
80  native_() {
81  if (!(enabled_ = pset.getUntrackedParameter<bool>("enable", enabled_)))
82  return;
83 
84  using namespace edm::storage;
85  StorageFactory* f = StorageFactory::getToModify();
86  doStats_ = pset.getUntrackedParameter<bool>("stats", doStats_);
87 
88  // values set in the site local config or in SiteLocalConfigService override
89  // any values set here for this service.
90  // These parameters here are needed only for backward compatibility
91  // for WMDM tools until we switch to only using the site local config for this info.
92  cacheHint_ = pset.getUntrackedParameter<std::string>("cacheHint", cacheHint_);
93  readHint_ = pset.getUntrackedParameter<std::string>("readHint", readHint_);
94  tempDir_ = pset.getUntrackedParameter<std::string>("tempDir", f->tempPath());
95  minFree_ = pset.getUntrackedParameter<double>("tempMinFree", f->tempMinFree());
96  native_ = pset.getUntrackedParameter<std::vector<std::string> >("native", native_);
97 
99 
100  // Retrieve values from SiteLocalConfigService.
101  // Any such values will override values set above.
103  if (pSLC.isAvailable()) {
104  if (std::string const* p = pSLC->sourceCacheTempDir()) {
105  tempDir_ = *p;
106  }
107  if (double const* p = pSLC->sourceCacheMinFree()) {
108  minFree_ = *p;
109  }
110  if (std::string const* p = pSLC->sourceCacheHint()) {
111  cacheHint_ = *p;
112  }
113  if (std::string const* p = pSLC->sourceReadHint()) {
114  readHint_ = *p;
115  }
116  if (unsigned int const* p = pSLC->sourceTimeout()) {
117  timeout_ = *p;
118  }
119  if (std::vector<std::string> const* p = pSLC->sourceNativeProtocols()) {
120  native_ = *p;
121  }
122  debugLevel_ = pSLC->debugLevel();
124  }
125 
126  // Prefetching does not work with storage-only; forcibly disable it.
127  if ((enablePrefetching_) && ((cacheHint_ == "storage-only") || (cacheHint_ == "auto-detect")))
128  cacheHint_ = "application-only";
129 
130  // tell factory how clients should access files
131  if (cacheHint_ == "application-only")
132  f->setCacheHint(StorageFactory::CACHE_HINT_APPLICATION);
133  else if (cacheHint_ == "storage-only")
134  f->setCacheHint(StorageFactory::CACHE_HINT_STORAGE);
135  else if (cacheHint_ == "lazy-download")
136  f->setCacheHint(StorageFactory::CACHE_HINT_LAZY_DOWNLOAD);
137  else if (cacheHint_ == "auto-detect")
138  f->setCacheHint(StorageFactory::CACHE_HINT_AUTO_DETECT);
139  else
140  throw cms::Exception("TFileAdaptor") << "Unrecognised 'cacheHint' value '" << cacheHint_
141  << "', recognised values are 'application-only',"
142  << " 'storage-only', 'lazy-download', 'auto-detect'";
143 
144  if (readHint_ == "direct-unbuffered")
145  f->setReadHint(StorageFactory::READ_HINT_UNBUFFERED);
146  else if (readHint_ == "read-ahead-buffered")
147  f->setReadHint(StorageFactory::READ_HINT_READAHEAD);
148  else if (readHint_ == "auto-detect")
149  f->setReadHint(StorageFactory::READ_HINT_AUTO);
150  else
151  throw cms::Exception("TFileAdaptor") << "Unrecognised 'readHint' value '" << readHint_
152  << "', recognised values are 'direct-unbuffered',"
153  << " 'read-ahead-buffered', 'auto-detect'";
154 
155  f->setTimeout(timeout_);
156  f->setDebugLevel(debugLevel_);
157 
158  // enable file access stats accounting if requested
159  f->enableAccounting(doStats_);
160 
161  // tell where to save files.
162  f->setTempDir(tempDir_, minFree_);
163 
164  // set our own root plugins
165  TPluginManager* mgr = gROOT->GetPluginManager();
166 
167  // Make sure ROOT parses system directories first.
168  mgr->LoadHandlersFromPluginDirs("TFile");
169  mgr->LoadHandlersFromPluginDirs("TSystem");
170 
171  if (!native("file"))
172  addType(mgr, "^file:");
173  if (!native("http"))
174  addType(mgr, "^http:");
175  if (!native("http"))
176  addType(mgr, "^http[s]?:");
177  if (!native("ftp"))
178  addType(mgr, "^ftp:");
179  /* always */ addType(mgr, "^web:");
180  /* always */ addType(mgr, "^gsiftp:");
181  /* always */ addType(mgr, "^sfn:");
182  if (!native("rfio"))
183  addType(mgr, "^rfio:");
184  if (!native("dcache"))
185  addType(mgr, "^dcache:");
186  if (!native("dcap"))
187  addType(mgr, "^dcap:");
188  if (!native("gsidcap"))
189  addType(mgr, "^gsidcap:");
190  if (!native("storm"))
191  addType(mgr, "^storm:");
192  if (!native("storm-lcg"))
193  addType(mgr, "^storm-lcg:");
194  if (!native("lstore"))
195  addType(mgr, "^lstore:");
196  if (!native("root"))
197  addType(mgr, "^root:", 1); // See comments in addType
198  if (!native("root"))
199  addType(mgr, "^[x]?root:", 1); // See comments in addType
200 
201  // Make sure the TStorageFactoryFile can be loaded regardless of the header auto-parsing setting
202  {
203  edm::SetClassParsing guard(true);
204  if (auto cl = TClass::GetClass("TStorageFactoryFile")) {
205  cl->GetClassInfo();
206  } else {
207  throw cms::Exception("TFileAdaptor") << "Unable to obtain TClass for TStorageFactoryFile";
208  }
209  }
210 }
unsigned int timeout_
Definition: TFileAdaptor.h:47
bool native(char const *proto) const
Definition: TFileAdaptor.cc:65
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
std::string cacheHint_
Definition: TFileAdaptor.h:43
std::string readHint_
Definition: TFileAdaptor.h:44
void termination(void) const
double minFree_
Definition: TFileAdaptor.h:46
std::string tempDir_
Definition: TFileAdaptor.h:45
virtual bool enablePrefetching() const =0
unsigned int debugLevel_
Definition: TFileAdaptor.h:48
bool enablePrefetching_
Definition: TFileAdaptor.h:42
virtual std::string const * sourceCacheTempDir() const =0
virtual unsigned int const * sourceTimeout() const =0
double f[11][100]
virtual unsigned int debugLevel() const =0
std::vector< std::string > native_
Definition: TFileAdaptor.h:49
static void addType(TPluginManager *mgr, char const *type, int altType=0)
Definition: TFileAdaptor.cc:39
virtual std::vector< std::string > const * sourceNativeProtocols() const =0
virtual double const * sourceCacheMinFree() const =0
virtual std::string const * sourceCacheHint() const =0
bool isAvailable() const
Definition: Service.h:40
virtual std::string const * sourceReadHint() const =0

Member Function Documentation

◆ addType()

void TFileAdaptor::addType ( TPluginManager *  mgr,
char const *  type,
int  altType = 0 
)
staticprivate

Register TFileAdaptor to be the handler for a given type.

Once registered, URLs matching a specified regexp (for example, ^lstore: to manage files starting with lstore://) will be managed by a TFileAdaptor instance, possibly overriding any built-in ROOT adaptors.

Parameters
[in]mgrThe ROOT plugin manager object.
[in]typeA regexp-string; URLs matching this string will use TFileAdaptor.
[in]altTypeDue to a limitation in the TPluginManager, if the type was previously managed by TXNetFile, we must invoke AddHandler with a slightly different syntax. Set this parameter to 1 if this applies to you. Otherwise, leave it at the default (0)

Definition at line 39 of file TFileAdaptor.cc.

Referenced by TFileAdaptor().

39  {
40  // HACK:
41  // The ROOT plug-in manager does not understand loading plugins with different
42  // signatures. So, because TXNetSystem is registered with a different constructor
43  // than all the other plugins, we must match its interface in order to override
44  // it.
45  if (altType == 0) {
46  mgr->AddHandler("TFile",
47  type,
48  "TStorageFactoryFile",
49  "IOPoolTFileAdaptor",
50  "TStorageFactoryFile(char const*,Option_t*,char const*,Int_t)");
51 
52  mgr->AddHandler("TSystem", type, "TStorageFactorySystem", "IOPoolTFileAdaptor", "TStorageFactorySystem()");
53  } else if (altType == 1) {
54  mgr->AddHandler("TFile",
55  type,
56  "TStorageFactoryFile",
57  "IOPoolTFileAdaptor",
58  "TStorageFactoryFile(char const*,Option_t*,char const*,Int_t, Int_t, Bool_t)");
59 
60  mgr->AddHandler(
61  "TSystem", type, "TStorageFactorySystem", "IOPoolTFileAdaptor", "TStorageFactorySystem(const char *,Bool_t)");
62  }
63 }

◆ fillDescriptions()

void TFileAdaptor::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 212 of file TFileAdaptor.cc.

References edm::ConfigurationDescriptions::add(), submitPVResolutionJobs::desc, and AlCaHLTBitMon_QueryRunRegistry::string.

212  {
214  desc.addOptionalUntracked<bool>("enable");
215  desc.addOptionalUntracked<bool>("stats");
216  desc.addOptionalUntracked<std::string>("cacheHint");
217  desc.addOptionalUntracked<std::string>("readHint");
218  desc.addOptionalUntracked<std::string>("tempDir");
219  desc.addOptionalUntracked<double>("tempMinFree");
220  desc.addOptionalUntracked<std::vector<std::string> >("native");
221  descriptions.add("AdaptorConfig", desc);
222 }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ native()

bool TFileAdaptor::native ( char const *  proto) const
private

Definition at line 65 of file TFileAdaptor.cc.

References spr::find(), and native_.

Referenced by TFileAdaptor().

65  {
66  return std::find(native_.begin(), native_.end(), "all") != native_.end() ||
67  std::find(native_.begin(), native_.end(), proto) != native_.end();
68 }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::vector< std::string > native_
Definition: TFileAdaptor.h:49

◆ stats()

void TFileAdaptor::stats ( std::ostream &  o) const
private

Definition at line 234 of file TFileAdaptor.cc.

References cacheHint_, doStats_, enablePrefetching_, EcalTangentSkim_cfg::o, readHint_, and edm::storage::StorageAccount::summaryText().

234  {
235  if (!doStats_) {
236  return;
237  }
238  float const oneMeg = 1048576.0;
239  o << "Storage parameters: adaptor: true"
240  << " Stats:" << (doStats_ ? "true" : "false") << '\n'
241  << " Prefetching:" << (enablePrefetching_ ? "true" : "false") << '\n'
242  << " Cache hint:" << cacheHint_ << '\n'
243  << " Read hint:" << readHint_ << '\n'
244  << "Storage statistics: " << edm::storage::StorageAccount::summaryText() << "; tfile/read=?/?/"
245  << (TFile::GetFileBytesRead() / oneMeg) << "MB/?ms/?ms/?ms"
246  << "; tfile/write=?/?/" << (TFile::GetFileBytesWritten() / oneMeg) << "MB/?ms/?ms/?ms";
247 }
static std::string summaryText(bool banner=false)
std::string cacheHint_
Definition: TFileAdaptor.h:43
std::string readHint_
Definition: TFileAdaptor.h:44
bool enablePrefetching_
Definition: TFileAdaptor.h:42

◆ statsXML()

void TFileAdaptor::statsXML ( std::map< std::string, std::string > &  data) const
private

Definition at line 249 of file TFileAdaptor.cc.

References cacheHint_, data, doStats_, enablePrefetching_, edm::storage::StorageAccount::fillSummary(), alignCSCRings::r, readHint_, and w().

Referenced by termination().

249  {
250  if (!doStats_) {
251  return;
252  }
253  float const oneMeg = 1048576.0;
254  data.insert(std::make_pair("Parameter-untracked-bool-enabled", "true"));
255  data.insert(std::make_pair("Parameter-untracked-bool-stats", (doStats_ ? "true" : "false")));
256  data.insert(std::make_pair("Parameter-untracked-bool-prefetching", (enablePrefetching_ ? "true" : "false")));
257  data.insert(std::make_pair("Parameter-untracked-string-cacheHint", cacheHint_));
258  data.insert(std::make_pair("Parameter-untracked-string-readHint", readHint_));
260  std::ostringstream r;
261  std::ostringstream w;
262  r << (TFile::GetFileBytesRead() / oneMeg);
263  w << (TFile::GetFileBytesWritten() / oneMeg);
264  data.insert(std::make_pair("ROOT-tfile-read-totalMegabytes", r.str()));
265  data.insert(std::make_pair("ROOT-tfile-write-totalMegabytes", w.str()));
266 }
T w() const
std::string cacheHint_
Definition: TFileAdaptor.h:43
std::string readHint_
Definition: TFileAdaptor.h:44
static void fillSummary(std::map< std::string, std::string > &summary)
bool enablePrefetching_
Definition: TFileAdaptor.h:42
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80

◆ termination()

void TFileAdaptor::termination ( void  ) const
private

Definition at line 225 of file TFileAdaptor.cc.

References data, edm::JobReport::reportPerformanceSummary(), and statsXML().

Referenced by TFileAdaptor().

225  {
226  std::map<std::string, std::string> data;
227  statsXML(data);
228  if (!data.empty()) {
230  reportSvc->reportPerformanceSummary("StorageStatistics", data);
231  }
232 }
void reportPerformanceSummary(std::string const &metricClass, std::map< std::string, std::string > const &metrics)
Definition: JobReport.cc:703
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
void statsXML(std::map< std::string, std::string > &data) const

Friends And Related Function Documentation

◆ TFileAdaptorUI

friend class TFileAdaptorUI
friend

Definition at line 26 of file TFileAdaptor.h.

Member Data Documentation

◆ cacheHint_

std::string TFileAdaptor::cacheHint_
private

Definition at line 43 of file TFileAdaptor.h.

Referenced by stats(), statsXML(), and TFileAdaptor().

◆ debugLevel_

unsigned int TFileAdaptor::debugLevel_
private

Definition at line 48 of file TFileAdaptor.h.

Referenced by TFileAdaptor().

◆ doStats_

bool TFileAdaptor::doStats_
private

Definition at line 41 of file TFileAdaptor.h.

Referenced by stats(), statsXML(), and TFileAdaptor().

◆ enabled_

bool TFileAdaptor::enabled_
private

Definition at line 40 of file TFileAdaptor.h.

Referenced by TFileAdaptor().

◆ enablePrefetching_

bool TFileAdaptor::enablePrefetching_
private

Definition at line 42 of file TFileAdaptor.h.

Referenced by stats(), statsXML(), and TFileAdaptor().

◆ minFree_

double TFileAdaptor::minFree_
private

Definition at line 46 of file TFileAdaptor.h.

Referenced by TFileAdaptor().

◆ native_

std::vector<std::string> TFileAdaptor::native_
private

Definition at line 49 of file TFileAdaptor.h.

Referenced by native(), and TFileAdaptor().

◆ readHint_

std::string TFileAdaptor::readHint_
private

Definition at line 44 of file TFileAdaptor.h.

Referenced by stats(), statsXML(), and TFileAdaptor().

◆ tempDir_

std::string TFileAdaptor::tempDir_
private

Definition at line 45 of file TFileAdaptor.h.

Referenced by TFileAdaptor().

◆ timeout_

unsigned int TFileAdaptor::timeout_
private

Definition at line 47 of file TFileAdaptor.h.

Referenced by TFileAdaptor().