Changeset 4694


Ignore:
Timestamp:
08/20/04 11:25:36 (20 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r4688 r4694  
    2020                                                 -*-*- END OF LINE -*-*-
    2121
     22 2004/08/20: Thomas Bretz
     23
     24   * macros/sql/filldotrbk.C:
     25     - removed obsolete output
     26
     27   * macros/sql/filldotrun.C:
     28     - removed obsolete output
     29     - updated to support ExcludedFDA-table
     30
     31   * mbase/MParList.[h,cc]:
     32     - added FindTask-member function
     33
     34   * mcalib/MHCalibrationChargeBlindCam.cc:
     35     - fixed a 'comparison between signed and unsigned'
     36
     37   * mfileio/MRead.h:
     38     - added GetFileName()
     39     - removed const-qualifier from CheckAndWrite
     40
     41   * mfileio/MReadMarsFile.cc:
     42     - changed some logiing output
     43
     44   * mfileio/MWriteAsciiFile.[h,cc], mfileio/MWriteFile.[h,cc]:
     45     - removed const-qualifier from CheckAndWrite
     46     
     47   * mfileio/MWriteRootFile.[h,cc]:
     48     - simplified the constructor by adding Init() function
     49     - added ReInit function to support file splitting
     50     - added file splitting support (GetNewFileName, ChangeFile)
     51     - added new constructor for file splitting
     52     - made gsDef* a static member
     53     - slight changed to PreProcess to support file-splitting
     54     - if file-spliiting is enabled return always kTRUE in IsFileOpen
     55     - added many new outputs in case of possible problems
     56
     57   * mraw/MRawFileRead.[h,cc]:
     58     - changed return type of GetFileName()
     59
     60   * mraw/MRawFileWrite.[h,cc]:
     61     - removed obsolete pParList data member
     62     - by default write all events to the 'Events' tree
     63
     64   * msql/MSQLServer.[h,cc]:
     65     - enhanced Query function
     66
     67
     68
    2269 2004/08/19: Marcos Lopez
    2370
     
    2673       the calibration file name, ignore the case, to deal with colors
    2774       written in capital letters.
     75
    2876
    2977
  • trunk/MagicSoft/Mars/NEWS

    r4601 r4694  
    1414   - Added a new task (MTaskEnv) which can be used in setup files to switch
    1515     between different tasks (for example to choose a signal extractor)
     16
     17   - Implemented automatic file splitting in MWriteRootFile
    1618
    1719
  • trunk/MagicSoft/Mars/macros/sql/filldotrbk.C

    r4680 r4694  
    193193        TSQLResult *res = serv.Query(query);
    194194        if (!res)
    195         {
    196             cout << "ERROR: " << query << endl << endl;
    197195            return 0;
    198         }
    199196
    200197        delete res;
  • trunk/MagicSoft/Mars/macros/sql/filldotrun.C

    r4680 r4694  
    107107    TSQLResult *res = serv.Query(query);
    108108    if (!res)
    109     {
    110         cout << "ERROR - Query: " << query << endl;
    111         return -1;
    112     }
     109        return -1;
    113110
    114111    TSQLRow *row=res->Next();
     
    134131    res=serv.Query(query);
    135132    if (!res)
    136     {
    137         cout << "ERROR - Query: " << query << endl;
    138         return -1;
    139     }
     133        return -1;
     134
    140135    delete res;
    141136
     
    157152    if (!fin)
    158153    {
    159         cout << "Could not open file " << fname << endl;
     154        cout << "Could not open file " << filename << endl;
    160155        return -1;
    161156    }
     
    379374        if (!TMath::IsNaN(l2uprate) && TMath::Finite(l2uprate))
    380375            query += Form("fL2RateUnpresc=%d, ", TMath::Nint(l2uprate));
    381         query += "fMagicNumberKEY=1";
     376        query += "fMagicNumberKEY=1, fExcludedFDAKEY=1";
    382377
    383378        //cout << query << endl;
     
    393388        TSQLResult *res = serv.Query(query);
    394389        if (!res)
    395         {
    396             cout << query << " - FAILED!" << endl;
    397390            return -1;
    398         }
    399391
    400392        delete res;
     
    406398
    407399// This tool will work from Period017 (2004_05_17) on...
    408 void filldotrun(const char *path="/data/MAGIC/Period018/ccdata", Bool_t dummy=kTRUE)
     400int filldotrun(const TString path="/data/MAGIC/Period018/ccdata", Bool_t dummy=kTRUE)
    409401{
    410402    MSQLServer serv("mysql://hercules:d99swMT!@localhost");
     
    423415    if (path.EndsWith(".run"))
    424416    {
     417        cout << path(TRegexp("CC_.*.run", kFALSE)) << flush;
     418        Int_t n = insert(serv, dummy, path);
     419        cout << " <" << n << "> " << (dummy?"DUMMY":"") << endl;
     420
     421        return n<0 ? 0 : 1;
     422    }
     423
     424    MDirIter Next(path, "CC_*.run", -1);
     425    while (1)
     426    {
     427        TString name = Next();
     428        if (name.IsNull())
     429            break;
     430
    425431        cout << name(TRegexp("CC_.*.run", kFALSE)) << flush;
    426432        Int_t n = insert(serv, dummy, name);
    427433        cout << " <" << n << "> " << (dummy?"DUMMY":"") << endl;
    428434
    429         return n<0 ? 0 : 1;
    430     }
    431 
    432     MDirIter Next(path, "CC_*.run", -1);
    433     while (1)
    434     {
    435         TString name = Next();
    436         if (name.IsNull())
    437             break;
    438 
    439         cout << name(TRegexp("CC_.*.run", kFALSE)) << flush;
    440         Int_t n = insert(serv, dummy, name);
    441         cout << " <" << n << "> " << (dummy?"DUMMY":"") << endl;
    442 
    443435        if (n<0)
    444436            return 0;
  • trunk/MagicSoft/Mars/mbase/MParList.cc

    r4601 r4694  
    368368// --------------------------------------------------------------------------
    369369//
     370//  Searches for the tasklist tlist (default: MTaskList) and returns
     371//  a task with the given name found in this list. If one of both isn't
     372//  found NULL is returned
     373//
     374MTask *MParList::FindTask(const char *name, const char *tlist) const
     375{
     376    TObject *l = FindObject(tlist, "MTaskList");
     377    return (MTask*)(l ? l->FindObject(name) : NULL);
     378}
     379
     380// --------------------------------------------------------------------------
     381//
    370382//  returns the ClassName without anything which is behind that last ';' in
    371383//  string.
  • trunk/MagicSoft/Mars/mbase/MParList.h

    r4601 r4694  
    2121
    2222class MLog;
     23class MTask;
    2324
    2425class MParList : public MParContainer
     
    5758    TObject *FindObject(const char *name, const char *classname) const;
    5859    TObject *FindObject(const TObject *obj, const char *classname) const;
     60
     61    MTask   *FindTask(const char *name, const char *tlist="MTaskList") const;
    5962
    6063    MParContainer *FindCreateObj(const char *classname, const char *objname=NULL);
  • trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeBlindCam.cc

    r4669 r4694  
    179179{
    180180
    181   const Int_t nblindpixels  = fSignal->GetNumBlindPixels();
     181  const UInt_t nblindpixels  = fSignal->GetNumBlindPixels();
    182182
    183183  Int_t runnr = 0;
     
    195195  if (fCam->GetNumBlindPixels() != nblindpixels)
    196196    {
    197       *fLog << err << "Size mismatch in MCalibrationChargeBlindCam ... abort." << endl;     
    198       *fLog << err << "Size of MCalibrationChargeBlindCam: " << fCam->GetNumBlindPixels()
    199             << "Size of MExtractedSignalBlindPixel: " << nblindpixels << endl;
     197        *fLog << err;
     198        *fLog << "Size mismatch in MCalibrationChargeBlindCam ... abort." << endl;
     199        *fLog << "  Size of MCalibrationChargeBlindCam: " << fCam->GetNumBlindPixels() << endl;
     200        *fLog << "  Size of MExtractedSignalBlindPixel: " << nblindpixels << endl;
    200201      return kFALSE;
    201202    }
     
    210211      fBlindPixelsArray->Expand(nblindpixels);
    211212
    212       for (Int_t i=0; i<nblindpixels; i++)
     213      for (UInt_t i=0; i<nblindpixels; i++)
    213214        {
    214215          (*fBlindPixelsArray)[i] = new MHCalibrationChargeBlindPix;
     
    230231  }
    231232
    232   for (Int_t i=0; i<nblindpixels; i++)
     233  for (UInt_t i=0; i<nblindpixels; i++)
    233234    {
    234235      TH1F *h = (*this)[i].GetHGausHist();
  • trunk/MagicSoft/Mars/mfileio/MRead.h

    r4601 r4694  
    1717    MRead() : fSelector(NULL) {}
    1818
    19     virtual UInt_t GetEntries() = 0;
    20     virtual Bool_t Rewind();
     19    virtual UInt_t  GetEntries() = 0;
     20    virtual TString GetFileName() const = 0;
     21    virtual Bool_t  Rewind();
    2122
    2223    void SetSelector(MFilter *f) { fSelector = f; }
  • trunk/MagicSoft/Mars/mfileio/MReadMarsFile.cc

    r3682 r4694  
    191191    if (!tlist)
    192192    {
    193         *fLog << err << dbginf << "ERROR - Task List not found in Parameter List." << endl;
     193        *fLog << err << dbginf << "ERROR - MTaskList not found in Parameter List." << endl;
    194194        return kFALSE;
    195195    }
  • trunk/MagicSoft/Mars/mfileio/MWriteAsciiFile.cc

    r3336 r4694  
    188188// a warning message is print.
    189189//
    190 Bool_t MWriteAsciiFile::CheckAndWrite() const
     190Bool_t MWriteAsciiFile::CheckAndWrite()
    191191{
    192192    Bool_t written = kFALSE;
  • trunk/MagicSoft/Mars/mfileio/MWriteAsciiFile.h

    r3336 r4694  
    2121    TObjArray fAutoDel; //! List of object to be deleted in the destructor
    2222
    23     virtual Bool_t CheckAndWrite() const;
     23    virtual Bool_t CheckAndWrite();
    2424    virtual Bool_t IsFileOpen() const;
    2525    virtual Bool_t GetContainer(MParList *pList);
  • trunk/MagicSoft/Mars/mfileio/MWriteFile.h

    r3336 r4694  
    88class MWriteFile : public MTask
    99{
     10protected:
     11    Bool_t ReInit(MParList *pList);
     12
    1013private:
    1114    Int_t PreProcess(MParList *pList);
    1215    Int_t Process();
    1316    Int_t PostProcess();
    14     Bool_t ReInit(MParList *pList);
    1517
    1618    virtual Bool_t      IsFileOpen() const = 0;
    17     virtual Bool_t      CheckAndWrite() const = 0;
     19    virtual Bool_t      CheckAndWrite() = 0;
    1820    virtual Bool_t      GetContainer(MParList *pList) = 0;
    1921    virtual const char *GetFileName() const = 0;
  • trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc

    r3710 r4694  
    1818!   Author(s): Thomas Bretz, 6/2001 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2003
     20!   Copyright: MAGIC Software Development, 2000-2004
    2121!
    2222!
     
    2424
    2525/////////////////////////////////////////////////////////////////////////////
    26 //                                                                         //
    27 // MWriteRootFile                                                          //
    28 //                                                                         //
    29 // This is a writer to store several containers to a root file.            //
    30 // The containers are added with AddContainer.                             //
    31 // To understand how it works, see base class MWriteFile                   //
    32 //                                                                         //
    33 // Warning: Checkout the Warning in MTaskList.                             //
    34 //                                                                         //
     26//
     27// MWriteRootFile
     28//
     29// This is a writer to store several containers to a root file.
     30// The containers are added with AddContainer.
     31// To understand how it works, see base class MWriteFile
     32//
     33// Warning: Look at the Warning in MTaskList.
     34//
     35// There is a special mode of operation which opens a new file for each new
     36// file read by the reading task (opening the new file is initiated by
     37// ReInit()) For more details se the corresponding constructor.
     38//
    3539/////////////////////////////////////////////////////////////////////////////
    3640#include "MWriteRootFile.h"
     
    4044#include <TFile.h>
    4145#include <TTree.h>
     46#include <TRegexp.h>
    4247
    4348#include "MLog.h"
    4449#include "MLogManip.h"
    4550
     51#include "MRead.h"
    4652#include "MParList.h"
    4753
     
    5157using namespace std;
    5258
    53 static const TString gsDefName  = "MWriteRootFile";
    54 static const TString gsDefTitle = "Task which writes a root-output file";
     59const TString MWriteRootFile::gsDefName  = "MWriteRootFile";
     60const TString MWriteRootFile::gsDefTitle = "Task which writes a root-output file";
     61
     62void MWriteRootFile::Init(const char *name, const char *title)
     63{
     64    fName  = name  ? name  : gsDefName.Data();
     65    fTitle = title ? title : gsDefTitle.Data();
     66
     67    //
     68    // Set the Arrays the owner of its entries. This means, that the
     69    // destructor of the arrays will delete all its entries.
     70    //
     71    fBranches.SetOwner();
     72
     73    //
     74    // Believing the root user guide, TTree instanced are owned by the
     75    // directory (file) in which they are. This means we don't have to
     76    // care about their destruction.
     77    //
     78    //fTrees.SetOwner();
     79}
    5580
    5681// --------------------------------------------------------------------------
     
    6186MWriteRootFile::MWriteRootFile() : fOut(NULL)
    6287{
    63     fName  = gsDefName;
    64     fTitle = gsDefTitle;
    65 
     88    Init();
     89
     90    //
     91    // Set the Arrays the owner of its entries. This means, that the
     92    // destructor of the arrays will delete all its entries.
     93    //
    6694    fBranches.SetOwner();
     95}
     96
     97// --------------------------------------------------------------------------
     98//
     99// Use this constructor to run in a special mode.
     100//
     101// In this mode for each input file a new output file is written. This
     102// happens in ReInit.
     103//
     104// comp:        Compression Level (see TFile, TBranch)
     105// rule:        Rule to create output file name (see GetNewFileName())
     106// overwrite:   Allow newly created file to overwrite old files ("RECREATE")
     107// ftitle:      File title stored in the file (see TFile)
     108// name, title: Name and title of this object
     109//
     110MWriteRootFile::MWriteRootFile(const Int_t comp,
     111                               const char *rule,
     112                               const Bool_t overwrite,
     113                               const char *ftitle,
     114                               const char *name,
     115                               const char *title) : fSplitRule(rule)
     116{
     117    Init(name, title);
     118
     119    //
     120    // Open a TFile in dummy mode! This is necessary to be able to create
     121    // the trees and branches, which are then (in ReInit) moved to
     122    // a valid file. (Stupid workaround - but does a good job)
     123    //
     124    fOut = new TFile("/dev/null", overwrite?"RECREATE":"NEW", ftitle, comp);
    67125}
    68126
     
    81139                               const char *title)
    82140{
    83     fName  = name  ? name  : gsDefName.Data();
    84     fTitle = title ? title : gsDefTitle.Data();
    85 
    86     //
    87     // Set the Arrays the owner of its entries. This means, that the
    88     // destructor of the arrays will delete all its entries.
    89     //
    90     fBranches.SetOwner();
    91 
    92     //
    93     // Believing the root user guide, TTree instanced are owned by the
    94     // directory (file) in which they are. This means we don't have to
    95     // care about their destruction.
    96     //
    97     //fTrees.SetOwner();
     141    Init(name, title);
     142
     143    //
     144    // If no name is given we open the TFile in some kind of dummy mode...
     145    //
     146    if (!fname)
     147    {
     148        fOut = new TFile("/dev/null", "READ", ftitle, comp);
     149        return;
     150    }
    98151
    99152    TString str(fname);
     
    112165// properly.
    113166//
    114 MWriteRootFile::~MWriteRootFile()
     167void MWriteRootFile::Close()
    115168{
    116169    //
     
    130183    //
    131184    delete fOut;
     185    fOut = 0;
    132186
    133187    //
     
    139193
    140194    *fLog << inf << "Output File closed and object deleted." << endl;
     195}
     196
     197// --------------------------------------------------------------------------
     198//
     199// call Close()
     200//
     201MWriteRootFile::~MWriteRootFile()
     202{
     203    Close();
    141204}
    142205
     
    350413            *fLog << inf << "Branch '" << cname << "' already existing... updating." << endl;
    351414            branch->SetAddress(entry->GetAddress());
     415
     416            if (!fSplitRule.IsNull())
     417            {
     418                *fLog << warn << endl;
     419                *fLog << "WARNING:   You are updating an existing branch.  For this" << endl;
     420                *fLog << "     case file-splitting mode is not allowed... disabled!" << endl;
     421                *fLog << endl;
     422                fSplitRule = "";
     423            }
    352424        }
    353425        else
     
    365437
    366438            branch = tree->Branch(branchname, cont->ClassName(), entry->GetAddress());
     439
    367440            //
    368441            // If the branch couldn't be created we have a problem.
     
    376449
    377450            *fLog << "done." << endl;
     451
     452            if (!tree->TestBit(kIsNewTree) && !fSplitRule.IsNull())
     453            {
     454                *fLog << warn << endl;
     455                *fLog << "WARNING:   You  have  created  a new branch  in  an existing tree." << endl;
     456                *fLog << "     For this case file-splitting mode is not allowed... disabled!" << endl;
     457                *fLog << endl;
     458                fSplitRule= "";
     459            }
    378460        }
    379461
     
    384466        entry->SetBranch(branch);
    385467    }
     468
    386469    return kTRUE;
    387470}
     
    401484// has the write flag, all containers in this tree are filled!
    402485//
    403 Bool_t MWriteRootFile::CheckAndWrite() const
     486Bool_t MWriteRootFile::CheckAndWrite()
    404487{
    405488    TObject *obj;
     
    438521    // Loop over all tree entries
    439522    //
    440     TIter NextTree(&fTrees);
    441     while ((obj=NextTree()))
    442     {
    443         TTree *t = (TTree*)obj;
     523    const Int_t n = fTrees.GetEntriesFast();
     524
     525    for (int idx=0; idx<n; idx++)
     526    {
     527        TTree *t = (TTree*)fTrees[idx];
    444528
    445529        //
     
    455539        //
    456540        t->ResetBit(kFillTree);
     541
    457542        if (!t->Fill())
    458543        {
     
    461546        }
    462547    }
     548
     549    //
     550    // For more information see TTree:ChangeFile()
     551    //
     552    TTree *t0 = (TTree*)fTrees[0];
     553    if (!t0 || fOut==t0->GetCurrentFile())
     554        return kTRUE;
     555
     556    *fLog << warn << endl;
     557    *fLog << "WARNING - MWriteRootFile:   Root's  TTree/TFile   has  opened   a  new  file" << endl;
     558    *fLog << "  automatically.  You can change this behaviour using TTree::SetMaxTreeSize." << endl;
     559    *fLog << "  You won't be able to read splitted  files  correctly with MReadMarsFile if" << endl;
     560    *fLog << "  they have more than one entry in 'RunHeaders' or you try to read more than" << endl;
     561    *fLog << "  one of such sequences at once." << endl;
     562    *fLog << endl;
     563
    463564    return kTRUE;
    464565}
     
    466567// --------------------------------------------------------------------------
    467568//
     569// Open a new file with the ame fname. Move all trees and branches from the
     570// old file to the new file.
     571//
     572Bool_t MWriteRootFile::ChangeFile(const char *fname)
     573{
     574    //
     575    // The following code is more or less a copy of TTree::ChangeFile
     576    //
     577    const Int_t   compr = fOut->GetCompressionLevel();
     578    const TString title = fOut->GetTitle();
     579
     580    *fLog << inf << "MWriteRootFile - Open new file " << fname << " (Title=" << title << ", Compression=" << compr << ")" << endl;
     581
     582    // Open new file with old setup
     583    TFile *newfile = TFile::Open(fname, "RECREATE", title, compr);
     584    if (!newfile)
     585    {
     586        *fLog << err << "ERROR - Cannot open new file " << fname << endl;
     587        return kFALSE;
     588    }
     589
     590    // Print statistics of old file
     591    const TString n = GetFileName();
     592    if (!n.IsNull() && n!=TString("/dev/null"))
     593        Print();
     594
     595    if (fOut->IsOpen())
     596        fOut->Write();
     597
     598    // Move all trees from the old file to the new file
     599    TObject *obj=0;
     600    while ((obj = fOut->GetList()->First()))
     601    {
     602        // Remove obj from old file (otherwise deleting
     603        // the old file will delete the objs)
     604        fOut->GetList()->Remove(obj);
     605
     606        // If this is not a tree do nothing.
     607        if (!obj->InheritsFrom("TTree"))
     608            continue;
     609
     610        // process all trees in the old file
     611        TTree *t = (TTree*)obj;
     612
     613        // reset and move to new file (this is done implicitly for all branches)
     614        t->Reset();
     615        t->SetDirectory(newfile);
     616    }
     617
     618    // Close/delete the old file (keys already written above)
     619    delete fOut;
     620
     621    // Replace current with new file
     622    fOut = newfile;
     623
     624    // Change current directory to new file
     625    gFile = fOut;
     626
     627    return kTRUE;
     628}
     629
     630// --------------------------------------------------------------------------
     631//
     632// A rule looks like:
     633//   "outputpath{s/source/destination}"
     634//
     635// outpath:                the output path into which the files are written
     636// {s/source/destination}  a substitution rule for the filename
     637//   while source can be a regular expression everything which matches this
     638//   regular expression (see TRegexp) will be replaced by destination.
     639//   Warning: The algorithm is recursive you may create endless loops!
     640//
     641// Example:
     642//   inputfile: /data/MAGIC/Period016/rootdata/20040621_23210_D_Mkn421_E.root
     643//   rule:      /outpath/{s/_D_/_Y_}
     644//   outfile:   /outpath/20040621_23210_Y_Mkn421_E.root
     645//
     646// If you need more difficult rules please send me an eMail...
     647//
     648TString MWriteRootFile::GetNewFileName(const char *inname) const
     649{
     650    // Remove the path from the filename
     651    TString fname(inname);
     652    if (fname.Last('/')>=0)
     653        fname.Remove(0, fname.Last('/')+1);
     654
     655    // Make a copy of the rule
     656    TString rule(fSplitRule);
     657
     658    // [characte class], ^ do not, [^{}] do not match { and }, [^{}]+ match at least not one { or }
     659    const TRegexp subst0("{s/[^{}/]+/[^{}/]+}");
     660
     661    TString path;
     662    Bool_t first = kTRUE;
     663
     664    Ssiz_t idx=0;
     665    while (1)
     666    {
     667        // Find a substitution exprsssion
     668        Ssiz_t len = 0;
     669        idx = subst0.Index(rule, &len);
     670        if (idx<0)
     671            break;
     672
     673        // If the first substitution expression is found in the rule
     674        // determin the path from everything before
     675        if (first)
     676        {
     677            path=rule(0, idx);
     678            first = kFALSE;
     679        }
     680
     681        // Extract a substitution expression
     682        TString expr = rule(idx, len);
     683        rule.Remove(idx, len);
     684
     685        expr.Remove(0,3);
     686        expr.Remove(expr.Length()-1);
     687
     688        // In all cases this is well defined (see Regexp)
     689        const Ssiz_t pos = expr.First('/');
     690
     691        // Split substitution rule into source and destination
     692        const TString src  = expr(0, pos);
     693        const TString dest = expr(pos+1, expr.Length());
     694
     695        // Replace source by destination
     696        const TRegexp regexp(src);
     697        while (1)
     698        {
     699            TString sub = fname(idx+dest.Length());
     700            idx = regexp.Index(fname, &len);
     701            if (idx<0)
     702                break;
     703
     704            fname.Replace(idx, len, dest);
     705        }
     706    }
     707
     708    // Check if we have a trailing '/'
     709    if (!path.IsNull() && path[path.Length()-1]!='/')
     710        path.Append("/");
     711
     712    // Create full qualified pathname
     713    path += fname;
     714    return path;
     715}
     716
     717// --------------------------------------------------------------------------
     718//
     719// ReInit. If file splitting is not allowed call MWriteFile::ReInit.
     720//
     721// In other cases get MRead from the TaskList (splitting is switched of if
     722// this is impossible).
     723//
     724// Convert the input- into a new output file-name.
     725//
     726// Open a new file, change all trees to the new file (calling ChangeFile()),
     727// and close the old one.
     728//
     729// Call MWriteFile::ReInit()
     730//
     731Bool_t MWriteRootFile::ReInit(MParList *pList)
     732{
     733    if (fSplitRule.IsNull())
     734        return MWriteFile::ReInit(pList);
     735
     736    MRead *read = (MRead*)pList->FindTask("MRead");
     737    if (!read)
     738    {
     739        *fLog << warn;
     740        *fLog << "WARNING: No Task 'MRead' found in the tasklist.  This task is" << endl;
     741        *fLog << "  necessary  to  get  the filename.  Without  a filename file" << endl;
     742        *fLog << "  file splitting is not allowed... disabled!" << endl;
     743        *fLog << endl;
     744        fSplitRule = "";
     745        return kTRUE;
     746    }
     747
     748    const TString fname = GetNewFileName(read->GetFileName());
     749    if (!ChangeFile(fname))
     750        return kFALSE;
     751
     752    return MWriteFile::ReInit(pList);
     753}
     754
     755// --------------------------------------------------------------------------
     756//
    468757// return open state of the root file.
    469758//
    470759Bool_t MWriteRootFile::IsFileOpen() const
    471760{
    472     return fOut->IsOpen();
     761    const char *n = fOut->GetName();
     762    return n==0 || *n==0 ? kTRUE : fOut->IsOpen();
    473763}
    474764
     
    479769const char *MWriteRootFile::GetFileName() const
    480770{
    481     return fOut->GetName();
     771    const char *n = fOut->GetName();
     772    return n==0 || *n==0 ? "<dummy>" : n;
    482773}
    483774
  • trunk/MagicSoft/Mars/mfileio/MWriteRootFile.h

    r3336 r4694  
    77#ifndef ROOT_TObjArray
    88#include <TObjArray.h>
     9#endif
     10#ifndef ROOT_TArrayL
     11#include <TArrayL.h>
    912#endif
    1013
     
    6871{
    6972private:
    70     TFile *fOut;
     73    static const TString gsDefName;
     74    static const TString gsDefTitle;
    7175
    72     TObjArray fBranches;
    73     TObjArray fTrees;     //!
     76    TFile *fOut;             // Current file
    7477
    75     //UInt_t fNumEvents; //! Number of events written in a run
     78    TObjArray fBranches;     // List of Branch setup (MRootFileBranch)
     79    TObjArray fTrees;        //! List of trees
    7680
    77     Bool_t      CheckAndWrite() const;
    78     Bool_t      IsFileOpen() const;
    79     Bool_t      GetContainer(MParList *pList);
    80     const char *GetFileName() const;
    81 
    82     void StreamPrimitive(ofstream &out) const;
    83     //Bool_t ReInit(MParList *pList);
     81    TString fSplitRule;      // file splitting allowed if rule existing (done in ReInit)
    8482
    8583    enum {
    8684        kFillTree  = BIT(14),
     85        // Be carefull these bits are already in use!
    8786        // TBranch::kAutoDelete = BIT(15)
    8887        // TBranchElement::kDeleteObject = BIT(16)
     
    9089    };
    9190
     91    // File handling
     92    void    Close();
     93    TString GetNewFileName(const char *fname) const;
     94    Bool_t  ChangeFile(const char *fname);
     95
     96    // MWrite
     97    Bool_t      CheckAndWrite();
     98    Bool_t      IsFileOpen() const;
     99    Bool_t      GetContainer(MParList *pList);
     100    const char *GetFileName() const;
     101
     102    // MTask
     103    Bool_t ReInit(MParList *pList);
     104    void   StreamPrimitive(ofstream &out) const;
     105
     106    // Constructor
     107    void Init(const char *name=0, const char *title=0);
     108
    92109public:
    93110    MWriteRootFile();
     111    MWriteRootFile(const Int_t comp,
     112                   const char *rule,
     113                   const Bool_t overwrite=kTRUE,
     114                   const char *ftitle="Untitled",
     115                   const char *name=NULL,
     116                   const char *title=NULL);
    94117    MWriteRootFile(const char *fname,
    95118                   const Option_t *opt="RECREATE",
    96119                   const char *ftitle="Untitled",
    97                    const Int_t comp=9,
     120                   const Int_t comp=2,
    98121                   const char *name=NULL,
    99122                   const char *title=NULL);
    100123    ~MWriteRootFile();
    101124
    102 
    103125    void AddContainer(const char *cname,   const char *tname=NULL, Bool_t must=kTRUE);
    104126    void AddContainer(MParContainer *cont, const char *tname=NULL, Bool_t must=kTRUE);
    105 
    106127
    107128    void Print(Option_t *t=NULL) const;
  • trunk/MagicSoft/Mars/mraw/MRawFileRead.cc

    r4577 r4694  
    109109    fFileNames->SetOwner();
    110110
    111     if(fname!=NULL)
    112       AddFile(fname);
     111    if (fname!=NULL)
     112        AddFile(fname);
    113113}
    114114
     
    230230// Return file name of current file.
    231231//
    232 const TString MRawFileRead::GetFileName() const
     232TString MRawFileRead::GetFileName() const
    233233{
    234234    const TObject *file = fFileNames->At(fNumFile-1);
  • trunk/MagicSoft/Mars/mraw/MRawFileRead.h

    r4601 r4694  
    3434    void SetInterleave(UInt_t i) { fInterleave = i; }
    3535
    36     const TString GetFileName() const;
     36    TString GetFileName() const;
    3737
    3838    Int_t  AddFile(const char *fname, Int_t entries=-1);
  • trunk/MagicSoft/Mars/mraw/MRawFileWrite.cc

    r4370 r4694  
    6565                             const char *ftitle,
    6666                             const Int_t comp,
    67                              const char *name, const char *title)
     67                             const char *name, const char *title) : fSplit(kFALSE)
    6868{
    6969    fName  = name  ? name  : "MRawFileWrite";
     
    8282MRawFileWrite::~MRawFileWrite()
    8383{
     84    if (fOut != fTData->GetCurrentFile())
     85    {
     86        *fLog << warn << endl;
     87        *fLog << "WARNING - MWriteRootFile:   Root's  TTree/TFile   has  opened   a  new  file" << endl;
     88        *fLog << "  automatically.  You can change this behaviour using TTree::SetMaxTreeSize." << endl;
     89        *fLog << "  You won't be able to read splitted  files  correctly with MReadMarsFile if" << endl;
     90        *fLog << "  they have more than one entry in 'RunHeaders' or you try to read more than" << endl;
     91        *fLog << "  one of such sequences at once." << endl;
     92        *fLog << endl;
     93    }
     94
     95    //
     96    // For more information see TTree:ChangeFile()
     97    //
     98    fOut = fTData->GetCurrentFile();
     99
    84100    //
    85101    // delete instance, this also does a fOut->Close()
     
    125141
    126142    //
    127     // remember the pointer to the parameter list fur further usage
    128     //
    129     pParList = pList;
    130 
    131     //
    132143    //  check if MEvtHeader exists in the Parameter list already.
    133144    //  if not create one and add them to the list
     
    180191    // create data trees for the three types of data
    181192    //
    182     fTData        = new TTree("Events",      "Normal Triggered Events");
    183     fTPedestal    = new TTree("Pedestals",   "Pedestal Triggered Events");
    184     fTCalibration = new TTree("Calibration", "Calibration Triggered Events");
     193    fTData        =          new TTree("Events",      "Normal Triggered Events");
     194    fTPedestal    = fSplit ? new TTree("Pedestals",   "Pedestal Triggered Events")    : fTData;
     195    fTCalibration = fSplit ? new TTree("Calibration", "Calibration Triggered Events") : fTData;
    185196
    186197    //
     
    207218    // FIXME: Can we calculate a good buffer size out of the event size?
    208219    //        using splitlevel=0 sppeds up writing by a factor of 5-10%
    209     fTData       ->Branch("MTime.",          "MTime",          &fTime,          32000);
     220    fTData->Branch("MTime.",          "MTime",          &fTime,          32000);
     221    fTData->Branch("MRawEvtHeader.",  "MRawEvtHeader",  &fRawEvtHeader,  32000);
     222    fTData->Branch("MRawEvtData.",    "MRawEvtData",    &fRawEvtData,    320000);
     223    fTData->Branch("MRawCrateArray.", "MRawCrateArray", &fRawCrateArray, 32000);
     224    if (!fSplit)
     225        return kTRUE;
     226
    210227    fTPedestal   ->Branch("MTime.",          "MTime",          &fTime,          32000);
    211228    fTCalibration->Branch("MTime.",          "MTime",          &fTime,          32000);
    212     fTData       ->Branch("MRawEvtHeader.",  "MRawEvtHeader",  &fRawEvtHeader,  32000);
    213229    fTPedestal   ->Branch("MRawEvtHeader.",  "MRawEvtHeader",  &fRawEvtHeader,  32000);
    214230    fTCalibration->Branch("MRawEvtHeader.",  "MRawEvtHeader",  &fRawEvtHeader,  32000);
    215     fTData       ->Branch("MRawEvtData.",    "MRawEvtData",    &fRawEvtData,    320000);
    216231    fTPedestal   ->Branch("MRawEvtData.",    "MRawEvtData",    &fRawEvtData,    320000);
    217232    fTCalibration->Branch("MRawEvtData.",    "MRawEvtData",    &fRawEvtData,    320000);
    218     //fTree->Branch("MRawCrateArray",  fRawCrateArray->GetArray(),      32000, 1);
    219     fTData       ->Branch("MRawCrateArray.", "MRawCrateArray", &fRawCrateArray, 32000);
    220233    fTPedestal   ->Branch("MRawCrateArray.", "MRawCrateArray", &fRawCrateArray, 32000);
    221234    fTCalibration->Branch("MRawCrateArray.", "MRawCrateArray", &fRawCrateArray, 32000);
  • trunk/MagicSoft/Mars/mraw/MRawFileWrite.h

    r4370 r4694  
    1919{
    2020private:
    21     MParList *pParList;
    22 
    2321    MTime          *fTime;
    2422    MRawRunHeader  *fRawRunHeader;
     
    3533    TFile *fOut;                    //!
    3634
     35    Bool_t fSplit;
     36
    3737    Int_t  PreProcess(MParList *pList);
    3838    Bool_t ReInit(MParList *pList);
     
    4747    ~MRawFileWrite();
    4848
     49    void EnableSplit(Bool_t b=kTRUE) { fSplit=b; }
     50
    4951    ClassDef(MRawFileWrite, 0)  // Task to write the raw data containers to a root file
    5052};
  • trunk/MagicSoft/Mars/msql/MSQLServer.cc

    r4577 r4694  
    410410}
    411411
     412// --------------------------------------------------------------------------
     413//
     414// Send a SQL query to the SQl server.
     415//
     416// If MSQLServer is no server (column, row, ...) NULL is returned and an
     417//  error message is send to stdout.
     418//
     419// If the query failed for some reason an error message is send to stdout
     420//  and NULL is returned.
     421//
     422// If everything works fine a TSQLResult is returned. Make sure that you
     423// delete it!
     424//
    412425TSQLResult *MSQLServer::Query(const char *sql) /*FOLD00*/
    413426{
    414     return fType==kIsServer ? fServ->Query(sql) : NULL;
     427    if (fType!=kIsServer)
     428    {
     429        cout << "ERROR: MSQLServer::Query - this is not a server!" << endl;
     430        return NULL;
     431    }
     432
     433    TSQLResult *res = fServ->Query(sql);
     434    if (!res)
     435    {
     436        cout << "ERROR: MSQLServer::Query - Query failed: " << sql << endl;
     437        return NULL;
     438    }
     439
     440    return res;
    415441}
    416442
Note: See TracChangeset for help on using the changeset viewer.