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 &pset, 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, int altType=0)

Private Attributes

std::string cacheHint_
unsigned int debugLevel_
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 &  pset,
edm::ActivityRegistry ar 
)

Definition at line 81 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_, debugLevel_, doStats_, StorageFactory::enableAccounting(), enabled_, Exception, f, reco::get(), edm::ParameterSet::getUntrackedParameter(), edm::Service< T >::isAvailable(), minFree_, native(), native_, AlCaHLTBitMon_ParallelJobs::p, StorageFactory::READ_HINT_AUTO, StorageFactory::READ_HINT_READAHEAD, StorageFactory::READ_HINT_UNBUFFERED, readHint_, StorageFactory::setCacheHint(), StorageFactory::setDebugLevel(), 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),
      debugLevel_(0U),
      native_() {
    if (!(enabled_ = pset.getUntrackedParameter<bool> ("enable", enabled_)))
      return;

    StorageFactory* f = StorageFactory::get();
    doStats_ = pset.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_ = pset.getUntrackedParameter<std::string> ("cacheHint", cacheHint_);
    readHint_ = pset.getUntrackedParameter<std::string> ("readHint", readHint_);
    tempDir_ = pset.getUntrackedParameter<std::string> ("tempDir", f->tempPath());
    minFree_ = pset.getUntrackedParameter<double> ("tempMinFree", f->tempMinFree());
    native_ = pset.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;
      }
      debugLevel_ = pSLC->debugLevel();
    }

    // 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_);
    f->setDebugLevel(debugLevel_);

    // 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:");
    // This is ready to go from a code point-of-view.
    // Waiting on the validation "OK" from Computing.
    if (!native("root"))      addType(mgr, "^root:", 1); // See comments in addType
  }

Member Function Documentation

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

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 40 of file TFileAdaptor.cc.

Referenced by TFileAdaptor().

                                                                            {

    // HACK:
    // The ROOT plug-in manager does not understand loading plugins with different
    // signatures.  So, because TXNetSystem is registered with a different constructor
    // than all the other plugins, we must match its interface in order to override
    // it.
    if (altType == 0) {
      mgr->AddHandler("TFile",
                      type,
                      "TStorageFactoryFile",
                      "IOPoolTFileAdaptor",
                      "TStorageFactoryFile(char const*,Option_t*,char const*,Int_t)");

      mgr->AddHandler("TSystem",
                      type,
                      "TStorageFactorySystem",
                      "IOPoolTFileAdaptor",
                      "TStorageFactorySystem()");
    } else if (altType == 1) {
      mgr->AddHandler("TFile",
                      type,
                      "TStorageFactoryFile",
                      "IOPoolTFileAdaptor",
                      "TStorageFactoryFile(char const*,Option_t*,char const*,Int_t, Int_t, Bool_t)");

      mgr->AddHandler("TSystem",
                      type,
                      "TStorageFactorySystem",
                      "IOPoolTFileAdaptor",
                      "TStorageFactorySystem(const char *,Bool_t)");
    }

  }
void TFileAdaptor::fillDescriptions ( edm::ConfigurationDescriptions descriptions) [static]

Definition at line 193 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 76 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 217 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 233 of file TFileAdaptor.cc.

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

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 207 of file TFileAdaptor.cc.

References 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().

unsigned int TFileAdaptor::debugLevel_ [private]

Definition at line 41 of file TFileAdaptor.h.

Referenced by 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 42 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().