Ignore:
Timestamp:
03/01/05 19:08:59 (20 years ago)
Author:
marcos
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mtemp/mucm/classes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mtemp/mucm/classes/MDataSetIter.cc

    r4693 r6691  
    6262
    6363#include "MRunIter.h"
     64#include "MSequence.h"
    6465
    6566#include "TObjArray.h"
    6667
    6768#include <TSystem.h>
    68 
     69#include <fstream>
    6970
    7071ClassImp(MDataSetIter);
     
    7980//
    8081MDataSetIter::MDataSetIter()
    81     :  fLastProcessedRun(0), fLog(&gLog), fDefCalRun(0)
     82    : fInitialRun(-1), fEndRun(-1), fLastProcessedDataRun(0), fLastDataRun(0), fDefCalRun(0), fDefCalRunPath(""), fLog(&gLog)
    8283{
    8384    fPedRuns = new MRunIter;
    8485    fCalRuns = new MRunIter;
    8586    fDataRuns = new MRunIter;
    86 }
    87 
     87    fSequence = new MSequence;
     88}
     89
     90
     91// ---------------------------------------------------------------------------
     92//
     93//  Add all the files inside a given directory to the fFileList.
     94//
     95void MDataSetIter::AddToFileList(MDirIter& dir)
     96{
     97    TString name;
     98   
     99    while (!(name=dir.Next()).IsNull())
     100        fFileList.Add((TObject*)(new TNamed((const char*)name, "")));
     101   
     102
     103    //
     104    // Sort File List by name
     105    //
     106    fFileList.Sort();
     107
     108    //
     109    // Find last Data runnumber of the filelist to be processed
     110    //
     111    FindLastDataRun();
     112}
     113
     114
     115// -------------------------------------------------------------------------
     116//
     117// Find last Data runnumber of the filelist to be processed
     118//
     119void MDataSetIter::FindLastDataRun()
     120{
     121
     122    if(fFileList.GetLast()==-1)
     123        return;
     124
     125
     126    TIter next(&fFileList,kIterBackward);
     127    TNamed* n;
     128
     129    while ( (n=(TNamed*)next()) )
     130    { 
     131        TString name, path, date, src;
     132        Int_t run;
     133        char type;
     134       
     135        ScanFileName(n->GetName(), name, path, date, src, &run, &type);
     136
     137        if(type!='D')
     138            continue;
     139
     140       
     141        if(fEndRun==-1)
     142        {
     143            if(run>fLastDataRun)
     144                fLastDataRun = run;
     145           
     146            break;
     147        }
     148        else
     149        {
     150            if(run<=fEndRun)
     151            {
     152                if(run>fLastDataRun)
     153                    fLastDataRun = run;
     154               
     155                break;
     156            }
     157           
     158        }
     159    }
     160
     161}
     162
     163
     164// ----------------------------------------------------------------------------
     165//
     166//  Overload MDirIter::AddDirectory
     167//
     168//  Each time a new directory is added, all the files inside that directory
     169//  are added to the fFileList.
     170//
     171//  Returns the number of directories added
     172//
     173Int_t MDataSetIter::AddDirectory(const char *dir, const char *filter, Int_t recursive)
     174{
     175    const Int_t rc = MDirIter::AddDirectory(dir, filter, recursive);
     176    if (rc==0)
     177        return 0;
     178 
     179    //
     180    // Add the files inside that directory to the fFileList. In order to
     181    // add only the files inside the new directory added, we create
     182    // and MDirIter with only that directory. Otherwise, it we call
     183    // directly this.Next() inside FillFileList the new files and the
     184    // previously existing one will be again adde to the fFileList.
     185    //
     186    MDirIter next(dir,filter,recursive);
     187    AddToFileList(next);
     188
     189    next.Print() ;
     190   
     191    return kTRUE;
     192}
     193
     194
     195// ----------------------------------------------------------------------------
     196//
     197//  Add a source name to the list of selected source names.
     198//
     199void MDataSetIter::SelectSourceName(const char *src)
     200{
     201    fSrcList.Add((TObject*)(new TNamed(src, src))); 
     202}
     203   
    88204
    89205// ----------------------------------------------------------------------------
     
    112228        return kFALSE;
    113229    }
     230
     231    //
     232    // Skip Green and Blue calib
     233    //
     234    if(src.Contains("Blue",TString::kIgnoreCase) || src.Contains("Green",TString::kIgnoreCase))
     235    {
     236        *fLog << warn << "Skipping Blue/Green run [" << src << "]" << endl;
     237        return kFALSE;
     238    }
     239
     240
    114241
    115242    //
     
    124251    if(src.Contains("-"))
    125252    {
    126         *fLog << warn << "For source [" << src << "] ignoring suffix ["
    127               << src( src.First("-")+1, src.Length() ) << "]" << endl;
     253        //*fLog << warn << "For source [" << src << "] ignoring suffix ["
     254        //     << src( src.First("-")+1, src.Length() ) << "]" << endl;
    128255        src.Remove(src.First("-"));
    129256    }
     
    141268        ValidSrc = n->GetName();
    142269       
    143         //if (src==ValidSrc)       // For dealing with new calib files as Mrk421blue5
    144         if (src.Contains(ValidSrc))
     270        if (src==ValidSrc)       // For dealing with new calib files as Mrk421blue5
     271        //if (src.Contains(ValidSrc))
    145272            return kTRUE;
    146273    }
     
    151278}
    152279
     280// -------------------------------------------------------------------
     281//     
     282// Compare two source names
     283//
     284Int_t MDataSetIter::CompareSourceNames(TString& src1, TString& src2)
     285{
     286    if(src1.Contains("-"))
     287    {
     288        //*fLog << warn << "For source [" << src << "] ignoring suffix ["
     289        //     << src( src.First("-")+1, src.Length() ) << "]" << endl;
     290        src1.Remove(src1.First("-"));
     291    }
     292
     293
     294    if(src2.Contains("-"))
     295    {
     296        //*fLog << warn << "For source [" << src << "] ignoring suffix ["
     297        //     << src( src.First("-")+1, src.Length() ) << "]" << endl;
     298        src2.Remove(src2.First("-"));
     299    }
     300
     301    return (src1.CompareTo(src2)==0) ? kTRUE : kFALSE;
     302}
    153303
    154304// ---------------------------------------------------------------------------
     
    163313    path = file(0,slash+1);
    164314    name = file(slash+1,file.Length());
    165    
     315 
     316    TString tmp = name;
     317   
     318
    166319    // Get date
    167     date = name(0,8);
    168    
     320    date = tmp(0,tmp.First('_'));
     321    tmp = tmp.Remove(0,tmp.First('_')+1);
     322
     323 
    169324    // Get run number
    170     const TString runstr = name(9,5);
     325    const TString runstr = tmp(0,tmp.First('_'));
    171326    *run = atoi(runstr.Data());
    172    
     327    tmp = tmp.Remove(0,tmp.First('_')+1);
     328
     329
    173330    // Get run type
    174     *type = name[15];
     331    *type = tmp[0];
     332    tmp = tmp.Remove(0,tmp.First('_')+1);
     333 
    175334
    176335    // Get source name
    177     src = name(17,name.Last('_')-17);
    178 }
    179 
    180 
    181 // ---------------------------------------------------------------------------
    182 //
    183 //  Add all the files inside a given directory to the fFileList.
    184 //
    185 void MDataSetIter::AddToFileList(MDirIter& dir)
    186 {
    187    
    188     TString name;
    189     while (!(name=dir.Next()).IsNull())
    190     {
    191         fFileList.Add((TObject*)(new TNamed((const char*)name, ""))); 
    192     }
    193 
    194     //
    195     // Sort File List by name
    196     //
    197     fFileList.Sort();
    198 }
    199 
    200 
    201 // ----------------------------------------------------------------------------
    202 //
    203 //  Overload MDirIter::AddDirectory
    204 //
    205 //  Each time a new directory is added, all the files inside that directory
    206 //  are added to the fFileList.
    207 //
    208 //  Returns the number of directories added
    209 //
    210 Int_t MDataSetIter::AddDirectory(const char *dir, const char *filter, Int_t recursive)
    211 {
    212     const Int_t rc = MDirIter::AddDirectory(dir, filter, recursive);
    213     if (rc==0)
    214         return 0;
    215  
    216     //
    217     // Add the files inside that directory to the fFileList. In order to
    218     // add only the files inside the new directory added, we create
    219     // and MDirIter with only that directory. Otherwise, it we call
    220     // directly this.Next() inside FillFileList the new files and the
    221     // previously existing one will be again adde to the fFileList.
    222     //
    223     MDirIter next(dir,filter,recursive);
    224     AddToFileList(next);
    225    
    226     return kTRUE;
    227 }
    228 
    229 
    230 // ----------------------------------------------------------------------------
    231 //
    232 //  Add a source name to the list of selected source names.
    233 //
    234 void MDataSetIter::SelectSourceName(const char *src)
    235 {
    236     fSrcList.Add((TObject*)(new TNamed(src, src))); 
    237 }
    238    
     336    //src = tmp(0,tmp.First('_'));
     337    //
     338    // To deal with  4C15 with filemames doesn't include '_E' (18-11-2004)
     339    //
     340    if (tmp.Contains('_'))
     341        src = tmp(0,tmp.First('_'));
     342    else       
     343        src = tmp(0,tmp.First('.'));
     344}
     345
    239346
    240347// ----------------------------------------------------------------------------
     
    248355    {
    249356        *fLog << warn << "Doesn't exist previous set." << endl;
    250        return kFALSE;
     357        return kFALSE;
    251358    }
    252359   
     
    264371   
    265372    ScanFileName(oldRuns.Next(), name, path, date, src, &run, &type);
    266    
    267    //   if( src != fSrcName)
    268 //      {
    269 //      *fLog << err << "Previous runs were for a diffrent source...exit." << endl;
    270 //      return kFALSE;
    271 //      }
    272 
    273         //
    274         // For dealing with calibration color we just ask than the srcname
    275         // contains the FirstSrcName
    276         //
    277         if( !src.Contains(fSrcName) )
    278         {
    279             *fLog << warn << "Previous runs were for a diffrent source [" << src << "] vs [" << fSrcName << "] ...exit." << endl;
    280             return kFALSE;
    281         }
    282 
     373 
     374   
     375    if ( !CompareSourceNames(src,fSrcName) )
     376    //
     377    // For dealing with calibration color we just ask than the srcname
     378    // contains the FirstSrcName
     379    //
     380    //if( !src.Contains(fSrcName) )
     381    {
     382        *fLog << warn << "Previous runs were for a diffrent source [" << src << "] vs [" << fSrcName << "] ...exit." << endl;
     383        return kFALSE;
     384    }
     385   
    283386   
    284387    return kTRUE;
     
    300403//
    301404// Process all the runs which runnumber is later to the last processed run
    302 //  (the first time this function is call fLastProcessedRun is 0, so it start
     405//  (the first time this function is call fLastProcessedDataRun is 0, so it start
    303406//  processing from the beginning)
    304407//
     
    310413   
    311414    if(fFileList.GetLast()==-1)
     415    {
     416        *fLog << warn << "File list empty." << endl;
    312417        return kFALSE;   
     418    }
    313419
    314420
     
    320426    MRunIter* oldCalRuns = 0;
    321427   
    322 
    323428    if(fDataRuns)
    324429      oldDataRuns = (MRunIter*)fDataRuns->Clone();
     
    340445    // the directory. Then Return kFALSE
    341446    //
    342     if ( fDataRuns->GetNumRuns()==0 ) 
     447    if ( fDataRuns->GetNumRuns()==0 )
    343448    {
    344449        *fLog << warn << "No more Data runs left." << endl;
     
    470575    // Print the runs of this data set
    471576    //
    472     Print();
     577    //Print();
    473578
    474579
     
    478583   
    479584
     585    return kTRUE;
     586}
     587
     588
     589// -----------------------------------------------------------------------
     590//
     591//  Write an ASCII file with the sequence info.
     592//  The name of the file is 'sequenceRunNum.txt' where
     593//  RunNum is the run number of the first data file to analyse. We use
     594//  the data runnumber instead of calib run because several sequences can
     595//  have the same calib run (just the P can change)
     596//
     597Int_t MDataSetIter::WriteSequence()
     598{
     599    //
     600    // Sequence
     601    //
     602    //fSequence->SetupDatRuns(fDataRuns, fPathData, "D");
     603    //fSequence->SetupPedRuns(fPedRuns, fPathData, "P");
     604    //fSequence->SetupCalRuns(fCalRuns, fPathData, "C");
     605   
     606    //fSequence->Print();
     607
     608    TString sped =  fPedRuns->GetRunsAsFileName();
     609    TString scal =  fCalRuns->GetRunsAsFileName();
     610    TString sdata = fDataRuns->GetRunsAsFileName();
     611
     612    sped.ReplaceAll("_"," ");
     613    scal.ReplaceAll("_"," ");
     614    sdata.ReplaceAll("_"," ");
     615
     616   
     617    Int_t seqnum;
     618    //sscanf(scal.Data(),"%d",&seqnum);
     619    sscanf(sdata.Data(),"%d",&seqnum);
     620
     621    TString fname = Form("sequence_%s_%d.txt",fDate.Data(), seqnum);
     622    ofstream out(fname);
     623
     624
     625    TString date = fDate;
     626    date.Insert(4,"-");
     627    date.Insert(7,"-");
     628
     629
     630    //out << "# Sequence number (identifier)" <<endl;
     631    out << "Sequence: " << seqnum << endl;
     632    //out << endl;
     633    //out << "# date of sunrise of the observation night" << endl;
     634    //out << "Night: 2004-09-21" << endl;
     635    out << "Night: " << date << endl;
     636    out << endl;
     637    //out << "# Source name of all runs of sequence" << endl;
     638    //out << "Source: " << fSrcName << endl;
     639    //out << endl;
     640    //out << "# List of all runs of this sequence" << endl;
     641    //out << "Runs: " << scal << " " << sped << " "<< sdata << endl; 
     642    //out << endl;
     643    //out << "# List of all calibration runs of this sequence" << endl;
     644    out << "CalRuns: " << scal << endl;
     645    //out << "# List of all pedestal runs of this sequence" << endl;
     646    out << "PedRuns: " << sped << endl;
     647    //out << "# List of all data runs of this sequence" << endl;
     648    out << "DatRuns: "<<  sdata << endl;
     649    out.close();
     650
     651   
    480652    return kTRUE;
    481653}
     
    520692    fCalRuns = new MRunIter();
    521693
    522 
    523     //
    524     TString FirstSrcName = "";       // SrcName of the first run found
     694    //
     695    // Init
     696    //
     697    TString FirstSrcName = "";     // SrcName of the first run found
    525698    Bool_t RunFound     = kFALSE;
    526699    Bool_t DataRunFound = kFALSE;
    527700    Bool_t CalRunFound  = kFALSE;
    528701    Bool_t PedRunFound  = kFALSE;
     702
     703   
    529704
    530705
     
    559734        ScanFileName(n->GetName(), name, path, date, src, &run, &type);
    560735
    561        
     736
     737        //
     738        // Check that runnumber is inside the desire range of range to analyse [fInitialRun,fEndRun]
     739        //
     740        if(fEndRun !=-1 && run > fEndRun)
     741            break;
     742        if(run < fInitialRun)
     743            continue;
     744
     745
    562746        //
    563         // Skip until finding the following run after the fLastDataRun
    564         //
    565         if( run <= fLastProcessedRun )
     747        // Skip until finding the following run after the last processed one, fLastDataRun
     748        //
     749        if( run <= fLastProcessedDataRun )
    566750            continue;
    567        
     751
    568752        //
    569753        // Check that the source name is among one of the selected source names
     
    571755        if( LockSrcName != "")
    572756        {       
    573             if( src != LockSrcName )
    574                 continue;
     757            FirstSrcName = LockSrcName;
    575758        }
    576         else
    577         {
    578             if( !CheckSourceName(src) )
    579                 continue;
    580         }
     759       
     760        if( !CheckSourceName(src) )
     761            continue;
     762
    581763
    582764        //
     
    608790        }
    609791
    610         if( src != FirstSrcName)
     792       
     793        if( !CompareSourceNames(src,FirstSrcName) )
    611794        {
    612             if(type!='C')
    613             { 
    614                 *fLog << err << "ERROR: Source Name differs inside data set ("
     795            *fLog << err << "ERROR: Source Name differs inside data set ("
    615796                  << src << " vs. " << FirstSrcName << ") ...exit." << endl;
    616                 return kFALSE;
    617             }
    618             else
    619             {
    620                 *fLog << warn << "Warning: Cal Source Name differs inside data set (" << src << " vs. " << FirstSrcName << ")." << endl;
    621             }
     797            return kFALSE;
    622798        }
     799
    623800
    624801
     
    641818                DataRunFound = kTRUE;
    642819
    643                 fLastProcessedRun = run;
    644                
     820                fLastProcessedDataRun = run;   
    645821            }
    646822            break;
     
    752928
    753929
     930// ------------------------------------------------------------------------------------
     931//
     932//  Deterimines wheather of data runs has been processed or not
     933//
     934Bool_t MDataSetIter::HasFinishedSuccesfully()
     935{
     936
     937    if(fEndRun==-1)
     938        *fLog << "LastDataRun = " << fLastDataRun << endl;
     939    else
     940        *fLog << "EndRun = " <<  fEndRun << endl;
     941   
     942    *fLog << "LastProcessedDataRun = " << fLastProcessedDataRun << endl;   
     943
     944
     945    if(fEndRun==-1)
     946        return fLastProcessedDataRun==fLastDataRun ? kTRUE : kFALSE;
     947    else
     948        return fLastProcessedDataRun==fEndRun ? kTRUE : kFALSE;
     949       
     950}
  • trunk/MagicSoft/Mars/mtemp/mucm/classes/MDataSetIter.h

    r4683 r6691  
    88#ifndef MARS_MRunIter
    99#include "MRunIter.h"
     10#endif
     11
     12#ifndef MARS_MSequence
     13#include "MSequence.h"
    1014#endif
    1115
     
    2529    TObjArray fSrcList;   // List with the valid source names
    2630
    27     Int_t fLastProcessedRun;  // Runnumber of the last processed run
     31   
     32    Int_t fInitialRun;  // Runnumber of the first run to proccess
     33    Int_t fEndRun;      // Runnumber of the last run to proccess
     34    Int_t fLastProcessedDataRun;  // Runnumber of the last processed run
     35    Int_t fLastDataRun; // Lst Data runnumber in fFileList
    2836
    2937    MRunIter* fPedRuns;
    3038    MRunIter* fCalRuns;
    3139    MRunIter* fDataRuns;
     40    MSequence* fSequence;
    3241
    3342    TString fSrcName;
    3443    TString fDate;
    3544
     45    Int_t fDefCalRun;
     46    TString fDefCalRunPath; 
     47
    3648    MLog *fLog;
    3749   
    38     Int_t fDefCalRun;
    39     TString fDefCalRunPath; 
    4050   
    4151    Int_t CheckSourceName(TString& src);
     52    Int_t CompareSourceNames(TString& src1, TString& src2);
    4253    void  AddToFileList(MDirIter& dir);
    43     void  ScanFileName(const TString& file, TString& name, TString& path, TString& date, TString& src, Int_t* run, char* type);
    44    
     54    void  ScanFileName(const TString& file, TString& name, TString& path, TString& date, TString& src, Int_t* run, char* type); 
     55    Int_t IsPreviousRunUsable(MRunIter& oldRun);
     56    Int_t Loop(TString option, TString LockSrcName="");
     57    void FindLastDataRun();
     58
    4559 public:
    4660   
     
    5266    Int_t NextDataSet();
    5367
    54     void SetInitialRun(Int_t run) { fLastProcessedRun = run; }
     68    void SetInitialRun(Int_t run) { fInitialRun = run; }
     69    void SetEndRun(Int_t run)
     70    {
     71        fEndRun = run;
     72        FindLastDataRun();
     73    }
     74    void SetDefCalRun(Int_t run, const char* path) {fDefCalRun = run; fDefCalRunPath = path; }
     75
     76    Int_t GetLastProcessedRun() const { return fLastProcessedDataRun; }
    5577
    5678    TString*  GetSrcName()  { return &fSrcName; }
     
    7496    void Reset()
    7597    {
    76         MDirIter::Reset();
    77         fLastProcessedRun = 0;
     98        fLastProcessedDataRun = 0;
    7899    }
    79100
    80101    void Print(const Option_t *option="") const;
     102   
     103    Bool_t HasFinishedSuccesfully();
    81104
    82     Int_t Loop(TString option, TString LockSrcName="");
    83 
    84     Int_t IsPreviousRunUsable(MRunIter& oldRun);
    85  
    86 
    87     Int_t GetLastProcessedRun() const { return fLastProcessedRun; }
    88 
    89     void SetDefCalRun(Int_t run, const char* path) {fDefCalRun = run; fDefCalRunPath = path; }
     105    Int_t WriteSequence();
    90106
    91107
    92     ClassDef(MDataSetIter, 1) // Iterator for runs
     108    ClassDef(MDataSetIter, 1) // Iterator for data set made of Pec, Cal and Data runs
    93109};
    94110
Note: See TracChangeset for help on using the changeset viewer.