Ignore:
Timestamp:
01/22/02 17:32:15 (23 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mhist/MFillH.cc

    r1082 r1209  
    3030//  histogram which is derived from MH can be filled with this task.        //
    3131//                                                                          //
    32 //  You must specifiy the parameter container with which data the histogram //
    33 //  container should be filled, and the histogram container which has       //
    34 //  to be filled. This can be done by either specifing the name of the      //
    35 //  objects in the parameter list or by specifiing a pointer to the object. //
    36 //  (s. Constructor)                                                        //
     32//  There are two options to use:                                           //
     33//                                                                          //
     34//  1) You specifiy the parameter container with which data the             //
     35//     histogram container should be filled, and the histogram container    //
     36//     which has to be filled. This can be done by either specifing the     //
     37//     name of the objects in the parameter list or by specifiing a pointer //
     38//     to the object. (s. Constructor)                                      //                  //
     39//                                                                          //
     40//  2) You specify the name and/or type of the histogram to become filled.  //
     41//     Any other action imust be taken by the histogram class.              //
     42//                                                                          //
     43//  PreProcess: In the preprocessing of this task we setup all pointers     //
     44//              to instances which are needed and call FillSetup of the     //
     45//              histogram class with the parameter list as an argument.     //
     46//                                                                          //
     47//  Process: The process function calls the Fill member function of the     //
     48//           histogram class instance (inheriting from MH) with either      //
     49//           a NULL pointer or a pointer to the corresponding container     //
     50//           as an argument.                                                //
    3751//                                                                          //
    3852//  WARNING:                                                                //
     
    8195// Constructor.
    8296//
    83 // - par is the name of the parameter container which should be filled into
    84 //   the histogram
    85 // - hist is the name of the histogram container (which must have been
    86 //   derived from MH)
    87 //
    88 MFillH::MFillH(const char *par, const char *hist, const char *name, const char *title)
     97// 1) - par is the name of the parameter container which should be filled into
     98//      the histogram
     99//    - hist is the name of the histogram container (which must have been
     100//      derived from MH)
     101//
     102//    In this case MH::Fill is called with a pointer to the corresponding
     103//    histogram instance.
     104//
     105// 2) - hist is the name and/or type of the histogram.
     106//      1) The name and type is identical, eg: "MHHillas"
     107//      2) They are not identical, eg: "MyHistogram [MHHillas]"
     108//         This searches for a class instance of MHHillas with the name
     109//         "MyHistogram". If it doesn't exist one is created.
     110//
     111//    In this case PreProcess calls MH::SetupFill with a pointer to the
     112//    parameter list and MH::Fill is called with a NULL-pointer.
     113//
     114MFillH::MFillH(const char *hist, const char *par, const char *name, const char *title)
    89115{
    90116    Init(name, title);
    91117
    92118    fHName = hist;
     119    fParContainerName = par;
     120}
     121
     122// --------------------------------------------------------------------------
     123//
     124// Constructor.
     125//
     126// 1) - par is a pointer to the instance of your parameter container from which
     127//      the data should be used to fill the histogram.
     128//    - hist is the name of the histogram container (which must have been
     129//      derived from MH)
     130//
     131//    In this case MH::Fill is called with a pointer to the corresponding
     132//    histogram instance.
     133//
     134// 2) - hist is the name and/or type of the histogram.
     135//      1) The name and type is identical, eg: "MHHillas"
     136//      2) They are not identical, eg: "MyHistogram [MHHillas]"
     137//         This searches for a class instance of MHHillas with the name
     138//         "MyHistogram". If it doesn't exist one is created. Everything
     139//         which is between the first '[' and the last ']' in the string
     140//         is used as the histogram type.
     141//
     142//    In this case PreProcess calls MH::SetupFill with a pointer to the
     143//    parameter list and MH::Fill is called with a NULL-pointer.
     144//
     145//
     146MFillH::MFillH(const char *hist, const MParContainer *par, const char *name, const char *title)
     147{
     148    Init(name, title);
     149
     150    fHName = hist;
     151    fParContainer = par;
     152    fParContainerName = par->GetName();
     153}
     154
     155// --------------------------------------------------------------------------
     156//
     157// Constructor.
     158//
     159// - par is a pointer to the instance of your parameter container from which
     160//   the data should be used to fill the histogram.
     161// - hist is a pointer to the instance of your histogram container (which must
     162//   have been derived from MH) into which the data should flow
     163//
     164MFillH::MFillH(MH *hist, const char *par, const char *name, const char *title)
     165{
     166    Init(name, title);
     167
     168    fH = hist;
     169    fHName = hist->GetName();
    93170    fParContainerName = par;
    94171}
     
    103180//   derived from MH)
    104181//
    105 MFillH::MFillH(const MParContainer *par, const char *hist, const char *name, const char *title)
    106 {
    107     Init(name, title);
    108 
    109     fHName = hist;
    110     fParContainer = par;
    111     fParContainerName = par->GetName();
    112 }
    113 
    114 // --------------------------------------------------------------------------
    115 //
    116 // Constructor.
    117 //
    118 // - par is a pointer to the instance of your parameter container from which
    119 //   the data should be used to fill the histogram.
    120 // - hist is a pointer to the instance of your histogram container (which must
    121 //   have been derived from MH) into which the data should flow
    122 //
    123 MFillH::MFillH(const char *par, MH *hist, const char *name, const char *title)
    124 {
    125     Init(name, title);
    126 
    127     fH = hist;
    128     fHName = hist->GetName();
    129     fParContainerName = par;
    130 }
    131 
    132 // --------------------------------------------------------------------------
    133 //
    134 // Constructor.
    135 //
    136 // - par is a pointer to the instance of your parameter container from which
    137 //   the data should be used to fill the histogram.
    138 // - hist is the name of the histogram container (which must have been
    139 //   derived from MH)
    140 //
    141 MFillH::MFillH(const MParContainer *par, MH *hist, const char *name, const char *title)
     182MFillH::MFillH(MH *hist, const MParContainer *par, const char *name, const char *title)
    142183{
    143184    Init(name, title);
     
    147188    fParContainer = par;
    148189    fParContainerName = par->GetName();
     190}
     191
     192TString MFillH::ExtractName(const char *name) const
     193{
     194    TString type = name;
     195
     196    const Ssiz_t first = type.First('[');
     197    const Ssiz_t last  = type.First(']');
     198
     199    if (!first || !last || first>=last)
     200        return type;
     201
     202    return type.Remove(first).Strip(TString::kBoth);
     203}
     204
     205TString MFillH::ExtractClass(const char *name) const
     206{
     207    TString type = name;
     208
     209    const Ssiz_t first = type.First('[');
     210    const Ssiz_t last  = type.First(']');
     211
     212    if (!first || !last || first>=last)
     213        return type;
     214
     215    const Ssiz_t length = last-first-1;
     216
     217    TString strip = fHName(first+1, length);
     218    return strip.Strip(TString::kBoth);
    149219}
    150220
     
    159229Bool_t MFillH::PreProcess(MParList *pList)
    160230{
    161     if (!fParContainer)
     231    //
     232    // Try to get the histogram container with name fHName from list
     233    // or create one with this name
     234    //
     235    if (!fH)
    162236    {
    163         fParContainer = (MParContainer*)pList->FindObject(fParContainerName);
    164         if (!fParContainer)
     237        const TString cls  = ExtractClass(fHName);
     238        const TString name = ExtractName(fHName);
     239
     240        TObject *obj = pList->FindCreateObj(cls, name);
     241        if (!obj)
     242            return kFALSE;
     243
     244        //
     245        // We were successfull getting it. Check whether it really inherits
     246        // from MH, FindCreateObj does only check for inheritance from
     247        // 'type'.
     248        //
     249        if (!obj->InheritsFrom(MH::Class()))
    165250        {
    166             *fLog << err << dbginf << fParContainerName << " [MParContainer] not found... aborting." << endl;
     251            *fLog << err << dbginf << obj->GetName() << " doesn't inherit ";
     252            *fLog << "from MH - cannot be used for MFillH... aborting." << endl;
    167253            return kFALSE;
    168254        }
     255
     256        fH = (MH*)obj;
    169257    }
    170258
    171     if (!fH)
     259    //
     260    // Now we have the histogram container available. Try to Setup Fill.
     261    //
     262    if (!fH->SetupFill(pList))
    172263    {
    173         fH = (MH*)pList->FindCreateObj(fHName);
    174         if (!fH)
    175             return kFALSE;
    176     }
    177 
    178     if (!fH->InheritsFrom("MH"))
    179     {
    180         *fLog << err << dbginf << fH->GetDescriptor() << " ";
    181         *fLog << "doesn't inherit from MH - cannot be used for MFillH... aborting." << endl;
     264        *fLog << err << dbginf << "Error: calling SetupFill for ";
     265        *fLog << fH->GetDescriptor() << "... aborting." << endl;
    182266        return kFALSE;
    183267    }
    184268
    185     return kTRUE;
     269    //
     270    // If also a parameter container is already set we are done.
     271    //
     272    if (fParContainer)
     273        return kTRUE;
     274
     275    //
     276    // If a name is given try to find the input container in the
     277    // list. If it could not be found we cannot proceed.
     278    //
     279    fParContainer = (MParContainer*)pList->FindObject(fParContainerName);
     280    if (fParContainer)
     281        return kTRUE;
     282
     283    *fLog << err << dbginf << fParContainerName << " [MParContainer] not found... aborting." << endl;
     284    return kFALSE;
    186285}
    187286
     
    192291Bool_t MFillH::Process()
    193292{
    194     fH->Fill(fParContainer);
    195 
    196     return kTRUE;
     293    return fH->Fill(fParContainer);
    197294}
    198295
Note: See TracChangeset for help on using the changeset viewer.