#include <DataBucket.h>
Public Member Functions | |
| DataBucket (TFolder *top) | |
| template<class T> int | Get (const char *path, std::vector< const T * > &v) const |
| template<class T> T * | Put (const T &obj, const char *path, int opt=kFixedSizeObject) |
| template<class T> int | PutArray (const T *obj, const char *path, int nObj, int opt=kFixedSizeObject) |
| template<class T> int | PutVector (const std::vector< T * > &obj, const char *path, int opt=kFixedSizeObject) |
| void | List (const char *opt="*") const |
| TFolder * | GetFolder (const char *path) const |
| TClonesArray * | GetClonesArray (const char *path) const |
| TObjArray * | GetObjArray (const char *path) const |
| void | ClearArrays (const TFolder *f=0) |
| TFolder * | MakeFolder (const char *path) |
| int | MakeFolders (const char *dirs[]) |
| int | Remove (const char *path) |
Static Public Attributes | |
| const int | kFixedSizeObject = 0x01 |
| Obsolete for ROOT>5.00. | |
| const int | kVariableSizeObject = 0x02 |
| Obsolete for ROOT>5.00. | |
Private Member Functions | |
| TClonesArray * | NewClonesArray (const char *path, const char *classname) |
| TObjArray * | NewObjArray (const char *path, const char *classname) |
Static Private Member Functions | |
| void | ListFolder (const TFolder &f, int lvl) |
| void | Split (const char *path, char *dir, char *base) |
Private Attributes | |
| TFolder * | fTopFolder |
| Folder managed. Not owned. | |
Definition at line 22 of file DataBucket.h.
|
|
Construct a data bucket to manage the folder "top"
Definition at line 23 of file DataBucket.cxx.
00023 : fTopFolder(f) { } |
|
|
Clear the contents of all containers located at and below a folder.
Definition at line 262 of file DataBucket.cxx. References fTopFolder. Referenced by edm::Event::Clear(), and edm::EventHandle::~EventHandle().
00263 {
00264 if (f==0) f = fTopFolder;
00265 TCollection* folders = f->GetListOfFolders();
00266 TIterator* iter = folders->MakeIterator();
00267 TObject* obj = 0;
00268 TFolder* fobj = 0;
00269 TClonesArray* carr = 0;
00270 TObjArray* oarr = 0;
00271 while ( (obj=iter->Next())!=0) {
00272 fobj = dynamic_cast<TFolder*>(obj);
00273 carr = dynamic_cast<TClonesArray*>(obj);
00274 oarr = dynamic_cast<TObjArray*>(obj);
00275 if (fobj) this->ClearArrays(fobj);
00276 if (carr) carr->Clear("C");
00277 if (oarr) oarr->Clear("C");
00278 }
00279 delete iter;
00280 }
|
|
||||||||||||||||
|
Retrieve all objects located in the bucket at a specific path.
In the first case, the collection name is guessed based on the class name. So for example, a Get(path,v) where v is a vector of objects of type 'DataObject' and "path=./directory" will retrieve the collection "./directory/DataObjects". This is the simplest method if no casting of object type is required. A code fragement for this example follows:
|
|
|
Return the object array stored at 'path'
Definition at line 99 of file DataBucket.cxx. References GetFolder(), and Split(). Referenced by Get(), Put(), PutArray(), and PutVector().
00100 {
00101 char pathto [strlen(path)+1];
00102 char objarray[strlen(path)+1];
00103 edm::DataBucket::Split(path, pathto, objarray);
00104
00105 TFolder* f = this->GetFolder(pathto);
00106 if (f==0) return 0;
00107
00108 TObject* obj = f->FindObjectAny(objarray);
00109 TClonesArray* carray = dynamic_cast<TClonesArray*>(obj);
00110
00111 return carray;
00112 }
|
|
|
Return the TFolder stored at 'path'
Definition at line 143 of file DataBucket.cxx. References fTopFolder, and Split(). Referenced by GetClonesArray(), GetObjArray(), MakeFolder(), NewClonesArray(), and NewObjArray().
00144 {
00145 // Check if we've been asked for the top folder
00146 if (strcmp("", path) == 0) { return fTopFolder; }
00147 if (strcmp(".", path) == 0) { return fTopFolder; }
00148 if (strcmp("/", path) == 0) { return fTopFolder; }
00149
00150 char pathto[strlen(path)+1];
00151 char folder[strlen(path)+1];
00152 edm::DataBucket::Split(path, pathto, folder);
00153
00154 TFolder* f1 = this->GetFolder(pathto);
00155 if (f1==0) return 0;
00156
00157 TFolder* f2 = dynamic_cast<TFolder*>(f1->FindObjectAny(folder));
00158 return f2;
00159 }
|
|
|
Return the object array stored at 'path'
Definition at line 121 of file DataBucket.cxx. References GetFolder(), and Split(). Referenced by Get(), Put(), PutArray(), and PutVector().
00122 {
00123 char pathto[strlen(path)];
00124 char objarray[strlen(path)];
00125 edm::DataBucket::Split(path, pathto, objarray);
00126
00127 TFolder* f = this->GetFolder(pathto);
00128 if (f==0) return 0;
00129
00130 TObject* obj = f->FindObjectAny(objarray);
00131 TObjArray* oarray = dynamic_cast<TObjArray*>(obj);
00132
00133 return oarray;
00134 }
|
|
|
List the entire contents of the data bucket on the screen.
Definition at line 246 of file DataBucket.cxx. References fTopFolder, and ListFolder(). Referenced by main(), edm::Event::Print(), testMakeOne(), and testWrite().
00247 {
00248 if (!opt) std::cout << "Listing folder with no option." << std::endl;
00249 edm::DataBucket::ListFolder(*fTopFolder, 1);
00250 }
|
|
||||||||||||
|
Print the contents of the folder to the screen
Definition at line 211 of file DataBucket.cxx. Referenced by List().
00212 {
00213 std::string pad;
00214 for (int i=0; i<lvl-1; ++i) pad += " ";
00215 if (lvl>0) pad += "|-";
00216 pad += "* ";
00217
00218 TCollection* folders = f.GetListOfFolders();
00219 TIterator* iter = folders->MakeIterator();
00220 TObject* obj = 0;
00221 TFolder* fobj = 0;
00222 TObjArray* aobj = 0;
00223 while ( (obj=iter->Next())!=0) {
00224 fobj = dynamic_cast<TFolder*>(obj);
00225 aobj = dynamic_cast<TObjArray*>(obj);
00226 if (fobj) {
00227 std::string pad2(pad);
00228 pad2 += fobj->GetName();
00229 std::cout << pad2 << "\n";
00230 edm::DataBucket::ListFolder(*fobj, lvl+1);
00231 }
00232 if (aobj) {
00233 std::cout << pad <<
00234 obj->GetName() << "[" << aobj->GetEntries() << "]\n";
00235 }
00236 }
00237 delete iter;
00238 }
|
|
|
Create ad configure a new folder at the absolute path name "path".
Definition at line 34 of file DataBucket.cxx. References GetFolder(), and Split(). Referenced by main(), MakeFolders(), testMakeOne(), and testWrite().
00035 {
00036 if (!path) return 0;
00037
00038 TFolder* f = 0;
00039 f = this->GetFolder(path);
00040 if (f!=0) return f;
00041
00042 char pathto[strlen(path)+1];
00043 char newdir[strlen(path)+1];
00044 edm::DataBucket::Split(path, pathto, newdir);
00045
00046 // Find the mother folder and add the daughter
00047 f = this->GetFolder(pathto);
00048 if (f==0) return 0;
00049 f->SetOwner(kTRUE);
00050 TFolder* newFolder = f->AddFolder(newdir, newdir, 0);
00051 newFolder->SetOwner(kTRUE);
00052
00053 return newFolder;
00054 }
|
|
|
Make a collection of folders all at once given a list of names.
Definition at line 70 of file DataBucket.cxx. References MakeFolder(). Referenced by main().
00071 {
00072 int n = 0;
00073 for (int i=0; dirs[i]!=0; ++i) {
00074 TFolder* f = this->MakeFolder(dirs[i]);
00075 if (f!=0) ++n;
00076 }
00077 return n;
00078 }
|
|
||||||||||||
|
Create a new TClonesArray at a specific location
Definition at line 169 of file DataBucket.cxx. References GetFolder(). Referenced by Put(), PutArray(), and PutVector().
00171 {
00172 TFolder* f = this->GetFolder(path);
00173 if (f==0) return 0;
00174
00175 TClonesArray* c = new TClonesArray(classname);
00176 f->Add(c);
00177
00178 return c;
00179 }
|
|
||||||||||||
|
Create a new TObjArray at a specific location
Definition at line 189 of file DataBucket.cxx. References GetFolder(). Referenced by Put(), PutArray(), and PutVector().
00191 {
00192 TFolder* f = this->GetFolder(path);
00193 if (f==0) return 0;
00194 std::string name;
00195 name = classname;
00196 name += "s";
00197 TObjArray* c = new TObjArray(100,0);
00198 c->SetOwner();
00199 c->SetName(name.c_str());
00200 f->Add(c);
00201 return c;
00202 }
|
|
||||||||||||||||||||
|
Place a copy of an object into the data store
|
|
||||||||||||||||||||||||
|
Place an array of objects into the data store.
Definition at line 244 of file DataBucket.h. References GetClonesArray(), GetObjArray(), kFixedSizeObject, kVariableSizeObject, NewClonesArray(), NewObjArray(), and edm::NO_FOLDER_FOUND.
00246 {
00247 static std::string collectName;
00248 static std::string fullPath;
00249 int indx;
00250 register int i;
00251
00252 collectName = obj[0].ClassName();
00253 fullPath = path;
00254 fullPath += "/";
00255 fullPath += collectName;
00256 fullPath += "s";
00257
00258 if (opt & kFixedSizeObject) {
00259 TClonesArray *c = this->GetClonesArray(fullPath.c_str());
00260 if (c == 0) {
00261 // No collection of this type of object. Make a new collection
00262 if ((c = this->NewClonesArray(path, collectName.c_str())) == 0) {
00263 std::cerr << "edm::DataBucket: no folder " << path << " found"
00264 << std::endl;
00265 throw Exception(__FILE__,__LINE__,NO_FOLDER_FOUND);
00266 }
00267 }
00268
00269 // Create new object of type T in event store. The "new with
00270 // placement" is a signature of the TClonesArray container
00271 assert(c != 0); // By this time we must have a home for the object
00272 indx = c->GetLast() + 1;
00273 const T* objPtr = obj;
00274 for (i = 0; i < nObj; ++i) {
00275 new ((*c)[indx++]) T(*objPtr++);
00276 }
00277 return indx; // Add OK
00278 }
00279
00280 if (opt & kVariableSizeObject) {
00281 TObjArray* c = this->GetObjArray(fullPath.c_str());
00282 if (c == 0) {
00283 // No collection of this type of object. Make a new collection
00284 if ((c = this->NewObjArray(path, collectName.c_str())) == 0) {
00285 std::cerr << "edm::DataBucket: no folder " << path << " found"
00286 << std::endl;
00287 throw Exception(__FILE__,__LINE__,NO_FOLDER_FOUND);
00288 }
00289 }
00290
00291 // Create new object of type T in event store.
00292 assert(c!=0); // By this time we must have a home for the object
00293 for (i = 0; i < nObj; ++i) {
00294 c->AddLast(new T(obj[i]));
00295 }
00296 return c->GetLast(); // Add OK
00297 }
00298
00299 return 0;
00300 }
|
|
||||||||||||||||||||
|
Place a vector of objects into the data store.
Definition at line 315 of file DataBucket.h. References GetClonesArray(), GetObjArray(), kFixedSizeObject, kVariableSizeObject, NewClonesArray(), NewObjArray(), and edm::NO_FOLDER_FOUND.
00317 {
00318 static std::string collectName;
00319 static std::string fullPath;
00320 int indx;
00321
00322 if (vec.empty()) return 0;
00323
00324 unsigned int vecSize = vec.size();
00325
00326 // This doesn't seem to work for some reason...
00327 // std::vector<const T*>::const_iterator itr(vec.begin());
00328 // std::vector<const T*>::const_iterator itrEnd(vec.end());
00329
00330 collectName = vec[0]->ClassName();
00331 fullPath = path;
00332 fullPath += "/";
00333 fullPath += collectName;
00334 fullPath += "s";
00335
00336 if (opt & kFixedSizeObject) {
00337 TClonesArray *c = this->GetClonesArray(fullPath.c_str());
00338 if (c == 0) {
00339 // No collection of this type of object. Make a new collection
00340 if ((c = this->NewClonesArray(path, collectName.c_str())) == 0) {
00341 std::cerr << "edm::DataBucket: no folder " << path << " found"
00342 << std::endl;
00343 throw Exception(__FILE__,__LINE__,NO_FOLDER_FOUND);
00344 }
00345 }
00346
00347 // Create new object of type T in event store. The "new with
00348 // placement" is a signature of the TClonesArray container
00349 assert(c != 0); // By this time we must have a home for the object
00350 indx = c->GetLast() + 1;
00351 for (unsigned int i = 0; i < vecSize; ++i) {// ; itr != itrEnd; ++itr) {
00352 new ((*c)[indx++]) T(*vec[i]);
00353 }
00354 return indx; // Add OK
00355 }
00356
00357 if (opt & kVariableSizeObject) {
00358 TObjArray* c = this->GetObjArray(fullPath.c_str());
00359 if (c == 0) {
00360 // No collection of this type of object. Make a new collection
00361 if ((c = this->NewObjArray(path, collectName.c_str())) == 0) {
00362 std::cerr << "edm::DataBucket: no folder " << path << " found"
00363 << std::endl;
00364 throw Exception(__FILE__,__LINE__,NO_FOLDER_FOUND);
00365 }
00366 }
00367
00368 // Create new object of type T in event store.
00369 assert(c!=0); // By this time we must have a home for the object
00370 for (unsigned int i = 0; i < vecSize; ++i) {//; itr != itrEnd; ++itr)
00371 c->AddLast(new T(*vec[i]));
00372 }
00373 return c->GetLast(); // Add OK
00374 }
00375
00376 return 0;
00377 }
|
|
|
Remove the collection and/or folder indicated by path
Definition at line 86 of file DataBucket.cxx.
00087 {
00088 if (path==0) return 0;
00089 else return 0;
00090 }
|
|
||||||||||||||||
|
Split a complete path name into two pieces, the target and the path to the target: /full/path/to/target -> /full/path/to, target
Definition at line 291 of file DataBucket.cxx. Referenced by GetClonesArray(), GetFolder(), GetObjArray(), and MakeFolder().
00292 {
00293 char cpy1[strlen(fullpath)+1];
00294 strcpy(cpy1,fullpath);
00295 strcpy(pathto, dirname(cpy1));
00296
00297 char cpy2[strlen(fullpath)+1];
00298 strcpy(cpy2,fullpath);
00299 strcpy(obj, basename(cpy2));
00300 }
|
|
|
Folder managed. Not owned.
Definition at line 59 of file DataBucket.h. Referenced by ClearArrays(), GetFolder(), and List(). |
|
|
Obsolete for ROOT>5.00.
Definition at line 24 of file DataBucket.h. Referenced by Put(), PutArray(), and PutVector(). |
|
|
Obsolete for ROOT>5.00.
Definition at line 25 of file DataBucket.h. Referenced by Put(), PutArray(), and PutVector(). |
1.3.5