CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
RootInputFileSequence.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 #include "RootFile.h"
5 
13 
14 #include "TSystem.h"
15 
16 namespace edm {
17  class BranchIDListHelper;
18  class EventPrincipal;
19  class LuminosityBlockPrincipal;
20  class RunPrincipal;
21 
23  : catalog_(catalog),
24  lfn_("unknown"),
25  lfnHash_(0U),
26  usedFallback_(false),
27  findFileForSpecifiedID_(nullptr),
28  fileIterBegin_(fileCatalogItems().begin()),
29  fileIterEnd_(fileCatalogItems().end()),
30  fileIter_(fileIterEnd_),
31  fileIterLastOpened_(fileIterEnd_),
32  rootFile_(),
33  indexesIntoFiles_(fileCatalogItems().size()) {}
34 
35  std::vector<FileCatalogItem> const& RootInputFileSequence::fileCatalogItems() const {
36  return catalog_.fileCatalogItems();
37  }
38 
39  std::shared_ptr<ProductRegistry const> RootInputFileSequence::fileProductRegistry() const {
40  assert(rootFile());
41  return rootFile()->productRegistry();
42  }
43 
44  std::shared_ptr<BranchIDListHelper const> RootInputFileSequence::fileBranchIDListHelper() const {
45  assert(rootFile());
46  return rootFile()->branchIDListHelper();
47  }
48 
50 
51  std::shared_ptr<RunAuxiliary> RootInputFileSequence::readRunAuxiliary_() {
52  assert(rootFile());
53  return rootFile()->readRunAuxiliary_();
54  }
55 
56  std::shared_ptr<LuminosityBlockAuxiliary> RootInputFileSequence::readLuminosityBlockAuxiliary_() {
57  assert(rootFile());
58  return rootFile()->readLuminosityBlockAuxiliary_();
59  }
60 
62  assert(rootFile());
63  rootFile()->readRun_(runPrincipal);
64  }
65 
67  assert(rootFile());
68  return rootFile()->fillProcessBlockHelper_();
69  }
70 
72  assert(rootFile());
73  return rootFile()->nextProcessBlock_(processBlockPrincipal);
74  }
75 
77  assert(rootFile());
78  rootFile()->readProcessBlock_(processBlockPrincipal);
79  }
80 
82  assert(rootFile());
83  rootFile()->readLuminosityBlock_(lumiPrincipal);
84  }
85 
86  // readEvent() is responsible for setting up the EventPrincipal.
87  //
88  // 1. fill an EventPrincipal with a unique EventID
89  // 2. For each entry in the provenance, put in one ProductResolver,
90  // holding the Provenance for the corresponding EDProduct.
91  // 3. set up the caches in the EventPrincipal to know about this
92  // ProductResolver.
93  //
94  // We do *not* create the EDProduct instance (the equivalent of reading
95  // the branch containing this EDProduct. That will be done by the Delayed Reader,
96  // when it is asked to do so.
97  //
98 
100  assert(rootFile());
101  return rootFile()->readEvent(eventPrincipal);
102  }
103 
106  EventNumber_t event) const {
107  if (!rootFile())
108  return false;
109  return rootFile()->containsItem(run, lumi, event);
110  }
111 
115  size_t fileNameHash) {
116  // Look for item in files not yet opened. We have a hash of the logical file name
117  assert(fileNameHash != 0U);
118  // If the lookup table is not yet filled in, fill it.
120  // We use a multimap because there may be hash collisions (Two different LFNs could have the same hash).
121  // We map the hash of the LFN to the index into the list of files.
123  std::make_unique<std::unordered_multimap<size_t, size_t>>(); // propagate_const<T> has no reset() function
124  auto hasher = std::hash<std::string>();
125  for (auto fileIter = fileIterBegin_; fileIter != fileIterEnd_; ++fileIter) {
126  findFileForSpecifiedID_->insert(std::make_pair(hasher(fileIter->logicalFileName()), fileIter - fileIterBegin_));
127  }
128  }
129  // Look up the logical file name in the table
130  auto range = findFileForSpecifiedID_->equal_range(fileNameHash);
131  for (auto iter = range.first; iter != range.second; ++iter) {
132  // Don't look in files previously opened, because those have already been searched.
133  if (!indexesIntoFiles_[iter->second]) {
134  setAtFileSequenceNumber(iter->second);
135  initFile_(false);
136  assert(rootFile());
137  bool found = rootFile()->setEntryAtItem(run, lumi, event);
138  if (found) {
139  return true;
140  }
141  }
142  }
143  // Not found
144  return false;
145  }
146 
148  // Look for item in files not yet opened. We do not have a valid hash of the logical file name.
149  for (auto it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
150  if (!*it) {
151  // File not yet opened.
153  initFile_(false);
154  assert(rootFile());
155  bool found = rootFile()->setEntryAtItem(run, lumi, event);
156  if (found) {
157  return true;
158  }
159  }
160  }
161  // Not found
162  return false;
163  }
164 
166  RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, size_t fileNameHash, bool currentFileFirst) {
167  // Attempt to find item in currently open input file.
168  bool found = currentFileFirst && rootFile() && rootFile()->setEntryAtItem(run, lumi, event);
169  if (!found) {
170  // If only one input file, give up now, to save time.
171  if (currentFileFirst && rootFile() && indexesIntoFiles_.size() == 1) {
172  return false;
173  }
174  // Look for item (run/lumi/event) in files previously opened without reopening unnecessary files.
175  for (auto it = indexesIntoFiles_.begin(), itEnd = indexesIntoFiles_.end(); it != itEnd; ++it) {
176  if (*it && (*it)->containsItem(run, lumi, event)) {
177  // We found it. Close the currently open file, and open the correct one.
178  std::vector<FileCatalogItem>::const_iterator currentIter = fileIter_;
180  if (fileIter_ != currentIter) {
181  initFile(false);
182  }
183  // Now get the item from the correct file.
184  assert(rootFile());
185  found = rootFile()->setEntryAtItem(run, lumi, event);
186  assert(found);
187  return true;
188  }
189  }
190  return (fileNameHash != 0U && skipToItemInNewFile(run, lumi, event, fileNameHash)) ||
192  }
193  return true;
194  }
195 
196  //Initiate the file using multiple data catalogs
198  bool skipBadFiles, bool deleteIndexIntoFile, InputSource* input, char const* inputTypeName, InputType inputType) {
199  // We are really going to close the open file.
200 
202  size_t currentIndexIntoFile = fileIterLastOpened_ - fileIterBegin_;
203  if (deleteIndexIntoFile) {
204  indexesIntoFiles_[currentIndexIntoFile].reset();
205  } else {
206  if (indexesIntoFiles_[currentIndexIntoFile])
207  indexesIntoFiles_[currentIndexIntoFile]->inputFileClosed();
208  }
210  }
211  closeFile_();
212 
213  if (noMoreFiles()) {
214  // No files specified
215  return;
216  }
217 
218  // Check if the logical file name was found.
219  if (fileNames()[0].empty()) {
220  // LFN not found in catalog.
222  if (!skipBadFiles) {
223  throw cms::Exception("LogicalFileNameNotFound", "RootFileSequenceBase::initTheFile()\n")
224  << "Logical file name '" << logicalFileName() << "' was not found in the file catalog.\n"
225  << "If you wanted a local file, you forgot the 'file:' prefix\n"
226  << "before the file name in your configuration file.\n";
227  }
228  LogWarning("") << "Input logical file: " << logicalFileName()
229  << " was not found in the catalog, and will be skipped.\n";
230  return;
231  }
232 
233  lfn_ = logicalFileName().empty() ? fileNames()[0] : logicalFileName();
234  lfnHash_ = std::hash<std::string>()(lfn_);
235 
236  std::shared_ptr<InputFile> filePtr;
237  std::list<std::string> originalInfo;
238 
239  std::vector<std::string> const& fNames = fileNames();
240 
241  //this tries to open the file using multiple PFNs corresponding to different data catalogs
242  std::list<std::string> exInfo;
243  for (std::vector<std::string>::const_iterator it = fNames.begin(); it != fNames.end(); ++it) {
244  try {
245  std::unique_ptr<InputSource::FileOpenSentry> sentry(
246  input ? std::make_unique<InputSource::FileOpenSentry>(*input, lfn_, false) : nullptr);
247  std::unique_ptr<char[]> name(gSystem->ExpandPathName(it->c_str()));
248  filePtr = std::make_shared<InputFile>(name.get(), " Initiating request to open file ", inputType);
249  break;
250  } catch (cms::Exception const& e) {
251  if (!skipBadFiles && std::next(it) == fNames.end()) {
254  ex.addContext("Calling RootInputFileSequence::initTheFile()");
255  std::ostringstream out;
256  out << "Input file " << (*it) << " could not be opened.";
257  ex.addAdditionalInfo(out.str());
258  //report previous exceptions when use other names to open file
259  for (auto const& s : exInfo)
260  ex.addAdditionalInfo(s);
261  throw ex;
262  } else {
263  exInfo.push_back("Calling RootInputFileSequence::initTheFile(): fail to open the file with name " + (*it));
264  }
265  }
266  }
267 
268  if (filePtr) {
269  size_t currentIndexIntoFile = fileIter_ - fileIterBegin_;
270  rootFile_ = makeRootFile(filePtr);
271  assert(rootFile_);
272  if (input) {
273  rootFile_->setSignals(&(input->preEventReadFromSourceSignal_), &(input->postEventReadFromSourceSignal_));
274  }
276  setIndexIntoFile(currentIndexIntoFile);
277  rootFile_->reportOpened(inputTypeName);
278  } else {
279  std::string fName = !fNames.empty() ? fNames[0] : "";
280  InputFile::reportSkippedFile(fName, logicalFileName()); //0 cause exception?
281  if (!skipBadFiles) {
282  throw Exception(errors::FileOpenError) << "RootFileSequenceBase::initTheFile(): Input file " << fName
283  << " was not found or could not be opened.\n";
284  }
285  LogWarning("RootInputFileSequence")
286  << "Input file: " << fName << " was not found or could not be opened, and will be skipped.\n";
287  }
288  }
289 
291  indexesIntoFiles_[index] = rootFile()->indexIntoFileSharedPtr();
292  }
293 
294 } // namespace edm
edm::RootInputFileSequence::noMoreFiles
bool noMoreFiles() const
Definition: RootInputFileSequence.h:71
edm::RootInputFileSequence::findFileForSpecifiedID_
edm::propagate_const< std::unique_ptr< std::unordered_multimap< size_t, size_t > > > findFileForSpecifiedID_
Definition: RootInputFileSequence.h:101
edm::RunNumber_t
unsigned int RunNumber_t
Definition: RunLumiEventNumber.h:14
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
RootInputFileSequence.h
edm::RootInputFileSequence::fileProductRegistry
std::shared_ptr< ProductRegistry const > fileProductRegistry() const
Definition: RootInputFileSequence.cc:39
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
edm::RootInputFileSequence::setAtFileSequenceNumber
void setAtFileSequenceNumber(size_t offset)
Definition: RootInputFileSequence.h:77
cms::Exception::addContext
void addContext(std::string const &context)
Definition: Exception.cc:165
getEcalConditions_orcoffint2r_cff.catalog
catalog
Definition: getEcalConditions_orcoffint2r_cff.py:40
edm::RootInputFileSequence::closeFile_
virtual void closeFile_()=0
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::RootInputFileSequence::lfnHash_
size_t lfnHash_
Definition: RootInputFileSequence.h:99
BranchID.h
edm::RootInputFileSequence::makeRootFile
virtual RootFileSharedPtr makeRootFile(std::shared_ptr< InputFile > filePtr)=0
edm::LuminosityBlockPrincipal
Definition: LuminosityBlockPrincipal.h:31
cms::cuda::assert
assert(be >=bs)
IndexIntoFile.h
edm::InputFileCatalog
Definition: InputFileCatalog.h:32
ProductRegistry.h
edm::RootInputFileSequence::indexesIntoFiles_
std::vector< std::shared_ptr< IndexIntoFile > > indexesIntoFiles_
Definition: RootInputFileSequence.h:107
remoteMonitoring_LED_IterMethod_cfg.skipBadFiles
skipBadFiles
Definition: remoteMonitoring_LED_IterMethod_cfg.py:24
edm::RootInputFileSequence::logicalFileName
std::string const & logicalFileName() const
Definition: RootInputFileSequence.h:84
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::LuminosityBlockNumber_t
unsigned int LuminosityBlockNumber_t
Definition: RunLumiEventNumber.h:13
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
edm::ProcessBlockPrincipal
Definition: ProcessBlockPrincipal.h:22
edm::InputType
InputType
Definition: InputType.h:5
edm::errors::FileOpenError
Definition: EDMException.h:49
MainPageGenerator.fName
fName
Definition: MainPageGenerator.py:301
edm::Exception
Definition: EDMException.h:77
edm::RootInputFileSequence::initFile
void initFile(bool skipBadFiles)
Definition: RootInputFileSequence.h:59
edm::RootInputFileSequence::setIndexIntoFile
void setIndexIntoFile(size_t index)
Definition: RootInputFileSequence.cc:290
edm::RootInputFileSequence::lfn_
std::string lfn_
Definition: RootInputFileSequence.h:98
alignCSCRings.s
s
Definition: alignCSCRings.py:92
edm::InputFile::reportSkippedFile
static void reportSkippedFile(std::string const &fileName, std::string const &logicalFileName)
Definition: InputFile.cc:75
edm::EventPrincipal
Definition: EventPrincipal.h:48
edm::RootInputFileSequence::fileIterBegin_
const std::vector< FileCatalogItem >::const_iterator fileIterBegin_
Definition: RootInputFileSequence.h:102
edm::RootInputFileSequence::nextProcessBlock_
bool nextProcessBlock_(ProcessBlockPrincipal &)
Definition: RootInputFileSequence.cc:71
mps_fire.end
end
Definition: mps_fire.py:242
edm::RootInputFileSequence::fileIter_
std::vector< FileCatalogItem >::const_iterator fileIter_
Definition: RootInputFileSequence.h:104
edm::EventNumber_t
unsigned long long EventNumber_t
Definition: RunLumiEventNumber.h:12
edm::RootInputFileSequence::readLuminosityBlockAuxiliary_
std::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_()
Definition: RootInputFileSequence.cc:56
edm::RootInputFileSequence::readRun_
void readRun_(RunPrincipal &runPrincipal)
Definition: RootInputFileSequence.cc:61
ParameterSetDescription.h
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
edm::RootInputFileSequence::RootInputFileSequence
RootInputFileSequence(ParameterSet const &pset, InputFileCatalog const &catalog)
Definition: RootInputFileSequence.cc:22
edm::RootInputFileSequence::fillProcessBlockHelper_
void fillProcessBlockHelper_()
Definition: RootInputFileSequence.cc:66
edm::RootInputFileSequence::initFile_
virtual void initFile_(bool skipBadFiles)=0
edm::ParameterSet
Definition: ParameterSet.h:47
cms::Exception::addAdditionalInfo
void addAdditionalInfo(std::string const &info)
Definition: Exception.cc:169
edm::RootInputFileSequence::fileIterLastOpened_
std::vector< FileCatalogItem >::const_iterator fileIterLastOpened_
Definition: RootInputFileSequence.h:105
visDQMUpload.hasher
hasher
Definition: visDQMUpload.py:158
edm::RootInputFileSequence::skipToItemInNewFile
bool skipToItemInNewFile(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
Definition: RootInputFileSequence.cc:147
edm::RootInputFileSequence::rootFile
std::shared_ptr< RootFile const > rootFile() const
Definition: RootInputFileSequence.h:93
StorageFactory.h
edm::RootInputFileSequence::containedInCurrentFile
bool containedInCurrentFile(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
Definition: RootInputFileSequence.cc:104
edm::RootInputFileSequence::rootFile_
edm::propagate_const< RootFileSharedPtr > rootFile_
Definition: RootInputFileSequence.h:106
RootFile.h
edm::RootInputFileSequence::readEvent
bool readEvent(EventPrincipal &cache)
Definition: RootInputFileSequence.cc:99
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::RootInputFileSequence::~RootInputFileSequence
virtual ~RootInputFileSequence()
Definition: RootInputFileSequence.cc:49
edm::RootInputFileSequence::catalog_
InputFileCatalog const & catalog_
Definition: RootInputFileSequence.h:97
edm::RootInputFileSequence::fileBranchIDListHelper
std::shared_ptr< BranchIDListHelper const > fileBranchIDListHelper() const
Definition: RootInputFileSequence.cc:44
writedatasetfile.run
run
Definition: writedatasetfile.py:27
edm::RootInputFileSequence::fileIterEnd_
const std::vector< FileCatalogItem >::const_iterator fileIterEnd_
Definition: RootInputFileSequence.h:103
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
Exception
Definition: hltDiff.cc:245
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::RootInputFileSequence::readRunAuxiliary_
std::shared_ptr< RunAuxiliary > readRunAuxiliary_()
Definition: RootInputFileSequence.cc:51
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
edm::RootInputFileSequence::initTheFile
void initTheFile(bool skipBadFiles, bool deleteIndexIntoFile, InputSource *input, char const *inputTypeName, InputType inputType)
Definition: RootInputFileSequence.cc:197
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
cms::Exception
Definition: Exception.h:70
edm::RootInputFileSequence::readProcessBlock_
void readProcessBlock_(ProcessBlockPrincipal &)
Definition: RootInputFileSequence.cc:76
edm::InputSource
Definition: InputSource.h:52
ParameterSet.h
edm::RunPrincipal
Definition: RunPrincipal.h:34
event
Definition: event.py:1
lumi
Definition: LumiSectionData.h:20
edm::InputFileCatalog::fileCatalogItems
std::vector< FileCatalogItem > const & fileCatalogItems() const
Definition: InputFileCatalog.h:39
edm::RootInputFileSequence::fileNames
std::vector< std::string > const & fileNames() const
Definition: RootInputFileSequence.h:82
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
edm::RootInputFileSequence::readLuminosityBlock_
void readLuminosityBlock_(LuminosityBlockPrincipal &lumiPrincipal)
Definition: RootInputFileSequence.cc:81
edm::RootInputFileSequence::skipToItem
bool skipToItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, size_t fileNameHash=0U, bool currentFileFirst=true)
Definition: RootInputFileSequence.cc:165
GetRecoTauVFromDQM_MC_cff.next
next
Definition: GetRecoTauVFromDQM_MC_cff.py:31
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
edm::RootInputFileSequence::fileCatalogItems
std::vector< FileCatalogItem > const & fileCatalogItems() const
Definition: RootInputFileSequence.cc:35