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::SAMProjectSource Class Reference

Fetch files from a pre-existing SAM project. More...

#include <SAMProjectSource.h>

Inheritance diagram for ana::SAMProjectSource:
ana::IFileSource

Public Member Functions

 SAMProjectSource (const std::string &proj, int fileLimit=-1)
 
virtual ~SAMProjectSource ()
 
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

ifdh_ns::ifdh * fIFDH
 
std::string fProjectURL
 
std::string fProcessID
 
TFile * fFile
 The most-recently-returned file. More...
 
int fNFiles
 

Static Protected Attributes

static bool fgGotTickets = false
 

Detailed Description

Fetch files from a pre-existing SAM project.

Definition at line 14 of file SAMProjectSource.h.

Constructor & Destructor Documentation

ana::SAMProjectSource::SAMProjectSource ( const std::string &  proj,
int  fileLimit = -1 
)
Parameters
projSAM project name (not URL)
fileLimitOptional maximum number of files to process

Definition at line 20 of file SAMProjectSource.cxx.

21  : fIFDH(new ifdh_ns::ifdh)
22  , fFile(0)
23  , fNFiles(fileLimit)
24  {
25  if(!fgGotTickets){
26  // No kerberos ticket means no point trying to voms-proxy-init. It likely
27  // also means we're in a grid job, where that would be counterproductive
28  // anyway.
29  if(system("klist -5 -s || klist -s") != 0) fgGotTickets = true;
30  }
31 
32  if(!fgGotTickets){
33  // This comes from NovaGridUtils, v02.10 onwards.
34  system("setup_fnal_security -b");
35 
36  fgGotTickets = true;
37  }
38 
39  // If X509_USER_PROXY isn't set, set it manually. Can help unconfuse IFDH
40  // about what x509 it's supposed to be using.
41  if(getenv("X509_USER_PROXY") == 0)
42  setenv("X509_USER_PROXY", TString::Format("/tmp/x509up_u%d", getuid()).Data(), 0);
43 
44  fIFDH->set_debug("0"); // shut up
45 
46  fProjectURL = fIFDH->findProject(proj, SAMExperiment());
47 
48  fProcessID = fIFDH->establishProcess(fProjectURL, "CAFAna", "v0.9", getenv("HOSTNAME"), getenv("USER"), SAMExperiment(), "", fileLimit);
49  }
ifdh_ns::ifdh * fIFDH
std::string SAMExperiment()
$SAM_EXPERIMENT or a nice error message and abort
TFile * fFile
The most-recently-returned file.
ana::SAMProjectSource::~SAMProjectSource ( )
virtual

Definition at line 52 of file SAMProjectSource.cxx.

53  {
54  if(fFile){
55  // Tidy up the final file
56  const std::string fname = fFile->GetName();
57  delete fFile;
58  unlink(fname.c_str());
59  }
60 
61  // End the process cleanly
62  fIFDH->endProcess(fProjectURL, fProcessID);
63 
64  // certainly wrong for fileLimit case
65  // status = fIFDH.endProject(fProjectURL);
66 
67  fIFDH->cleanup();
68  }
string fname
Definition: demo.py:5
ifdh_ns::ifdh * fIFDH
TFile * fFile
The most-recently-returned file.

Member Function Documentation

TFile * ana::SAMProjectSource::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 71 of file SAMProjectSource.cxx.

72  {
73  if(fFile){
74  // Tidy up the previous file
75  const std::string fname = fFile->GetName();
76  delete fFile;
77  fFile = 0;
78  unlink(fname.c_str());
79 
80  // And let SAM know we're done with it
81  fIFDH->updateFileStatus(fProjectURL, fProcessID, fname, "consumed");
82  }
83 
84  std::string tmp;
85 
86  tmp = fIFDH->getNextFile(fProjectURL, fProcessID);
87  const std::string uri(tmp);
88  if(uri.empty()) return 0; // out of files
89 
90  tmp = fIFDH->fetchInput(uri);
91  const std::string fname(tmp);
92  assert(!fname.empty());
93 
94  // Let SAM know we got it OK
95  fIFDH->updateFileStatus(fProjectURL, fProcessID, fname, "transferred");
96 
97  // Additional newlines because ifdh currently spams us with certificate
98  // messages.
99  if(fNFiles < 0) std::cout << std::endl << "Processing " << basename((char *)fname.c_str()) << std::endl << std::endl;
100 
101  fFile = new TFile(fname.c_str());
102  return fFile;
103  }
string fname
Definition: demo.py:5
ifdh_ns::ifdh * fIFDH
TFile * fFile
The most-recently-returned file.
BEGIN_PROLOG could also be cout
int ana::SAMProjectSource::NFiles ( ) const
inlineoverridevirtual

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

Reimplemented from ana::IFileSource.

Definition at line 24 of file SAMProjectSource.h.

24 {return fNFiles;}

Member Data Documentation

TFile* ana::SAMProjectSource::fFile
protected

The most-recently-returned file.

Definition at line 31 of file SAMProjectSource.h.

bool ana::SAMProjectSource::fgGotTickets = false
staticprotected

Definition at line 35 of file SAMProjectSource.h.

ifdh_ns::ifdh* ana::SAMProjectSource::fIFDH
protected

Definition at line 26 of file SAMProjectSource.h.

int ana::SAMProjectSource::fNFiles
protected

Definition at line 33 of file SAMProjectSource.h.

std::string ana::SAMProjectSource::fProcessID
protected

Definition at line 29 of file SAMProjectSource.h.

std::string ana::SAMProjectSource::fProjectURL
protected

Definition at line 28 of file SAMProjectSource.h.


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