Ignore:
Timestamp:
07/01/08 15:04:01 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mjobs
Files:
6 edited

Legend:

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

    r8895 r8989  
    1818!   Author(s): Thomas Bretz, 1/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2004-2007
     20!   Copyright: MAGIC Software Development, 2004-2008
    2121!
    2222!
     
    177177//
    178178//
     179// ===========================================================================
     180//
    179181// ToDO:
    180182//   * Default paths could be moved into the global .rootrc
    181183//
     184// ===========================================================================
     185//
     186//
     187// Class Version 3:
     188// ----------------
     189//  + fFileName
     190//  + fDataSet
    182191//
    183192// Class Version 2:
     193// ----------------
    184194//  + fMonteCarlo
    185195//  + fWobbleMode
     
    297307
    298308        // FIXME: The sequence number from the sequence file is assigned!!!
    299         MSequence *seq = new MSequence(useds?fName:name, dir, num[i]);
     309        MSequence *seq = new MSequence(useds?fFileName:name, dir, num[i]);
    300310        seq->ExcludeRuns(excl);
    301311
     
    354364void MDataSet::Init(const char *fname, const UInt_t num, TString sequences, TString &data)
    355365{
     366    fName  = "MDataSet";
     367    fTitle = "DataSet file";
     368
    356369    // Store given file name as name
    357     fName = fname;
     370    fFileName = fname;
    358371
    359372    // Delete the stored Sequences automatically at destruction
     
    361374    fSequencesOff.SetOwner();
    362375
     376    // Expand the file name (eg $MARS or ~ are expanded)
     377    gSystem->ExpandPathName(fFileName);
     378
     379    // Check its accessibility
     380    const Bool_t access = !gSystem->AccessPathName(fFileName, kFileExists);
     381    if (!access)
     382    {
     383        gLog << err << "ERROR - Dataset file " << fname << " not accessible!" << endl;
     384        fNumAnalysis = (UInt_t)-1;
     385        return;
     386    }
     387
    363388    // Determin the prefix to access this resource
    364389    const TString prefix = num==(UInt_t)-1 ? "" : Form("%d", num);
    365390
    366     // Expand the file name (eg $MARS or ~ are expanded)
    367     TString expname(fname);
    368     gSystem->ExpandPathName(expname);
    369 
    370     // Check its accessibility
    371     const Bool_t access = !gSystem->AccessPathName(expname, kFileExists);
    372     if (!access)
    373         gLog << err << "ERROR - Dataset file " << expname << " not accessible!" << endl;
    374 
    375391    // Open and read the file
    376     MEnv env(expname);
     392    MEnv env(fFileName);
    377393
    378394    // Get analysis number and name
    379395    fNumAnalysis = GetEnvValue2(env, prefix, "AnalysisNumber", (Int_t)num);
    380     fTitle       = GetEnvValue2(env, prefix, "Name", expname);
     396    fDataSet     = GetEnvValue2(env, prefix, "Name", GetBaseName());
    381397
    382398    // Get sequences from file
     
    443459//---------------------------------------------------------------------------
    444460//
    445 // Make sure that the name used for writing doesn't contain a full path
    446 //
    447 const char *MDataSet::GetName() const
    448 {
    449     const char *pos = strrchr(GetRcName(), '/');
    450     return pos>0 ? pos+1 : GetRcName();
     461// Return the name of the file
     462//
     463const char *MDataSet::GetBaseName() const
     464{
     465    return gSystem->BaseName(fFileName);
     466}
     467
     468//---------------------------------------------------------------------------
     469//
     470// Return the directory of the file
     471//
     472const char *MDataSet::GetFilePath() const
     473{
     474    return gSystem->DirName(fFileName);
    451475}
    452476
     
    456480// Return '+' if both can be accessed, '-' otherwise.
    457481//
    458 void MDataSet::PrintFile(const MSequence &seq)
     482void MDataSet::PrintFile(ostream &out, const MSequence &seq)
    459483{
    460484    const Char_t access =
     
    462486        !gSystem->AccessPathName(seq.GetDataPath(), kFileExists) ? '+' : '-';
    463487
    464     gLog << "#  " << access << " " << seq.GetFileName() << " <" << seq.GetDataPath() << ">" << endl;
     488    out << "#  " << access << " " << seq.GetFileName() << " <" << seq.GetDataPath() << ">" << endl;
    465489}
    466490
     
    469493// Helper to print a seqeunce in Print()
    470494//
    471 void MDataSet::PrintSeq(const MSequence &seq) const
    472 {
    473     const Bool_t useds = seq.GetFileName()==fName;
    474 
    475     gLog << "Sequence" << Form("%08d", seq.GetSequence()) << ".File:   " << (useds?"-":seq.GetFileName()) << endl;
    476     gLog << "Sequence" << Form("%08d", seq.GetSequence()) << ".Dir:    " << seq.GetDataPath() << endl;
     495void MDataSet::PrintSeq(ostream &out, const MSequence &seq) const
     496{
     497    const Bool_t useds = seq.GetFileName()==fFileName;
     498
     499    out << "Sequence" << Form("%08d", seq.GetSequence()) << ".File:   " << (useds?"-":seq.GetFileName()) << endl;
     500    out << "Sequence" << Form("%08d", seq.GetSequence()) << ".Dir:    " << seq.GetDataPath() << endl;
    477501    if (!useds && seq.GetNumExclRuns()>0)
    478         gLog << "Sequence" << Form("%08d", seq.GetSequence()) << ".Exclude: " << seq.GetExcludedRuns() << endl;
     502        out << "Sequence" << Form("%08d", seq.GetSequence()) << ".Exclude: " << seq.GetExcludedRuns() << endl;
    479503
    480504    if (useds)
    481505    {
    482         gLog << endl;
    483         seq.Print("prefixed");
    484         gLog << endl << "# ---" << endl;
    485     }
    486 }
    487 
    488 
    489 // --------------------------------------------------------------------------
    490 //
    491 // Print the contents of the sequence
    492 //
    493 void MDataSet::Print(Option_t *o) const
    494 {
    495     gLog << all;
     506        out << endl;
     507        seq.Print(out, "prefixed");
     508        out << endl << "# ---" << endl;
     509    }
     510}
     511
     512// --------------------------------------------------------------------------
     513//
     514// Print the contents of the dataset to the ostream out
     515//
     516void MDataSet::Print(ostream &out, Option_t *o) const
     517{
    496518    if (!IsValid())
    497519    {
    498         gLog << "Dataset: " << fName << " <invalid - no analysis number available>" << endl;
     520        out << "Dataset: " << fFileName << " <invalid - no analysis number available>" << endl;
    499521        return;
    500522    }
    501     gLog << "# Path: " << GetRcName() << endl;
    502     gLog << "# Name: " << GetName() << endl;
    503     gLog << endl;
    504     gLog << "AnalysisNumber: " << fNumAnalysis << endl << endl;
    505 
    506     if (!fTitle.IsNull())
    507         gLog << "Name: " << fTitle << endl << endl;
    508 
    509     gLog << "SequencesOn:   ";
     523    out << "# Path: " << GetFilePath() << endl;
     524    out << "# Name: " << GetBaseName() << endl;
     525    out << endl;
     526    out << "AnalysisNumber: " << fNumAnalysis << endl << endl;
     527
     528    if (!fDataSet.IsNull())
     529        out << "Name: " << fDataSet << endl << endl;
     530
     531    out << "SequencesOn:   ";
    510532    for (int i=0; i<fNumSequencesOn.GetSize(); i++)
    511         gLog << " " << fNumSequencesOn[i];
    512     gLog << endl;
    513     gLog << "SequencesOff:  ";
    514     for (int i=0; i<fNumSequencesOff.GetSize(); i++)
    515         gLog << " " << fNumSequencesOff[i];
    516     gLog << endl << endl;
    517 
    518     gLog << "SourceName: " << fNameSource << endl;
    519     gLog << "Catalog: " << fCatalog << endl;
    520 
    521     gLog << "WobbleMode: " << (fWobbleMode?"Yes":"No") << endl << endl;
    522     gLog << "MonteCarlo: " << (fMonteCarlo?"Yes":"No") << endl << endl;
    523 
    524     gLog << "Comment: " << fComment << endl;
     533        out << " " << fNumSequencesOn[i];
     534    out << endl;
     535    if (fNumSequencesOff.GetSize()>0)
     536    {
     537        out << "SequencesOff:  ";
     538        for (int i=0; i<fNumSequencesOff.GetSize(); i++)
     539            out << " " << fNumSequencesOff[i];
     540        out << endl;
     541    }
     542
     543    out << endl;
     544    if (!fNameSource.IsNull())
     545        out << "SourceName: " << fNameSource << endl;
     546    out << "Catalog: " << fCatalog << endl;
     547
     548    out << "WobbleMode: " << (fWobbleMode?"Yes":"No") << endl << endl;
     549    out << "MonteCarlo: " << (fMonteCarlo?"Yes":"No") << endl << endl;
     550
     551    if (!fComment.IsNull())
     552        out << "Comment: " << fComment << endl;
    525553
    526554    if (fSequencesOn.GetEntries()>0)
    527         gLog << endl;
     555        out << endl;
    528556
    529557    // FIXME: If file==fName --> print Sequence0000.content
     
    533561    MSequence *seq=0;
    534562    while ((seq=(MSequence*)NextOn()))
    535         PrintSeq(*seq);
     563        PrintSeq(out, *seq);
    536564    if (fSequencesOff.GetEntries()>0)
    537         gLog << endl;
     565        out << endl;
    538566    while ((seq=(MSequence*)NextOff()))
    539         PrintSeq(*seq);
     567        PrintSeq(out, *seq);
    540568
    541569    if (TString(o).Contains("files", TString::kIgnoreCase))
    542570    {
    543         gLog << endl;
    544         gLog << "# On-Data Files:" << endl;
     571        out << endl;
     572        out << "# On-Data Files:" << endl;
    545573        NextOn.Reset();
    546574        while ((seq=(MSequence*)NextOn()))
    547             PrintFile(*seq);
    548 
    549         gLog << endl;
    550         gLog << "# Off-Data Files:" << endl;
     575            PrintFile(out, *seq);
     576
     577        out << endl;
     578        out << "# Off-Data Files:" << endl;
    551579        NextOff.Reset();
    552580        while ((seq=(MSequence*)NextOff()))
    553             PrintFile(*seq);
     581            PrintFile(out, *seq);
    554582
    555583        return;
    556584    }
     585}
     586
     587// --------------------------------------------------------------------------
     588//
     589// Print the contents of the dataset to the gLog stream
     590//
     591void MDataSet::Print(Option_t *o) const
     592{
     593    gLog << all;
     594    Print(gLog, o);
     595}
     596
     597// --------------------------------------------------------------------------
     598//
     599// Print the contents of the dataset to the file with name filename
     600//
     601void MDataSet::WriteFile(const char *name, const Option_t *o) const
     602{
     603    ofstream fout(name);
     604    if (!fout)
     605    {
     606        gLog << err << "Cannot open file " << name << ": ";
     607        gLog << strerror(errno) << endl;
     608        return;
     609    }
     610
     611    Print(fout, o);
    557612}
    558613
     
    755810}
    756811
     812/*
    757813// --------------------------------------------------------------------------
    758814//
     
    786842    }
    787843}
     844*/
  • trunk/MagicSoft/Mars/mjobs/MDataSet.h

    r8888 r8989  
    2121private:
    2222    static const TString fgCatalog; //! Default Catalog path
     23
     24    TString fFileName;        // File name to original file (MParContainer::fName is not streamed)
     25    TString fDataSet;         // Name of the dataset given by the user
    2326
    2427    UInt_t  fNumAnalysis;     // Analysis number (artificial)
     
    4548    void ResolveSequences(const TEnv &env, const TString &prefix, const TArrayI &num, TList &list/*, const TString &sequences, const TString &data*/) const;
    4649    Bool_t GetWobbleMode(const TEnv &env, const TString &prefix) const;
    47     static void PrintFile(const MSequence &obj);
    48     void PrintSeq(const MSequence &seq) const;
     50    static void PrintFile(ostream &out, const MSequence &obj);
     51    void PrintSeq(ostream &out, const MSequence &seq) const;
    4952
    5053    // Directory and file handling
    51     void ReplaceDir(TList &list, const TString &old, const TString &news) const;
    52     void ReplaceFile(TList &list, const TString &old, const TString &news) const;
     54    //void ReplaceDir(TList &list, const TString &old, const TString &news) const;
     55    //void ReplaceFile(TList &list, const TString &old, const TString &news) const;
    5356
    5457    void SetupDefaultPath(TString &path, const TString &def) const
     
    7275
    7376public:
    74     MDataSet() : fNumAnalysis((UInt_t)-1) { }
     77    MDataSet() : fNumAnalysis((UInt_t)-1)
     78    {
     79        fName  = "MDataSet";
     80        fTitle = "DataSet file";
     81    }
    7582    MDataSet(const char *fname, TString sequences="", TString data="");
    7683    MDataSet(const char *fname, Int_t num, TString sequences="", TString data="");
    7784
    78     const char *GetName() const;
    79     const char *GetRcName() const { return fName; }
     85    const char    *GetBaseName() const;
     86    const char    *GetFilePath() const;
     87    const TString &GetFileName() const { return fFileName; }
     88    const TString &GetDataSet()  const { return fDataSet;  }
    8089
    8190    void Copy(TObject &obj) const
     
    154163    Bool_t AddFilesOff(MDirIter &iter) const;
    155164
     165    /*
    156166    void ReplaceDir(const TString &old, const TString &news)
    157167    {
     
    165175        ReplaceFile(fSequencesOff, old, news);
    166176    }
     177    */
     178
     179    // I/O
     180    void WriteFile(const char *filename, const Option_t *o) const;
     181    void WriteFile(const char *filename) const { WriteFile(filename,""); } //*MENU *ARGS={filename=>fBaseName}
    167182
    168183    // TObject
     184    void Print(ostream &out, Option_t *o) const;
    169185    void Print(Option_t *o) const;
    170186    void Print() const { Print(""); } //*MENU*
    171187
    172     ClassDef(MDataSet, 2)
     188    ClassDef(MDataSet, 3)
    173189};
    174190
  • trunk/MagicSoft/Mars/mjobs/MJCut.cc

    r8907 r8989  
    1818!   Author(s): Thomas Bretz, 1/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2007
     20!   Copyright: MAGIC Software Development, 2000-2008
    2121!
    2222!
     
    461461    *fLog << inf;
    462462    fLog->Separator(GetDescriptor());
    463     *fLog << "Filling MHSrcPosCam " << set.GetName() << endl;
     463    *fLog << "Filling MHSrcPosCam " << set.GetBaseName() << endl;
    464464    *fLog << endl;
    465465
     
    591591    *fLog << inf;
    592592    fLog->Separator(GetDescriptor());
    593     *fLog << "Perform cuts for data set " << set.GetName() << endl;
     593    *fLog << "Perform cuts for data set " << set.GetBaseName() << endl;
    594594    *fLog << endl;
    595595
     
    693693    TString fname0(path);
    694694    TString fname1(path);
    695     fname0 += fNameSummary.IsNull() ?  (TString) Form("ganymed%08d-summary.root", set.GetNumAnalysis()) : fNameSummary;
    696     fname1 += fNameResult.IsNull()  ?  (TString) Form("ganymed%08d.root",         set.GetNumAnalysis()) : fNameResult;
    697 
    698     MWriteRootFile *write0 = CanStoreSummary() ? new MWriteRootFile(fPathOut.IsNull()?0:fname0.Data(), fOverwrite?"RECREATE":"NEW") : 0;
    699     MWriteRootFile *write1 = CanStoreResult()  ? new MWriteRootFile(fPathOut.IsNull()?0:fname1.Data(), fOverwrite?"RECREATE":"NEW") : 0;
     695    fname0 += fNameSummary.IsNull() ? (TString) Form("ganymed%08d-summary.root", set.GetNumAnalysis()) : fNameSummary;
     696    fname1 += fNameResult.IsNull()  ? (TString) Form("ganymed%08d.root",         set.GetNumAnalysis()) : fNameResult;
     697
     698    MWriteRootFile dummy0(fPathOut.IsNull()||!CanStoreSummary()?0:fname0.Data(), fOverwrite?"RECREATE":"NEW");
     699    MWriteRootFile dummy1(fPathOut.IsNull()||!CanStoreResult() ?0:fname1.Data(), fOverwrite?"RECREATE":"NEW");
     700
     701    MWriteRootFile *write0 = CanStoreSummary() ? &dummy0 : 0;
     702    MWriteRootFile *write1 = CanStoreResult()  ? &dummy1 : 0;
    700703    SetupWriter(write0, "WriteAfterCut0");
    701704    SetupWriter(write1, "WriteAfterCut3");
     
    10461049    }
    10471050
    1048     if (write0)
    1049         delete write0;
    1050     if (write1)
    1051         delete write1;
    1052 
    10531051    // FIXME: Perform fit and plot energy dependant alpha plots
    10541052    // and fit result to new tabs!
  • trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc

    r8985 r8989  
    1818!   Author(s): Thomas Bretz, 4/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2007
     20!   Copyright: MAGIC Software Development, 2000-2008
    2121!
    2222!
     
    311311
    312312    TH1D *time   = (TH1D*)arr.FindObjectInCanvas("ExcessTime", "TH1D", "Hist");
    313     if (!size)
     313    if (!time)
    314314    {
    315315        *fLog << err;
     
    690690Bool_t MJSpectrum::Refill(MParList &plist, TH1D &h2)/*const*/
    691691{
    692     // Try to find the class used to determin the signal!
     692    // Try to find the class used to determine the signal!
    693693    TString cls("MHAlpha");
    694694    if (fDisplay)
     
    14981498    *fLog << inf;
    14991499    fLog->Separator(GetDescriptor());
    1500     *fLog << "Compile Monte Carlo sample (dataset " << set.GetName() << ")" << endl;
     1500    *fLog << "Compile Monte Carlo sample (dataset " << set.GetBaseName() << ")" << endl;
    15011501    *fLog << endl;
    15021502
     
    15391539    if (ontime<0)
    15401540    {
    1541         *fLog << err << GetDescriptor() << ": Could not determin effective on time..." << endl;
     1541        *fLog << err << GetDescriptor() << ": Could not determine effective on time..." << endl;
    15421542        return kFALSE;
    15431543    }
     
    16051605    // -------------- Fill excess events versus energy ---------------
    16061606
    1607     // Refill excess histogram to determin the excess events
     1607    // Refill excess histogram to determine the excess events
    16081608    TH1D excess;
    16091609    if (!Refill(plist, excess))
     
    18771877        return kTRUE;
    18781878
    1879     TNamed ganame("ganymed.root", gSystem->BaseName(fPathIn));
     1879    TNamed ganame("ganymed.root", fPathIn.Data());
    18801880
    18811881    // Write the output
  • trunk/MagicSoft/Mars/mjobs/MSequence.cc

    r8969 r8989  
    141141//    seq.SetupPedRuns(iter, "/mypath", "[DPC]");
    142142//
     143//
    143144// ===========================================================================
    144145//
     146// ToDO:
     147//   * Default paths could be moved into the global .rootrc
     148//
     149// ===========================================================================
     150//
     151//
    145152//  Class Version 2:
     153//  ----------------
    146154//   + fMonteCarlo
    147155//
    148156//  Class Version 3:
     157//  ----------------
    149158//   + fComment
    150159//
    151160//  Class Version 4:
     161//  ----------------
    152162//   + fExclRuns
    153163//
    154164//  Class Version 5:
     165//  ----------------
    155166//   + fRunsSub
    156167//   + fDatRunsSub
     
    163174
    164175#include <stdlib.h>
     176#include <errno.h>
     177
     178#include <fstream>
    165179
    166180#include <TEnv.h>
     
    538552        *fLog << err;
    539553        *fLog << "ERROR - No input files for sequence #" << GetSequence() << endl;
    540         *fLog << "        read from " << GetName() << endl;
     554        *fLog << "        read from " << GetBaseName() << endl;
    541555        *fLog << "        found in" << (def?" default-path ":" ") << d << endl;
    542556        return 0;
     
    550564    *fLog << "        " << (def?" default-path ":" ") << d << endl;
    551565    *fLog << "        but " << n2 << " files were defined in sequence file" << endl;
    552     *fLog << "        " << GetName() << endl;
     566    *fLog << "        " << GetBaseName() << endl;
    553567    if (fLog->GetDebugLevel()<=4)
    554568        return 0;
     
    580594
    581595    gLog << warn;
    582     gLog << "WARNING - in " << fFileName << ":" << endl;
     596    gLog << "WARNING - in " << GetBaseName() << ":" << endl;
    583597    gLog << "          LightCondition-tag is '" << str << "' but must be n/a, no_moon, twilight, moon or day." << endl;
    584598    return kNA;
     
    591605MSequence::MSequence(const char *fname, const char *path, UInt_t seq)
    592606{
    593     fName  = fname;
    594     fTitle = path;
     607    fName  = "MSequence";
     608    fTitle = "Sequence file";
    595609
    596610    fFileName = fname;
    597611    fDataPath = path;
    598612
    599     gSystem->ExpandPathName(fName);
    600     gSystem->ExpandPathName(fTitle);
    601 
    602     const Bool_t rc1 = gSystem->AccessPathName(fName, kFileExists);
    603     const Bool_t rc2 = !fTitle.IsNull() && gSystem->AccessPathName(fTitle, kFileExists);
     613    gSystem->ExpandPathName(fFileName);
     614    gSystem->ExpandPathName(fDataPath);
     615
     616    const Bool_t rc1 = gSystem->AccessPathName(fFileName, kFileExists);
     617    const Bool_t rc2 = !fDataPath.IsNull() && gSystem->AccessPathName(fDataPath, kFileExists);
    604618
    605619    if (rc1)
    606         gLog << err << "ERROR - Sequence file '" << fName << "' doesn't exist." << endl;
     620        gLog << err << "ERROR - Sequence file '" << fname << "' doesn't exist." << endl;
    607621    if (rc2)
    608         gLog << err << "ERROR - Directory '" << fTitle << "' doesn't exist." << endl;
    609 
    610     MEnv env(fName);
     622        gLog << err << "ERROR - Directory '" << path << "' doesn't exist." << endl;
     623
     624    MEnv env(fFileName);
    611625
    612626    fSequence = (UInt_t)env.GetValue("Sequence", (Int_t)seq);
     
    659673// Make sure that the name used for writing doesn't contain a full path
    660674//
    661 const char *MSequence::GetName() const
    662 {
    663     const char *pos = strrchr(GetRcName(), '/');
    664     return pos>0 ? pos+1 : GetRcName();
     675const char *MSequence::GetBaseName() const
     676{
     677    return gSystem->BaseName(fFileName);
     678}
     679
     680//---------------------------------------------------------------------------
     681//
     682// Make sure that the name used for writing doesn't contain a full path
     683//
     684const char *MSequence::GetFilePath() const
     685{
     686    return gSystem->DirName(fFileName);
    665687}
    666688
     
    752774// simplyfing the file setup
    753775//
    754 TString MSequence::PrintRuns(const char *pre, const char *name, const TArrayI &r, const TArrayI &f) const
     776TString MSequence::PrintRuns(ostream &out, const char *pre, const char *name, const TArrayI &r, const TArrayI &f) const
    755777{
    756778    if (r.GetSize()==0)
    757779        return "";
    758780
    759     gLog << pre << name;
     781    out << pre << name;
    760782    if (f.GetSize()==0)
    761783        const_cast<TArrayI&>(f).Set(r.GetSize());
     
    763785#ifdef DEBUG
    764786    for (int i=0; i<r.GetSize(); i++)
    765         gLog << "  " << r[i] << "." << f[i];
    766     gLog << endl;
     787        out << "  " << r[i] << "." << f[i];
     788    out << endl;
    767789    return "";
    768790#endif
     
    776798        if (!rc.IsNull())
    777799        {
    778             gLog << rc;
     800            out << rc;
    779801            continue;
    780802        }
     
    788810        if (n==1)
    789811        {
    790             gLog << " " << r[pos];
     812            out << " " << r[pos];
    791813            if (f[pos]>0)
    792                 gLog << "." << f[pos];
     814                out << "." << f[pos];
    793815        }
    794816        else
     
    802824            if (isseq)
    803825            {
    804                 gLog << " " << r[pos] << ".";
     826                out << " " << r[pos] << ".";
    805827                if (f[pos]!=0)
    806                     gLog << f[pos];
    807                 gLog << ":" << f[pos+n-1];
     828                    out << f[pos];
     829                out << ":" << f[pos+n-1];
    808830            }
    809831            else
    810832            {
    811                 gLog << " " << r[pos] << "+";
     833                out << " " << r[pos] << "+";
    812834
    813835                str += '\n';
     
    821843    }
    822844
    823     gLog << endl;
     845    out << endl;
    824846
    825847    return str;
     
    830852// Print the numbers in the classical way (one run after the other)
    831853//
    832 void MSequence::PrintRunsClassic(const char *pre, const char *name, const TArrayI &r) const
    833 {
    834     gLog << pre << name;
     854void MSequence::PrintRunsClassic(ostream &out, const char *pre, const char *name, const TArrayI &r) const
     855{
     856    out << pre << name;
    835857    for (int i=0; i<r.GetSize(); i++)
    836         gLog << " " << r[i];
    837     gLog << endl;
     858        out << " " << r[i];
     859    out << endl;
    838860}
    839861
     
    842864// Print the contents of the sequence
    843865//
    844 void MSequence::Print(Option_t *o) const
     866void MSequence::Print(ostream &out, Option_t *o) const
    845867{
    846868    const TString opt(o);
     
    848870    const TString pre = opt.Contains("prefixed") ? Form("Sequence%08d.", fSequence) : "";
    849871
    850     gLog << all;
    851872    if (!IsValid())
    852873    {
    853         gLog << pre << "Sequence: " << fFileName << " <invalid>" << endl;
     874        out << pre << "Sequence: " << fFileName << " <invalid>" << endl;
    854875        return;
    855876    }
    856     gLog << "# Path: " << GetRcName() << endl;
    857     gLog << "# Name: " << GetName() << endl;
    858     gLog << endl;
     877    out << "# Path: " << GetFileName() << endl;
     878    out << "# Name: " << GetBaseName() << endl;
     879    out << endl;
    859880    if (pre.IsNull())
    860         gLog << "Sequence:       " << fSequence << endl;
     881        out << "Sequence:       " << fSequence << endl;
    861882    if (fMonteCarlo)
    862         gLog << pre << "MonteCarlo:     Yes" << endl;
    863     gLog << pre <<"Period:         " << fPeriod << endl;
    864     gLog << pre << "Night:          " << fNight << endl << endl;
    865     gLog << pre << "LightCondition: ";
     883        out << pre << "MonteCarlo:     Yes" << endl;
     884    if (fPeriod>=0)
     885        out << pre << "Period:         " << fPeriod << endl;
     886    if (fNight!=MTime())
     887        out << pre << "Night:          " << fNight << endl;
     888    out << endl;
     889    out << pre << "LightCondition: ";
    866890    switch (fLightCondition)
    867891    {
    868     case kNA:       gLog << "n/a" << endl;      break;
    869     case kNoMoon:   gLog << "NoMoon" << endl;   break;
    870     case kTwilight: gLog << "Twilight" << endl; break;
    871     case kMoon:     gLog << "Moon" << endl;     break;
    872     case kDay:      gLog << "Day" << endl;     break;
    873     }
    874     gLog << pre << "Start:          " << fStart << endl;
    875     gLog << pre << "LastRun:        " << fLastRun << endl;
    876     gLog << pre << "NumEvents:      " << fNumEvents << endl;
    877     gLog << pre << "Project:        " << fProject << endl;
    878     gLog << pre << "Source:         " << fSource << endl;
    879     gLog << pre << "TriggerTable:   " << fTriggerTable << endl;
    880     gLog << pre << "HvSettings:     " << fHvSettings << endl << endl;
     892    case kNA:       out << "n/a" << endl;      break;
     893    case kNoMoon:   out << "NoMoon" << endl;   break;
     894    case kTwilight: out << "Twilight" << endl; break;
     895    case kMoon:     out << "Moon" << endl;     break;
     896    case kDay:      out << "Day" << endl;     break;
     897    }
     898
     899    if (fStart!=MTime())
     900        out << pre << "Start:          " << fStart << endl;
     901    if (fLastRun>=0)
     902        out << pre << "LastRun:        " << fLastRun << endl;
     903    if (fNumEvents>=0)
     904        out << pre << "NumEvents:      " << fNumEvents << endl;
     905    if (!fProject.IsNull())
     906        out << pre << "Project:        " << fProject << endl;
     907    if (!fSource.IsNull())
     908        out << pre << "Source:         " << fSource << endl;
     909    if (!fTriggerTable.IsNull())
     910        out << pre << "TriggerTable:   " << fTriggerTable << endl;
     911    if (!fHvSettings.IsNull())
     912        out << pre << "HvSettings:     " << fHvSettings << endl;
     913    out << endl;
    881914
    882915    TString str;
    883916    if (!HasSubRuns() && opt.Contains("classic"))
    884917    {
    885         PrintRunsClassic(pre, "Runs:     ", fRuns);
    886         PrintRunsClassic(pre, "CalRuns:  ", fCalRuns);
    887         PrintRunsClassic(pre, "PedRuns:  ", fPedRuns);
    888         PrintRunsClassic(pre, "DataRuns: ", fDatRuns);
    889         PrintRunsClassic(pre, "Exclude:  ", fExclRuns);
     918        PrintRunsClassic(out, pre, "Runs:     ", fRuns);
     919        PrintRunsClassic(out, pre, "CalRuns:  ", fCalRuns);
     920        PrintRunsClassic(out, pre, "PedRuns:  ", fPedRuns);
     921        PrintRunsClassic(out, pre, "DataRuns: ", fDatRuns);
     922        PrintRunsClassic(out, pre, "Exclude:  ", fExclRuns);
    890923    }
    891924    else
    892925    {
    893         str += PrintRuns(pre, "Runs:     ", fRuns,     fRunsSub);
    894         str += PrintRuns(pre, "CalRuns:  ", fCalRuns,  fCalRunsSub);
    895         str += PrintRuns(pre, "PedRuns:  ", fPedRuns,  fPedRunsSub);
    896         str += PrintRuns(pre, "DataRuns: ", fDatRuns,  fDatRunsSub);
    897         str += PrintRuns(pre, "Exclude:  ", fExclRuns, fExclRunsSub);
     926        str += PrintRuns(out, pre, "Runs:     ", fRuns,     fRunsSub);
     927        str += PrintRuns(out, pre, "CalRuns:  ", fCalRuns,  fCalRunsSub);
     928        str += PrintRuns(out, pre, "PedRuns:  ", fPedRuns,  fPedRunsSub);
     929        str += PrintRuns(out, pre, "DataRuns: ", fDatRuns,  fDatRunsSub);
     930        str += PrintRuns(out, pre, "Exclude:  ", fExclRuns, fExclRunsSub);
    898931    }
    899932
    900933    if (!fDataPath.IsNull())
    901         gLog << endl << pre << "DataPath: " << fDataPath << endl;
     934        out << endl << pre << "DataPath: " << fDataPath << endl;
    902935
    903936    if (!str.IsNull())
    904         gLog << str << endl;
    905 
    906     gLog << endl << pre << "Comment: " << fComment << endl;
     937        out << str << endl;
     938
     939    out << endl;
     940
     941    if (!fComment.IsNull())
     942        out << pre << "Comment: " << fComment << endl;
     943}
     944
     945// --------------------------------------------------------------------------
     946//
     947// Print the contents of the sequence to gLog
     948//
     949void MSequence::Print(Option_t *o) const
     950{
     951    gLog << all;
     952    Print(gLog, o);
     953}
     954
     955// --------------------------------------------------------------------------
     956//
     957// Print the contents of the sequence to the file with name filename
     958//
     959void MSequence::WriteFile(const char *name, const Option_t *o) const
     960{
     961    ofstream fout(name);
     962    if (!fout)
     963    {
     964        gLog << err << "Cannot open file " << name << ": ";
     965        gLog << strerror(errno) << endl;
     966        return;
     967    }
     968
     969    Print(fout, o);
    907970}
    908971
  • trunk/MagicSoft/Mars/mjobs/MSequence.h

    r8969 r8989  
    2222    };
    2323private:
    24     TString fFileName;
    25     TString fDataPath;
     24    TString fFileName;         // Expanded file name
     25    TString fDataPath;         // Path to data files
    2626
    27     UInt_t fSequence;
     27    UInt_t fSequence;          // Sequence number
    2828
    29     MTime  fStart;
     29    MTime  fStart;             // Start time of sequence
    3030
    31     UInt_t fLastRun;
    32     UInt_t fNumEvents;
     31    UInt_t fLastRun;           // Last run in sequence (necessary?)
     32    UInt_t fNumEvents;         // Number of events in sequence
    3333
    34     UInt_t fPeriod;
    35     MTime  fNight;
     34    UInt_t fPeriod;            // Observation period of the sequence
     35    MTime  fNight;             // Night (day of sunrise) of the sequence
    3636
    3737    LightCondition_t fLightCondition;
     
    4343    TString fComment;
    4444
    45     TArrayI fRuns;
    46     TArrayI fRunsSub;
     45    TArrayI fRuns;            // Run numbers
     46    TArrayI fRunsSub;         // Sub runs (files)
    4747
    48     TArrayI fCalRuns;
    49     TArrayI fCalRunsSub;
     48    TArrayI fCalRuns;         // Numbers of calibration runs/files
     49    TArrayI fCalRunsSub;      // Sub runs (files) of calibration runs
    5050
    51     TArrayI fPedRuns;
    52     TArrayI fPedRunsSub;
     51    TArrayI fPedRuns;         // Numbers of pedestal runs/files
     52    TArrayI fPedRunsSub;      // Sub runs (files) of pedestal runs
    5353
    54     TArrayI fDatRuns;
    55     TArrayI fDatRunsSub;
     54    TArrayI fDatRuns;         // Numbers of data runs/files
     55    TArrayI fDatRunsSub;      // Sub runs (files) of data runs
    5656
    57     TArrayI fExclRuns;
    58     TArrayI fExclRunsSub;
     57    TArrayI fExclRuns;        // Numbers of excluded runs/files
     58    TArrayI fExclRunsSub;     // Sub runs (files) of excluded runs
    5959
    60     Bool_t fMonteCarlo;
     60    Bool_t fMonteCarlo;       // Flag for Monte Carlo sequences
    6161
    6262    // Helper for interpretation
     
    7878    TString GetNumSequence(Int_t &pos, const TArrayI &n, const TArrayI &f) const;
    7979
    80     void    PrintRunsClassic(const char *pre, const char *name, const TArrayI &r) const;
    81     TString PrintRuns(const char *pre, const char *name, const TArrayI &r, const TArrayI &f) const;
     80    void    PrintRunsClassic(ostream &out, const char *pre, const char *name, const TArrayI &r) const;
     81    TString PrintRuns(ostream &out, const char *pre, const char *name, const TArrayI &r, const TArrayI &f) const;
    8282
    8383    // General helper
     
    9292public:
    9393    MSequence() : fSequence((UInt_t)-1), fLastRun((UInt_t)-1),
    94         fNumEvents((UInt_t)-1), fPeriod((UInt_t)-1), fMonteCarlo(kFALSE) { }
     94        fNumEvents((UInt_t)-1), fPeriod((UInt_t)-1), fMonteCarlo(kFALSE)
     95    {
     96        fName  = "MSequence";
     97        fTitle = "Sequence file";
     98    }
    9599    MSequence(const char *fname, const char *path="", UInt_t id=(UInt_t)-1);
    96     MSequence(const MSequence &s) : fSequence(s.fSequence), fStart(s.fStart),
     100    MSequence(const MSequence &s) : MParContainer(s),
     101        fFileName(s.fFileName), fDataPath(s.fDataPath),
     102        fSequence(s.fSequence), fStart(s.fStart),
    97103        fLastRun(s.fLastRun), fNumEvents(s.fNumEvents), fPeriod(s.fPeriod),
    98104        fNight(s.fNight), fProject(s.fProject), fSource(s.fSource),
     
    101107        fDatRuns(s.fDatRuns), fMonteCarlo(s.fMonteCarlo) { }
    102108
     109    // I/O
     110    void WriteFile(const char *filename, const Option_t *o) const;
     111    void WriteFile(const char *filename) const { WriteFile(filename,""); } //*MENU *ARGS={filename=>fBaseName}
     112
    103113    // TObject
     114    void Print(ostream &out, Option_t *o) const;
    104115    void Print(Option_t *o) const;
    105116    void Print() const { Print(""); } //*MENU*
    106 
    107     const char *GetName() const;
    108     const char *GetRcName() const { return fName; }
    109117
    110118    // Genaral interface
     
    151159
    152160    // Filesystem getter
     161    const char    *GetBaseName() const;
     162    const char    *GetFilePath() const;
    153163    const TString &GetFileName() const { return fFileName; }
    154164    const TString &GetDataPath() const { return fDataPath; }
Note: See TracChangeset for help on using the changeset viewer.