CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes

TFileAdaptor Class Reference

#include <TFileAdaptor.h>

List of all members.

Public Member Functions

void stats (std::ostream &o) const
void statsXML (std::map< std::string, std::string > &data) const
void termination (void) const
 TFileAdaptor (edm::ParameterSet const &p, edm::ActivityRegistry &ar)

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)

Private Member Functions

bool native (char const *proto) const

Static Private Member Functions

static void addType (TPluginManager *mgr, char const *type)

Private Attributes

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

Detailed Description

Definition at line 17 of file TFileAdaptor.h.


Constructor & Destructor Documentation

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

Definition at line 45 of file TFileAdaptor.cc.

References addType(), StorageFactory::CACHE_HINT_APPLICATION, StorageFactory::CACHE_HINT_AUTO_DETECT, StorageFactory::CACHE_HINT_LAZY_DOWNLOAD, StorageFactory::CACHE_HINT_STORAGE, cacheHint_, doStats_, StorageFactory::enableAccounting(), enabled_, Exception, f, reco::get(), edm::ParameterSet::getUntrackedParameter(), edm::Service< T >::isAvailable(), minFree_, native(), native_, L1TEmulatorMonitor_cff::p, StorageFactory::READ_HINT_AUTO, StorageFactory::READ_HINT_READAHEAD, StorageFactory::READ_HINT_UNBUFFERED, readHint_, StorageFactory::setCacheHint(), StorageFactory::setReadHint(), StorageFactory::setTempDir(), StorageFactory::setTimeout(), tempDir_, StorageFactory::tempMinFree(), StorageFactory::tempPath(), termination(), timeout_, and edm::ActivityRegistry::watchPostEndJob().

    : enabled_(true),
      doStats_(true),
      cacheHint_("application-only"),
      readHint_("auto-detect"),
      tempDir_(),
      minFree_(0),
      timeout_(0U),
      native_() {
    if (!(enabled_ = p.getUntrackedParameter<bool> ("enable", enabled_)))
      return;

    StorageFactory* f = StorageFactory::get();
    doStats_ = p.getUntrackedParameter<bool> ("stats", doStats_);

    // values set in the site local config or in SiteLocalConfigService override
    // any values set here for this service.
    // These parameters here are needed only for backward compatibility
    // for WMDM tools until we switch to only using the site local config for this info.
    cacheHint_ = p.getUntrackedParameter<std::string> ("cacheHint", cacheHint_);
    readHint_ = p.getUntrackedParameter<std::string> ("readHint", readHint_);
    tempDir_ = p.getUntrackedParameter<std::string> ("tempDir", f->tempPath());
    minFree_ = p.getUntrackedParameter<double> ("tempMinFree", f->tempMinFree());
    native_ = p.getUntrackedParameter<std::vector<std::string> >("native", native_);

    ar.watchPostEndJob(this, &TFileAdaptor::termination);

    // Retrieve values from SiteLocalConfigService.
    // Any such values will override values set above.
    edm::Service<edm::SiteLocalConfig> pSLC;
    if (pSLC.isAvailable()) {
      if (std::string const* p = pSLC->sourceCacheTempDir()) {
        tempDir_ = *p;
      }
      if (double const* p = pSLC->sourceCacheMinFree()) {
        minFree_ = *p;
      }
      if (std::string const* p = pSLC->sourceCacheHint()) {
        cacheHint_ = *p;
      }
      if (std::string const* p = pSLC->sourceReadHint()) {
        readHint_ = *p;
      }
      if (unsigned int const* p = pSLC->sourceTimeout()) {
        timeout_ = *p;
      }
      if (std::vector<std::string> const* p = pSLC->sourceNativeProtocols()) {
        native_ = *p;
      }
    }

    // tell factory how clients should access files
    if (cacheHint_ == "application-only")
      f->setCacheHint(StorageFactory::CACHE_HINT_APPLICATION);
    else if (cacheHint_ == "storage-only")
      f->setCacheHint(StorageFactory::CACHE_HINT_STORAGE);
    else if (cacheHint_ == "lazy-download")
      f->setCacheHint(StorageFactory::CACHE_HINT_LAZY_DOWNLOAD);
    else if (cacheHint_ == "auto-detect")
      f->setCacheHint(StorageFactory::CACHE_HINT_AUTO_DETECT);
    else
      throw cms::Exception("TFileAdaptor")
        << "Unrecognised 'cacheHint' value '" << cacheHint_
        << "', recognised values are 'application-only',"
        << " 'storage-only', 'lazy-download', 'auto-detect'";

    if (readHint_ == "direct-unbuffered")
      f->setReadHint(StorageFactory::READ_HINT_UNBUFFERED);
    else if (readHint_ == "read-ahead-buffered")
      f->setReadHint(StorageFactory::READ_HINT_READAHEAD);
    else if (readHint_ == "auto-detect")
      f->setReadHint(StorageFactory::READ_HINT_AUTO);
    else
      throw cms::Exception("TFileAdaptor")
        << "Unrecognised 'readHint' value '" << readHint_
        << "', recognised values are 'direct-unbuffered',"
        << " 'read-ahead-buffered', 'auto-detect'";

    f->setTimeout(timeout_);

    // enable file access stats accounting if requested
    f->enableAccounting(doStats_);

    // tell where to save files.
    f->setTempDir(tempDir_, minFree_);

    // set our own root plugins
    TPluginManager* mgr = gROOT->GetPluginManager();
    mgr->LoadHandlersFromPluginDirs();

    if (!native("file"))      addType(mgr, "^file:");
    if (!native("https"))      addType(mgr, "^https:");
    if (!native("ftp"))       addType(mgr, "^ftp:");
    /* always */              addType(mgr, "^web:");
    /* always */              addType(mgr, "^gsiftp:");
    /* always */              addType(mgr, "^sfn:");
    if (!native("rfio"))      addType(mgr, "^rfio:");
    if (!native("dcache"))    addType(mgr, "^dcache:");
    if (!native("dcap"))      addType(mgr, "^dcap:");
    if (!native("gsidcap"))   addType(mgr, "^gsidcap:");
    if (!native("storm"))     addType(mgr, "^storm:");
    if (!native("storm-lcg")) addType(mgr, "^storm-lcg:");
    if (!native("lstore"))    addType(mgr, "^lstore:");
  }

