Ignore:
Timestamp:
07/24/07 14:36:39 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mjobs
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mjobs/MJCut.cc

    r8636 r8644  
    553553
    554554    // --------------------------------------------------------------------------------
     555
     556    if (!set.IsWobbleMode() && fNumOffSourcePos!=1)
     557    {
     558        *fLog << inf << "No wobble mode but NumOffSoucePos!=1 (" << fNumOffSourcePos << ")... reset to 1." << endl;
     559        fNumOffSourcePos = 1;
     560    }
    555561
    556562    // Possible source position (eg. Wobble Mode)
  • trunk/MagicSoft/Mars/mjobs/MJob.cc

    r8587 r8644  
    1818!   Author(s): Thomas Bretz, 8/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2004
     20!   Copyright: MAGIC Software Development, 2000-2007
    2121!
    2222!
     
    3434// SetDebugEnv(3) // do 2) and debug setting env completely
    3535//
     36// To allow overwriting the output files call SetOverwrite()
     37//
    3638/////////////////////////////////////////////////////////////////////////////
    3739#include "MJob.h"
     
    6668}
    6769
     70//------------------------------------------------------------------------
     71//
     72// If MJob is the owner of fEnv delete fEnv.
     73//
     74// Reset the owenership bit.
     75//
     76// Set fEnv to NULL.
     77//
    6878void MJob::ClearEnv()
    6979{
     
    7484}
    7585
     86//------------------------------------------------------------------------
     87//
     88// ClearEnv()
     89//
    7690MJob::~MJob()
    7791{
     
    7993}
    8094
    81 Bool_t MJob::SetEnv(const char *env, const char *prefix)
    82 {
    83     ClearEnv();
    84 
    85     fEnv = new MEnv(env);
    86     SetBit(kIsOwner);
    87 
    88     if (!fEnv->IsValid())
    89     {
    90         ClearEnv();
    91         return kFALSE;
    92     }
    93 
     95//------------------------------------------------------------------------
     96//
     97// If prefix==0 the prefix is taken from fName up to the first
     98// whitespace.
     99//
     100// A trailing dot is removed.void MJob::SetPrefix(const char *prefix)
     101void MJob::SetPrefix(const char *prefix)
     102{
    94103    fEnvPrefix = prefix;
     104
    95105    if (!prefix)
    96106        fEnvPrefix = fName.First(' ')>0 ? fName(0, fName.First(' ')) : fName;
     
    98108    if (fEnvPrefix.EndsWith("."))
    99109        fEnvPrefix.Remove(fEnvPrefix.Length()-1);
    100 
    101     return kTRUE;
    102 }
    103 
     110}
     111
     112//------------------------------------------------------------------------
     113//
     114// Create a new MEnv from the file env. MJob takes of course the
     115// ownership of the newly created MEnv.
     116//
     117// SetPrefix(prefix)
     118//
     119// return kFALSE if MEnv is invalid
     120//
     121Bool_t MJob::SetEnv(const char *env, const char *prefix)
     122{
     123    SetEnv(new MEnv(env), prefix);
     124
     125    // Take the owenership of the MEnv instance
     126    SetBit(kIsOwner);
     127
     128    return fEnv->IsValid();
     129}
     130
     131//------------------------------------------------------------------------
     132//
     133// Set a new fEnv and a new general prefix.
     134//
     135// Calls SetPrefix(prefix)
     136//
     137// MJob does not take the owenership of the MEnv instance.
     138//
    104139void MJob::SetEnv(MEnv *env, const char *prefix)
    105140{
     
    108143    fEnv = env;
    109144
    110     fEnvPrefix = prefix;
    111     if (!prefix)
    112         fEnvPrefix = fName.First(' ')>0 ? fName(0, fName.First(' ')) : fName;
    113 
    114     if (fEnvPrefix.EndsWith("."))
    115         fEnvPrefix.Remove(fEnvPrefix.Length()-1);
    116 }
    117 
    118 void MJob::FixPath(TString &path) const
     145    SetPrefix(prefix);
     146}
     147
     148//------------------------------------------------------------------------
     149//
     150// Removes LF's from the path (necessary if the resource file was written
     151// with a different operating system than Linux.
     152//
     153// Removes a trailing slash if the path is not the root-path.
     154//
     155// Adds fname to the path if given.
     156//
     157void MJob::FixPath(TString &path)
    119158{
    120159    path.ReplaceAll("\015", "");
     
    127166}
    128167
     168//------------------------------------------------------------------------
     169//
     170// Calls FixPath
     171//
     172// Adds fname to the path if given.
     173//
     174TString MJob::CombinePath(TString path, TString fname)
     175{
     176    FixPath(path);
     177
     178    if (fname.IsNull())
     179        return path;
     180
     181    if (path!=(TString)"/")
     182        path += "/";
     183
     184    path += fname;
     185
     186    return path;
     187}
     188
     189//------------------------------------------------------------------------
     190//
     191// Sets the output path. The exact meaning (could also be a file) is
     192// deined by the derived class.
     193//
    129194void MJob::SetPathOut(const char *path)
    130195{
     
    133198}
    134199
     200//------------------------------------------------------------------------
     201//
     202// Sets the input path. The exact meaning (could also be a file) is
     203// deined by the derived class.
     204//
    135205void MJob::SetPathIn(const char *path)
    136206{
     
    139209}
    140210
     211//------------------------------------------------------------------------
     212//
     213// Returns the TEnv
     214//
    141215const TEnv *MJob::GetEnv() const
    142216{
     
    144218}
    145219
     220//------------------------------------------------------------------------
     221//
     222// Checks GetEnvValue(*fEnv, fEnvPrefix, name, dftl)
     223// For details see MParContainer
     224//
    146225Int_t MJob::GetEnv(const char *name, Int_t dflt) const
    147226{
     
    149228}
    150229
     230//------------------------------------------------------------------------
     231//
     232// Checks GetEnvValue(*fEnv, fEnvPrefix, name, dftl)
     233// For details see MParContainer
     234//
    151235Double_t MJob::GetEnv(const char *name, Double_t dflt) const
    152236{
     
    154238}
    155239
     240//------------------------------------------------------------------------
     241//
     242// Checks GetEnvValue(*fEnv, fEnvPrefix, name, dftl)
     243// For details see MParContainer
     244//
    156245const char *MJob::GetEnv(const char *name, const char *dflt) const
    157246{
     
    159248}
    160249
     250//------------------------------------------------------------------------
     251//
     252// Checks IsEnvDefined(*fEnv, fEnvPrefix, name, fEnvDebug>2)
     253// For details see MParContainer
     254//
    161255Bool_t MJob::HasEnv(const char *name) const
    162256{
     
    164258}
    165259
     260//------------------------------------------------------------------------
     261//
     262// Check the resource file for
     263//   PathOut
     264//   PathIn
     265//   MaxEvents
     266//   Overwrite
     267//   EnvDebug
     268//
     269// and call the virtual function CheckEnvLocal
     270//
    166271Bool_t MJob::CheckEnv()
    167272{
     
    202307}
    203308
     309//------------------------------------------------------------------------
     310//
     311// Call the eventsloops ReadEnv and print untouched resources afterwards
     312// if fEnvDebug>1
     313//
    204314Bool_t MJob::SetupEnv(MEvtLoop &loop) const
    205315{
     
    214324
    215325    return kTRUE;
     326}
     327
     328//------------------------------------------------------------------------
     329//
     330// Checks whether write permissions to fname exists including
     331// the fOverwrite data amember.
     332//
     333Bool_t MJob::HasWritePermission(TString fname) const
     334{
     335    gSystem->ExpandPathName(fname);
     336
     337    const Bool_t exists = !gSystem->AccessPathName(fname, kFileExists);
     338    if (!exists)
     339        return kTRUE;
     340
     341    const Bool_t write = !gSystem->AccessPathName(fname, kWritePermission);
     342    if (!write)
     343    {
     344        *fLog << err << "ERROR - No permission to write to " << fname << endl;
     345        return kFALSE;
     346    }
     347
     348    if (!fOverwrite)
     349        return kTRUE;
     350
     351    *fLog << err;
     352    *fLog << "ERROR - File " << fname << " already exists and overwrite not allowed." << endl;
     353
     354    return kFALSE;
    216355}
    217356
     
    274413//------------------------------------------------------------------------
    275414//
    276 // Write containers in cont (and - if available) the status display to
    277 // fPathOut+"/"+name
     415// Write containers in cont to fPathOut+"/"+name, or fPathOut only
     416// if name is empty.
    278417//
    279418Bool_t MJob::WriteContainer(TCollection &cont, const char *name, const char *option, const int compr) const
     
    285424    }
    286425
    287     TString oname(fPathOut);
    288     if (!TString(name).IsNull())
    289     {
    290         if (oname!="/")
    291             oname += "/";
    292         oname += name;
    293     }
     426    const TString oname = CombinePath(fPathOut, name);
    294427
    295428    *fLog << inf << "Writing to file: " << oname << endl;
    296429
    297     TString title("File Written by ");
     430    TString title("File written by ");
    298431    title += fName;
    299432
     
    308441}
    309442
     443//------------------------------------------------------------------------
     444//
     445// return kTRUE if no display is set.
     446//
     447// Write the display to the TFile with name name, options option and
     448// compression level comp.
     449//
     450// If name IsNull fPathOut is assumed to contain the name, otherwise
     451// name is appended to fPathOut. fPathOut might be null.
     452//
    310453Bool_t MJob::WriteDisplay(const char *name, const char *option, const int compr) const
    311454{
     
    348491
    349492    // check if path ends with a slash
    350     if (!path.EndsWith("/"))
    351         path += "/";
    352 
    353     // compile full qualified path
    354     path += fname;
     493    path = CombinePath(path, fname);
    355494
    356495    gLog << dbg << "MJob::ExpandPath - Filename expanded to " << path << endl;
     
    360499}
    361500
     501//------------------------------------------------------------------------
     502//
     503// Sorts the array.
     504//
    362505void MJob::SortArray(TArrayI &arr)
    363506{
  • trunk/MagicSoft/Mars/mjobs/MJob.h

    r8518 r8644  
    1414    enum { kIsOwner = BIT(14) };
    1515
    16     void FixPath(TString &path) const;
     16    // Helper functions for paths
     17    static TString CombinePath(TString path, TString fname);
     18    static void FixPath(TString &path);
     19
     20    // Helper functions to set a new fEnv
     21    void SetPrefix(const char *prefix);
    1722    void ClearEnv();
    1823
     24    // Data members for resource files
    1925    const MEnv *fEnv;         // Resource file
    2026    TString     fEnvPrefix;   // Prefix for resources
     
    2834    Int_t     fMaxEvents;     // Maximum number of events
    2935
     36    // FIXME: Split into MJobSequence and MJobDataSet
    3037    MSequence fSequence;      // Sequence
    3138
     
    7178    TString GetPathIn() const   { return fPathIn; }
    7279
     80    Bool_t HasWritePermission(TString fname) const;
     81
    7382    // Others
    7483    MStatusDisplay *GetDisplay() { return fDisplay; }
Note: See TracChangeset for help on using the changeset viewer.