| 1 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 2 | // //
|
|---|
| 3 | // MParList //
|
|---|
| 4 | // //
|
|---|
| 5 | // This class contains a list of different parameter containers. //
|
|---|
| 6 | // //
|
|---|
| 7 | // A parameter container is an object which is derived from //
|
|---|
| 8 | // MParContainer. //
|
|---|
| 9 | // //
|
|---|
| 10 | // Normally a parameter container is used for data exchange between two //
|
|---|
| 11 | // tasks at runtime. //
|
|---|
| 12 | // //
|
|---|
| 13 | // You can add every parameter container (Named object) to the //
|
|---|
| 14 | // instance and access it from somewhere else via its Name. //
|
|---|
| 15 | // //
|
|---|
| 16 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 17 | #include "MParList.h"
|
|---|
| 18 |
|
|---|
| 19 | #include <TNamed.h>
|
|---|
| 20 | #include <TClass.h>
|
|---|
| 21 |
|
|---|
| 22 | #include "MLog.h"
|
|---|
| 23 |
|
|---|
| 24 | ClassImp(MParList)
|
|---|
| 25 |
|
|---|
| 26 | MParList::MParList(const char *name, const char *title)
|
|---|
| 27 | {
|
|---|
| 28 | //
|
|---|
| 29 | // default constructor
|
|---|
| 30 | // creates an empty list
|
|---|
| 31 | //
|
|---|
| 32 | *fName = name ? name : "MParList";
|
|---|
| 33 | *fTitle = title ? title : "List of Parameter Containers";
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | MParList::MParList(MParList &ts)
|
|---|
| 37 | {
|
|---|
| 38 | //
|
|---|
| 39 | // copy constructor
|
|---|
| 40 | //
|
|---|
| 41 |
|
|---|
| 42 | fContainer.AddAll(&ts.fContainer);
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | void MParList::SetLogStream(MLog *log)
|
|---|
| 46 | {
|
|---|
| 47 | //
|
|---|
| 48 | // create the Iterator over the tasklist
|
|---|
| 49 | //
|
|---|
| 50 | TIter Next(&fContainer);
|
|---|
| 51 |
|
|---|
| 52 | MParContainer *cont=NULL;
|
|---|
| 53 |
|
|---|
| 54 | //
|
|---|
| 55 | // loop over all tasks for preproccesing
|
|---|
| 56 | //
|
|---|
| 57 | while ( (cont=(MParContainer*)Next()) )
|
|---|
| 58 | cont->SetLogStream(log);
|
|---|
| 59 |
|
|---|
| 60 | MParContainer::SetLogStream(log);
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | Bool_t MParList::AddToList(MParContainer *obj, MParContainer *where)
|
|---|
| 64 | {
|
|---|
| 65 | //
|
|---|
| 66 | // Add an Container to the list.
|
|---|
| 67 | //
|
|---|
| 68 | // If 'where' is given, the object will be added after this.
|
|---|
| 69 | //
|
|---|
| 70 |
|
|---|
| 71 | //
|
|---|
| 72 | // check if the object (you want to add) exists
|
|---|
| 73 | //
|
|---|
| 74 |
|
|---|
| 75 | if (!obj) return kTRUE;
|
|---|
| 76 |
|
|---|
| 77 | *fLog << "Adding " << obj->GetName() << " to " << GetName() << "... " << flush;
|
|---|
| 78 | //
|
|---|
| 79 | // check if it is in the list yet
|
|---|
| 80 | //
|
|---|
| 81 | if (fContainer.FindObject(obj))
|
|---|
| 82 | {
|
|---|
| 83 | *fLog << "WARNING: MParList::add: Container already added" << endl;
|
|---|
| 84 | return kTRUE;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | //
|
|---|
| 88 | // check if you want to add the new parameter container somewhere
|
|---|
| 89 | // special (in that case you specify "where")
|
|---|
| 90 | //
|
|---|
| 91 | if (where)
|
|---|
| 92 | {
|
|---|
| 93 | if (!fContainer.FindObject(where))
|
|---|
| 94 | {
|
|---|
| 95 | *fLog << "ERROR: MParList::add: Cannot find parameter container after which the new one should be added!" << endl;
|
|---|
| 96 | return kFALSE;
|
|---|
| 97 | }
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | fContainer.Add(obj);
|
|---|
| 101 | *fLog << "Done." << endl;
|
|---|
| 102 |
|
|---|
| 103 | return kTRUE;
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | TObject *MParList::FindObject(const char *name) const
|
|---|
| 107 | {
|
|---|
| 108 | //
|
|---|
| 109 | // Find an object in the list.
|
|---|
| 110 | // 'name' is the name of the object you are searching for.
|
|---|
| 111 | //
|
|---|
| 112 | return (TObject*)fContainer.FindObject(name);
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | MParContainer *MParList::FindCreateObj(const char *name)
|
|---|
| 116 | {
|
|---|
| 117 | //
|
|---|
| 118 | // Find an object in the list.
|
|---|
| 119 | // 'name' is the name of the object you are searching for.
|
|---|
| 120 | // If the object doesn't exist we try to create one from the
|
|---|
| 121 | // dictionary. If this isn't possible NULL is returned
|
|---|
| 122 | //
|
|---|
| 123 | MParContainer *pcont = (MParContainer*)FindObject(name);
|
|---|
| 124 |
|
|---|
| 125 | if (pcont)
|
|---|
| 126 | return pcont;
|
|---|
| 127 |
|
|---|
| 128 | //
|
|---|
| 129 | // if object is not existing in the list try to create one
|
|---|
| 130 | //
|
|---|
| 131 | *fLog << "MParList::CreateObject - Warning: '" << name << "' not found... creating." << endl;
|
|---|
| 132 |
|
|---|
| 133 | //
|
|---|
| 134 | // try to get class from root environment
|
|---|
| 135 | //
|
|---|
| 136 | TClass *cls = gROOT->GetClass(name);
|
|---|
| 137 |
|
|---|
| 138 | if (!cls)
|
|---|
| 139 | {
|
|---|
| 140 | //
|
|---|
| 141 | // if class is not existing in the root environment
|
|---|
| 142 | //
|
|---|
| 143 | *fLog << "MParList::CreateObject - Warning: Class '" << name << "' not existing in dictionary." << endl;
|
|---|
| 144 | return NULL;
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | //
|
|---|
| 148 | // create the container and add it to the list
|
|---|
| 149 | //
|
|---|
| 150 | pcont = (MParContainer*)cls->New();
|
|---|
| 151 | AddToList(pcont);
|
|---|
| 152 |
|
|---|
| 153 | //
|
|---|
| 154 | // Find an object in the list.
|
|---|
| 155 | // 'name' is the name of the object you are searching for.
|
|---|
| 156 | //
|
|---|
| 157 | return pcont;
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | void MParList::Print(Option_t *t)
|
|---|
| 161 | {
|
|---|
| 162 | //
|
|---|
| 163 | // print some information about the current status of MParList
|
|---|
| 164 | //
|
|---|
| 165 | *fLog << "ParList: " << this->GetName() << " <" << this->GetTitle() << ">" << endl;
|
|---|
| 166 | *fLog << endl;
|
|---|
| 167 |
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|