Member Function Documentation

void TFileAdaptor::addType ( TPluginManager *  mgr,
char const *  type 
) [static, private]

Definition at line 25 of file TFileAdaptor.cc.

Referenced by TFileAdaptor().

                                                             {
    mgr->AddHandler("TFile",
                    type,
                    "TStorageFactoryFile",
                    "IOPoolTFileAdaptor",
                    "TStorageFactoryFile(char const*,Option_t*,char const*,Int_t)");

    mgr->AddHandler("TSystem",
                    type,
                    "TStorageFactorySystem",
                    "IOPoolTFileAdaptor",
                    "TStorageFactorySystem()");
  }
void TFileAdaptor::fillDescriptions ( edm::ConfigurationDescriptions descriptions) [static]

Definition at line 151 of file TFileAdaptor.cc.

References edm::ConfigurationDescriptions::add(), and edm::ParameterSetDescription::addOptionalUntracked().

                                                                           {
    edm::ParameterSetDescription desc;
    desc.addOptionalUntracked<bool>("enable");
    desc.addOptionalUntracked<bool>("stats");
    desc.addOptionalUntracked<std::string>("cacheHint");
    desc.addOptionalUntracked<std::string>("readHint");
    desc.addOptionalUntracked<std::string>("tempDir");
    desc.addOptionalUntracked<double>("tempMinFree");
    desc.addOptionalUntracked<std::vector<std::string> >("native");
    descriptions.add("AdaptorConfig", desc);
  }
