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 "/cvmfs/nova.opensciencegrid.org/externals/cafanacore/v01.10/src/CAFAna/Core/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...
 

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 15 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.

References fgGotTickets, fIFDH, ProjMan::fileLimit, genie::utils::style::Format(), fProcessID, fProjectURL, cet::getenv(), string, and system().

21  : fIFDH(new ifdh_ns::ifdh)
22  , fFile(0)
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, getenv("SAM_STATION"));
47 
48  // grid jobs don't always have $USER set, but often they have $GRID_USER instead
49  char * strPtr;
50  std::string userStr;
51  if ( (strPtr = getenv("USER")) || (strPtr = getenv("GRID_USER")) )
52  userStr = strPtr;
53  else
54  userStr = "unknown";
55 
56  // grid jobs don't always have $HOSTNAME set, sometimes they use $OSG_HOSTNAME instead
57  std::string hostNameStr;
58  strPtr = getenv("HOSTNAME");
59  if(!strPtr) strPtr = getenv("OSG_HOSTNAME");
60  hostNameStr = strPtr;
61 
62  fProcessID = fIFDH->establishProcess(fProjectURL, "CAFAna", "v0.9", hostNameStr.c_str(), userStr.c_str(), "nova", "", fileLimit);
63  }
system("rm -rf microbeam.root")
ifdh_ns::ifdh * fIFDH
std::string getenv(std::string const &name)
ifdh
Definition: ProjMan.py:8
fileLimit
Definition: ProjMan.py:109
Float_t proj
Definition: plot.C:35
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
TFile * fFile
The most-recently-returned file.
enum BeamMode string
ana::SAMProjectSource::~SAMProjectSource ( )
virtual

Definition at line 66 of file SAMProjectSource.cxx.

References fFile, fIFDH, plot_validation_datamc::fname, fProcessID, fProjectURL, and string.

67  {
68  if(fFile){
69  // Tidy up the final file
70  const std::string fname = fFile->GetName();
71  delete fFile;
72  unlink(fname.c_str());
73  }
74 
75  // End the process cleanly
76  fIFDH->endProcess(fProjectURL, fProcessID);
77 
78  // certainly wrong for fileLimit case
79  // status = fIFDH.endProject(fProjectURL);
80 
81  fIFDH->cleanup();
82  }
ifdh_ns::ifdh * fIFDH
TFile * fFile
The most-recently-returned file.
enum BeamMode string

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 85 of file SAMProjectSource.cxx.

References ana::assert(), om::cout, allTimeWatchdog::endl, fFile, fIFDH, plot_validation_datamc::fname, fNFiles, fProcessID, fProjectURL, and string.

86  {
87  if(fFile){
88  // Tidy up the previous file
89  const std::string fname = fFile->GetName();
90  delete fFile;
91  fFile = 0;
92  unlink(fname.c_str());
93 
94  // And let SAM know we're done with it
95  fIFDH->updateFileStatus(fProjectURL, fProcessID, fname, "consumed");
96  }
97 
98  const std::string uri = fIFDH->getNextFile(fProjectURL, fProcessID);
99  if(uri.empty()) return 0; // out of files
100 
101  const std::string fname = fIFDH->fetchInput(uri);
102  assert(!fname.empty());
103 
104  // Let SAM know we got it OK
105  fIFDH->updateFileStatus(fProjectURL, fProcessID, fname, "transferred");
106 
107  // Additional newlines because ifdh currently spams us with certificate
108  // messages.
109  if(fNFiles < 0) std::cout << std::endl << "Processing " << basename((char *)fname.c_str()) << std::endl << std::endl;
110 
111  fFile = new TFile(fname.c_str());
112  return fFile;
113  }
ifdh_ns::ifdh * fIFDH
OStream cout
Definition: OStream.cxx:6
assert(nhit_max >=nhit_nbins)
TFile * fFile
The most-recently-returned file.
const XML_Char const XML_Char * uri
Definition: expat.h:380
enum BeamMode string
int ana::SAMProjectSource::NFiles ( ) const
inlineoverridevirtual

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

Reimplemented from ana::IFileSource.

Definition at line 25 of file SAMProjectSource.h.

25 {return fNFiles;}

Member Data Documentation

TFile* ana::SAMProjectSource::fFile
protected

The most-recently-returned file.

Definition at line 32 of file SAMProjectSource.h.

Referenced by GetNextFile(), and ~SAMProjectSource().

bool ana::SAMProjectSource::fgGotTickets = false
staticprotected

Definition at line 36 of file SAMProjectSource.h.

Referenced by SAMProjectSource().

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

Definition at line 27 of file SAMProjectSource.h.

Referenced by GetNextFile(), SAMProjectSource(), and ~SAMProjectSource().

int ana::SAMProjectSource::fNFiles
protected

Definition at line 34 of file SAMProjectSource.h.

Referenced by GetNextFile().

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

Definition at line 30 of file SAMProjectSource.h.

Referenced by GetNextFile(), SAMProjectSource(), and ~SAMProjectSource().

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

Definition at line 29 of file SAMProjectSource.h.

Referenced by GetNextFile(), SAMProjectSource(), and ~SAMProjectSource().


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