Ignore:
Timestamp:
08/31/07 14:11:36 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

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

    r8674 r8724  
    3535//       AnalysisNumber: 1
    3636//
    37 //       SequencesOn: 35222
     37//       Name: SecondCrab
     38//
     39//       SequencesOn: 35222 35229
    3840//       SequencesOff: 36817
    3941//
     
    4749//       Sequence00036817.Dir: /data2/wuerzburg/Crab-Analyse/images/036817
    4850//
     51//       WobbleMode: No
    4952//       MonteCarlo: No
     53//
     54//       SourceName: CrabNebula
     55//       Catalog: /magic/datacenter/setup/magic_favorites_dc.edb
    5056//
    5157// AnalysisNumber: The analysis number is an artifical number used to name
     
    8086// stored using Sequence%08d.Dir (make sure you have 8 digits!)
    8187//
    82 //
     88// WobbleMode: This is just a flag which is passed to the program
     89// end eveluated (or not) by the individual program, which takes this
     90// dataset as an input. For example this is necessary in ganymed to do
     91// some wobble mode special setup. If no resource is given (or it is
     92// set to "auto") wobble mode if set if the datset contains no off-
     93// sequences.
     94//
     95// MonetCarlo: This is just a flag which is passed to the program
     96// end eveluated (or not) by the individual program, which takes this
     97// dataset as an input. For example this tells ganymed to skip some
     98// parts accessing time stamps which are not available in the MCs.
     99//
     100// SequencePath/DataPath: This determined were the sequences and data-files
     101// are stored. The priorities are as follows:
     102//  0) Build in default path:          /magic/sequences   /magic/data/star
     103//  1) Def.path from dataset file:       SequencePath         DataPath
     104//  2) Indiv.path from dataset file:  12345.SequencePath   12345.DataPath
     105//  3) Path from command line:            Argument in the constructors
     106//  4) Path for an indiv. dataset:         Sequences00022555.File/Dir
     107//
     108// Catalog: This is the xephem-style file from the central control
     109// containing the observed sky positions.
     110//
     111// SourceName: The source name, as defined in the catalog, of the object
     112// the data corresponds to.
     113//
     114// Name: A name is stored for your convinience
     115//
     116// Comment: It is just stored.
     117//
     118// General Remark: MDataSet doesn't implement any action on the given
     119// resources. Whether a resource is used, necessary or ignored, and
     120// what will happen if you change the resource is always defined by the
     121// executed macro or program.
    83122//
    84123// Resource file entries are case sensitive!
     124//
     125//
     126// Collection of datsets
     127// ---------------------
     128//
     129//  You can combine more than one datset in a file (if your program
     130//  supports this) Such a dataset file could look like this:
     131//
     132//       35222.SequencesOn: 35222
     133//       35222.SequencesOff: 36817
     134//
     135//       65778.SequencesOn: 65778
     136//
     137//       12345.SequencesOn: 12345
     138//
     139//       12345.SequencePath: /home/nobody/specialsequences
     140//       65778.DataPath:     /home/nobody/specialstars
     141//
     142//       SequencePath: /home/nobody/defaultsequences
     143//       DataPath:     /home/nobody/defaultstars
     144//
     145//       Sequence00035222.File: sequences/sequence035222.txt
     146//       Sequence00035222.Dir:  /data2/wuerzburg/Crab-Analyse/images/035222
     147//
     148//       35222.WobbleMode: Off
     149//       WobbleMode: On
     150//
    85151//
    86152// IMPORTANT:
     
    89155//   * Sequence filenames should also have names allowing to order them
    90156//     in time, but it is not necessary.
     157//
     158//
     159// ToDO:
     160//   * Default paths could be moved into the global .rootrc
     161//
    91162//
    92163// Class Version 2:
     
    183254// The entries are sorted by filename.
    184255//
    185 void MDataSet::ResolveSequences(TEnv &env, const TArrayI &num, TList &list) const
     256void MDataSet::ResolveSequences(const TEnv &env, const TString &prefix, const TArrayI &num, TList &list) const
    186257{
    187258    TString sequences = fPathSequences;
     
    190261    for (int i=0; i<num.GetSize(); i++)
    191262    {
    192         TString name = env.GetValue(Form("Sequence%08d.File", num[i]), "");
    193         TString dir  = env.GetValue(Form("Sequence%08d.Dir",  num[i]), "");
     263        TString name = GetEnvValue2(env, prefix, Form("Sequence%08d.File", num[i]), "");
     264        TString dir  = GetEnvValue2(env, prefix, Form("Sequence%08d.Dir",  num[i]), "");
    194265
    195266        // Set default sequence file and dir name
     
    213284}
    214285
    215 // --------------------------------------------------------------------------
    216 //
    217 // Read the file fname as setup file for the sequence.
    218 //
    219 MDataSet::MDataSet(const char *fname, TString sequences, TString data)
    220 {
     286Bool_t MDataSet::GetWobbleMode(const TEnv &env, const TString &prefix) const
     287{
     288    TString wob = GetEnvValue2(env, prefix, "WobbleMode", "auto");
     289
     290    wob.ToLower();
     291    wob=wob.Strip(TString::kBoth);
     292
     293    if (wob=="auto")
     294        return !HasOffSequences();
     295
     296    return GetEnvValue2(env, prefix, "WobbleMode", kFALSE);
     297}
     298
     299// --------------------------------------------------------------------------
     300//
     301// Read a dataset from the file fname. If num is != -1 all resources are
     302// prefixed with the number. This allows constrcutions like:
     303//
     304//   89123.SequencesOn: 1 2 3 4
     305//   89130.SequencesOn: 5 6 7 8
     306//
     307// For one dataset:
     308//
     309//   89123.DataPath: /magic/data/star
     310//
     311// For all other datasets:
     312//
     313//   DataPath: /magic/data/star
     314//
     315// For one sequence of one datasets:
     316//
     317//   89123.Sequence00000002.Dir: /magic/data/star
     318//
     319// and therefore allows storage of several datsets in one file with
     320// a defaults for non specific resources.
     321//
     322// sequences and data are the path to the sequences (/magic/sequences)
     323// and the data (/magic/data/star) respectively. Both can be overwritten
     324// be a default from the dataset file or a resource for an individual
     325// sequence.
     326//
     327void MDataSet::Init(const char *fname, const UInt_t num, TString sequences, TString &data)
     328{
     329    // Store given file name as name
    221330    fName = fname;
    222331
     332    // Delete the stored Sequences automatically at destruction
    223333    fSequencesOn.SetOwner();
    224334    fSequencesOff.SetOwner();
    225335
     336    // Determin the prefix to access this resource
     337    const TString prefix = num==(UInt_t)-1 ? "" : Form("%d", num);
     338
     339    // Expand the file name (eg $MARS or ~ are expanded)
    226340    TString expname(fname);
    227341    gSystem->ExpandPathName(expname);
    228342
     343    // Check its accessibility
    229344    const Bool_t access = !gSystem->AccessPathName(expname, kFileExists);
    230345    if (!access)
    231346        gLog << err << "ERROR - Dataset file " << expname << " not accessible!" << endl;
    232347
     348    // Open and read the file
    233349    MEnv env(expname);
    234350
    235     fNumAnalysis = env.GetValue("AnalysisNumber", -1);
    236     fTitle       = env.GetValue("Name", expname);
    237 
     351    // Get analysis number and name
     352    fNumAnalysis = GetEnvValue2(env, prefix, "AnalysisNumber", (Int_t)num);
     353    fTitle       = GetEnvValue2(env, prefix, "Name", expname);
     354
     355    // Get sequences from file
    238356    TString str;
    239     str = env.GetValue("SequencesOn",  "");
     357    str = GetEnvValue2(env, prefix, "SequencesOn",  "");
    240358    Split(str, fNumSequencesOn);
    241     str = env.GetValue("SequencesOff", "");
     359    str = GetEnvValue2(env, prefix, "SequencesOff", "");
    242360    Split(str, fNumSequencesOff);
    243361
    244     fNameSource   = env.GetValue("SourceName", "");
    245     fCatalog      = env.GetValue("Catalog",    fgCatalog);
    246     fWobbleMode   = env.GetValue("WobbleMode", kFALSE);
    247     fMonteCarlo   = env.GetValue("MonteCarlo", kFALSE);
    248     fComment      = env.GetValue("Comment",    "");
    249 
    250     const TString defpathseq  = env.GetValue("SequencePath", GetDefPathSequences());
    251     const TString defpathdata = env.GetValue("DataPath",     GetDefPathDataFiles());
     362    // Get other resources
     363    fNameSource   = GetEnvValue2(env, prefix, "SourceName", "");
     364    fCatalog      = GetEnvValue2(env, prefix, "Catalog",    fgCatalog);
     365    fMonteCarlo   = GetEnvValue2(env, prefix, "MonteCarlo", kFALSE);
     366    fComment      = GetEnvValue2(env, prefix, "Comment",    "");
     367
     368    fWobbleMode   = GetWobbleMode(env, prefix); // needs the number of off sequences
     369
     370    fNameSource = fNameSource.Strip(TString::kBoth);
     371    fCatalog    = fCatalog.Strip(TString::kBoth);
     372
     373    // Check for sequence and data path (GetDefPath needs the monte carlo flag)
     374    const TString defpathseq  = GetEnvValue2(env, prefix, "SequencePath", GetDefPathSequences());
     375    const TString defpathdata = GetEnvValue2(env, prefix, "DataPath",     GetDefPathDataFiles());
    252376
    253377    SetupDefaultPath(sequences, defpathseq);
     
    257381    fPathDataFiles = data;
    258382
    259     ResolveSequences(env, fNumSequencesOn,  fSequencesOn);
    260     ResolveSequences(env, fNumSequencesOff, fSequencesOff);
    261 
    262     fNameSource = fNameSource.Strip(TString::kBoth);
    263     fCatalog    = fCatalog.Strip(TString::kBoth);
     383    // Resolve sequences
     384    ResolveSequences(env, prefix, fNumSequencesOn,  fSequencesOn);
     385    ResolveSequences(env, prefix, fNumSequencesOff, fSequencesOff);
    264386
    265387    // --- Now "touch" resources which are not yet stored in MDataSet ---
     
    272394        env.PrintUntouched();
    273395    }
     396}
     397
     398// --------------------------------------------------------------------------
     399//
     400// Constructor. See Read for more details.
     401//
     402MDataSet::MDataSet(const char *fname, TString sequences, TString data)
     403{
     404    Init(fname, (UInt_t)-1, sequences, data);
     405}
     406
     407// --------------------------------------------------------------------------
     408//
     409// Constructor. See Read for more details.
     410//
     411MDataSet::MDataSet(const char *fname, Int_t num, TString sequences, TString data)
     412{
     413    Init(fname, num, sequences, data);
    274414}
    275415
     
    330470    gLog << "Catalog: " << fCatalog << endl;
    331471
    332     gLog << "WobbleMode: " << (fWobbleMode?"On":"Off") << endl << endl;
     472    gLog << "WobbleMode: " << (fWobbleMode?"Yes":"No") << endl << endl;
    333473    gLog << "MonteCarlo: " << (fMonteCarlo?"Yes":"No") << endl << endl;
    334474
Note: See TracChangeset for help on using the changeset viewer.