23 #include "CLHEP/Random/RandFlat.h"
34 unsigned int nStreams,
37 inputType_(inputType),
42 findFileForSpecifiedID_(
nullptr),
43 fileIterBegin_(fileCatalogItems().
begin()),
44 fileIterEnd_(fileCatalogItems().
end()),
45 fileIter_(fileIterEnd_),
46 fileIterLastOpened_(fileIterEnd_),
49 indexesIntoFiles_(fileCatalogItems().
size()),
50 orderedProcessHistoryIDs_(),
53 eventsRemainingInFile_(0),
61 initialNumberOfEventsToSkip_(inputType !=
InputType::
SecondaryFile ? pset.getUntrackedParameter<unsigned int>(
"skipEvents", 0U) : 0U),
63 skipBadFiles_(pset.getUntrackedParameter<bool>(
"skipBadFiles",
false)),
64 bypassVersionCheck_(pset.getUntrackedParameter<bool>(
"bypassVersionCheck",
false)),
65 treeCacheSize_(noEventSort_ ? pset.getUntrackedParameter<unsigned int>(
"cacheSize", roottree::
defaultCacheSize) : 0U),
66 treeMaxVirtualSize_(pset.getUntrackedParameter<int>(
"treeMaxVirtualSize", -1)),
67 setRun_(pset.getUntrackedParameter<unsigned int>(
"setRunNumber", 0U)),
68 productSelectorRules_(pset,
"inputCommands",
"InputSource"),
70 dropDescendants_(pset.getUntrackedParameter<bool>(
"dropDescendantsOfDroppedBranches", inputType !=
InputType::
SecondarySource)),
71 labelRawDataLikeMC_(pset.getUntrackedParameter<bool>(
"labelRawDataLikeMC",
true)),
72 usingGoToEvent_(
false),
73 enablePrefetching_(
false),
74 usedFallback_(
false) {
94 std::ifstream
f(
"/dev/urandom");
96 f.read(reinterpret_cast<char*>(&seed),
sizeof(seed));
97 std::default_random_engine dre(seed);
99 std::uniform_int_distribution<int> distribution(0, count - 1);
102 int offset = distribution(dre);
132 std::vector<FileCatalogItem>
const&
142 std::unique_ptr<FileBlock>
156 return std::unique_ptr<FileBlock>(
new FileBlock);
165 std::unique_ptr<InputSource::FileCloseSentry>
185 !needIndexesForDuplicateChecker &&
187 if(deleteIndexIntoFile) {
206 throw cms::Exception(
"LogicalFileNameNotFound",
"RootInputFileSequence::initFile()\n")
207 <<
"Logical file name '" <<
fileIter_->logicalFileName() <<
"' was not found in the file catalog.\n"
208 <<
"If you wanted a local file, you forgot the 'file:' prefix\n"
209 <<
"before the file name in your configuration file.\n";
211 LogWarning(
"") <<
"Input logical file: " <<
fileIter_->logicalFileName() <<
" was not found in the catalog, and will be skipped.\n";
222 bool hasFallbackUrl = !fallbackName.empty() && fallbackName !=
fileIter_->fileName();
224 std::shared_ptr<InputFile> filePtr;
225 std::list<std::string> originalInfo;
227 std::unique_ptr<InputSource::FileOpenSentry>
234 std::ostringstream
out;
242 ex.addContext(
"Calling RootInputFileSequence::initFile()");
243 std::ostringstream
out;
244 out <<
"Input file " <<
fileIter_->fileName() <<
" could not be opened.";
245 ex.addAdditionalInfo(out.str());
250 if(!filePtr && (hasFallbackUrl)) {
253 std::unique_ptr<InputSource::FileOpenSentry>
255 std::string fallbackFullName = gSystem->ExpandPathName(fallbackName.c_str());
258 filePtr.reset(
new InputFile(fallbackFullName.c_str(),
" Fallback request to file ",
inputType_));
264 ex.addContext(
"Calling RootInputFileSequence::initFile()");
265 std::ostringstream
out;
266 out <<
"Input file " <<
fileIter_->fileName() <<
" could not be opened.\n";
267 out <<
"Fallback Input file " << fallbackName <<
" also could not be opened.";
268 if (originalInfo.size()) {
269 out << std::endl <<
"Original exception info is above; fallback exception info is below.";
270 ex.addAdditionalInfo(out.str());
271 for (
auto const &
s : originalInfo) {
272 ex.addAdditionalInfo(
s);
275 ex.addAdditionalInfo(out.str());
307 currentIndexIntoFile,
316 indexesIntoFiles_[currentIndexIntoFile] =
rootFile_->indexIntoFileSharedPtr();
317 char const* inputType = 0;
328 "RootInputFileSequence::initFile(): Input file " <<
fileIter_->fileName() <<
" was not found or could not be opened.\n";
330 LogWarning(
"") <<
"Input file: " <<
fileIter_->fileName() <<
" was not found or could not be opened, and will be skipped.\n";
334 std::shared_ptr<ProductRegistry const>
340 std::shared_ptr<BranchIDListHelper const>
363 if(!mergeInfo.empty()) {
387 if(!mergeInfo.empty()) {
398 std::shared_ptr<RunAuxiliary>
404 std::shared_ptr<LuminosityBlockAuxiliary>
407 return rootFile_->readLuminosityBlockAuxiliary_();
419 rootFile_->readLuminosityBlock_(lumiPrincipal);
469 return rootFile_->containsItem(run, lumi, event);
506 bool atEnd =
rootFile_->skipEvents(offset);
507 if((offset > 0 || atEnd) && !
nextFile()) {
531 bool closedOriginalFile =
false;
532 std::vector<FileCatalogItem>::const_iterator originalFile =
fileIter_;
536 typedef std::vector<std::shared_ptr<IndexIntoFile> >::const_iterator Iter;
554 closedOriginalFile =
true;
563 if(closedOriginalFile) {
567 rootFile_->setPosition(originalPosition);
576 assert(fileNameHash != 0U);
582 auto hasher = std::hash<std::string>();
589 for(
auto iter = range.first;
iter != range.second; ++
iter) {
608 typedef std::vector<std::shared_ptr<IndexIntoFile> >::const_iterator Iter;
635 typedef std::vector<std::shared_ptr<IndexIntoFile> >::const_iterator Iter;
637 if(*it && (*it)->containsItem(run, lumi, event)) {
639 std::vector<FileCatalogItem>::const_iterator currentIter =
fileIter_;
646 found =
rootFile_->setEntryAtItem(run, lumi, event);
686 std::shared_ptr<ProductRegistry const>
693 std::vector<std::string>
rules;
694 rules.reserve(wantedBranches.size() + 1);
695 rules.emplace_back(
"drop *");
697 rules.push_back(
"keep " + branch +
"_*");
707 bool completed =
rootFile_->skipEntries(offset);
716 completed =
rootFile_->skipEntries(offset);
778 rootFile_->indexIntoFileIter().run() !=
id.run() ||
779 rootFile_->indexIntoFileIter().lumi() !=
id.luminosityBlock()) {
786 bool found =
rootFile_->setEntryAtNextEventInLumi(
id.
run(),
id.luminosityBlock());
788 found =
rootFile_->readCurrentEvent(cache);
812 "RootInputFileSequence::readOneSpecified(): Secondary Input files" <<
813 " do not contain specified event:\n" <<
id <<
"\n";
816 found =
rootFile_->readCurrentEvent(cache);
819 if(fileNameHash == 0U) {
837 if(newSeqNumber != currentSeqNumber) {
839 currentSeqNumber = newSeqNumber;
844 "RootInputFileSequence::readOneRandom(): Secondary Input file " <<
fileIter_->fileName() <<
" contains no events.\n";
853 bool found =
rootFile_->readCurrentEvent(cache);
870 rootFile_->indexIntoFileIter().run() !=
id.run() ||
871 rootFile_->indexIntoFileIter().lumi() !=
id.luminosityBlock()) {
876 int eventsInLumi = 0;
878 while(
rootFile_->setEntryAtNextEventInLumi(
id.run(),
id.luminosityBlock())) ++eventsInLumi;
881 int eventInLumi = CLHEP::RandFlat::shootInt(engine, eventsInLumi);
882 for(
int i = 0;
i < eventInLumi; ++
i) {
883 bool found =
rootFile_->setEntryAtNextEventInLumi(
id.
run(),
id.luminosityBlock());
888 bool found =
rootFile_->setEntryAtNextEventInLumi(
id.
run(),
id.luminosityBlock());
890 found =
rootFile_->readCurrentEvent(cache);
893 bool found =
rootFile_->setEntryAtItem(
id.
run(),
id.luminosityBlock(), 0);
906 ->setComment(
"Skip the first 'skipEvents' events that otherwise would have been processed.");
908 ->setComment(
"True: Process runs, lumis and events in the order they appear in the file (but see notes 1 and 2).\n"
909 "False: Process runs, lumis and events in each file in numerical order (run#, lumi#, event#) (but see note 3).\n"
910 "Note 1: Events within the same lumi will always be processed contiguously.\n"
911 "Note 2: Lumis within the same run will always be processed contiguously.\n"
912 "Note 3: Any sorting occurs independently in each input file (no sorting across input files).");
914 ->setComment(
"True: Ignore any missing or unopenable input file.\n"
915 "False: Throw exception if missing or unopenable input file.");
917 ->setComment(
"True: Bypass release version check.\n"
918 "False: Throw exception if reading file in a release prior to the release in which the file was written.");
920 ->setComment(
"Size of ROOT TTree prefetch cache. Affects performance.");
922 ->setComment(
"Size of ROOT TTree TBasket cache. Affects performance.");
924 ->setComment(
"If non-zero, change number of first run to this number. Apply same offset to all runs. Allowed only for simulation.");
925 desc.
addUntracked<
bool>(
"dropDescendantsOfDroppedBranches",
true)
926 ->setComment(
"If True, also drop on input any descendent of any branch dropped on input.");
929 ->setComment(
"'strict': Branches in each input file must match those in the first file.\n"
930 "'permissive': Branches in each input file may be any subset of those in the first file.");
932 ->setComment(
"If True: replace module label for raw data to match MC. Also use 'LHC' as process.");
945 std::vector<FileCatalogItem>::const_iterator itr(
fileIter_);
958 if(!
rootFile_->wasFirstEventJustRead()) {
970 for(
auto const& branchID : associationsFromSecondary) {
EventNumber_t event() const
T getUntrackedParameter(std::string const &, T const &) const
void stagein(const std::string &url)
static void fillDescription(ParameterSetDescription &desc, char const *parameterName)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
virtual std::string explainSelf() const
unsigned long long EventNumber_t
static void fillDescription(ParameterSetDescription &desc)
LuminosityBlockNumber_t luminosityBlock() const
unsigned int const defaultCacheSize
unsigned int LuminosityBlockNumber_t
std::list< std::string > const & additionalInfo() const
static std::string const input
static StorageFactory * get(void)
tuple InputFile
Open Root file and provide MEs ############.
EventID const & eventID() const
std::string merge(ProductRegistry const &other, std::string const &fileName, BranchDescription::MatchMode branchesMustMatch=BranchDescription::Permissive)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
static EntryNumber_t const invalidEntry
void addUntrackedParameter(std::string const &name, T const &value)
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
static void fillDescription(ParameterSetDescription &desc)
size_t fileNameHash() const
void updateFromInput(ProductList const &other)
void activateTimeout(const std::string &url)
volatile std::atomic< bool > shutdown_flag false
tuple size
Write out results.