Ignore:
Timestamp:
06/17/08 18:09:42 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mjobs
Files:
3 edited

Legend:

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

    r8964 r8969  
    268268
    269269    // Plot the trigger pattern rates vs. run-number
    270     MH3 hrate("MRawRunHeader.fRunNumber", "MTriggerPattern.GetUnprescaled");
     270    MH3 hrate("MRawRunHeader.GetFileID", "MTriggerPattern.GetUnprescaled");
    271271    hrate.SetWeight("1./MRawRunHeader.GetRunLength");
    272272    hrate.SetName("Rate");
    273     hrate.SetTitle("Event rate after cleaning [Hz];Run Number;Trigger Type;");
     273    hrate.SetTitle("Event rate after cleaning [Hz];File Id;Trigger Type;");
    274274    hrate.InitLabels(MH3::kLabelsX);
    275275    hrate.DefaultLabelY("ERROR");
  • trunk/MagicSoft/Mars/mjobs/MSequence.cc

    r8795 r8969  
    1818!   Author(s): Thomas Bretz, 8/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2004-2007
     20!   Copyright: MAGIC Software Development, 2004-2008
    2121!
    2222!
     
    8080//
    8181//   # List of all runs of this sequence (not needed)
    82 //   Runs: 31015 31016 31017 31018 31019 31020 31021 31022 31023 31024 31025 31026 31027 31028 31029 31030 31031 31032
     82//   Runs: 31015:31017 31018 31019.0 31019.3 31019.5:7 31020+ 31021::3
    8383//
    8484//   # List of all calibration runs of this sequence (necessary if accessed)
     
    8787//   PedRuns: 31018
    8888//   # List of all data runs belonging to this sequence (necessary)
    89 //   DatRuns: 31019 31020 31022 31023 31024 31025 31027 31028 31030 31032
     89//   DatRuns: 31019.0 31019.3 31019:5:7 31020+ 31021::3
     90//
     91//   Run00031020: :3 7:9 15
    9092//
    9193//   # Just for fun ;-) (not needed, but helpful)
     
    9496// ===========================================================================
    9597//
     98//   Runs are devided into file since run 1000000. These Run-/Filenumbers
     99//   are given by a dot. X.Y means Run X, File Y.
     100//
     101//   In the Runs, CalRuns, PedRuns and DatRuns tag you can use
     102//   several abbreviationa:
     103//
     104//    31015:31017     means      31015.0 31016.0 31017.0
     105//    31018           means      31018.0
     106//    31019.3         means      31019.3
     107//    31019.5:7       means      31019.5 31019.6 31019.7
     108//    31020+          means      file list for run 21020 given below
     109//    31021::3        means      31021.0 31021.1 31021.2 31021.3
     110//
     111//   For the run-list defined above (note the number must have 8 digits,
     112//   for example 'Run00031020') you can also use abbreviations:
     113//
     114//    :3              means      0 1 2 3
     115//    7:9             means      7 8 9
     116//
     117// ===========================================================================
     118//
    96119//  For special cases you can also setup a sequence directly from a macro,
    97120//  for example:
     
    101124//    MSequence seq;
    102125//    seq.SetNight("2004-07-06");
    103 //    seq.AddPedRuns(31751);
    104 //    seq.AddCalRuns(31752);
    105 //    seq.AddDatRuns(31753, 31764);
     126//    seq.AddRun(31751, 'P');
     127//    seq.AddRun(31752, 'C');
     128//    seq.AddRuns(31753, 31764, 'D');
    106129//    seq.SetupPedRuns(pediter);
    107130//    seq.SetupCalRuns(caliter);
     
    114137//    MSequence seq;
    115138//    seq.SetNight("2004-07-06");
    116 //    seq.AddRuns(31753, 31764);
     139//    seq.AddFiles(31753, 0, 120);
    117140//    seq.SetupRuns(iter);
    118141//    seq.SetupPedRuns(iter, "/mypath", "[DPC]");
     
    129152//   + fExclRuns
    130153//
     154//  Class Version 5:
     155//   + fRunsSub
     156//   + fDatRunsSub
     157//   + fPedRunsSub
     158//   + fCalRunsSub
     159//   + fExclRunsSub
     160//
    131161/////////////////////////////////////////////////////////////////////////////
    132162#include "MSequence.h"
     
    135165
    136166#include <TEnv.h>
    137 #include <TRegexp.h>
     167#include <TPRegexp.h>
    138168#include <TSystem.h> // TSystem::ExpandPath
    139169
     
    151181using namespace std;
    152182
    153 MSequence::~MSequence()
    154 {
    155     /*
    156     TExMapIter iter(&fFileNames);
    157 
    158     Long_t key, val;
    159 
    160     while (iter.Next(key, val))
    161         delete (TString*)val;
    162         */
    163 }
    164 
    165 
    166 // --------------------------------------------------------------------------
    167 //
    168 // Copy the run numbers from the TString runs into the TArrayI data.
    169 // Runs which are twice in the list are only added once. In this case
     183// --------------------------------------------------------------------------
     184//
     185// This adds an run/file entry to the data/sub arrays. If it is already
     186// contained a waring is printed.
     187//
     188void MSequence::AddEntry(Int_t run, Int_t file, TArrayI &data, TArrayI &sub) const
     189{
     190    const Int_t n = data.GetSize();
     191
     192    // skip already existing entries
     193    if (IsContained(data, sub, run, file))
     194    {
     195        *fLog << warn << "WARNING - File " << run << "." << file << " already in list... skipped." << endl;
     196        return;
     197    }
     198
     199    if (run<1000000 && file>0)
     200        *fLog << warn << "WARNING - Run number " << run << "<" << "1,000,000 but file " << file << ">0..." << endl;
     201
     202    // set new entry
     203    data.Set(n+1);
     204    sub.Set(n+1);
     205
     206    data[n] = run;
     207    sub[n]  = file;
     208}
     209
     210// --------------------------------------------------------------------------
     211//
     212// Evaluate a token in thr Run string. Add the coresponding run/files
     213// with AddEntry
     214//
     215void MSequence::EvalEntry(const TEnv *env, const TString &prefix, const TString &num, TArrayI &data, TArrayI &sub) const
     216{
     217    // Split entry into run and file
     218    const Int_t run = num.Atoi();
     219
     220    // Syntax error forbidden by construction
     221    const Ssiz_t p1 = num.First('.');
     222    const Ssiz_t p2 = num.Last(':');
     223
     224    // ---------------------------------------------------------------
     225
     226    const Int_t n1 = atoi(num.Data()+p1+1);
     227    const Int_t n2 = atoi(num.Data()+p2+1);
     228
     229    // ---------------------------------------------------------------
     230    //  p1>=0 && p2<0  (. but no :)    run.n1     run.file1
     231    if (p1>=0 && p2<0)
     232    {
     233        AddEntry(run, n1, data, sub);
     234        return;
     235    }
     236
     237    // ---------------------------------------------------------------
     238    //  p1>=0 && p2>=0  (. and :)      run:n1:n2  run.file1-run.file2
     239    if (p1>=0 && p2>=0)
     240    {
     241        if (n2<n1)
     242        {
     243            *fLog << warn << "WARNING - Invalid range '" << num << "'... ignored." << endl;
     244            return;
     245        }
     246
     247        for (int i=n1; i<=n2; i++)
     248            AddEntry(run, i, data, sub);
     249        return;
     250    }
     251
     252    // ---------------------------------------------------------------
     253    //  p1<0 && p2>=0  (no . but :)    n1:n2      run1-run2
     254    if (p1<0 && p2>=0)
     255    {
     256        if (n2<run)
     257        {
     258            *fLog << warn << "WARNING - Invalid range in '" << num << "'... ignored." << endl;
     259            return;
     260        }
     261
     262        for (int i=run; i<=n2; i++)
     263            AddEntry(i, 0, data, sub);
     264        return;
     265    }
     266
     267    // ---------------------------------------------------------------
     268    //  p0<0 and p1<0  (no . and no :)   run     run
     269
     270    if (!num.EndsWith("+"))
     271    {
     272        AddEntry(run, 0, data, sub);
     273        return;
     274    }
     275
     276    if (!env)
     277        return;
     278
     279    TPRegexp regexp("([0-9]*:[0-9]+|[0-9]+(:[0-9]*)?)( +|$)");
     280
     281    TString files = GetEnvValue2(*env, prefix, Form("Run%08d", run), "");
     282    if (files.IsNull())
     283    {
     284        AddEntry(run, 0, data, sub);
     285        return;
     286    }
     287
     288    while (!files.IsNull())
     289    {
     290        const TString num = files(regexp);
     291        if (num.IsNull())
     292        {
     293            *fLog << warn << "WARNING - File in run " << run << " is NaN (not a number): '" << files << "'" << endl;
     294            break;
     295        }
     296
     297        const Ssiz_t p1 = num.First(':');
     298        if (p1>=0)
     299        {
     300            const Int_t n1 = atoi(num.Data());
     301            const Int_t n2 = atoi(num.Data()+p1+1);
     302
     303            if (n2<n1)
     304            {
     305                *fLog << warn << "WARNING - Invalid range in '" << num << "'... ignored." << endl;
     306                return;
     307            }
     308
     309            // FIXME: n2==0 || n2<n1
     310            for (int i=n1; i<=n2; i++)
     311                AddEntry(run, i, data, sub);
     312        }
     313        else
     314        {
     315            const Int_t file = atoi(num.Data());
     316            AddEntry(run, file, data, sub);
     317        }
     318
     319        files.Remove(0, files.First(num)+num.Length());
     320    }
     321}
     322
     323// --------------------------------------------------------------------------
     324//
     325// Interprete the TString and add the run/files to the arrays.
     326// Run/files which are twice in the list are only added once. In this case
    170327// a warning is emitted.
    171328//
    172 void MSequence::Split(TString &runs, TArrayI &data) const
    173 {
    174     const TRegexp regexp("[0-9]+");
     329void MSequence::Split(TString &runs, TArrayI &data, TArrayI &sub, const TEnv *env, const TString prefix) const
     330{
     331    TPRegexp regexp("^[0-9]+([+]|(:|[.]([0-9]*:)?)[0-9]+)?( +|$)");
    175332
    176333    data.Set(0);
     334    sub.Set(0);
    177335
    178336    runs.ReplaceAll("\t", " ");
     
    182340    {
    183341        const TString num = runs(regexp);
    184 
    185342        if (num.IsNull())
    186343        {
    187             *fLog << warn << "WARNING - Run is NaN (not a number): '" << runs << "'" << endl;
     344            *fLog << warn << "WARNING - Run syntax error: '" << runs << "'" << endl;
    188345            break;
    189346        }
    190347
    191         const Int_t run = atoi(num.Data());
    192         const Int_t n   = data.GetSize();
    193 
    194         // skip already existing entries
    195         int i;
    196         for (i=0; i<n; i++)
    197             if (data[i] == run)
    198                 break;
    199 
    200         if (i<n)
    201             *fLog << warn << "WARNING - Run #" << run << " already in list... skipped." << endl;
    202         else
    203         {
    204             // set new entry
    205             data.Set(n+1);
    206             data[n] = run;
    207         }
     348        EvalEntry(env, prefix, num.Strip(TString::kTrailing), data, sub);
    208349
    209350        runs.Remove(0, runs.First(num)+num.Length());
    210351    }
    211352
    212     MJob::SortArray(data);
    213 }
    214 
    215 UInt_t MSequence::SetupRuns(MDirIter &iter, const TArrayI &arr, FileType_t type, const char *path) const
    216 {
    217     TString d(path);
     353    SortArrays(data, sub);
     354}
     355
     356// --------------------------------------------------------------------------
     357//
     358// Get the String from the TEnv file prefixed by prefix-name.
     359// Intepret the string using Split which adds the run/files to the arrays.
     360//
     361void MSequence::Split(const TEnv &env, const TString &prefix, const char *name, TArrayI &data, TArrayI &sub) const
     362{
     363    TString str = GetEnvValue2(env, prefix, name, "");
     364    Split(str, data, sub, &env, prefix);
     365}
     366
     367// --------------------------------------------------------------------------
     368//
     369// Compile path from the given path name and expand it. If it IsNull()
     370// the path is compiled as standard path from tha datacenter). The
     371// returned path will end with a "/".
     372//
     373TString MSequence::GetPathName(TString d, FileType_t type) const
     374{
     375    // Setup path
    218376    if (d.IsNull())
    219         d = fDataPath;
    220 
    221     const Bool_t def = d.IsNull();
    222 
    223     // For this particular case we assume that the files are added one by
    224     // one without wildcards.
    225     const Int_t n0 = iter.GetNumEntries();
    226 
    227     // Setup path
    228     if (def)
    229377    {
    230378        d = GetStandardPath();
     
    256404        d += '/';
    257405
     406    return d;
     407}
     408
     409// --------------------------------------------------------------------------
     410//
     411// Return the expression describing the file-name for the file defined
     412// by i-th entry of the the given arrays. The file type identifier is
     413// defined by type. The source name is replaced by a wildcard and
     414// the extension is defined by the type as well.
     415//
     416TString MSequence::GetFileName(UInt_t i, const TArrayI &arr, const TArrayI &sub, FileType_t type) const
     417{
     418    const char *id="_";
     419    switch (type)
     420    {
     421    case kRawDat:
     422    case kRootDat:
     423        id = "D";
     424        break;
     425    case kRawPed:
     426    case kRootPed:
     427        id = "P";
     428        break;
     429    case kRawCal:
     430    case kRootCal:
     431        id = "C";
     432        break;
     433    case kRawAll:
     434    case kRootAll:
     435        id = "[PCD]";
     436        break;
     437    case kCalibrated:
     438        id = "Y";
     439        break;
     440    case kImages:
     441        id = "I";
     442        break;
     443    }
     444
     445    // ------------- Create file name --------------
     446    TString n = fNight.GetStringFmt("%Y%m%d_");
     447
     448    if (arr[i]>999999)
     449        n += "M1_";
     450
     451    // R. DeLosReyes and T. Bretz
     452    // Changes to read the DAQ numbering format. Changes takes place
     453    // between runs 35487 and 00035488 (2004_08_30)
     454    n += Form(arr[i]>35487 || fMonteCarlo ? "%08d" : "%05d", arr[i]);
     455
     456    if (arr[i]>999999 && sub.GetSize()>0)
     457        n += Form(".%05d", sub[i]);
     458
     459    n += "_";
     460    n += id;
     461    n += "_*";
     462
     463    if (arr[i]<1000000)
     464        n += "_E";
     465
     466    switch (type)
     467    {
     468    case kRawDat:
     469    case kRawPed:
     470    case kRawCal:
     471    case kRawAll:
     472        n += ".raw.?g?z?";
     473        break;
     474    default:
     475        n += ".root";
     476    }
     477
     478    return n;
     479}
     480
     481// --------------------------------------------------------------------------
     482//
     483// Add the entries from the arrays to the MDirIter
     484//
     485UInt_t MSequence::SetupRuns(MDirIter &iter, const TArrayI &arr, const TArrayI &sub, FileType_t type, const char *path) const
     486{
     487    TString d(path);
     488    if (d.IsNull())
     489        d = fDataPath;
     490
     491    const Bool_t def = d.IsNull();
     492
     493    d = GetPathName(d, type);
     494
     495    // For this particular case we assume that the files are added one by
     496    // one without wildcards.
     497    const Int_t n0 = iter.GetNumEntries();
     498
    258499    Int_t excluded = 0;
    259500    for (int i=0; i<arr.GetSize(); i++)
    260501    {
    261         if (IsExcluded(arr[i]))
     502        if (IsExcluded(arr[i], sub[i]))
    262503        {
    263504            excluded++;
     
    265506        }
    266507
    267         // R. DeLosReyes and T. Bretz
    268         // Changes to read the DAQ numbering format. Changes takes place
    269         // between runs 35487 and 00035488 (2004_08_30)
    270         const char *fmt = arr[i]>35487 || fMonteCarlo ? "%08d_%s_*_E" : "%05d_%s_*_E";
    271 
    272         TString n;
    273         const char *id="_";
    274         switch (type)
    275         {
    276         case kRawDat:
    277         case kRootDat:
    278             id = "D";
    279             break;
    280         case kRawPed:
    281         case kRootPed:
    282             id = "P";
    283             break;
    284         case kRawCal:
    285         case kRootCal:
    286             id = "C";
    287             break;
    288         case kRawAll:
    289         case kRootAll:
    290             id = "[PCD]";
    291             break;
    292         case kCalibrated:
    293             id = "Y";
    294             break;
    295         case kImages:
    296             id = "I";
    297             break;
    298         }
    299 
    300         // Create file name
    301         n =  fNight.GetStringFmt("%Y%m%d_");
    302         n += Form(fmt, arr[i], id);
    303 
    304         switch (type)
    305         {
    306         case kRawDat:
    307         case kRawPed:
    308         case kRawCal:
    309         case kRawAll:
    310             n += ".raw.?g?z?";
    311             break;
    312         default:
    313             n += ".root";
    314         }
     508        const TString n = GetFileName(i, arr, sub, type);
    315509
    316510        // Check existance and accessibility of file
     
    367561// --------------------------------------------------------------------------
    368562//
    369 // Read the file fname as setup file for the sequence.
    370 //
    371 //void MSequence::GetFileNames(TEnv &env, const TArrayI &arr)
    372 //{
    373     /*
    374     for (int i=0; i<arr.GetSize(); i++)
    375     {
    376         // Get run number
    377         const Int_t num = arr[i];
    378 
    379         // Check if name already set
    380         if (fFileNames.GetValue(num))
    381             continue;
    382 
    383         TString *str = new TString(env.GetValue(Form("%d", num), ""));
    384         fFileNames.Add(num, (Long_t)str);
    385         }
    386         */
    387 //}
    388 
    389 // --------------------------------------------------------------------------
    390 //
    391 // Get a file name corresponding to the run-number num, returns 0 if n/a
    392 //
    393 //const char *MSequence::GetFileName(UInt_t num)
    394 //{
    395 //    return 0;
    396     /*
    397     TString *str = (TString*)fFileNames.GetValue(num);
    398     return str ? str->Data() : 0;*/
    399 //}
    400 
     563// Get LightCondition from resource file and convert it to LIghtCondition_t
     564//
    401565MSequence::LightCondition_t MSequence::ReadLightCondition(TEnv &env, const char *prefix) const
    402566{
     
    472636    fComment      = GetEnvValue2(env, prefix, "Comment",    "");
    473637
    474     str = GetEnvValue2(env, prefix, "Runs", "");
    475     Split(str, fRuns);
    476     str = GetEnvValue2(env, prefix, "CalRuns", "");
    477     Split(str, fCalRuns);
    478     str = GetEnvValue2(env, prefix, "PedRuns", "");
    479     Split(str, fPedRuns);
    480     str = GetEnvValue2(env, prefix, "DatRuns", "");
    481     Split(str, fDatRuns);
    482     str = GetEnvValue2(env, prefix, "Exclude", "");
    483     Split(str, fExclRuns);
    484 
    485   //  GetFileNames(env, fRuns);
    486   //  GetFileNames(env, fCalRuns);
    487   //  GetFileNames(env, fPedRuns);
    488   //  GetFileNames(env, fDatRuns);
     638    Split(env, prefix, "Runs",    fRuns,     fRunsSub);
     639    Split(env, prefix, "CalRuns", fCalRuns,  fCalRunsSub);
     640    Split(env, prefix, "PedRuns", fPedRuns,  fPedRunsSub);
     641    Split(env, prefix, "DatRuns", fDatRuns,  fDatRunsSub);
     642    Split(env, prefix, "Exclude", fExclRuns, fExclRunsSub);
    489643
    490644    // Dummies:
     
    513667// --------------------------------------------------------------------------
    514668//
     669// Find a sequence of continous numbers in f starting at pos (looking
     670// only at n entries). The output is converted into sequences
     671// of X (single r) and X:Y (a sequence between x and r). The function
     672// returnes when position pos+n is reached
     673//
     674TString MSequence::GetNumSequence(Int_t pos, Int_t n, const TArrayI &f) const
     675{
     676    TString str;
     677
     678    Int_t p=pos;
     679    while (p<pos+n)
     680    {
     681        str += Form(" %d", f[p]);
     682
     683        if (p==pos+n-1)
     684            break;
     685
     686        int i=0;
     687        while (++i<n)
     688            if (f[p+i]-f[p]!=i)
     689                break;
     690
     691        if (i>1)
     692            str += Form(":%d", f[p+i-1]);
     693
     694        p += i;
     695    }
     696
     697    return str;
     698}
     699
     700// --------------------------------------------------------------------------
     701//
     702// Search for a sequence of continous numbers in r with f==0 starting at p.
     703// A new starting p is returned. The output is converted into sequences
     704// of X (single r) and X:Y (a sequence between x and r). The function
     705// returnes with the next f!=0.
     706//
     707TString MSequence::GetNumSequence(Int_t &p, const TArrayI &r, const TArrayI &f) const
     708{
     709    TString str;
     710
     711    while (p<r.GetSize() && f[p]==0)
     712    {
     713        // serach for the first entry which doesn't fit
     714        // or has a file number which is != 0
     715        int i=0;
     716        while (p+ ++i<r.GetSize())
     717            if (r[p+i]-r[p]!=i || f[p+i]!=0)
     718                break;
     719
     720        // None found (i-1==0)
     721        if (i-1==0)
     722            return str;
     723
     724        // The last run found in the sequence (e.g. 5.0) is followed
     725        // by an identical run number but file != 0 (e.g. 5.1)
     726        if (p+i<f.GetSize() && r[p+i]==r[p] && f[p+i]!=0)
     727            i--;
     728
     729        // Now we have to check again whether found no valid entry
     730        if (i-1==0)
     731            return str;
     732
     733        str += Form(" %d", r[p]);
     734        // p now points to the last entry which fits and
     735        // has a file number == 0
     736        p += i-1;
     737        // Only one      found (i-1==1)
     738        // More tahn one found (i-1>1)
     739        str += i-1==1 ? " " : ":";
     740        str += Form("%d", r[p]);
     741
     742        // One step forward
     743        p++;
     744    }
     745
     746    return str;
     747}
     748
     749// --------------------------------------------------------------------------
     750//
     751// Print the runs in a compressed wa. Returns the RunXXXXXXX string
     752// simplyfing the file setup
     753//
     754TString MSequence::PrintRuns(const char *pre, const char *name, const TArrayI &r, const TArrayI &f) const
     755{
     756    if (r.GetSize()==0)
     757        return "";
     758
     759    gLog << pre << name;
     760    if (f.GetSize()==0)
     761        const_cast<TArrayI&>(f).Set(r.GetSize());
     762
     763#ifdef DEBUG
     764    for (int i=0; i<r.GetSize(); i++)
     765        gLog << "  " << r[i] << "." << f[i];
     766    gLog << endl;
     767    return "";
     768#endif
     769
     770    TString str;
     771
     772    Int_t pos = 0;
     773    while (pos<r.GetSize())
     774    {
     775        TString rc = GetNumSequence(pos, r, f);
     776        if (!rc.IsNull())
     777        {
     778            gLog << rc;
     779            continue;
     780        }
     781
     782        Int_t n = GetSubArray(pos, r.GetSize(), (Int_t*)r.GetArray());
     783        // end reached
     784        if (n<0)
     785            break;
     786
     787        // This can happen if it is the last entry
     788        if (n==1)
     789        {
     790            gLog << " " << r[pos];
     791            if (f[pos]>0)
     792                gLog << "." << f[pos];
     793        }
     794        else
     795        {
     796            // Check for sequence
     797            Bool_t isseq = kTRUE;
     798            for (int i=1; i<n; i++)
     799                if (f[pos+i]-f[pos]!=i)
     800                    isseq=kFALSE;
     801
     802            if (isseq)
     803            {
     804                gLog << " " << r[pos] << ".";
     805                if (f[pos]!=0)
     806                    gLog << f[pos];
     807                gLog << ":" << f[pos+n-1];
     808            }
     809            else
     810            {
     811                gLog << " " << r[pos] << "+";
     812
     813                str += '\n';
     814                str += pre;
     815                str += Form("Run%08d:", r[pos]);
     816                str += GetNumSequence(pos, n, f);
     817            }
     818        }
     819
     820        pos += n;
     821    }
     822
     823    gLog << endl;
     824
     825    return str;
     826}
     827
     828// --------------------------------------------------------------------------
     829//
     830// Print the numbers in the classical way (one run after the other)
     831//
     832void MSequence::PrintRunsClassic(const char *pre, const char *name, const TArrayI &r) const
     833{
     834    gLog << pre << name;
     835    for (int i=0; i<r.GetSize(); i++)
     836        gLog << " " << r[i];
     837    gLog << endl;
     838}
     839
     840// --------------------------------------------------------------------------
     841//
    515842// Print the contents of the sequence
    516843//
    517844void MSequence::Print(Option_t *o) const
    518845{
    519     const TString pre = TString(o).Contains("prefixed") ? Form("Sequence%08d.", fSequence) : "";
     846    const TString opt(o);
     847
     848    const TString pre = opt.Contains("prefixed") ? Form("Sequence%08d.", fSequence) : "";
    520849
    521850    gLog << all;
     
    550879    gLog << pre << "TriggerTable:   " << fTriggerTable << endl;
    551880    gLog << pre << "HvSettings:     " << fHvSettings << endl << endl;
    552     if (fRuns.GetSize()>0)
    553     {
    554         gLog << pre << "Runs:";
    555         for (int i=0; i<fRuns.GetSize(); i++)
    556             gLog << " " << fRuns[i];
    557         gLog << endl;
    558     }
    559     if (fCalRuns.GetSize()>0)
    560     {
    561         gLog << pre << "CalRuns:";
    562         for (int i=0; i<fCalRuns.GetSize(); i++)
    563             gLog << " " << fCalRuns[i];
    564         gLog << endl;
    565     }
    566     if (fPedRuns.GetSize()>0)
    567     {
    568         gLog << pre << "PedRuns:";
    569         for (int i=0; i<fPedRuns.GetSize(); i++)
    570             gLog << " " << fPedRuns[i];
    571         gLog << endl;
    572     }
    573     if (fDatRuns.GetSize()>0)
    574     {
    575         gLog << pre << "DatRuns:";
    576         for (int i=0; i<fDatRuns.GetSize(); i++)
    577             gLog << " " << fDatRuns[i];
    578         gLog << endl;
    579     }
    580     if (fExclRuns.GetSize()>0)
    581     {
    582         gLog << pre << "Exclude:";
    583         for (int i=0; i<fExclRuns.GetSize(); i++)
    584             gLog << " " << fExclRuns[i];
    585         gLog << endl;
    586     }
     881
     882    TString str;
     883    if (!HasSubRuns() && opt.Contains("classic"))
     884    {
     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);
     890    }
     891    else
     892    {
     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);
     898    }
     899
    587900    if (!fDataPath.IsNull())
    588901        gLog << endl << pre << "DataPath: " << fDataPath << endl;
     902
     903    if (!str.IsNull())
     904        gLog << str << endl;
    589905
    590906    gLog << endl << pre << "Comment: " << fComment << endl;
     
    604920UInt_t MSequence::SetupPedRuns(MDirIter &iter, const char *path, Bool_t raw) const
    605921{
    606     return SetupRuns(iter, fPedRuns, raw?kRawPed:kRootPed, path);
     922    return SetupRuns(iter, fPedRuns, fPedRunsSub, raw?kRawPed:kRootPed, path);
    607923}
    608924
     
    620936UInt_t MSequence::SetupDatRuns(MDirIter &iter, const char *path, Bool_t raw) const
    621937{
    622     return SetupRuns(iter, fDatRuns, raw?kRawDat:kRootDat, path);
     938    return SetupRuns(iter, fDatRuns, fDatRunsSub, raw?kRawDat:kRootDat, path);
    623939}
    624940
     
    636952UInt_t MSequence::SetupAllRuns(MDirIter &iter, const char *path, Bool_t raw) const
    637953{
    638     return SetupRuns(iter, fRuns, raw?kRawAll:kRootAll, path);
     954    return SetupRuns(iter, fRuns, fRunsSub, raw?kRawAll:kRootAll, path);
    639955}
    640956
     
    652968UInt_t MSequence::SetupCalRuns(MDirIter &iter, const char *path, Bool_t raw) const
    653969{
    654     return SetupRuns(iter, fCalRuns, raw?kRawCal:kRootCal, path);
     970    return SetupRuns(iter, fCalRuns, fCalRunsSub, raw?kRawCal:kRootCal, path);
    655971}
    656972
     
    668984UInt_t MSequence::SetupDatRuns(MDirIter &iter, FileType_t type, const char *path) const
    669985{
    670     return SetupRuns(iter, fDatRuns, type, path);
    671 }
    672 
    673 // --------------------------------------------------------------------------
    674 //
    675 // If you want to add runs manually, use this function.
    676 //
    677 UInt_t MSequence::AddRuns(UInt_t first, UInt_t last, TArrayI *runs)
    678 {
    679     if (last<first)
    680     {
    681         *fLog << warn << "MSequence::AddRuns - WARNING: Last runnumber " << last;
    682         *fLog << " smaller than first " << first << "... ignored." << endl;
    683         return 0;
    684     }
    685     if (!IsValid())
    686     {
    687         *fLog << inf << "Setting Sequence number to #" << first << endl;
    688         fSequence = first;
    689     }
    690 
    691     const UInt_t nall = fRuns.GetSize();
    692     const UInt_t nrun = runs ? runs->GetSize() : 0;
    693     const UInt_t add  = last-first+1;
    694 
    695     fRuns.Set(nall+add);
    696     if (runs)
    697         runs->Set(nrun+add);
    698 
    699     for (UInt_t i=0; i<add; i++)
    700     {
    701         fRuns[nall+i] = first+i;
    702         if (runs)
    703             (*runs)[nrun+i] = first+i;
    704     }
    705     return add;
    706 }
    707 
    708 Bool_t MSequence::IsContained(const TArrayI &arr, UInt_t run) const
    709 {
    710     for (int i=0; i<arr.GetSize(); i++)
    711         if (run==(UInt_t)arr[i])
    712             return kTRUE;
     986    return SetupRuns(iter, fDatRuns, fDatRunsSub, type, path);
     987}
     988
     989// --------------------------------------------------------------------------
     990//
     991// check if the run/file is contained in the arrays.
     992//
     993Bool_t MSequence::IsContained(const TArrayI &arr, const TArrayI &sub, UInt_t run, UInt_t file) const
     994{
     995    // Backward compatibilty
     996    if (sub.GetSize()==0)
     997    {
     998        for (int i=0; i<arr.GetSize(); i++)
     999            if (run==(UInt_t)arr[i])
     1000                return kTRUE;
     1001    }
     1002    else
     1003    {
     1004        for (int i=0; i<arr.GetSize(); i++)
     1005            if (run==(UInt_t)arr[i] && file==(UInt_t)sub[i])
     1006                return kTRUE;
     1007    }
    7131008    return kFALSE;
    7141009}
    7151010
    716 /*
    717 // --------------------------------------------------------------------------
    718 //
    719 // Check if num is found in arr. If it is found remove it. Copy all
    720 // following entries one back and decrease the array size by 1.
    721 //
    722 void MSequence::ExcludeRun(TArrayI &arr, UInt_t num)
    723 {
    724     UInt_t *ptr = (UInt_t*)arr.GetArray();
    725 
    726     Int_t i = 0;
    727     for (i=0; i<arr.GetSize(); i++)
    728         if (ptr[i]==num)
    729             break;
    730 
    731     if (i==arr.GetSize())
    732         return;
    733 
    734     for (; i<arr.GetSize()-1; i++)
    735         ptr[i] = ptr[i+1];
    736 
    737     arr.Set(arr.GetSize()-1);
    738 }
    739 */
     1011// --------------------------------------------------------------------------
     1012//
     1013// Add a file (run/file) to the arrays defined by type (P, C, D, X)
     1014//
     1015void MSequence::AddFile(UInt_t run, UInt_t file, char type)
     1016{
     1017    TArrayI *r=0, *f=0;
     1018    switch (type)
     1019    {
     1020    case 'P':
     1021        r = &fPedRuns;
     1022        f = &fPedRunsSub;
     1023        break;
     1024    case 'D':
     1025        r = &fDatRuns;
     1026        f = &fDatRunsSub;
     1027        break;
     1028    case 'C':
     1029        r = &fCalRuns;
     1030        f = &fCalRunsSub;
     1031        break;
     1032    default:
     1033        r = &fRuns;
     1034        f = &fRunsSub;
     1035        break;
     1036    }
     1037
     1038    AddEntry(run, file, *r, *f);
     1039
     1040    MJob::SortArray(fExclRuns);
     1041}
    7401042
    7411043// --------------------------------------------------------------------------
     
    7431045// Exclude this run (i.e. add it to fExclRuns)
    7441046//
    745 void MSequence::ExcludeRun(UInt_t num)
    746 {
    747     /*
    748      ExcludeRun(fRuns,    num);
    749      ExcludeRun(fCalRuns, num);
    750      ExcludeRun(fPedRuns, num);
    751      ExcludeRun(fDatRuns, num);
    752      */
    753 
    754     if (IsExcluded(num))
    755         return;
    756 
    757     // set new entry
    758     const Int_t n = fExclRuns.GetSize();
    759     fExclRuns.Set(n+1);
    760     fExclRuns[n] = num;
     1047void MSequence::ExcludeFile(UInt_t run, UInt_t file/*, Bool_t force*/)
     1048{
     1049//    if (force && IsExcluded(run, file))
     1050//        return;
     1051
     1052    AddEntry(run, file, fExclRuns, fExclRunsSub);
    7611053
    7621054    MJob::SortArray(fExclRuns);
     
    7691061void MSequence::ExcludeRuns(TString runs)
    7701062{
    771     TArrayI data;
    772     Split(runs, data);
    773 
     1063    // FIXME: Decode stream!!!
     1064
     1065    TArrayI data, sub;
     1066    Split(runs, data, sub);
    7741067    for (int i=0; i<data.GetSize(); i++)
    775         ExcludeRun(data[i]);
    776 }
    777 
     1068        ExcludeFile(data[i], sub[i]);
     1069}
     1070
     1071// --------------------------------------------------------------------------
     1072//
     1073// Return the excluded runs (to be more precise:the excluded files)
     1074// in a string
     1075//
    7781076const TString MSequence::GetExcludedRuns() const
    7791077{
     
    7821080    {
    7831081        rc += fExclRuns[i];
     1082        if (fExclRunsSub.GetSize()>0)
     1083        {
     1084            rc += ".";
     1085            rc += fExclRunsSub[i];
     1086        }
    7841087        rc += " ";
    7851088    }
     
    8281131}
    8291132
     1133// --------------------------------------------------------------------------
     1134//
     1135// Search starting at position p in array arr and return the number
     1136// of elemets which are identical to the starting entry (the starting entry
     1137// is also counted)
     1138//
     1139Int_t MSequence::GetSubArray(Int_t p, Int_t n, Int_t *arr)
     1140{
     1141    Int_t *ptr0 = arr+p;
     1142
     1143    Int_t *ptr = ptr0;
     1144    Int_t *end = arr+n;
     1145
     1146    while (ptr<end && *ptr==*ptr0)
     1147        ptr++;
     1148
     1149    return ptr-ptr0;
     1150}
     1151
     1152// --------------------------------------------------------------------------
     1153//
     1154// Sort the array arr2 starting at position p for following entries
     1155// for which arr1 is equal. If not at least two entries are found which
     1156// can be sorted return -1.
     1157//
     1158// The absolute index of the next entry in arr1 is returned.
     1159//
     1160Int_t MSequence::SortArraySub(Int_t p, Int_t n, Int_t *arr1, Int_t *arr2)
     1161{
     1162    Int_t *ptr2 = arr2+p;
     1163
     1164    Int_t cnt = GetSubArray(p, n, arr1);
     1165    if (cnt==0)
     1166        return -1;
     1167
     1168    TArrayI srt(cnt, ptr2);
     1169    MJob::SortArray(srt);
     1170
     1171    memcpy(ptr2, srt.GetArray(), srt.GetSize()*sizeof(Int_t));
     1172
     1173    return p+srt.GetSize();
     1174}
     1175
     1176void MSequence::SortArrays(TArrayI &arr1, TArrayI &arr2)
     1177{
     1178    if (arr1.GetSize()!=arr2.GetSize())
     1179        return;
     1180
     1181    TArrayI idx(arr1.GetSize());
     1182
     1183    TArrayI srt1(arr1);
     1184    TArrayI srt2(arr2);
     1185
     1186    TMath::Sort(arr1.GetSize(), srt1.GetArray(), idx.GetArray(), kFALSE);
     1187
     1188    for (int i=0; i<arr1.GetSize(); i++)
     1189    {
     1190        arr1[i] = srt1[idx[i]];
     1191        arr2[i] = srt2[idx[i]];
     1192    }
     1193
     1194    Int_t p = 0;
     1195    while (p>=0)
     1196        p = SortArraySub(p, arr1.GetSize(), arr1.GetArray(), arr2.GetArray());
     1197}
  • trunk/MagicSoft/Mars/mjobs/MSequence.h

    r8780 r8969  
    44#ifndef ROOT_TArrayI
    55#include <TArrayI.h>
    6 #endif
    7 
    8 #ifndef ROOT_TExMap
    9 #include <TExMap.h>
    106#endif
    117
     
    4844
    4945    TArrayI fRuns;
     46    TArrayI fRunsSub;
     47
    5048    TArrayI fCalRuns;
     49    TArrayI fCalRunsSub;
     50
    5151    TArrayI fPedRuns;
     52    TArrayI fPedRunsSub;
     53
    5254    TArrayI fDatRuns;
     55    TArrayI fDatRunsSub;
    5356
    5457    TArrayI fExclRuns;
     58    TArrayI fExclRunsSub;
    5559
    5660    Bool_t fMonteCarlo;
    5761
    58     //TExMap fFileNames;
     62    // Helper for interpretation
     63    void    AddEntry(Int_t run, Int_t file, TArrayI &data, TArrayI &sub) const;
     64    void    EvalEntry(const TEnv *env, const TString &prefix, const TString &num, TArrayI &data, TArrayI &sub) const;
    5965
    60     void Split(TString &runs, TArrayI &data) const;
    61     //void GetFileNames(TEnv &env, const TArrayI &arr);
     66    void    Split(TString &runs, TArrayI &data, TArrayI &sub, const TEnv *env=0, const TString prefix="") const;
     67    void    Split(const TEnv &env, const TString &prefix, const char *name, TArrayI &data, TArrayI &sub) const;
    6268
    6369    LightCondition_t ReadLightCondition(TEnv &env, const char *prefix) const;
    6470
    65     const char *GetFileName(UInt_t num);
     71    // Helper for file setup
     72    TString GetPathName(TString d, FileType_t type) const;
     73    TString GetFileName(UInt_t num, const TArrayI &arr, const TArrayI &sub, FileType_t type) const;
     74    UInt_t  SetupRuns(MDirIter &iter, const TArrayI &arr, const TArrayI &file, FileType_t type, const char *path=0) const;
    6675
    67     //UInt_t SetupRuns(MDirIter &iter, const TArrayI &arr, const char *path, char *id, Bool_t raw=kFALSE) const;
    68     UInt_t SetupRuns(MDirIter &iter, const TArrayI &arr, FileType_t type, const char *path=0) const;
    69     UInt_t AddRuns(UInt_t first, UInt_t last, TArrayI *runs);
    70     void   ExcludeRun(TArrayI &arr, UInt_t num);
    71     Bool_t IsContained(const TArrayI &arr, UInt_t num) const;
     76    // Helper for Print()
     77    TString GetNumSequence(Int_t pos, Int_t n, const TArrayI &f) const;
     78    TString GetNumSequence(Int_t &pos, const TArrayI &n, const TArrayI &f) const;
     79
     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;
     82
     83    // General helper
     84    Bool_t  HasSubRuns() const { return fRunsSub.GetSize()!=0 || fDatRunsSub.GetSize()!=0 || fPedRunsSub.GetSize()!=0 || fCalRunsSub.GetSize()!=0 || fExclRunsSub.GetSize()!=0; }
     85    Bool_t  IsContained(const TArrayI &arr, const TArrayI &sub, UInt_t num, UInt_t file) const;
     86
     87    // Some helpers to handle the arrays
     88    static Int_t SortArraySub(Int_t p, Int_t n, Int_t *arr1, Int_t *arr2);
     89    static void  SortArrays(TArrayI &arr1, TArrayI &arr2);
     90    static Int_t GetSubArray(Int_t p, Int_t n, Int_t *arr1);
    7291
    7392public:
     
    81100        fRuns(s.fRuns), fCalRuns(s.fCalRuns), fPedRuns(s.fPedRuns),
    82101        fDatRuns(s.fDatRuns), fMonteCarlo(s.fMonteCarlo) { }
    83     ~MSequence();
    84102
    85103    // TObject
    86104    void Print(Option_t *o) const;
    87     void Print() const { Print(); } //*MENU*
     105    void Print() const { Print(""); } //*MENU*
    88106
    89107    const char *GetName() const;
     
    93111    Bool_t IsValid() const { return fSequence!=(UInt_t)-1; }
    94112    Bool_t IsMonteCarlo() const { return fMonteCarlo; }
    95     Bool_t IsExcluded(UInt_t run) const { return IsContained(fExclRuns, run); }
    96     Bool_t IsContained(UInt_t run) const { return IsContained(fCalRuns, run) || IsContained(fPedRuns, run) || IsContained(fDatRuns, run); }
     113    Bool_t IsExcluded(UInt_t run, UInt_t file) const { return IsContained(fExclRuns, fExclRunsSub, run, file); }
     114    Bool_t IsContained(UInt_t run, UInt_t file) const { return IsContained(fCalRuns, fCalRunsSub, run, file) || IsContained(fPedRuns, fPedRunsSub, run, file) || IsContained(fDatRuns, fDatRunsSub, run, file); }
     115
     116    // Setter
     117    void SetNight(const char*night);
     118
     119    void AddRun(UInt_t run, char type='*') { AddFile(run, 0, type); }
     120    void AddRuns(UInt_t run1, UInt_t run2, char type='*') { for (UInt_t i=run1; i<=run2; i++) AddFile(i, 0, type); }
     121    void AddFile(UInt_t run, UInt_t file, char type='*');
     122    void AddFiles(UInt_t run, UInt_t f1, UInt_t f2, char type='*') { for (UInt_t i=f1; i<=f2; i++) AddFile(run, i, type); }
     123
     124    void ExcludeFile(UInt_t num, UInt_t file=0);
     125    void ExcludeRuns(TString runs);
    97126
    98127    void SetMonteCarlo(Bool_t ismc=kTRUE) { fMonteCarlo=ismc; }
    99128
     129    // Getter
     130    UInt_t GetNumExclRuns() const { return fExclRuns.GetSize(); }
     131
     132    UInt_t GetSequence() const { return fSequence; }
     133    UInt_t GetLastRun() const  { return fLastRun; }
     134    UInt_t GetPeriod() const   { return fPeriod; }
     135    Bool_t HasMoon() const { return fLightCondition==kMoon; }
     136
     137    LightCondition_t GetLightCondition() const { return fLightCondition; }
     138
     139    const MTime   &GetStart() const { return fStart; }
     140    const MTime   &GetNight() const { return fNight; }
     141    const TString &GetSource() const { return fSource; }
     142
     143    const TString GetExcludedRuns() const;
     144
     145    // Filesystem interface
    100146    UInt_t SetupPedRuns(MDirIter &iter, const char *path=0, Bool_t raw=kFALSE) const;
    101147    UInt_t SetupDatRuns(MDirIter &iter, const char *path=0, Bool_t raw=kFALSE) const;
     
    103149    UInt_t SetupCalRuns(MDirIter &iter, const char *path=0, Bool_t raw=kFALSE) const;
    104150    UInt_t SetupDatRuns(MDirIter &iter, FileType_t type, const char *path=0) const;
    105  /*
    106     UInt_t SetupPedRuns(MDirIter &iter, FileType_t type, const char *path=0);
    107     UInt_t SetupDatRuns(MDirIter &iter, FileType_t type, const char *path=0);
    108     UInt_t SetupAllRuns(MDirIter &iter, FileType_t type, const char *path=0);
    109     UInt_t SetupCalRuns(MDirIter &iter, FileType_t type, const char *path=0);
    110    */
    111151
    112     // Getter
    113 //    UInt_t GetNumAllRuns() const { return fRuns.GetSize(); }
    114 //    UInt_t GetNumDatRuns() const { return fDatRuns.GetSize(); }
    115 //    UInt_t GetNumPedRuns() const { return fPedRuns.GetSize(); }
    116 //    UInt_t GetNumCalRuns() const { return fCalRuns.GetSize(); }
    117     UInt_t GetNumExclRuns() const { return fExclRuns.GetSize(); }
    118 
    119     UInt_t GetSequence() const { return fSequence; }
    120     UInt_t GetLastRun() const  { return fLastRun; }
    121     UInt_t GetPeriod() const   { return fPeriod; }
    122     LightCondition_t GetLightCondition() const { return fLightCondition; }
    123     Bool_t HasMoon() const { return fLightCondition==kMoon; }
    124 
    125     const UInt_t GetFirstRun() const { return fRuns[0]; }
    126     const UInt_t GetFirstCalRun() const { return fCalRuns[0]; }
    127     const UInt_t GetLastCalRun() const { return fCalRuns[fCalRuns.GetSize()-1]; }
    128 //    const TArrayI &GetDatRuns() const { return fDatRuns; }
    129 //    const TArrayI &GetPedRuns() const { return fPedRuns; }
    130 //    const TArrayI &GetCalRuns() const { return fCalRuns; }
    131     const TArrayI &GetExclRuns() const { return fExclRuns; }
    132 
    133     const MTime &GetStart() const { return fStart; }
    134     const MTime &GetNight() const { return fNight; }
    135     const TString &GetSource() const { return fSource; }
     152    // Filesystem getter
     153    const TString &GetFileName() const { return fFileName; }
     154    const TString &GetDataPath() const { return fDataPath; }
    136155
    137156    const TString GetStandardPath() const { return fMonteCarlo?"/magic/montecarlo/":"/magic/data/"; }
    138157
    139     const TString &GetFileName() const { return fFileName; }
    140     const TString &GetDataPath() const { return fDataPath; }
    141 
    142     const TString GetExcludedRuns() const;
    143 
    144     // Setter
    145     void SetNight(const char*night);
    146 
    147     UInt_t AddRuns(UInt_t first, UInt_t last)    { return MSequence::AddRuns(first, last, 0); }
    148     UInt_t AddCalRuns(UInt_t first, UInt_t last) { return MSequence::AddRuns(first, last, &fCalRuns); }
    149     UInt_t AddPedRuns(UInt_t first, UInt_t last) { return MSequence::AddRuns(first, last, &fPedRuns); }
    150     UInt_t AddDatRuns(UInt_t first, UInt_t last) { return MSequence::AddRuns(first, last, &fDatRuns); }
    151 
    152     UInt_t AddRuns(UInt_t num)    { return AddRuns(num, num); }
    153     UInt_t AddCalRuns(UInt_t num) { return AddCalRuns(num, num); }
    154     UInt_t AddPedRuns(UInt_t num) { return AddPedRuns(num, num); }
    155     UInt_t AddDatRuns(UInt_t num) { return AddDatRuns(num, num); }
    156 
    157     void ExcludeRun(UInt_t num);
    158     void ExcludeRuns(TString runs);
    159 
    160158    static Bool_t InflatePath(TString &seq, Bool_t ismc=kFALSE);
    161159
    162     ClassDef(MSequence, 4)
     160    ClassDef(MSequence, 5) // Describes a sequences, reads and writes sequence files
    163161};
    164162
Note: See TracChangeset for help on using the changeset viewer.