bool TFileAdaptor::native ( char const *  proto) const [private]

Definition at line 40 of file TFileAdaptor.cc.

References spr::find(), and native_.

Referenced by TFileAdaptor().

                                              {
    return std::find(native_.begin(), native_.end(), "all") != native_.end()
      || std::find(native_.begin(), native_.end(), proto) != native_.end();
  }
void TFileAdaptor::stats ( std::ostream &  o) const

Definition at line 175 of file TFileAdaptor.cc.

References cacheHint_, doStats_, readHint_, and StorageAccount::summaryText().

                                         {
    if (!doStats_) {
      return;
    }
    float const oneMeg = 1048576.0;
    o << "Storage parameters: adaptor: true"
      << " Stats:" << (doStats_ ? "true" : "false") << '\n'
      << " Cache hint:" << cacheHint_ << '\n'
      << " Read hint:" << readHint_ << '\n'
      << "Storage statistics: "
      << StorageAccount::summaryText()
      << "; tfile/read=?/?/" << (TFile::GetFileBytesRead() / oneMeg) << "MB/?ms/?ms/?ms"
      << "; tfile/write=?/?/" << (TFile::GetFileBytesWritten() / oneMeg) << "MB/?ms/?ms/?ms";
  }
void TFileAdaptor::statsXML ( std::map< std::string, std::string > &  data) const

Definition at line 191 of file TFileAdaptor.cc.

References cacheHint_, doStats_, StorageAccount::fillSummary(), csvReporter::r, and readHint_.

Referenced by termination().

                                                                 {
    if (!doStats_) {
      return;
    }
    float const oneMeg = 1048576.0;
    data.insert(std::make_pair("Parameter-untracked-bool-enabled", "true"));
    data.insert(std::make_pair("Parameter-untracked-bool-stats", (doStats_ ? "true" : "false")));
    data.insert(std::make_pair("Parameter-untracked-string-cacheHint", cacheHint_));
    data.insert(std::make_pair("Parameter-untracked-string-readHint", readHint_));
    StorageAccount::fillSummary(data);
    std::ostringstream r;
    std::ostringstream w;
    r << (TFile::GetFileBytesRead() / oneMeg);
    w << (TFile::GetFileBytesWritten() / oneMeg);
    data.insert(std::make_pair("ROOT-tfile-read-totalMegabytes", r.str()));
    data.insert(std::make_pair("ROOT-tfile-write-totalMegabytes", w.str()));
  }
void TFileAdaptor::termination ( void  ) const

Definition at line 165 of file TFileAdaptor.cc.

References runTheMatrix::data, and statsXML().

Referenced by TFileAdaptor().

                                      {
    std::map<std::string, std::string> data;
    statsXML(data);
    if (!data.empty()) {
      edm::Service<edm::JobReport> reportSvc;
      reportSvc->reportPerformanceSummary("StorageStatistics", data);
    }
  }

Member Data Documentation

std::string TFileAdaptor::cacheHint_ [private]

Definition at line 36 of file TFileAdaptor.h.

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

bool TFileAdaptor::doStats_ [private]

Definition at line 35 of file TFileAdaptor.h.

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

bool TFileAdaptor::enabled_ [private]

Definition at line 34 of file TFileAdaptor.h.

Referenced by TFileAdaptor().

double TFileAdaptor::minFree_ [private]

Definition at line 39 of file TFileAdaptor.h.

Referenced by TFileAdaptor().

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

Definition at line 41 of file TFileAdaptor.h.

Referenced by native(), and TFileAdaptor().

std::string TFileAdaptor::readHint_ [private]

Definition at line 37 of file TFileAdaptor.h.

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

std::string TFileAdaptor::tempDir_ [private]

Definition at line 38 of file TFileAdaptor.h.

Referenced by TFileAdaptor().

unsigned int TFileAdaptor::timeout_ [private]

Definition at line 40 of file TFileAdaptor.h.

Referenced by TFileAdaptor().