All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
ana::FileListSource Class Reference

Simple file source based on an explicit list provided by the user. More...

#include <FileListSource.h>

Inheritance diagram for ana::FileListSource:
ana::IFileSource ana::SAMQuerySource ana::WildcardSource

Public Member Functions

 FileListSource (const std::vector< std::string > &files, int stride=-1, int offset=-1)
 default offset and stride mean obey cmd-line options More...
 
virtual ~FileListSource ()
 
virtual TFile * GetNextFile () override
 Returns the next file in sequence, ready for reading. More...
 
int NFiles () const override
 May return -1 indicating the number of files is not known. More...
 
- Public Member Functions inherited from ana::IFileSource
virtual ~IFileSource ()
 

Protected Attributes

std::vector< std::string > fFileNames
 The list of files. More...
 
std::vector< std::string >
::iterator 
fIt
 Iterator into fFileNames. More...
 
int fStride
 
int fN
 Number of files that will actually be returned. More...
 
TFile * fFile
 The most-recently-returned file. More...
 

Static Protected Attributes

static bool fgGotTickets = false
 Have we renewed our tickets? More...
 

Detailed Description

Simple file source based on an explicit list provided by the user.

Definition at line 11 of file FileListSource.h.

Constructor & Destructor Documentation

ana::FileListSource::FileListSource ( const std::vector< std::string > &  files,
int  stride = -1,
int  offset = -1 
)

default offset and stride mean obey cmd-line options

Definition at line 15 of file FileListSource.cxx.

17  : fFileNames(files.begin(), files.end()),
18  fIt(fFileNames.begin()),
19  fStride(stride),
20  fFile(0)
21  {
22  if(fFileNames.empty()){
23  fN = 0;
24  return;
25  }
26 
27  if(offset < 0){
28  if(getenv("CAFANA_OFFSET"))
29  offset = atoi(getenv("CAFANA_OFFSET"));
30 
31  offset = std::max(offset, 0);
32  }
33 
34  if(fStride < 0){
35  if(getenv("CAFANA_STRIDE"))
36  fStride = atoi(getenv("CAFANA_STRIDE"));
37 
38  fStride = std::max(fStride, 1);
39  }
40 
41  if(fStride > int(files.size())){
42  std::cerr << "Warning: stride " << fStride
43  << " is greater than the number of files: " << files.size()
44  << ". This is strange and inefficient." << std::endl;
45  // Needs to be nonzero otherwise some callers go off into SAM-query
46  // land. Having a slightly misleading progress bar is a small price to
47  // pay in this weird case.
48  fN = 1;
49  return;
50  }
51 
52  // How many files will we process from the list with this offset and
53  // stride?
54  fN = (int(files.size())-offset-1)/fStride+1;
55 
56  for(const std::string& loc: files){
57  if(loc.rfind("/pnfs/", 0) == 0){ // ie begins with
58  if(!fgGotTickets){
59  // No kerberos ticket means no point trying to voms-proxy-init. It
60  // likely also means we're in a grid job, where that would be
61  // counterproductive anyway.
62  if(system("klist -5 -s || klist -s") != 0) fgGotTickets = true;
63  }
64 
65  if(!fgGotTickets){
66  // This comes from NovaGridUtils, v02.10 onwards.
67  // system("setup_fnal_security -b");
68 
69  fgGotTickets = true;
70  break;
71  }
72  }
73  }
74 
75  for(int i = 0; i < offset; ++i){
76  ++fIt;
77  if(fIt == fFileNames.end()) break;
78  }
79  }
BEGIN_PROLOG TPC Trig offset(g4 rise time) ProjectToHeight
Definition: CORSIKAGen.fcl:7
std::vector< std::string >::iterator fIt
Iterator into fFileNames.
BEGIN_PROLOG could also be cerr
int fN
Number of files that will actually be returned.
std::vector< std::string > fFileNames
The list of files.
static bool fgGotTickets
Have we renewed our tickets?
TFile * fFile
The most-recently-returned file.
ana::FileListSource::~FileListSource ( )
virtual

Definition at line 82 of file FileListSource.cxx.

83  {
84  delete fFile;
85  }
TFile * fFile
The most-recently-returned file.

Member Function Documentation

TFile * ana::FileListSource::GetNextFile ( )
overridevirtual

Returns the next file in sequence, ready for reading.

A null return means that the end of the sequence has been reached. DO NOT close or delete the file that is returned.

Implements ana::IFileSource.

Definition at line 88 of file FileListSource.cxx.

89  {
90  // Tidy up the last file we gave, which the caller no longer needs
91  delete fFile;
92  fFile = 0;
93 
94  if(fIt == fFileNames.end()) return 0; // Ran out of files
95 
96  // If the file is on pnfs rewrite it to an xrootd address
97  std::string loc = *fIt;
98  // loc = pnfs2xrootd(loc); // no-op for non /pnfs locations
99 
100  fFile = TFile::Open(loc.c_str()); // This pattern allows xrootd
101  assert(fFile);
102 
103  for(int i = 0; i < fStride; ++i){
104  if(fIt == fFileNames.end()) break;
105  ++fIt; // Move on to the next file, for the subsequent call
106  }
107 
108  return fFile;
109  }
std::vector< std::string >::iterator fIt
Iterator into fFileNames.
std::vector< std::string > fFileNames
The list of files.
TFile * fFile
The most-recently-returned file.
int ana::FileListSource::NFiles ( ) const
inlineoverridevirtual

May return -1 indicating the number of files is not known.

Reimplemented from ana::IFileSource.

Definition at line 20 of file FileListSource.h.

20 {return fN;}
int fN
Number of files that will actually be returned.

Member Data Documentation

TFile* ana::FileListSource::fFile
protected

The most-recently-returned file.

Definition at line 26 of file FileListSource.h.

std::vector<std::string> ana::FileListSource::fFileNames
protected

The list of files.

Definition at line 22 of file FileListSource.h.

bool ana::FileListSource::fgGotTickets = false
staticprotected

Have we renewed our tickets?

Definition at line 27 of file FileListSource.h.

std::vector<std::string>::iterator ana::FileListSource::fIt
protected

Iterator into fFileNames.

Definition at line 23 of file FileListSource.h.

int ana::FileListSource::fN
protected

Number of files that will actually be returned.

Definition at line 25 of file FileListSource.h.

int ana::FileListSource::fStride
protected

Definition at line 24 of file FileListSource.h.


The documentation for this class was generated from the following files: