Logo ROOT   6.18/05
Reference Guide
TAlienCollection.cxx
Go to the documentation of this file.
1// @(#)root/alien:$Id$
2// Author: Andreas-Joachim Peters 9/5/2005
3
4/*************************************************************************
5 * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12//////////////////////////////////////////////////////////////////////////
13// //
14// TAlienCollection //
15// //
16// Class which manages collection of files on AliEn middleware. //
17// The file collection is in the form of an XML file. //
18// //
19// The internal list is managed as follows: //
20// TList* ===> TMap*(file) ===> TMap*(attributes) //
21// //
22//////////////////////////////////////////////////////////////////////////
23
24#include "TAlienCollection.h"
25#include "TAlienResult.h"
26#include "TAlienFile.h"
27#include "TDSet.h"
28#include "TMap.h"
29#include "TFile.h"
30#include "TXMLEngine.h"
31#include "TObjString.h"
32#include "TEntryList.h"
33#include "TObjArray.h"
34#include "TROOT.h"
35#include "TError.h"
36#include "TFileCollection.h"
37#include "TFileInfo.h"
38#include <cstdlib>
39
41
42////////////////////////////////////////////////////////////////////////////////
43/// Create Alien event collection by reading collection from the specified XML file.
44/// You can restrict the number of importet entries using the maxentries value.
45
46TAlienCollection::TAlienCollection(const char *localcollectionfile,
47 UInt_t maxentries)
48{
49 fXmlFile = localcollectionfile;
50 fFileGroupList = new TList();
53 fCurrent = 0;
54 fNofGroups = 0;
59 fFileStager = 0;
60 fExportUrl = "";
61 fInfoComment = "";
62 fCollectionName = "unnamed";
64 if (localcollectionfile != 0) {
65 ParseXML(maxentries);
66 }
67}
68
69////////////////////////////////////////////////////////////////////////////////
70/// Create Alien event collection using an event list.
71
73 UInt_t nofgroupfiles)
74{
75 fFileGroupList = eventlist;
78 fCurrent = 0;
79 fNofGroups = nofgroups;
80 fNofGroupfiles = nofgroupfiles;
84 fFileStager = 0;
85 fExportUrl = "";
86 fInfoComment = "";
87 fCollectionName = "unnamed";
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// Clean up event file collection.
93
95{
97 delete fFileGroupList;
98
100 delete fFileGroupListIter;
101
102 if (fTagFilterList)
103 delete fTagFilterList;
104}
105
106////////////////////////////////////////////////////////////////////////////////
107/// Static method used to create an Alien event collection, by reading
108/// an XML collection from the specified url. All ROOT URLs are supported.
109/// You can restrict the number of importet entries using the maxentries value
110
111TGridCollection *TAlienCollection::Open(const char *collectionurl,
112 UInt_t maxentries)
113{
114 //! stage the url to gSystem->TempDirectory() for remote url
115
116 TString coll(collectionurl);
117 Bool_t isRemote = coll.Contains(":/") && !coll.Contains("file:");
118 if (isRemote) {
119 TUUID uuid;
120 coll = gSystem->TempDirectory();
121 coll += "/aliencollection.";
122 coll += uuid.AsString();
123 if (!TFile::Cp(collectionurl, coll.Data())) {
124 ::Error("TAlienCollection::Open", "Cannot make a local copy of collection with url %s",
125 collectionurl);
126 return 0;
127 }
128 }
129
130 TAlienCollection *collection =
131 new TAlienCollection(coll, maxentries);
132
133 if (isRemote && gSystem->Unlink(coll.Data())) {
134 ::Error("TAlienCollection::Open", "Cannot remove the local copy of the collection %s",
135 coll.Data());
136 }
137
138 return dynamic_cast <TAlienCollection * > (collection);
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Open the file specified by <filename> from the currently active file group in the collection via its TURL.
143
144TFile *TAlienCollection::OpenFile(const char *filename)
145{
146 const char *turl = GetTURL(filename);
147 if (turl) {
148 return TFile::Open(turl);
149 }
150 return 0;
151}
152
153////////////////////////////////////////////////////////////////////////////////
154/// Static method used to create an Alien event collection, by creating
155/// collection from a TGridResult GetCollection result (TAlien::GetCollection)
156
158 Option_t* /*option*/)
159{
160 if (!queryresult)
161 return 0;
162
163 TList *filelist = new TList();
164
165 TIterator* fileiter = queryresult->MakeIterator();
166 TMap *filemap = 0;
167
168 while ((filemap = ((TMap *) fileiter->Next()))) {
169 if (!filemap->GetValue("origLFN"))
170 continue;
171
172 filemap->Add(new TObjString("lfn"), new TObjString(filemap->GetValue("origLFN")->GetName()));
173 filemap->Add(new TObjString("turl"), new TObjString(Form("alien://%s", filemap->GetValue("origLFN")->GetName())));
174 TString bname = gSystem->BaseName(filemap->GetValue("origLFN")->GetName());
175 filemap->Add(new TObjString("name"), new TObjString(bname.Data()));
176
177 TMap* filegroup = new TMap();
178 filegroup->Add(new TObjString(bname.Data()), filemap);
179 filegroup->Add(new TObjString(""), filemap);
180
181 // store the filegroup
182 filelist->Add(filegroup);
183 }
184 delete fileiter;
185
186 return new TAlienCollection(filelist, filelist->GetEntries(), 1);;
187}
188
189////////////////////////////////////////////////////////////////////////////////
190/// Static method used to create an Alien event collection, by creating
191/// collection from a TGridResult Query result (TAlien::Query)
192/// nogrouping means that files in the same directory are treated as not belonging to a file group
193
195 Bool_t nogrouping)
196{
197 UInt_t nofgroups = 0;
198 UInt_t nofgroupfiles = 0;
199
200 if (!queryresult) {
201 return 0;
202 }
203
204 TIterator *fileiter = queryresult->MakeIterator();
205 TMap *filemap = 0;
206 TString prev_bname = "";
207 TString prev_dname = "";
208 TMap *filegroup = 0;
209
210 TList *filelist = new TList();
211
212 while ((filemap = ((TMap *) fileiter->Next()))) {
213 if (!filemap->GetValue("lfn"))
214 continue;
215 TString dname =
216 gSystem->DirName(filemap->GetValue("lfn")->GetName());
217 TString bname =
218 gSystem->BaseName(filemap->GetValue("lfn")->GetName());
219 filemap->Add(new TObjString("name"), new TObjString(bname.Data()));
220 if ((!nogrouping)
221 && ((bname != prev_bname) && (dname == prev_dname)
222 && (filegroup))) {
223 // add to group
224 filegroup->Add(new TObjString(bname.Data()), filemap);
225 if (nofgroups == 0)
226 nofgroupfiles++;
227 } else {
228 // new group
229 if (filegroup) {
230 // store the old filegroup
231 filelist->Add(filegroup);
232 nofgroups++;
233 }
234 if (nofgroups == 0)
235 nofgroupfiles++;
236 filegroup = new TMap();
237 filegroup->Add(new TObjString(bname.Data()), filemap);
238 filegroup->Add(new TObjString(""), filemap);
239 }
240
241 prev_bname = bname;
242 prev_dname = dname;
243 }
244 if (filegroup) {
245 nofgroups++;
246 filelist->Add(filegroup);
247 }
248 // set tag filter list
249 TList *filterlist = new TList();
250 filterlist->Add(new TObjString("type"));
251 filterlist->Add(new TObjString("dir"));
252 filterlist->Add(new TObjString("perm"));
253 filterlist->Add(new TObjString("owner"));
254 filterlist->Add(new TObjString("ctime"));
255 filterlist->Add(new TObjString("seStringlist"));
256 filterlist->Add(new TObjString("aclId"));
257 filterlist->Add(new TObjString("expiretime"));
258 filterlist->Add(new TObjString("replicated"));
259 filterlist->Add(new TObjString("entryId"));
260 filterlist->Add(new TObjString("gowner"));
261 filterlist->Add(new TObjString("selist"));
262 filterlist->Add(new TObjString("select"));
263 filterlist->Add(new TObjString("online"));
264
265
266 TAlienCollection *newcollection =
267 new TAlienCollection(filelist, nofgroups, nofgroupfiles);
268 if (newcollection) {
269 newcollection->SetTagFilterList(filterlist);
270 }
271 return dynamic_cast <TAlienCollection *> (newcollection);
272}
273
274////////////////////////////////////////////////////////////////////////////////
275/// Reset file iterator.
276
278{
280 fCurrent = 0;
281}
282
283////////////////////////////////////////////////////////////////////////////////
284/// Parse event file collection XML file.
285/// <maxentries> stops the parsing after <maxentries>.
286
288{
289 TXMLEngine xml;
290 UInt_t parsedentries = 0;
291
293 if (!xdoc) {
294 Error("ParseXML", "cannot parse the xml file %s", fXmlFile.Data());
295 return;
296 }
297
298 XMLNodePointer_t xalien = xml.DocGetRootElement(xdoc);
299 if (!xalien) {
300 Error("ParseXML", "cannot find the <alien> tag in %s",
301 fXmlFile.Data());
302 return;
303 }
304
305 XMLNodePointer_t xcollection = xml.GetChild(xalien);
306 if (!xcollection) {
307 Error("ParseXML", "cannot find the <collection> tag in %s",
308 fXmlFile.Data());
309 return;
310 }
311
312 if (xml.GetAttr(xcollection,"name")) {
313 fCollectionName = TString(xml.GetAttr(xcollection,"name"));
314 } else {
315 fCollectionName = ("unnamed");
316 }
317
318 XMLNodePointer_t xevent = xml.GetChild(xcollection);;
319 if (!xevent) {
320 Error("ParseXML", "cannot find the <event> tag in %s",
321 fXmlFile.Data());
322 return;
323 }
324
325 fNofGroups = 0;
326 fNofGroupfiles = 0;
329
330 do {
331 if (TString(xml.GetNodeName(xevent)) == "event") {
332 parsedentries++;
333 fNofGroups++;
334 TMap *files = new TMap();
335
336 // here is our event
337 // printf("Found event: %s\n",xml.GetAttr(xevent,"name"));
338
339 // files
340 XMLNodePointer_t xfile = xml.GetChild(xevent);
341 if (!xfile)
342 continue;
343
344 Bool_t firstfile = kTRUE;
345 do {
346 // here we have an event file
347 // get the attributes;
348 xml.GetAttr(xfile, "lfn");
349 xml.GetAttr(xfile, "turl");
350
351 TMap *attributes = new TMap();
352 TObjString *oname = new TObjString(xml.GetAttr(xfile, "name"));
353 TObjString *oturl = new TObjString(xml.GetAttr(xfile, "turl"));
354 TObjString *olfn = new TObjString(xml.GetAttr(xfile, "lfn"));
355 TObjString *omd5 = new TObjString(xml.GetAttr(xfile, "md5"));
356 TObjString *osize = new TObjString(xml.GetAttr(xfile, "size"));
357 TObjString *oguid = new TObjString(xml.GetAttr(xfile, "guid"));
358 TObjString *osurl = new TObjString(xml.GetAttr(xfile, "surl"));
359 TObjString *osselect =
360 new TObjString(xml.GetAttr(xfile, "select"));
361 TObjString *ossexporturl =
362 new TObjString(xml.GetAttr(xfile, "exporturl"));
363 TObjString *osonline =
364 new TObjString(xml.GetAttr(xfile, "online"));
365
366 TObjString *oseStringlist =
367 new TObjString(xml.GetAttr(xfile, "seStringlist"));
368 TObjString *oevlist =
369 new TObjString(xml.GetAttr(xfile, "evlist"));
370 // if oevlist is defined, we parse it and fill a TEntyList
371 if (oevlist && strlen(oevlist->GetName())) {
372 TEntryList *xmlentrylist =
373 new TEntryList(oturl->GetName(), oguid->GetName());
374 TString stringevlist = oevlist->GetName();
375 TObjArray *evlist = stringevlist.Tokenize(",");
376 for (Int_t n = 0; n < evlist->GetEntries(); n++) {
377 xmlentrylist->
378 Enter(atol
379 (((TObjString *) evlist->At(n))->GetName()));
380 }
381 attributes->Add(new TObjString("evlist"), xmlentrylist);
382 }
383 attributes->Add(new TObjString("name"), oname);
384 attributes->Add(new TObjString("turl"), oturl);
385 attributes->Add(new TObjString("lfn"), olfn);
386 attributes->Add(new TObjString("md5"), omd5);
387 attributes->Add(new TObjString("size"), osize);
388 attributes->Add(new TObjString("guid"), oguid);
389 attributes->Add(new TObjString("seStringlist"), oseStringlist);
390
391 if (osurl && strlen(osurl->GetName())) {
392 attributes->Add(new TObjString("surl"), osurl);
394 }
395 if (osselect && strlen(osselect->GetName())) {
396 attributes->Add(new TObjString("select"), osselect);
398 }
399 if (osonline && strlen(osonline->GetName())) {
400 attributes->Add(new TObjString("online"), osonline);
402 }
403
404 if (ossexporturl && strlen(ossexporturl->GetName())) {
405 attributes->Add(new TObjString("exporturl"), ossexporturl);
406 fExportUrl = ossexporturl->GetName();
407 }
408
409 files->Add(new TObjString(xml.GetAttr(xfile, "name")),
410 attributes);
411
412 // we add the first file always as a file without name to the map
413 if (firstfile) {
414 files->Add(new TObjString(""), attributes);
415 firstfile = kFALSE;
416 }
417 if (fNofGroups == 1)
419 } while ((xfile = xml.GetNext(xfile)));
420 fFileGroupList->Add(files);
421 }
422
423 if (TString(xml.GetNodeName(xevent)) == "info") {
424 if (xml.GetAttr(xevent,"comment")) {
425 fInfoComment = TString(xml.GetAttr(xevent,"comment"));
426 } else {
427 fInfoComment = "";
428 }
429 }
430
431 if (TString(xml.GetNodeName(xevent)) == "export") {
432 if (xml.GetAttr(xevent,"url")) {
433 SetExportUrl(xml.GetAttr(xevent,"url"));
434 } else {
435 fExportUrl = "";
436 }
437 }
438 if (parsedentries >= maxentries)
439 return;
440 } while ((xevent = xml.GetNext(xevent)));
441}
442
443////////////////////////////////////////////////////////////////////////////////
444/// Return next event file map.
445
447{
449 return fCurrent;
450}
451
452////////////////////////////////////////////////////////////////////////////////
453/// Prints statistics, selection and status about the loaded collection.
454
456{
457 TIter *statuslist = new TIter(fFileGroupList);
458 statuslist->Reset();
459 TMap *oldcurrent = fCurrent;
460 TMap *nextgroup = 0;
461 UInt_t gc;
462 UInt_t fc;
463 UInt_t onlinegroups;
464 UInt_t offlinegroups;
465 UInt_t onlinefiles;
466 UInt_t offlinefiles;
467 UInt_t totalfiles;
468 Long64_t totalfilesize;
469 Long64_t onlinefilesize;
470 Long64_t offlinefilesize;
471
472 gc = 0;
473 fc = 0;
474 onlinegroups = offlinegroups = onlinefiles = offlinefiles = totalfiles =
475 totalfilesize = onlinefilesize = offlinefilesize = 0;
476 while ((nextgroup = (TMap *) statuslist->Next())) {
477 gc++;
478 fc = 0;
479 Bool_t online;
480 Bool_t selected;
481 online = kTRUE;
482 selected = kFALSE;
483 TMap *attributes;
484 TIterator *nextfile = nextgroup->MakeIterator();
485 nextfile->Reset();
486 while ((attributes = (TMap *) nextfile->Next())) {
487 fCurrent = nextgroup;
488 if (TString(attributes->GetName()) != "") {
489 totalfiles++;
490 totalfilesize += GetSize(attributes->GetName());
491 }
492 if (IsSelected(attributes->GetName())) {
493 selected = kTRUE;
494 if (TString(attributes->GetName()) != "") {
495 fc++;
496 fCurrent = nextgroup;
497 if (!IsOnline(attributes->GetName())) {
498 online = kFALSE;
499 offlinefiles++;
500 offlinefilesize += GetSize(attributes->GetName());
501 } else {
502 onlinefiles++;
503 onlinefilesize += GetSize(attributes->GetName());
504 }
505 }
506 }
507 }
508 if (selected) {
509 if (online)
510 onlinegroups++;
511 else
512 offlinegroups++;
513 }
514 }
515 fCurrent = oldcurrent;
516 Info("Status", "=========================================");
517 Info("Status", " Tot. Number of files: %u", totalfiles);
518 Info("Status", " Tot. Size: %0.2f GB",
519 totalfilesize / 1024.0 / 1024.0 / 1024.0);
520 Info("Status", " Number of file groups: %u", gc);
521 Info("Status", "Number of files per group: %u", fc);
522 Info("Status", "-----------------------------------------");
523 Info("Status", "Online (staged [selected]):");
524 Info("Status", " Number of file groups: %u", onlinegroups);
525 Info("Status", " Number of files: %u", onlinefiles);
526 Info("Status", " Size: %0.2f GB",
527 onlinefilesize / 1024.0 / 1024.0 / 1024.0);
528 Info("Status", " Fraction avail: %0.2f %%",
529 100.0 * onlinefilesize / (onlinefilesize + offlinefilesize +
530 0.0000001));
531 Info("Status", "-----------------------------------------");
532 Info("Status", "Offline (to be staged [selected]):");
533 Info("Status", " Number of file groups: %u", offlinegroups);
534 Info("Status", " Number of files: %u", offlinefiles);
535 Info("Status", " Size: %0.2f GB",
536 offlinefilesize / 1024.0 / 1024.0 / 1024.0);
537 Info("Status", " Fraction miss: %0.2f %%",
538 100.0 * offlinefilesize / (onlinefilesize + offlinefilesize +
539 0.0000001));
540 Info("Status", "=========================================\n");
541
542 delete statuslist;
543}
544
545////////////////////////////////////////////////////////////////////////////////
546/// Set's a key value pair in a tagmap. If it is existing, the existing tag is overwritten. If not, it is created.
547
548void TAlienCollection::SetTag(const char *tag, const char *value,
549 TMap * tagmap)
550{
551 if ((!tag) || (!value) || (!tagmap)) {
552 return;
553 }
554 TObject *delobject = tagmap->FindObject(tag);
555 if (delobject) {
556 TObject *keyobject = ((TPair *) delobject)->Key();
557 tagmap->Remove(keyobject);;
558 }
559 tagmap->Add(new TObjString(tag), new TObjString(value));
560}
561
562
563////////////////////////////////////////////////////////////////////////////////
564/// Selects all files with name <filename> in the collection
565/// All files can be selected using "*" as filename
566
567Bool_t TAlienCollection::SelectFile(const char *filename, Int_t nstart, Int_t nstop)
568{
569 Int_t cnt=0;
571 Reset();
572 TMap *nextgroup;
573 while ((nextgroup = (TMap *) Next())) {
574 cnt++;
575 TMap *attributes;
576 TIterator *nextfile = nextgroup->MakeIterator();
577 nextfile->Reset();
578 if ( ((nstart == -1 ) && (nstop == -1)) ||
579 ((nstart != -1 ) && (cnt >= nstart) && (nstop == -1)) ||
580 ((nstart != -1 ) && (cnt >= nstart) && (nstop != -1) && (cnt <= nstop)) ||
581 ((nstop != -1 ) && (cnt <= nstop) && (nstart == -1))) {
582 while ((attributes = (TMap *) nextfile->Next())) {
583 if (TString(attributes->GetName()) != "") {
584 if ((TString(attributes->GetName()) == TString(filename)) ||
585 (TString(filename) == TString("*"))) {
586 SetTag("select", "1",
587 ((TMap *) nextgroup->GetValue(attributes->GetName())));
588 }
589 }
590 }
591 }
592 }
593 return kTRUE;
594}
595
596////////////////////////////////////////////////////////////////////////////////
597/// Deselects the file <filename> from the loaded collection
598/// All files can be deselected using "*" as <filename>
599
600Bool_t TAlienCollection::DeselectFile(const char *filename, Int_t nstart, Int_t nstop)
601{
602 Int_t cnt=0;
603 Reset();
604 TMap *nextgroup;
605 while ((nextgroup = (TMap *) Next())) {
606 cnt++;
607 TMap *attributes;
608 TIterator *nextfile = nextgroup->MakeIterator();
609 nextfile->Reset();
610 if ( ((nstart == -1 ) && (nstop == -1)) ||
611 ((nstart != -1 ) && (cnt >= nstart) && (nstop == -1)) ||
612 ((nstart != -1 ) && (cnt >= nstart) && (nstop != -1) && (cnt <= nstop)) ||
613 ((nstop != -1 ) && (cnt <= nstop) && (nstart == -1))) {
614 while ((attributes = (TMap *) nextfile->Next())) {
615 if (TString(attributes->GetName()) != "") {
616 if ((TString(attributes->GetName()) == TString(filename)) ||
617 (TString(filename) == TString("*"))) {
618 SetTag("select", "0",
619 ((TMap *) nextgroup->GetValue(attributes->GetName())));
620 }
621 }
622 }
623 }
624 }
625
626 return kTRUE;
627}
628
629////////////////////////////////////////////////////////////////////////////////
630/// Invert the selection.
631
633{
634 Int_t cnt=0;
636 Reset();
637 TMap *nextgroup;
638 while ((nextgroup = (TMap *) Next())) {
639 cnt++;
640 TMap *attributes;
641 TIterator *nextfile = nextgroup->MakeIterator();
642 nextfile->Reset();
643 while ((attributes = (TMap *) nextfile->Next())) {
644 if (IsSelected(attributes->GetName())) {
645 SetTag("select", "0",
646 ((TMap *) nextgroup->GetValue(attributes->GetName())));
647 } else {
648 SetTag("select", "1",
649 ((TMap *) nextgroup->GetValue(attributes->GetName())));
650 }
651 }
652 }
653 return kTRUE;
654}
655
656////////////////////////////////////////////////////////////////////////////////
657/// downscales the selection with scaler
658
660{
661 Int_t cnt = 0;
662
663 Reset();
664 TMap *nextgroup;
665 while ((nextgroup = (TMap *) Next())) {
666 cnt++;
667 TMap *attributes;
668 TIterator *nextfile = nextgroup->MakeIterator();
669 nextfile->Reset();
670 if (cnt%scaler) {
671 while ((attributes = (TMap *) nextfile->Next())) {
672 if (TString(attributes->GetName()) != "") {
673 SetTag("select", "0",
674 ((TMap *) nextgroup->GetValue(attributes->GetName())));
675 }
676 }
677 }
678 }
679 return kTRUE;
680}
681
682
683////////////////////////////////////////////////////////////////////////////////
684/// Return next event file map.
685
687{
688 if (fFileGroupList->Remove(map)) {
689 return kTRUE;
690 } else {
691 return kFALSE;
692 }
693}
694
695////////////////////////////////////////////////////////////////////////////////
696/// Get a file's transport URL (TURL). Returns 0 in case of error.
697
698const char *TAlienCollection::GetTURL(const char *filename)
699{
700 if (fCurrent) {
701 TMap *obj = (TMap *) fCurrent->GetValue(filename);
702 if (obj) {
703 if (obj->GetValue("turl")) {
704 return (((TObjString *) obj->GetValue("turl"))->GetName());
705 }
706 }
707 }
708 Error("GetTURL", "cannot get TURL of file %s", filename);
709 return 0;
710}
711
712////////////////////////////////////////////////////////////////////////////////
713/// Get a file's storage URL (SURL). Returns 0 in case of error.
714
715const char *TAlienCollection::GetSURL(const char *filename)
716{
717 if (fCurrent) {
718 TMap *obj = (TMap *) fCurrent->GetValue(filename);
719 if (obj) {
720 if (obj->GetValue("surl")) {
721 return (((TObjString *) obj->GetValue("surl"))->GetName());
722 }
723 }
724 }
725 Error("GetSURL", "cannot get SURL of file %s", filename);
726 return 0;
727}
728
729////////////////////////////////////////////////////////////////////////////////
730/// Get a file's online tag. Returns false if not online or CheckIfOnline was never executed, true if online
731
733{
734 if (fCurrent) {
735 TMap *obj = (TMap *) fCurrent->GetValue(filename);
736 if (obj) {
737 if (obj->GetValue("online")) {
738 TString online =
739 (((TObjString *) obj->GetValue("online"))->GetName());
740 if (online == "1") {
741 return kTRUE;
742 } else {
743 return kFALSE;
744 }
745 }
746 }
747 }
748 // Error("IsOnline", "cannot get online tag of file %s", filename);
749 return kFALSE;
750}
751
752////////////////////////////////////////////////////////////////////////////////
753/// Get a file's online tag. Returns false if not online or CheckIfOnline was never executed, true if online
754
756{
757 if (fCurrent) {
758 TMap *obj = (TMap *) fCurrent->GetValue(filename);
759 if (obj) {
760 if (obj->GetValue("select")) {
761 TString selected;
762 selected =
763 (((TObjString *) obj->GetValue("select"))->GetName());
764 if (selected == TString("1")) {
765 return kTRUE;
766 } else {
767 return kFALSE;
768 }
769 }
770 }
771 }
772 return kFALSE;
773}
774
775////////////////////////////////////////////////////////////////////////////////
776/// Get a file's event list. Returns 0 in case of error.
777
779{
780 if (fCurrent) {
781 TMap *obj = (TMap *) fCurrent->GetValue(filename);
782 if (obj) {
783 if (obj->GetValue("evlist")) {
784 return ((TEntryList *) obj->GetValue("evlist"));
785 }
786 }
787 }
788 Error("GetEntryList", "cannot get evelist of file %s", filename);
789 return 0;
790}
791
792////////////////////////////////////////////////////////////////////////////////
793/// Get a file's LFN. Returns 0 in case of error.
794
795const char *TAlienCollection::GetLFN(const char *filename)
796{
797 if (fCurrent) {
798 TMap *obj = (TMap *) fCurrent->GetValue(filename);
799 if (obj) {
800 if (obj->GetValue("lfn")) {
801 return (((TObjString *) obj->GetValue("lfn"))->GetName());
802 }
803 }
804 }
805 Error("GetLFN", "cannot get LFN");
806 return 0;
807}
808
809////////////////////////////////////////////////////////////////////////////////
810/// Get a file's LFN. Returns 0 in case of error.
811
813{
814 if (fCurrent) {
815 TMap *obj = (TMap *) fCurrent->GetValue(filename);
816 if (obj) {
817 if (obj->GetValue("size")) {
818 TString ssize =
819 (((TObjString *) obj->GetValue("size"))->GetName());
820 return ssize.Atoll();
821 }
822 }
823 }
824 Error("GetSize", "cannot get size of %s", filename);
825 return 0;
826}
827
828////////////////////////////////////////////////////////////////////////////////
829/// Print event file collection.
830
832{
833 Info("Print", "dumping %d elements", fFileGroupList->GetSize());
834 TIter next(fFileGroupList);
835 TMap *filemap;
836 Int_t count = 0;
837 while ((filemap = (TMap *) next())) {
838 count++;
839 Info("Print", "printing element %d", count);
840 filemap->Print();
841 }
842}
843
844////////////////////////////////////////////////////////////////////////////////
845/// Return a TDSet from a collection. Filter, Selections and online tags are not
846/// taken into account.
847
848TDSet *TAlienCollection::GetDataset(const char *type, const char *objname,
849 const char *dir)
850{
851 Reset();
852 TDSet *dset = new TDSet(type, objname, dir);
853 if (!dset) {
854 return 0;
855 }
856
857 while (Next()) {
858 if (((TObjString *) fCurrent->GetValue("")))
859 dset->Add(((TMap *) (fCurrent->GetValue("")))->GetValue("turl")->
860 GetName());;
861 }
862 return dset;
863}
864
865////////////////////////////////////////////////////////////////////////////////
866/// Return a TGridResult.
867/// If files have been selected in this collection, only the selected files
868/// are returned. If <onlyonline> is set to kTRUE, only files which are
869/// 'online' (staged) are included. If no online check was done, TGridResult
870/// will be empty. <publicaccess> adds the publicaccess option to the TGridResult entries
871
873 Bool_t onlyonline,
874 Bool_t publicaccess)
875{
876 Reset();
877 TGridResult *result = new TAlienResult();
878
879 while (Next()) {
880 if (((TObjString *) fCurrent->GetValue(filename))) {
881 TMap *attributes = (TMap *) fCurrent->GetValue(filename)->Clone();
882 if (publicaccess) {
883 attributes->Add(new TObjString("options"),
884 new TObjString("&publicaccess=1"));
885 }
886 if ((!fHasSelection) || (IsSelected(filename))) {
887 if ((!onlyonline) || (fHasOnline && IsOnline(filename))) {
888 result->Add(attributes);
889 }
890 }
891 }
892 }
893 return dynamic_cast < TGridResult * >(result);
894}
895
896////////////////////////////////////////////////////////////////////////////////
897/// return kTRUE if comparator overlaps with this
898/// all objects in this collection, which are not defined in the <comparator> collection are removed.
899
901{
902 if ((!comparator)) {
903 return kFALSE;
904 }
905
906loopagain:
907 // loop over col1 and try to find it in col2
908 this->Reset();
909 // loop over all elements in reference (=this)
910 TMap *overlapmap;
911 while ((overlapmap = this->Next())) {
912 comparator->Reset();
913 Bool_t found = kFALSE;
914 // try to find in the comparator collection
915 while ((comparator->Next())) {
916 TString s1 = this->GetLFN();
917 TString s2 = comparator->GetLFN();
918 if (s1 == s2) {
919 found = kTRUE;
920 break;
921 }
922 }
923 if (!found) {
924 this->Remove(overlapmap);
925 goto loopagain;
926 }
927 }
928 return kTRUE;
929}
930
931////////////////////////////////////////////////////////////////////////////////
932/// adds <addcollection> to this collection - equal elements are skipped
933
935{
936 if ((!addcollection)) {
937 return;
938 }
939 // loop over col1 and try to find it in col2
940 addcollection->Reset();
941 // loop over all elements in reference (=this)
942 TMap *addmap;
943 while ((addmap = addcollection->Next())) {
944 Reset();
945 // try to find in the comparator collection
946 TString s2 = addcollection->GetLFN();
947 while (Next()) {
948 TString s1 = GetLFN();
949 // printf("%s = %s\n", s1.Data(), s2.Data());
950 if (s1 == s2) {
951 Error("Add",
952 "File group with lfn %s exists already in this collection - skipping",
953 GetLFN());
954 goto leaveloop;
955 }
956 }
957 TMap *clonemap;
958 clonemap = (TMap *) addmap->Clone();
959 fFileGroupList->Add(clonemap);
960leaveloop:
961 ;
962 }
963}
964
965////////////////////////////////////////////////////////////////////////////////
966/// adds <addcollection> to this collection - NO check for identical elements
967
969{
970 if ((!addcollection)) {
971 return;
972 }
973 addcollection->Reset();
974 TMap *addmap, *clonemap;
975 while ((addmap = addcollection->Next())) {
976 clonemap = (TMap *) addmap->Clone();
977 fFileGroupList->Add(clonemap);
978 }
979}
980
981////////////////////////////////////////////////////////////////////////////////
982/// retrieves all the SURLS for the LFNS
983
985{
986 Bool_t ok = kTRUE;
987 UInt_t lc = 0;
988 Reset();
989 TMap *filemap;
990 while ((filemap = Next())) {
991 // loop over all files in this map
992 TIterator *nextfile = filemap->MakeIterator();
993 TMap *attributes;
994 while ((attributes = (TMap *) nextfile->Next())) {
995 if (TString(attributes->GetName()) != "") {
996 lc++;
997 if (fHasSelection && (!IsSelected(attributes->GetName())))
998 continue;
999 // there is always an "" entry in the map to point to the first file of a file group
1000 if (verbose)
1001 Info("LookupSUrls", "Lookup SURL for %s [%u/%u]",
1002 GetTURL(attributes->GetName()), lc,
1004 TString surl =
1005 TAlienFile::SUrl(GetTURL(attributes->GetName()));
1006 if (!surl.Data()) {
1007 ok = kFALSE;
1008 } else {
1009 // delete the surl map entry, if it exists already
1010 TObject *delobject =
1011 ((TMap *) filemap->GetValue(attributes->GetName()))->
1012 FindObject("surl");
1013 if (delobject) {
1014 TObject *keyobject = ((TPair *) delobject)->Key();
1015 ((TMap *) filemap->GetValue(attributes->GetName()))->
1016 Remove(keyobject);;
1017 }
1018
1019 ((TMap *) filemap->GetValue(attributes->GetName()))->
1020 Add(new TObjString("surl"),
1021 new TObjString(surl.Data()));
1022 if (verbose)
1023 Info("LookupSUrls", "SURL = %s", surl.Data());
1024
1025 }
1026
1027 }
1028 }
1029 }
1030 if (ok) {
1031 fHasSUrls = kTRUE;
1032 }
1033 return ok;
1034}
1035
1036////////////////////////////////////////////////////////////////////////////////
1037/// Execute the 'stage' method for all files in this collection (trigger staging).
1038/// The <bulk> stage method is currently not working.
1039
1041{
1042 if (!fHasSUrls) {
1043 Error("Stage",
1044 "You have to execute LookupSUrls() before you can stage this collection");
1045 return kFALSE;
1046 }
1047 UInt_t fc = 0;
1048 Reset();
1049 TMap *filemap;
1050
1051 if (!bulk) {
1052 while ((filemap = Next())) {
1053 // loop over all files in this map
1054 TIterator *nextfile = filemap->MakeIterator();
1055 TMap *attributes;
1056 while ((attributes = (TMap *) nextfile->Next())) {
1057 if (TString(attributes->GetName()) != "") {
1058 fc++;
1059 if (fHasSelection && (!IsSelected(attributes->GetName())))
1060 continue;
1061
1062 if (!fFileStager) {
1063 fFileStager =
1064 TFileStager::Open(GetSURL(attributes->GetName()));
1065 }
1066 if ((fFileStager)->Stage(GetSURL(attributes->GetName()),option)) {
1067 // file staged
1068 Info("Stage", "[%05u/%05u] <Staged> : %s", fc,
1070 GetLFN(attributes->GetName()));
1071 } else {
1072 // file stage failed
1073 Error("Stage", "[%05u/%05u] <Failed to stage> : %s",
1075 GetLFN(attributes->GetName()));
1076 }
1077 }
1078 }
1079 }
1080 } else {
1081 // bulk request
1082 TList* stagelist = new TList();
1083 stagelist->SetOwner(kTRUE);
1084 Bool_t stageresult=kFALSE;
1085 Reset();
1086 while ((filemap = Next())) {
1087 TIterator *nextfile = filemap->MakeIterator();
1088 TMap *attributes;
1089 while ((attributes = (TMap *) nextfile->Next())) {
1090 if (TString(attributes->GetName()) != "") {
1091 fc++;
1092 stagelist->Add( new TUrl((GetSURL(attributes->GetName()))));
1093 }
1094 }
1095 }
1096
1097 if (fc) {
1098 if (!fFileStager) {
1099 fFileStager = TFileStager::Open(stagelist->First()->GetName());
1100 }
1101
1102 stageresult = (fFileStager)->Stage(stagelist,option);
1103 }
1104 delete stagelist;
1105 return stageresult;
1106 }
1107 return kTRUE;
1108}
1109
1110////////////////////////////////////////////////////////////////////////////////
1111/// Run an online check if files are currently accessible (staged) or offline (to be staged).
1112/// The <bulk> check is currently not working.
1113
1115{
1116 if (!fHasSUrls) {
1117 Error("CheckIfOnline",
1118 "You have to execute LookupSUrls() before you can prepare this collection");
1119 return kFALSE;
1120 }
1121
1122 Reset();
1123 TMap *filemap;
1124 UInt_t fc=0;
1125
1126 if (!bulk) {
1127 while ((filemap = Next())) {
1128 // loop over all files in this map
1129 TIterator *nextfile = filemap->MakeIterator();
1130 TMap *attributes;
1131 while ((attributes = (TMap *) nextfile->Next())) {
1132 if (fHasSelection && (!IsSelected(attributes->GetName())))
1133 continue;
1134 if (TString(attributes->GetName()) != "") {
1135 fc++;
1136 // check if we have a fFileStager
1137 if (!fFileStager) {
1138 fFileStager =
1139 TFileStager::Open(GetSURL(attributes->GetName()));
1140 }
1141 Bool_t online = kFALSE;
1142 if ((fFileStager)->IsStaged(GetSURL(attributes->GetName()))) {
1143 // file is online
1144 Info("CheckIfOnline", "[%05u/%05u] <Online> : %s", fc,
1146 GetLFN(attributes->GetName()));
1147 online = kTRUE;
1148 } else {
1149 // file is offline
1150 Info("CheckIfOnline", "[%05u/%05u]<Offline> : %s", fc,
1152 GetLFN(attributes->GetName()));
1153 online = kFALSE;
1154 }
1155
1156 {
1157 // set the online tag in the collection
1158 // delete the online tag entry, if it exists already
1159 TObject *delobject =
1160 ((TMap *) filemap->GetValue(attributes->GetName()))->
1161 FindObject("online");
1162 if (delobject) {
1163 TObject *keyobject = ((TPair *) delobject)->Key();
1164 ((TMap *) filemap->GetValue(attributes->GetName()))->
1165 Remove(keyobject);;
1166 }
1167 if (online)
1168 ((TMap *) filemap->GetValue(attributes->GetName()))->
1169 Add(new TObjString("online"),
1170 new TObjString("1"));
1171 else
1172 ((TMap *) filemap->GetValue(attributes->GetName()))->
1173 Add(new TObjString("online"),
1174 new TObjString("0"));
1175 }
1176 }
1177 }
1178 }
1179 } else {
1180 // bulk lookup
1181 TList *lookuplist = new TList();
1182 if (lookuplist) {
1183 lookuplist->SetOwner(kTRUE);
1184 while ((filemap = Next())) {
1185 // loop over all files in this map
1186 TIterator *nextfile = filemap->MakeIterator();
1187 TMap *attributes;
1188 while ((attributes = (TMap *) nextfile->Next())) {
1189 if (TString(attributes->GetName()) != "") {
1190 fc++;
1191 // check if we have a fFileStager
1192 if (!fFileStager) {
1193 fFileStager =
1194 TFileStager::Open(GetSURL(attributes->GetName()));
1195 }
1196 lookuplist->
1197 Add(new TObjString(GetSURL(attributes->GetName())));
1198 }
1199 }
1200 }
1201
1202 TList *onlinelist = fFileStager->GetStaged(lookuplist);
1203 if (!onlinelist)
1204 return kFALSE;
1205
1206 Reset();
1207 fc=0;
1208 while ((filemap = Next())) {
1209 // loop over all files in this map
1210 TIterator *nextfile = filemap->MakeIterator();
1211 TMap *attributes;
1212 while ((attributes = (TMap *) nextfile->Next())) {
1213 if (TString(attributes->GetName()) != "") {
1214 fc++;
1215 Bool_t online;
1216 // check if it is in the online list
1217 if (onlinelist->
1218 FindObject(GetSURL(attributes->GetName()))) {
1219 // this file is online
1220 Info("CheckIfOnline", "[%05u/%05u] <Online> : %s", fc,
1222 GetLFN(attributes->GetName()));
1223 online = kTRUE;
1224 } else {
1225 // this file is offline
1226 Info("CheckIfOnline", "[%05u/%05u]<Offline> : %s", fc,
1228 GetLFN(attributes->GetName()));
1229 online = kFALSE;
1230 }
1231
1232 {
1233 // set the online tag in the collection
1234 // delete the online tag entry, if it exists already
1235 TObject *delobject =
1236 ((TMap *) filemap->
1237 GetValue(attributes->GetName()))->
1238 FindObject("online");
1239 if (delobject) {
1240 TObject *keyobject = ((TPair *) delobject)->Key();
1241 ((TMap *) filemap->
1242 GetValue(attributes->GetName()))->
1243 Remove(keyobject);
1244 }
1245 if (online)
1246 ((TMap *) filemap->
1247 GetValue(attributes->GetName()))->
1248 Add(new TObjString("online"), new TObjString("1"));
1249 else
1250 ((TMap *) filemap->
1251 GetValue(attributes->GetName()))->
1252 Add(new TObjString("online"), new TObjString("0"));
1253 }
1254 }
1255 }
1256 }
1257
1258 SafeDelete(onlinelist);
1259 SafeDelete(lookuplist);
1260 } else {
1262 return kFALSE;
1263 }
1264 }
1265
1266 fHasOnline = kTRUE;
1267 return kTRUE;
1268}
1269
1270////////////////////////////////////////////////////////////////////////////////
1271/// Exports the contens of the TAlienCollection into an XML formatted file.
1272/// By default exports only selected files. By default exports only accessible (online) files.
1273/// You can change this behaviour by specifying online=kFALSE or selected=kFALSE.
1274/// <name> specifies a name you want to assign to this collection.
1275/// <comment> can be a user comment to this collection.
1276/// If <exporturl>="" the collection is exported to the URL which was stored inside the collection or
1277/// was specified by the ExportUrl(const char* url) method.
1278
1279Bool_t TAlienCollection::ExportXML(const char *exporturl, Bool_t selected, Bool_t online,
1280 const char *name , const char *comment)
1281{
1282
1283 TFile *exportfile;
1284
1285 if ((exporturl == 0) || (TString(exporturl) == "")) {
1286 if (!(exporturl = GetExportUrl())) {
1287 Error("ExportXML",
1288 "You used the option to store to the collection export url, but this is not defined!");
1289 return kFALSE;
1290 }
1291 }
1292 TUrl expfn(exporturl);
1293 TString options = expfn.GetOptions();
1294 if (options.Length()) {
1295 options += ",filetype=raw";
1296 } else {
1297 options = "filetype=raw";
1298 }
1299 expfn.SetOptions(options.Data());
1300
1301 if (!(exportfile = TFile::Open(expfn.GetUrl(), "RECREATE"))) {
1302 Error("ExportXML", "Cannot open export URL %s", expfn.GetUrl());
1303 return kFALSE;
1304 }
1305
1306 Bool_t expret = ExportXML(exportfile, selected, online, name, comment);
1307 exportfile->Close();
1308 return expret;
1309}
1310
1311////////////////////////////////////////////////////////////////////////////////
1312/// Internal Export function to write a collection as an XML file. See above.
1313
1315 Bool_t online, const char *name,
1316 const char *comment)
1317{
1318 char outline[4096];
1319
1320 // write headers
1321 snprintf(outline,4096,
1322 "<?xml version=\"1.0\"?>\n<alien>\n <collection name=\"%s\">\n",
1323 name);
1324 if ((exportfile->WriteBuffer(outline, strlen(outline)))) {
1325 Error("ExportXML", "Error writing XML to export file");
1326 exportfile->Close();
1327 return kFALSE;
1328 }
1329 // write events
1330 TMap *oldcurrent = fCurrent;
1331 TMap *nextgroup;
1332 TIter *filegroups = new TIter(fFileGroupList);
1333 filegroups->Reset();
1334 UInt_t groupcnt = 0;
1335 while ((nextgroup = (TMap *) filegroups->Next())) {
1336 Bool_t isselected;
1337 isselected = kFALSE;
1338 TMap *attributes;
1339 TIterator *nextfile = nextgroup->MakeIterator();
1340 nextfile->Reset();
1341 // check if something is selected
1342 while ((attributes = (TMap *) nextfile->Next())) {
1343 if (TString(attributes->GetName()) != "") {
1344 fCurrent = nextgroup;
1345 if (IsSelected(attributes->GetName())) {
1346 isselected = kTRUE;
1347 }
1348
1349 }
1350 }
1351 if ((!selected) || isselected) {
1352 // loop again and export files
1353 nextfile->Reset();
1354 groupcnt++;
1355 // open new event header
1356 snprintf(outline,4096, " <event name=\"%d\">\n", groupcnt);
1357 if ((exportfile->WriteBuffer(outline, strlen(outline)))) {
1358 Error("ExportXML", "Error writing XML to export file");
1359 exportfile->Close();
1360 return kFALSE;
1361 }
1362 while ((attributes = (TMap *) nextfile->Next())) {
1363 if (TString(attributes->GetName()) != "") {
1364 fCurrent = nextgroup;
1365 if ((!selected) || (IsSelected(attributes->GetName()))) {
1366 if ((!online) || (IsOnline(attributes->GetName()))) {
1367 // export this file
1368 /////////////////////////////////////////////////////////////
1369 // open file tag
1370 snprintf(outline,4096, " <file ");
1371 if ((exportfile->
1372 WriteBuffer(outline, strlen(outline)))) {
1373 Error("ExportXML",
1374 "Error writing XML to export file");
1375 exportfile->Close();
1376 return kFALSE;
1377 }
1378 // loop over map keys
1379 TIterator *mkeys =
1380 ((TMap *) nextgroup->
1381 GetValue(attributes->GetName()))->MakeIterator();
1382 mkeys->Reset();
1383 TObjString *tagname = 0;
1384 TObjString *tagval = 0;
1385 while ((tagname = (TObjString *) mkeys->Next())) {
1386 Bool_t filtered = kFALSE;
1387 // check for filtered tags from the filter list
1388 if (fTagFilterList) {
1389 TIter next(fTagFilterList);
1390 TObjString *filtertag;
1391 while ((filtertag = (TObjString *) next())) {
1392 if (TString(tagname->GetName()) ==
1393 TString(filtertag->GetName())) {
1394 filtered = kTRUE;
1395 break;
1396 }
1397 }
1398 }
1399 if (!filtered) {
1400 tagval =
1401 (TObjString *) ((TMap *) nextgroup->
1402 GetValue(attributes->
1403 GetName()))->
1404 GetValue(tagname);
1405 if (TString(tagname->GetName()) != "evlist") {
1406 snprintf(outline,4096, "%s=\"%s\" ",
1407 tagname->GetName(),
1408 tagval->GetName());
1409 } else {
1410 // the eventlist has to be converted from TEventList to a string list with komma separation
1411 TEntryList *xmlentrylist =
1412 (TEntryList *) tagval;
1413 if (!xmlentrylist)
1414 continue;
1415 TString slist = "";
1416 for (Int_t i = 0; i < xmlentrylist->GetN(); i++) {
1417 if (i > 0)
1418 slist += ",";
1419 slist += xmlentrylist->GetEntry(i);
1420 }
1421 snprintf(outline,4096, "%s=\"%s\" ",
1422 tagname->GetName(), slist.Data());
1423 }
1424
1425 if ((exportfile->
1426 WriteBuffer(outline, strlen(outline)))) {
1427 Error("ExportXML",
1428 "Error writing XML to export file");
1429 exportfile->Close();
1430 return kFALSE;
1431 }
1432 }
1433 }
1434
1435 // close file tag
1436 snprintf(outline,4096, "/>\n");
1437 if ((exportfile->
1438 WriteBuffer(outline, strlen(outline)))) {
1439 Error("ExportXML",
1440 "Error writing XML to export file");
1441 exportfile->Close();
1442 return kFALSE;
1443 }
1444 }
1445 }
1446 }
1447 }
1448
1449 // close event
1450 snprintf(outline,4096, " </event>\n");
1451 if ((exportfile->WriteBuffer(outline, strlen(outline)))) {
1452 Error("ExportXML", "Error writing XML to export file");
1453 exportfile->Close();
1454 return kFALSE;
1455 }
1456 }
1457 }
1458
1459 fCurrent = oldcurrent;
1460
1461 // write export url if present
1462 if (GetExportUrl()) {
1463 snprintf(outline,4096, " <export url=\"%s\">\n",GetExportUrl());
1464 if ((exportfile->WriteBuffer(outline, strlen(outline)))) {
1465 Error("ExportXML", "Error writing XML to export file");
1466 exportfile->Close();
1467 return kFALSE;
1468 }
1469 }
1470
1471
1472 // write trailer
1473 snprintf(outline,4096,
1474 " <info comment=\"%s\" />\n</collection>\n</alien>\n",
1475 comment);
1476 if ((exportfile->WriteBuffer(outline, strlen(outline)))) {
1477 Error("ExportXML", "Error writing XML to export file");
1478 exportfile->Close();
1479 return kFALSE;
1480 }
1481
1482 delete filegroups;
1483
1484 return kTRUE;
1485}
1486
1487////////////////////////////////////////////////////////////////////////////////
1488/// Set the 'default' export URL for an XML collection. A collection can be restored to the export URL using ExportXML("");
1489
1491{
1492 if (exporturl)
1493 fExportUrl = exporturl;
1494
1495 if (fExportUrl == "") {
1496 Info("ExportUrl",
1497 "There is no remote url defined in this collection");
1498 return kFALSE;
1499 }
1500 return kTRUE;
1501}
1502
1503////////////////////////////////////////////////////////////////////////////////
1504/// Adds to a file given by infile the collection identification , f.e.
1505/// for collection files sitting in directories like 100/1/AliESD.root
1506/// ...
1507/// 110/1/AliESD.root
1508/// "./histo.root" will be converted to "./histo.100_1-110_1.230.root
1509///
1510/// The name syntax is <oldname>.<first run>_<first event>-<last run>.<last event>.<nevents>.root
1511///
1512/// By default the found files are renamed on the local disk
1513/// example:
1514/// - you specify f.e. as arguments GetOutputFileName("*.root",kTRUE);
1515/// --->> this renames all ROOT files corresponding to the collection contents
1516
1517const char *TAlienCollection::GetOutputFileName(const char *infile,
1518 Bool_t rename, const char* suffix)
1519{
1520 Bool_t first = kTRUE;
1521 TString firstrun;
1522 TString firstevent;
1523 TString lastrun;
1524 TString lastevent;
1525 UInt_t nevents = 0;
1526
1527 Reset();
1528 while (Next()) {
1530 TString s2(gSystem->BaseName(s1.Data()));
1531 TString s3(gSystem->DirName(s1.Data()));
1532 TString s4(gSystem->BaseName(s3.Data()));
1533 nevents++;
1534 if (first) {
1535 first = kFALSE;
1536 firstevent = s2;
1537 firstrun = s4;
1538 }
1539 lastevent = s2;
1540 lastrun = s4;
1541 }
1542
1543 // list the matching files
1544 TString pcmd("ls ");
1545 pcmd += infile;
1546 //printf("Pipe is %s\n",pcmd.Data());
1547 FILE *fp = gSystem->OpenPipe(pcmd.Data(), "r");
1548 if (fp) {
1549 char rootfile[4096];
1550 Int_t item;
1551 while ((item = fscanf(fp, "%4095s", rootfile)) == 1) {
1552 TString rootdir(gSystem->DirName(rootfile));
1553 TString rootbase(gSystem->BaseName(rootfile));
1554 TString rootbasenosuffix;
1555 rootbasenosuffix = rootbase(0, rootbase.First('.'));;
1556 // build new name like <oldname>.<firstrun>_<firstevent>-<lastrun>_<lastevent>.root
1557 TString newrootname;
1558 if (rootdir.Length()) {
1559 newrootname += rootdir;
1560 newrootname += "/";
1561 }
1562 newrootname += rootbasenosuffix;
1563 newrootname += ".";
1564 newrootname += firstrun;
1565 newrootname += "_";
1566 newrootname += firstevent;
1567 newrootname += "-";
1568 newrootname += lastrun;
1569 newrootname += "_";
1570 newrootname += lastevent;
1571 newrootname += ".";
1572 newrootname += nevents;
1573 newrootname += ".";
1574 newrootname += suffix;
1575 Info("GetOutputFilename", "Renaming File %s to %s", rootfile,
1576 newrootname.Data());
1577 fLastOutFileName = newrootname;
1578 if (rename) {
1579 gSystem->Rename(rootfile, newrootname.Data());
1580 }
1581 }
1582 gSystem->ClosePipe(fp);
1583 }
1584 return fLastOutFileName.Data();
1585}
1586
1587////////////////////////////////////////////////////////////////////////////////
1588/// creates a TFileCollection objects and fills it with the information from this collection
1589/// note that TFileCollection has a flat structure and no groups --> all files are filles on a flat level
1590/// the TFileInfo of each file in the TFileCollection is filled with turl, size, md5, guid
1591///
1592/// the object has to be deleted by the user
1593
1594TFileCollection *TAlienCollection::GetFileCollection(const char* name, const char* title) const
1595{
1596 TFileCollection* collection = new TFileCollection(name, title);
1597
1598 TIter next(fFileGroupList);
1599 TMap* group = 0;
1600 while ((group = dynamic_cast<TMap*>(next()))) {
1601 TIter next2(group);
1602 TObjString* key = 0;
1603 while ((key = dynamic_cast<TObjString*> (next2()))) {
1604 if (key->String().Length() == 0)
1605 continue;
1606
1607 TMap* file = dynamic_cast<TMap*> (group->GetValue(key));
1608 if (!file)
1609 continue;
1610
1611 TObjString* turl = dynamic_cast<TObjString*> (file->GetValue("turl"));
1612 TObjString* size = dynamic_cast<TObjString*> (file->GetValue("size"));
1613 TObjString* md5 = dynamic_cast<TObjString*> (file->GetValue("md5"));
1614 TObjString* guid = dynamic_cast<TObjString*> (file->GetValue("guid"));
1615
1616 if (!turl || turl->String().Length() == 0)
1617 continue;
1618
1619 TFileInfo* fileInfo = new TFileInfo(turl->String(), size->String().Atoi(), guid->String(), md5->String());
1620 collection->Add(fileInfo);
1621 }
1622 }
1623
1624 collection->Update();
1625
1626 return collection;
1627}
#define SafeDelete(p)
Definition: RConfig.hxx:543
#define s1(x)
Definition: RSha256.hxx:91
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
long long Long64_t
Definition: RtypesCore.h:69
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
#define ClassImp(name)
Definition: Rtypes.h:365
const char rootdir[]
char name[80]
Definition: TGX11.cxx:109
int type
Definition: TGX11.cxx:120
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
Definition: TSystem.h:560
void * XMLNodePointer_t
Definition: TXMLEngine.h:17
void * XMLDocPointer_t
Definition: TXMLEngine.h:20
#define snprintf
Definition: civetweb.c:1540
static struct mg_connection * fc(struct mg_context *ctx)
Definition: civetweb.c:3728
void Print(Option_t *opt) const
Print event file collection.
const char * GetExportUrl()
Bool_t IsSelected(const char *name="")
Get a file's online tag. Returns false if not online or CheckIfOnline was never executed,...
const char * GetLFN(const char *name="")
Get a file's LFN. Returns 0 in case of error.
const char * GetSURL(const char *name="")
Get a file's storage URL (SURL). Returns 0 in case of error.
const char * GetTURL(const char *name="")
Get a file's transport URL (TURL). Returns 0 in case of error.
void Reset()
Reset file iterator.
Bool_t Remove(TMap *map)
Return next event file map.
Bool_t ExportXML(TFile *file, Bool_t selected, Bool_t online, const char *name, const char *comment)
Internal Export function to write a collection as an XML file. See above.
TMap * Next()
Return next event file map.
void Add(TGridCollection *addcollection)
adds <addcollection> to this collection - equal elements are skipped
Bool_t InvertSelection()
Invert the selection.
UInt_t GetNofGroupfiles() const
static TAlienCollection * OpenAlienCollection(TGridResult *queryresult, Option_t *option="")
Static method used to create an Alien event collection, by creating collection from a TGridResult Get...
void Status()
Prints statistics, selection and status about the loaded collection.
Bool_t LookupSUrls(Bool_t verbose=kTRUE)
retrieves all the SURLS for the LFNS
TDSet * GetDataset(const char *type, const char *objname="*", const char *dir="/")
Return a TDSet from a collection.
TString fExportUrl
pointer to the file stager object
Bool_t OverlapCollection(TGridCollection *comparator)
return kTRUE if comparator overlaps with this all objects in this collection, which are not defined i...
static TGridCollection * OpenQuery(TGridResult *queryresult, Bool_t nogrouping=kFALSE)
Static method used to create an Alien event collection, by creating collection from a TGridResult Que...
TFileCollection * GetFileCollection(const char *name="", const char *title="") const
creates a TFileCollection objects and fills it with the information from this collection note that TF...
TFileStager * fFileStager
virtual void ParseXML(UInt_t maxentries)
Parse event file collection XML file.
TMap * fCurrent
event file list iterator
TEntryList * GetEntryList(const char *name)
Get a file's event list. Returns 0 in case of error.
void SetTagFilterList(TList *filterlist)
Bool_t DownscaleSelection(UInt_t scaler=2)
downscales the selection with scaler
TFile * OpenFile(const char *filename)
Open the file specified by <filename> from the currently active file group in the collection via its ...
Long64_t GetSize(const char *name="")
Get a file's LFN. Returns 0 in case of error.
TGridResult * GetGridResult(const char *filename="", Bool_t onlyonline=kTRUE, Bool_t publicaccess=kFALSE)
Return a TGridResult.
static TGridCollection * Open(const char *collectionurl, UInt_t maxentries=1000000)
Static method used to create an Alien event collection, by reading an XML collection from the specifi...
Bool_t DeselectFile(const char *name, Int_t=-1, Int_t=-1)
Deselects the file <filename> from the loaded collection All files can be deselected using "*" as <fi...
UInt_t GetNofGroups() const
UInt_t fNofGroups
current event file map
Bool_t IsOnline(const char *name="")
Get a file's online tag. Returns false if not online or CheckIfOnline was never executed,...
Bool_t SetExportUrl(const char *exporturl=0)
Set the 'default' export URL for an XML collection. A collection can be restored to the export URL us...
void SetTag(const char *tag, const char *value, TMap *tagmap)
Set's a key value pair in a tagmap. If it is existing, the existing tag is overwritten....
const char * GetOutputFileName(const char *infile, Bool_t rename=kTRUE, const char *suffix="root")
Adds to a file given by infile the collection identification , f.e.
Bool_t CheckIfOnline(Bool_t bulk=kFALSE)
Run an online check if files are currently accessible (staged) or offline (to be staged).
virtual ~TAlienCollection()
Clean up event file collection.
Bool_t SelectFile(const char *name, Int_t=-1, Int_t=-1)
Selects all files with name <filename> in the collection All files can be selected using "*" as filen...
TIter * fFileGroupListIter
void AddFast(TGridCollection *addcollection)
adds <addcollection> to this collection - NO check for identical elements
Bool_t Stage(Bool_t bulk=kFALSE, Option_t *option="")
Execute the 'stage' method for all files in this collection (trigger staging).
static TString SUrl(const char *lfn)
Get surl from lfn by asking AliEn catalog.
Definition: TAlienFile.cxx:612
virtual const char * GetName() const
Return name of this collection.
virtual void Print(Option_t *option="") const
Default print for collections, calls Print(option, 1).
virtual Int_t GetEntries() const
Definition: TCollection.h:177
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual TObject * Clone(const char *newname="") const
Make a clone of an collection using the Streamer facility.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
This class implements a data set to be used for PROOF processing.
Definition: TDSet.h:153
virtual Bool_t Add(const char *file, const char *objname=0, const char *dir=0, Long64_t first=0, Long64_t num=-1, const char *msd=0)
Add file to list of files to be analyzed.
Definition: TDSet.cxx:1052
A List of entry numbers in a TTree or TChain.
Definition: TEntryList.h:26
virtual Long64_t GetEntry(Int_t index)
Return the number of the entry #index of this TEntryList in the TTree or TChain See also Next().
Definition: TEntryList.cxx:655
virtual Long64_t GetN() const
Definition: TEntryList.h:75
Class that contains a list of TFileInfo's and accumulated meta data information about its entries.
Int_t Update(Long64_t avgsize=-1)
Update accumulated information about the elements of the collection (e.g.
Int_t Add(TFileInfo *info)
Add TFileInfo to the collection.
Class describing a generic file including meta information.
Definition: TFileInfo.h:38
static TFileStager * Open(const char *stager)
Open a stager, after having loaded the relevant plug-in.
virtual TList * GetStaged(TCollection *pathlist)
Retrieves the staging (online) status for a list of path names.
Definition: TFileStager.cxx:47
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:48
virtual void Close(Option_t *option="")
Close a file.
Definition: TFile.cxx:914
virtual Bool_t WriteBuffer(const char *buf, Int_t len)
Write a buffer to the file.
Definition: TFile.cxx:2377
virtual Bool_t Cp(const char *dst, Bool_t progressbar=kTRUE, UInt_t buffersize=1000000)
Allows to copy this file to the dst URL.
Definition: TFile.cxx:4876
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseGeneralPurpose, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3980
virtual TMap * Next()
virtual const char * GetLFN(const char *="")
virtual void Reset()
TObject * Next()
Definition: TCollection.h:249
void Reset()
Definition: TCollection.h:252
Iterator abstract base class.
Definition: TIterator.h:30
virtual void Reset()=0
virtual TObject * Next()=0
A doubly linked list.
Definition: TList.h:44
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:819
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const
Return a list iterator.
Definition: TList.cxx:719
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:656
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Definition: TMap.h:40
TIterator * MakeIterator(Bool_t dir=kIterForward) const
Create an iterator for TMap.
Definition: TMap.cxx:257
void Add(TObject *obj)
This function may not be used (but we need to provide it since it is a pure virtual in TCollection).
Definition: TMap.cxx:53
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
Definition: TMap.cxx:235
TObject * FindObject(const char *keyname) const
Check if a (key,value) pair exists with keyname as name of the key.
Definition: TMap.cxx:214
TObject * Remove(TObject *key)
Remove the (key,value) pair with key from the map.
Definition: TMap.cxx:295
An array of TObjects.
Definition: TObjArray.h:37
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:522
TObject * At(Int_t idx) const
Definition: TObjArray.h:166
Collectable string class.
Definition: TObjString.h:28
const char * GetName() const
Returns name of object.
Definition: TObjString.h:38
TString & String()
Definition: TObjString.h:48
Mother of all ROOT objects.
Definition: TObject.h:37
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:357
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:144
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition: TObject.cxx:321
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:854
Class used by TMap to store (key,value) pairs.
Definition: TMap.h:102
Basic string class.
Definition: TString.h:131
Ssiz_t Length() const
Definition: TString.h:405
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1921
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition: TString.cxx:499
const char * Data() const
Definition: TString.h:364
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Definition: TString.cxx:2197
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:619
Long64_t Atoll() const
Return long long value of string.
Definition: TString.cxx:1947
virtual const char * DirName(const char *pathname)
Return the directory name in pathname.
Definition: TSystem.cxx:1013
virtual FILE * OpenPipe(const char *command, const char *mode)
Open a pipe.
Definition: TSystem.cxx:671
virtual int Rename(const char *from, const char *to)
Rename a file.
Definition: TSystem.cxx:1340
virtual int ClosePipe(FILE *pipe)
Close the pipe.
Definition: TSystem.cxx:680
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:941
virtual int Unlink(const char *name)
Unlink, i.e.
Definition: TSystem.cxx:1371
virtual const char * TempDirectory() const
Return a user configured or systemwide directory to create temporary files in.
Definition: TSystem.cxx:1472
This class defines a UUID (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDent...
Definition: TUUID.h:42
const char * AsString() const
Return UUID as string. Copy string immediately since it will be reused.
Definition: TUUID.cxx:560
This class represents a WWW compatible URL.
Definition: TUrl.h:35
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:385
void SetOptions(const char *opt)
Definition: TUrl.h:90
const char * GetOptions() const
Definition: TUrl.h:74
XMLNodePointer_t GetChild(XMLNodePointer_t xmlnode, Bool_t realnode=kTRUE)
returns first child of xmlnode
XMLNodePointer_t DocGetRootElement(XMLDocPointer_t xmldoc)
returns root node of document
const char * GetNodeName(XMLNodePointer_t xmlnode)
returns name of xmlnode
const char * GetAttr(XMLNodePointer_t xmlnode, const char *name)
returns value of attribute for xmlnode
Definition: TXMLEngine.cxx:549
XMLDocPointer_t ParseFile(const char *filename, Int_t maxbuf=100000)
Parses content of file and tries to produce xml structures.
XMLNodePointer_t GetNext(XMLNodePointer_t xmlnode, Bool_t realnode=kTRUE)
return next to xmlnode node if realnode==kTRUE, any special nodes in between will be skipped
const Int_t n
Definition: legend1.C:16
Definition: file.py:1
Definition: first.py:1
const char * cnt
Definition: TXMLSetup.cxx:74