Logo ROOT  
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->GetDirName(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 SafeDelete(lookuplist);
1205 return kFALSE;
1206 }
1207
1208 Reset();
1209 fc=0;
1210 while ((filemap = Next())) {
1211 // loop over all files in this map
1212 TIterator *nextfile = filemap->MakeIterator();
1213 TMap *attributes;
1214 while ((attributes = (TMap *) nextfile->Next())) {
1215 if (TString(attributes->GetName()) != "") {
1216 fc++;
1217 Bool_t online;
1218 // check if it is in the online list
1219 if (onlinelist->
1220 FindObject(GetSURL(attributes->GetName()))) {
1221 // this file is online
1222 Info("CheckIfOnline", "[%05u/%05u] <Online> : %s", fc,
1224 GetLFN(attributes->GetName()));
1225 online = kTRUE;
1226 } else {
1227 // this file is offline
1228 Info("CheckIfOnline", "[%05u/%05u]<Offline> : %s", fc,
1230 GetLFN(attributes->GetName()));
1231 online = kFALSE;
1232 }
1233
1234 {
1235 // set the online tag in the collection
1236 // delete the online tag entry, if it exists already
1237 TObject *delobject =
1238 ((TMap *) filemap->
1239 GetValue(attributes->GetName()))->
1240 FindObject("online");
1241 if (delobject) {
1242 TObject *keyobject = ((TPair *) delobject)->Key();
1243 ((TMap *) filemap->
1244 GetValue(attributes->GetName()))->
1245 Remove(keyobject);
1246 }
1247 if (online)
1248 ((TMap *) filemap->
1249 GetValue(attributes->GetName()))->
1250 Add(new TObjString("online"), new TObjString("1"));
1251 else
1252 ((TMap *) filemap->
1253 GetValue(attributes->GetName()))->
1254 Add(new TObjString("online"), new TObjString("0"));
1255 }
1256 }
1257 }
1258 }
1259
1260 SafeDelete(onlinelist);
1261 SafeDelete(lookuplist);
1262 } else {
1264 return kFALSE;
1265 }
1266 }
1267
1268 fHasOnline = kTRUE;
1269 return kTRUE;
1270}
1271
1272////////////////////////////////////////////////////////////////////////////////
1273/// Exports the contens of the TAlienCollection into an XML formatted file.
1274/// By default exports only selected files. By default exports only accessible (online) files.
1275/// You can change this behaviour by specifying online=kFALSE or selected=kFALSE.
1276/// <name> specifies a name you want to assign to this collection.
1277/// <comment> can be a user comment to this collection.
1278/// If <exporturl>="" the collection is exported to the URL which was stored inside the collection or
1279/// was specified by the ExportUrl(const char* url) method.
1280
1281Bool_t TAlienCollection::ExportXML(const char *exporturl, Bool_t selected, Bool_t online,
1282 const char *name , const char *comment)
1283{
1284
1285 TFile *exportfile;
1286
1287 if ((exporturl == 0) || (TString(exporturl) == "")) {
1288 if (!(exporturl = GetExportUrl())) {
1289 Error("ExportXML",
1290 "You used the option to store to the collection export url, but this is not defined!");
1291 return kFALSE;
1292 }
1293 }
1294 TUrl expfn(exporturl);
1295 TString options = expfn.GetOptions();
1296 if (options.Length()) {
1297 options += ",filetype=raw";
1298 } else {
1299 options = "filetype=raw";
1300 }
1301 expfn.SetOptions(options.Data());
1302
1303 if (!(exportfile = TFile::Open(expfn.GetUrl(), "RECREATE"))) {
1304 Error("ExportXML", "Cannot open export URL %s", expfn.GetUrl());
1305 return kFALSE;
1306 }
1307
1308 Bool_t expret = ExportXML(exportfile, selected, online, name, comment);
1309 exportfile->Close();
1310 return expret;
1311}
1312
1313////////////////////////////////////////////////////////////////////////////////
1314/// Internal Export function to write a collection as an XML file. See above.
1315
1317 Bool_t online, const char *name,
1318 const char *comment)
1319{
1320 char outline[4096];
1321
1322 // write headers
1323 snprintf(outline,4096,
1324 "<?xml version=\"1.0\"?>\n<alien>\n <collection name=\"%s\">\n",
1325 name);
1326 if ((exportfile->WriteBuffer(outline, strlen(outline)))) {
1327 Error("ExportXML", "Error writing XML to export file");
1328 exportfile->Close();
1329 return kFALSE;
1330 }
1331 // write events
1332 TMap *oldcurrent = fCurrent;
1333 TMap *nextgroup;
1334 TIter *filegroups = new TIter(fFileGroupList);
1335 filegroups->Reset();
1336 UInt_t groupcnt = 0;
1337 while ((nextgroup = (TMap *) filegroups->Next())) {
1338 Bool_t isselected;
1339 isselected = kFALSE;
1340 TMap *attributes;
1341 TIterator *nextfile = nextgroup->MakeIterator();
1342 nextfile->Reset();
1343 // check if something is selected
1344 while ((attributes = (TMap *) nextfile->Next())) {
1345 if (TString(attributes->GetName()) != "") {
1346 fCurrent = nextgroup;
1347 if (IsSelected(attributes->GetName())) {
1348 isselected = kTRUE;
1349 }
1350
1351 }
1352 }
1353 if ((!selected) || isselected) {
1354 // loop again and export files
1355 nextfile->Reset();
1356 groupcnt++;
1357 // open new event header
1358 snprintf(outline,4096, " <event name=\"%d\">\n", groupcnt);
1359 if ((exportfile->WriteBuffer(outline, strlen(outline)))) {
1360 Error("ExportXML", "Error writing XML to export file");
1361 exportfile->Close();
1362 return kFALSE;
1363 }
1364 while ((attributes = (TMap *) nextfile->Next())) {
1365 if (TString(attributes->GetName()) != "") {
1366 fCurrent = nextgroup;
1367 if ((!selected) || (IsSelected(attributes->GetName()))) {
1368 if ((!online) || (IsOnline(attributes->GetName()))) {
1369 // export this file
1370 /////////////////////////////////////////////////////////////
1371 // open file tag
1372 snprintf(outline,4096, " <file ");
1373 if ((exportfile->
1374 WriteBuffer(outline, strlen(outline)))) {
1375 Error("ExportXML",
1376 "Error writing XML to export file");
1377 exportfile->Close();
1378 return kFALSE;
1379 }
1380 // loop over map keys
1381 TIterator *mkeys =
1382 ((TMap *) nextgroup->
1383 GetValue(attributes->GetName()))->MakeIterator();
1384 mkeys->Reset();
1385 TObjString *tagname = 0;
1386 TObjString *tagval = 0;
1387 while ((tagname = (TObjString *) mkeys->Next())) {
1388 Bool_t filtered = kFALSE;
1389 // check for filtered tags from the filter list
1390 if (fTagFilterList) {
1391 TIter next(fTagFilterList);
1392 TObjString *filtertag;
1393 while ((filtertag = (TObjString *) next())) {
1394 if (TString(tagname->GetName()) ==
1395 TString(filtertag->GetName())) {
1396 filtered = kTRUE;
1397 break;
1398 }
1399 }
1400 }
1401 if (!filtered) {
1402 tagval =
1403 (TObjString *) ((TMap *) nextgroup->
1404 GetValue(attributes->
1405 GetName()))->
1406 GetValue(tagname);
1407 if (TString(tagname->GetName()) != "evlist") {
1408 snprintf(outline,4096, "%s=\"%s\" ",
1409 tagname->GetName(),
1410 tagval->GetName());
1411 } else {
1412 // the eventlist has to be converted from TEventList to a string list with komma separation
1413 TEntryList *xmlentrylist =
1414 (TEntryList *) tagval;
1415 if (!xmlentrylist)
1416 continue;
1417 TString slist = "";
1418 for (Int_t i = 0; i < xmlentrylist->GetN(); i++) {
1419 if (i > 0)
1420 slist += ",";
1421 slist += xmlentrylist->GetEntry(i);
1422 }
1423 snprintf(outline,4096, "%s=\"%s\" ",
1424 tagname->GetName(), slist.Data());
1425 }
1426
1427 if ((exportfile->
1428 WriteBuffer(outline, strlen(outline)))) {
1429 Error("ExportXML",
1430 "Error writing XML to export file");
1431 exportfile->Close();
1432 return kFALSE;
1433 }
1434 }
1435 }
1436
1437 // close file tag
1438 snprintf(outline,4096, "/>\n");
1439 if ((exportfile->
1440 WriteBuffer(outline, strlen(outline)))) {
1441 Error("ExportXML",
1442 "Error writing XML to export file");
1443 exportfile->Close();
1444 return kFALSE;
1445 }
1446 }
1447 }
1448 }
1449 }
1450
1451 // close event
1452 snprintf(outline,4096, " </event>\n");
1453 if ((exportfile->WriteBuffer(outline, strlen(outline)))) {
1454 Error("ExportXML", "Error writing XML to export file");
1455 exportfile->Close();
1456 return kFALSE;
1457 }
1458 }
1459 }
1460
1461 fCurrent = oldcurrent;
1462
1463 // write export url if present
1464 if (GetExportUrl()) {
1465 snprintf(outline,4096, " <export url=\"%s\">\n",GetExportUrl());
1466 if ((exportfile->WriteBuffer(outline, strlen(outline)))) {
1467 Error("ExportXML", "Error writing XML to export file");
1468 exportfile->Close();
1469 return kFALSE;
1470 }
1471 }
1472
1473
1474 // write trailer
1475 snprintf(outline,4096,
1476 " <info comment=\"%s\" />\n</collection>\n</alien>\n",
1477 comment);
1478 if ((exportfile->WriteBuffer(outline, strlen(outline)))) {
1479 Error("ExportXML", "Error writing XML to export file");
1480 exportfile->Close();
1481 return kFALSE;
1482 }
1483
1484 delete filegroups;
1485
1486 return kTRUE;
1487}
1488
1489////////////////////////////////////////////////////////////////////////////////
1490/// Set the 'default' export URL for an XML collection. A collection can be restored to the export URL using ExportXML("");
1491
1493{
1494 if (exporturl)
1495 fExportUrl = exporturl;
1496
1497 if (fExportUrl == "") {
1498 Info("ExportUrl",
1499 "There is no remote url defined in this collection");
1500 return kFALSE;
1501 }
1502 return kTRUE;
1503}
1504
1505////////////////////////////////////////////////////////////////////////////////
1506/// Adds to a file given by infile the collection identification , f.e.
1507/// for collection files sitting in directories like 100/1/AliESD.root
1508/// ...
1509/// 110/1/AliESD.root
1510/// "./histo.root" will be converted to "./histo.100_1-110_1.230.root
1511///
1512/// The name syntax is <oldname>.<first run>_<first event>-<last run>.<last event>.<nevents>.root
1513///
1514/// By default the found files are renamed on the local disk
1515/// example:
1516/// - you specify f.e. as arguments GetOutputFileName("*.root",kTRUE);
1517/// --->> this renames all ROOT files corresponding to the collection contents
1518
1519const char *TAlienCollection::GetOutputFileName(const char *infile,
1520 Bool_t rename, const char* suffix)
1521{
1522 Bool_t first = kTRUE;
1523 TString firstrun;
1524 TString firstevent;
1525 TString lastrun;
1526 TString lastevent;
1527 UInt_t nevents = 0;
1528
1529 Reset();
1530 while (Next()) {
1532 TString s2(gSystem->BaseName(s1.Data()));
1533 TString s3 = gSystem->GetDirName(s1.Data());
1534 TString s4(gSystem->BaseName(s3.Data()));
1535 nevents++;
1536 if (first) {
1537 first = kFALSE;
1538 firstevent = s2;
1539 firstrun = s4;
1540 }
1541 lastevent = s2;
1542 lastrun = s4;
1543 }
1544
1545 // list the matching files
1546 TString pcmd("ls ");
1547 pcmd += infile;
1548 //printf("Pipe is %s\n",pcmd.Data());
1549 FILE *fp = gSystem->OpenPipe(pcmd.Data(), "r");
1550 if (fp) {
1551 char rootfile[4096];
1552 Int_t item;
1553 while ((item = fscanf(fp, "%4095s", rootfile)) == 1) {
1554 TString rootdir = gSystem->GetDirName(rootfile);
1555 TString rootbase(gSystem->BaseName(rootfile));
1556 TString rootbasenosuffix;
1557 rootbasenosuffix = rootbase(0, rootbase.First('.'));;
1558 // build new name like <oldname>.<firstrun>_<firstevent>-<lastrun>_<lastevent>.root
1559 TString newrootname;
1560 if (rootdir.Length()) {
1561 newrootname += rootdir;
1562 newrootname += "/";
1563 }
1564 newrootname += rootbasenosuffix;
1565 newrootname += ".";
1566 newrootname += firstrun;
1567 newrootname += "_";
1568 newrootname += firstevent;
1569 newrootname += "-";
1570 newrootname += lastrun;
1571 newrootname += "_";
1572 newrootname += lastevent;
1573 newrootname += ".";
1574 newrootname += nevents;
1575 newrootname += ".";
1576 newrootname += suffix;
1577 Info("GetOutputFilename", "Renaming File %s to %s", rootfile,
1578 newrootname.Data());
1579 fLastOutFileName = newrootname;
1580 if (rename) {
1581 gSystem->Rename(rootfile, newrootname.Data());
1582 }
1583 }
1584 gSystem->ClosePipe(fp);
1585 }
1586 return fLastOutFileName.Data();
1587}
1588
1589////////////////////////////////////////////////////////////////////////////////
1590/// creates a TFileCollection objects and fills it with the information from this collection
1591/// note that TFileCollection has a flat structure and no groups --> all files are filles on a flat level
1592/// the TFileInfo of each file in the TFileCollection is filled with turl, size, md5, guid
1593///
1594/// the object has to be deleted by the user
1595
1596TFileCollection *TAlienCollection::GetFileCollection(const char* name, const char* title) const
1597{
1598 TFileCollection* collection = new TFileCollection(name, title);
1599
1600 TIter next(fFileGroupList);
1601 TMap* group = 0;
1602 while ((group = dynamic_cast<TMap*>(next()))) {
1603 TIter next2(group);
1604 TObjString* key = 0;
1605 while ((key = dynamic_cast<TObjString*> (next2()))) {
1606 if (key->String().Length() == 0)
1607 continue;
1608
1609 TMap* file = dynamic_cast<TMap*> (group->GetValue(key));
1610 if (!file)
1611 continue;
1612
1613 TObjString* turl = dynamic_cast<TObjString*> (file->GetValue("turl"));
1614 TObjString* size = dynamic_cast<TObjString*> (file->GetValue("size"));
1615 TObjString* md5 = dynamic_cast<TObjString*> (file->GetValue("md5"));
1616 TObjString* guid = dynamic_cast<TObjString*> (file->GetValue("guid"));
1617
1618 if (!turl || turl->String().Length() == 0)
1619 continue;
1620
1621 TFileInfo* fileInfo = new TFileInfo(turl->String(), size->String().Atoi(), guid->String(), md5->String());
1622 collection->Add(fileInfo);
1623 }
1624 }
1625
1626 collection->Update();
1627
1628 return collection;
1629}
#define SafeDelete(p)
Definition: RConfig.hxx:543
#define s1(x)
Definition: RSha256.hxx:91
const Bool_t kFALSE
Definition: RtypesCore.h:90
long long Long64_t
Definition: RtypesCore.h:71
const Bool_t kTRUE
Definition: RtypesCore.h:89
const char Option_t
Definition: RtypesCore.h:64
#define ClassImp(name)
Definition: Rtypes.h:361
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:556
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:657
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:36
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:46
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:53
virtual Bool_t WriteBuffer(const char *buf, Int_t len)
Write a buffer to the file.
Definition: TFile.cxx:2337
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:4839
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3942
void Close(Option_t *option="") override
Close a file.
Definition: TFile.cxx:873
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:821
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const
Return a list iterator.
Definition: TList.cxx:721
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:658
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:258
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:54
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
Definition: TMap.cxx:236
TObject * FindObject(const char *keyname) const
Check if a (key,value) pair exists with keyname as name of the key.
Definition: TMap.cxx:215
TObject * Remove(TObject *key)
Remove the (key,value) pair with key from the map.
Definition: TMap.cxx:296
An array of TObjects.
Definition: TObjArray.h:37
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:523
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:891
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:865
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 FILE * OpenPipe(const char *command, const char *mode)
Open a pipe.
Definition: TSystem.cxx:660
virtual int Rename(const char *from, const char *to)
Rename a file.
Definition: TSystem.cxx:1345
virtual int ClosePipe(FILE *pipe)
Close the pipe.
Definition: TSystem.cxx:669
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:930
virtual TString GetDirName(const char *pathname)
Return the directory name in pathname.
Definition: TSystem.cxx:1027
virtual int Unlink(const char *name)
Unlink, i.e.
Definition: TSystem.cxx:1376
virtual const char * TempDirectory() const
Return a user configured or systemwide directory to create temporary files in.
Definition: TSystem.cxx:1477
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:562
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:387
void SetOptions(const char *opt)
Definition: TUrl.h:89
const char * GetOptions() const
Definition: TUrl.h:73
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
static const std::string comment("comment")
Definition: file.py:1
Definition: first.py:1
const char * cnt
Definition: TXMLSetup.cxx:74