CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
InputFileCatalog.cc
Go to the documentation of this file.
1 //
4 
6 
9 
10 #include <boost/algorithm/string.hpp>
11 
12 namespace edm {
13 
14  InputFileCatalog::InputFileCatalog(std::vector<std::string> const& fileNames, std::string const& override, bool useLFNasPFNifLFNnotFound) :
15  logicalFileNames_(fileNames),
16  fileNames_(fileNames),
17  fallbackFileNames_(fileNames.size()),
18  fileCatalogItems_(),
19  fileLocator_(),
20  overrideFileLocator_(),
21  fallbackFileLocator_(),
22  overrideFallbackFileLocator_() {
23 
24  init(override, "", useLFNasPFNifLFNnotFound);
25  }
26 
27  InputFileCatalog::InputFileCatalog(std::vector<std::string> const& fileNames, std::string const& override, std::string const& overrideFallback, bool useLFNasPFNifLFNnotFound) :
28  logicalFileNames_(fileNames),
29  fileNames_(fileNames),
30  fallbackFileNames_(fileNames.size()),
31  fileCatalogItems_(),
32  fileLocator_(),
33  overrideFileLocator_(),
34  fallbackFileLocator_(),
35  overrideFallbackFileLocator_() {
36 
37  init(override, overrideFallback, useLFNasPFNifLFNnotFound);
38  }
39 
41 
42  void InputFileCatalog::init(std::string const& inputOverride, std::string const& inputOverrideFallback, bool useLFNasPFNifLFNnotFound) {
43 
44  fileCatalogItems_.reserve(fileNames_.size());
45  typedef std::vector<std::string>::iterator iter;
46  for(iter it = fileNames_.begin(), lt = logicalFileNames_.begin(), itEnd = fileNames_.end(), ft = fallbackFileNames_.begin();
47  it != itEnd; ++it, ++lt, ++ft) {
48  boost::trim(*it);
49  if (it->empty()) {
50  throw Exception(errors::Configuration, "InputFileCatalog::InputFileCatalog()\n")
51  << "An empty string specified in the fileNames parameter for input source.\n";
52  }
53  if (isPhysical(*it)) {
54  // Clear the LFN.
55  lt->clear();
56  } else {
57  if (!fileLocator_) {
58  fileLocator_.reset(new FileLocator("", false));
59  }
60  if (!overrideFileLocator_ && !inputOverride.empty()) {
61  overrideFileLocator_.reset(new FileLocator(inputOverride, false));
62  }
63  if (!fallbackFileLocator_) {
64  try {
65  fallbackFileLocator_.reset(new FileLocator("", true));
66  } catch (cms::Exception const& e) {
67  // No valid fallback locator is OK too.
68  }
69  }
70  if (!overrideFallbackFileLocator_ && !inputOverrideFallback.empty()) {
71  overrideFallbackFileLocator_.reset(new FileLocator(inputOverrideFallback, true));
72  }
73  boost::trim(*lt);
74  findFile(*it, *ft, *lt, useLFNasPFNifLFNnotFound);
75  }
76  fileCatalogItems_.push_back(FileCatalogItem(*it, *lt, *ft));
77  }
78  }
79 
80  void InputFileCatalog::findFile(std::string& pfn, std::string& fallbackPfn, std::string const& lfn, bool useLFNasPFNifLFNnotFound) {
82  pfn = overrideFileLocator_->pfn(lfn);
83  if (pfn.empty()) {
84  pfn = fileLocator_->pfn(lfn);
85  }
86  } else {
87  pfn = fileLocator_->pfn(lfn);
88  }
89  if (pfn.empty() && useLFNasPFNifLFNnotFound) {
90  pfn = lfn;
91  }
92  // Empty PFN will be found by caller.
93 
95  fallbackPfn = overrideFallbackFileLocator_->pfn(lfn);
96  if (fallbackFileLocator_ && fallbackPfn.empty()) {
97  fallbackPfn = fallbackFileLocator_->pfn(lfn);
98  }
99  } else if (fallbackFileLocator_) {
100  fallbackPfn = fallbackFileLocator_->pfn(lfn);
101  // Empty fallback PFN is OK.
102  }
103  }
104 }
list pfn
Definition: dbtoconf.py:76
boost::scoped_ptr< FileLocator > fallbackFileLocator_
std::vector< FileCatalogItem > fileCatalogItems_
boost::scoped_ptr< FileLocator > overrideFileLocator_
boost::scoped_ptr< FileLocator > fileLocator_
std::vector< std::string > fileNames_
static bool isPhysical(std::string const &name)
boost::scoped_ptr< FileLocator > overrideFallbackFileLocator_
std::vector< std::string > fallbackFileNames_
< trclass="colgroup">< tdclass="colgroup"colspan=5 > DT local reconstruction</td ></tr >< tr >< td >< ahref="classDTRecHit1DPair.html"> DTRecHit1DPair</a ></td >< td >< ahref="DataFormats_DTRecHit.html"> edm::RangeMap & lt
tuple fileNames
Definition: LaserDQM_cfg.py:34
void init(std::string const &override, std::string const &overrideFallback, bool useLFNasPFNifLFNnotFound)
InputFileCatalog(std::vector< std::string > const &fileNames, std::string const &override, bool useLFNasPFNifLFNnotFound=false)
std::vector< std::string > logicalFileNames_
void findFile(std::string &pfn, std::string &fallbackPfn, std::string const &lfn, bool useLFNasPFNifLFNnotFound)
tuple size
Write out results.