40 ClassImp(TAlienCollection);
46 TAlienCollection::TAlienCollection(
const char *localcollectionfile,
49 fXmlFile = localcollectionfile;
50 fFileGroupList =
new TList();
51 fFileGroupList->SetOwner(kTRUE);
52 fFileGroupListIter =
new TIter(fFileGroupList);
57 fHasSelection = kFALSE;
62 fCollectionName =
"unnamed";
64 if (localcollectionfile != 0) {
72 TAlienCollection::TAlienCollection(TList *eventlist, UInt_t nofgroups,
75 fFileGroupList = eventlist;
76 fFileGroupList->SetOwner(kTRUE);
77 fFileGroupListIter =
new TIter(fFileGroupList);
79 fNofGroups = nofgroups;
80 fNofGroupfiles = nofgroupfiles;
82 fHasSelection = kFALSE;
87 fCollectionName =
"unnamed";
94 TAlienCollection::~TAlienCollection()
97 delete fFileGroupList;
99 if (fFileGroupListIter)
100 delete fFileGroupListIter;
103 delete fTagFilterList;
111 TGridCollection *TAlienCollection::Open(
const char *collectionurl,
116 TString coll(collectionurl);
117 Bool_t isRemote = coll.Contains(
":/") && !coll.Contains(
"file:");
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",
130 TAlienCollection *collection =
131 new TAlienCollection(coll, maxentries);
133 if (isRemote && gSystem->Unlink(coll.Data())) {
134 ::Error(
"TAlienCollection::Open",
"Cannot remove the local copy of the collection %s",
138 return dynamic_cast <TAlienCollection * > (collection);
144 TFile *TAlienCollection::OpenFile(
const char *filename)
146 const char *turl = GetTURL(filename);
148 return TFile::Open(turl);
157 TAlienCollection *TAlienCollection::OpenAlienCollection(TGridResult * queryresult,
163 TList *filelist =
new TList();
165 TIterator* fileiter = queryresult->MakeIterator();
168 while ((filemap = ((TMap *) fileiter->Next()))) {
169 if (!filemap->GetValue(
"origLFN"))
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()));
177 TMap* filegroup =
new TMap();
178 filegroup->Add(
new TObjString(bname.Data()), filemap);
179 filegroup->Add(
new TObjString(
""), filemap);
182 filelist->Add(filegroup);
186 return new TAlienCollection(filelist, filelist->GetEntries(), 1);;
194 TGridCollection *TAlienCollection::OpenQuery(TGridResult * queryresult,
197 UInt_t nofgroups = 0;
198 UInt_t nofgroupfiles = 0;
204 TIterator *fileiter = queryresult->MakeIterator();
206 TString prev_bname =
"";
207 TString prev_dname =
"";
210 TList *filelist =
new TList();
212 while ((filemap = ((TMap *) fileiter->Next()))) {
213 if (!filemap->GetValue(
"lfn"))
216 gSystem->DirName(filemap->GetValue(
"lfn")->GetName());
218 gSystem->BaseName(filemap->GetValue(
"lfn")->GetName());
219 filemap->Add(
new TObjString(
"name"),
new TObjString(bname.Data()));
221 && ((bname != prev_bname) && (dname == prev_dname)
224 filegroup->Add(
new TObjString(bname.Data()), filemap);
231 filelist->Add(filegroup);
236 filegroup =
new TMap();
237 filegroup->Add(
new TObjString(bname.Data()), filemap);
238 filegroup->Add(
new TObjString(
""), filemap);
246 filelist->Add(filegroup);
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"));
266 TAlienCollection *newcollection =
267 new TAlienCollection(filelist, nofgroups, nofgroupfiles);
269 newcollection->SetTagFilterList(filterlist);
271 return dynamic_cast <TAlienCollection *> (newcollection);
277 void TAlienCollection::Reset()
279 fFileGroupListIter->Reset();
287 void TAlienCollection::ParseXML(UInt_t maxentries)
290 UInt_t parsedentries = 0;
292 XMLDocPointer_t xdoc = xml.ParseFile(fXmlFile);
294 Error(
"ParseXML",
"cannot parse the xml file %s", fXmlFile.Data());
298 XMLNodePointer_t xalien = xml.DocGetRootElement(xdoc);
300 Error(
"ParseXML",
"cannot find the <alien> tag in %s",
305 XMLNodePointer_t xcollection = xml.GetChild(xalien);
307 Error(
"ParseXML",
"cannot find the <collection> tag in %s",
312 if (xml.GetAttr(xcollection,
"name")) {
313 fCollectionName = TString(xml.GetAttr(xcollection,
"name"));
315 fCollectionName = (
"unnamed");
318 XMLNodePointer_t xevent = xml.GetChild(xcollection);;
320 Error(
"ParseXML",
"cannot find the <event> tag in %s",
331 if (TString(xml.GetNodeName(xevent)) ==
"event") {
334 TMap *files =
new TMap();
340 XMLNodePointer_t xfile = xml.GetChild(xevent);
344 Bool_t firstfile = kTRUE;
348 xml.GetAttr(xfile,
"lfn");
349 xml.GetAttr(xfile,
"turl");
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"));
366 TObjString *oseStringlist =
367 new TObjString(xml.GetAttr(xfile,
"seStringlist"));
368 TObjString *oevlist =
369 new TObjString(xml.GetAttr(xfile,
"evlist"));
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++) {
379 (((TObjString *) evlist->At(n))->GetName()));
381 attributes->Add(
new TObjString(
"evlist"), xmlentrylist);
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);
391 if (osurl && strlen(osurl->GetName())) {
392 attributes->Add(
new TObjString(
"surl"), osurl);
395 if (osselect && strlen(osselect->GetName())) {
396 attributes->Add(
new TObjString(
"select"), osselect);
397 fHasSelection = kTRUE;
399 if (osonline && strlen(osonline->GetName())) {
400 attributes->Add(
new TObjString(
"online"), osonline);
404 if (ossexporturl && strlen(ossexporturl->GetName())) {
405 attributes->Add(
new TObjString(
"exporturl"), ossexporturl);
406 fExportUrl = ossexporturl->GetName();
409 files->Add(
new TObjString(xml.GetAttr(xfile,
"name")),
414 files->Add(
new TObjString(
""), attributes);
419 }
while ((xfile = xml.GetNext(xfile)));
420 fFileGroupList->Add(files);
423 if (TString(xml.GetNodeName(xevent)) ==
"info") {
424 if (xml.GetAttr(xevent,
"comment")) {
425 fInfoComment = TString(xml.GetAttr(xevent,
"comment"));
431 if (TString(xml.GetNodeName(xevent)) ==
"export") {
432 if (xml.GetAttr(xevent,
"url")) {
433 SetExportUrl(xml.GetAttr(xevent,
"url"));
438 if (parsedentries >= maxentries)
440 }
while ((xevent = xml.GetNext(xevent)));
446 TMap *TAlienCollection::Next()
448 fCurrent = (TMap *) fFileGroupListIter->Next();
455 void TAlienCollection::Status()
457 TIter *statuslist =
new TIter(fFileGroupList);
459 TMap *oldcurrent = fCurrent;
464 UInt_t offlinegroups;
468 Long64_t totalfilesize;
469 Long64_t onlinefilesize;
470 Long64_t offlinefilesize;
474 onlinegroups = offlinegroups = onlinefiles = offlinefiles = totalfiles =
475 totalfilesize = onlinefilesize = offlinefilesize = 0;
476 while ((nextgroup = (TMap *) statuslist->Next())) {
484 TIterator *nextfile = nextgroup->MakeIterator();
486 while ((attributes = (TMap *) nextfile->Next())) {
487 fCurrent = nextgroup;
488 if (TString(attributes->GetName()) !=
"") {
490 totalfilesize += GetSize(attributes->GetName());
492 if (IsSelected(attributes->GetName())) {
494 if (TString(attributes->GetName()) !=
"") {
496 fCurrent = nextgroup;
497 if (!IsOnline(attributes->GetName())) {
500 offlinefilesize += GetSize(attributes->GetName());
503 onlinefilesize += GetSize(attributes->GetName());
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 +
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 +
540 Info(
"Status",
"=========================================\n");
548 void TAlienCollection::SetTag(
const char *tag,
const char *value,
551 if ((!tag) || (!value) || (!tagmap)) {
554 TObject *delobject = tagmap->FindObject(tag);
556 TObject *keyobject = ((TPair *) delobject)->Key();
557 tagmap->Remove(keyobject);;
559 tagmap->Add(
new TObjString(tag),
new TObjString(value));
567 Bool_t TAlienCollection::SelectFile(
const char *filename, Int_t nstart, Int_t nstop)
570 fHasSelection = kTRUE;
573 while ((nextgroup = (TMap *) Next())) {
576 TIterator *nextfile = nextgroup->MakeIterator();
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())));
600 Bool_t TAlienCollection::DeselectFile(
const char *filename, Int_t nstart, Int_t nstop)
605 while ((nextgroup = (TMap *) Next())) {
608 TIterator *nextfile = nextgroup->MakeIterator();
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())));
632 Bool_t TAlienCollection::InvertSelection()
635 fHasSelection = kTRUE;
638 while ((nextgroup = (TMap *) Next())) {
641 TIterator *nextfile = nextgroup->MakeIterator();
643 while ((attributes = (TMap *) nextfile->Next())) {
644 if (IsSelected(attributes->GetName())) {
645 SetTag(
"select",
"0",
646 ((TMap *) nextgroup->GetValue(attributes->GetName())));
648 SetTag(
"select",
"1",
649 ((TMap *) nextgroup->GetValue(attributes->GetName())));
659 Bool_t TAlienCollection::DownscaleSelection(UInt_t scaler)
665 while ((nextgroup = (TMap *) Next())) {
668 TIterator *nextfile = nextgroup->MakeIterator();
671 while ((attributes = (TMap *) nextfile->Next())) {
672 if (TString(attributes->GetName()) !=
"") {
673 SetTag(
"select",
"0",
674 ((TMap *) nextgroup->GetValue(attributes->GetName())));
686 Bool_t TAlienCollection::Remove(TMap * map)
688 if (fFileGroupList->Remove(map)) {
698 const char *TAlienCollection::GetTURL(
const char *filename)
701 TMap *obj = (TMap *) fCurrent->GetValue(filename);
703 if (obj->GetValue(
"turl")) {
704 return (((TObjString *) obj->GetValue(
"turl"))->GetName());
708 Error(
"GetTURL",
"cannot get TURL of file %s", filename);
715 const char *TAlienCollection::GetSURL(
const char *filename)
718 TMap *obj = (TMap *) fCurrent->GetValue(filename);
720 if (obj->GetValue(
"surl")) {
721 return (((TObjString *) obj->GetValue(
"surl"))->GetName());
725 Error(
"GetSURL",
"cannot get SURL of file %s", filename);
732 Bool_t TAlienCollection::IsOnline(
const char *filename)
735 TMap *obj = (TMap *) fCurrent->GetValue(filename);
737 if (obj->GetValue(
"online")) {
739 (((TObjString *) obj->GetValue(
"online"))->GetName());
755 Bool_t TAlienCollection::IsSelected(
const char *filename)
758 TMap *obj = (TMap *) fCurrent->GetValue(filename);
760 if (obj->GetValue(
"select")) {
763 (((TObjString *) obj->GetValue(
"select"))->GetName());
764 if (selected == TString(
"1")) {
778 TEntryList *TAlienCollection::GetEntryList(
const char *filename)
781 TMap *obj = (TMap *) fCurrent->GetValue(filename);
783 if (obj->GetValue(
"evlist")) {
784 return ((TEntryList *) obj->GetValue(
"evlist"));
788 Error(
"GetEntryList",
"cannot get evelist of file %s", filename);
795 const char *TAlienCollection::GetLFN(
const char *filename)
798 TMap *obj = (TMap *) fCurrent->GetValue(filename);
800 if (obj->GetValue(
"lfn")) {
801 return (((TObjString *) obj->GetValue(
"lfn"))->GetName());
805 Error(
"GetLFN",
"cannot get LFN");
812 Long64_t TAlienCollection::GetSize(
const char *filename)
815 TMap *obj = (TMap *) fCurrent->GetValue(filename);
817 if (obj->GetValue(
"size")) {
819 (((TObjString *) obj->GetValue(
"size"))->GetName());
820 return ssize.Atoll();
824 Error(
"GetSize",
"cannot get size of %s", filename);
831 void TAlienCollection::Print(Option_t *)
const
833 Info(
"Print",
"dumping %d elements", fFileGroupList->GetSize());
834 TIter next(fFileGroupList);
837 while ((filemap = (TMap *) next())) {
839 Info(
"Print",
"printing element %d", count);
848 TDSet *TAlienCollection::GetDataset(
const char *type,
const char *objname,
852 TDSet *dset =
new TDSet(type, objname, dir);
858 if (((TObjString *) fCurrent->GetValue(
"")))
859 dset->Add(((TMap *) (fCurrent->GetValue(
"")))->GetValue(
"turl")->
872 TGridResult *TAlienCollection::GetGridResult(
const char *filename,
877 TGridResult *result =
new TAlienResult();
880 if (((TObjString *) fCurrent->GetValue(filename))) {
881 TMap *attributes = (TMap *) fCurrent->GetValue(filename)->Clone();
883 attributes->Add(
new TObjString(
"options"),
884 new TObjString(
"&publicaccess=1"));
886 if ((!fHasSelection) || (IsSelected(filename))) {
887 if ((!onlyonline) || (fHasOnline && IsOnline(filename))) {
888 result->Add(attributes);
893 return dynamic_cast < TGridResult * >(result);
900 Bool_t TAlienCollection::OverlapCollection(TGridCollection * comparator)
911 while ((overlapmap = this->Next())) {
913 Bool_t found = kFALSE;
915 while ((comparator->Next())) {
916 TString s1 = this->GetLFN();
917 TString s2 = comparator->GetLFN();
924 this->Remove(overlapmap);
934 void TAlienCollection::Add(TGridCollection * addcollection)
936 if ((!addcollection)) {
940 addcollection->Reset();
943 while ((addmap = addcollection->Next())) {
946 TString s2 = addcollection->GetLFN();
948 TString s1 = GetLFN();
952 "File group with lfn %s exists already in this collection - skipping",
958 clonemap = (TMap *) addmap->Clone();
959 fFileGroupList->Add(clonemap);
968 void TAlienCollection::AddFast(TGridCollection * addcollection)
970 if ((!addcollection)) {
973 addcollection->Reset();
974 TMap *addmap, *clonemap;
975 while ((addmap = addcollection->Next())) {
976 clonemap = (TMap *) addmap->Clone();
977 fFileGroupList->Add(clonemap);
984 Bool_t TAlienCollection::LookupSUrls(Bool_t verbose)
990 while ((filemap = Next())) {
992 TIterator *nextfile = filemap->MakeIterator();
994 while ((attributes = (TMap *) nextfile->Next())) {
995 if (TString(attributes->GetName()) !=
"") {
997 if (fHasSelection && (!IsSelected(attributes->GetName())))
1001 Info(
"LookupSUrls",
"Lookup SURL for %s [%u/%u]",
1002 GetTURL(attributes->GetName()), lc,
1003 fNofGroups * fNofGroupfiles);
1005 TAlienFile::SUrl(GetTURL(attributes->GetName()));
1010 TObject *delobject =
1011 ((TMap *) filemap->GetValue(attributes->GetName()))->
1014 TObject *keyobject = ((TPair *) delobject)->Key();
1015 ((TMap *) filemap->GetValue(attributes->GetName()))->
1019 ((TMap *) filemap->GetValue(attributes->GetName()))->
1020 Add(
new TObjString(
"surl"),
1021 new TObjString(surl.Data()));
1023 Info(
"LookupSUrls",
"SURL = %s", surl.Data());
1040 Bool_t TAlienCollection::Stage(Bool_t bulk,Option_t* option)
1044 "You have to execute LookupSUrls() before you can stage this collection");
1052 while ((filemap = Next())) {
1054 TIterator *nextfile = filemap->MakeIterator();
1056 while ((attributes = (TMap *) nextfile->Next())) {
1057 if (TString(attributes->GetName()) !=
"") {
1059 if (fHasSelection && (!IsSelected(attributes->GetName())))
1064 TFileStager::Open(GetSURL(attributes->GetName()));
1066 if ((fFileStager)->Stage(GetSURL(attributes->GetName()),option)) {
1068 Info(
"Stage",
"[%05u/%05u] <Staged> : %s", fc,
1069 GetNofGroups() * GetNofGroupfiles(),
1070 GetLFN(attributes->GetName()));
1073 Error(
"Stage",
"[%05u/%05u] <Failed to stage> : %s",
1074 fc, GetNofGroups() * GetNofGroupfiles(),
1075 GetLFN(attributes->GetName()));
1082 TList* stagelist =
new TList();
1083 stagelist->SetOwner(kTRUE);
1084 Bool_t stageresult=kFALSE;
1086 while ((filemap = Next())) {
1087 TIterator *nextfile = filemap->MakeIterator();
1089 while ((attributes = (TMap *) nextfile->Next())) {
1090 if (TString(attributes->GetName()) !=
"") {
1092 stagelist->Add(
new TUrl((GetSURL(attributes->GetName()))));
1099 fFileStager = TFileStager::Open(stagelist->First()->GetName());
1102 stageresult = (fFileStager)->Stage(stagelist,option);
1114 Bool_t TAlienCollection::CheckIfOnline(Bool_t bulk)
1117 Error(
"CheckIfOnline",
1118 "You have to execute LookupSUrls() before you can prepare this collection");
1127 while ((filemap = Next())) {
1129 TIterator *nextfile = filemap->MakeIterator();
1131 while ((attributes = (TMap *) nextfile->Next())) {
1132 if (fHasSelection && (!IsSelected(attributes->GetName())))
1134 if (TString(attributes->GetName()) !=
"") {
1139 TFileStager::Open(GetSURL(attributes->GetName()));
1141 Bool_t online = kFALSE;
1142 if ((fFileStager)->IsStaged(GetSURL(attributes->GetName()))) {
1144 Info(
"CheckIfOnline",
"[%05u/%05u] <Online> : %s", fc,
1145 GetNofGroups() * GetNofGroupfiles(),
1146 GetLFN(attributes->GetName()));
1150 Info(
"CheckIfOnline",
"[%05u/%05u]<Offline> : %s", fc,
1151 GetNofGroups() * GetNofGroupfiles(),
1152 GetLFN(attributes->GetName()));
1159 TObject *delobject =
1160 ((TMap *) filemap->GetValue(attributes->GetName()))->
1161 FindObject(
"online");
1163 TObject *keyobject = ((TPair *) delobject)->Key();
1164 ((TMap *) filemap->GetValue(attributes->GetName()))->
1168 ((TMap *) filemap->GetValue(attributes->GetName()))->
1169 Add(
new TObjString(
"online"),
1170 new TObjString(
"1"));
1172 ((TMap *) filemap->GetValue(attributes->GetName()))->
1173 Add(
new TObjString(
"online"),
1174 new TObjString(
"0"));
1181 TList *lookuplist =
new TList();
1183 lookuplist->SetOwner(kTRUE);
1184 while ((filemap = Next())) {
1186 TIterator *nextfile = filemap->MakeIterator();
1188 while ((attributes = (TMap *) nextfile->Next())) {
1189 if (TString(attributes->GetName()) !=
"") {
1194 TFileStager::Open(GetSURL(attributes->GetName()));
1197 Add(
new TObjString(GetSURL(attributes->GetName())));
1202 TList *onlinelist = fFileStager->GetStaged(lookuplist);
1208 while ((filemap = Next())) {
1210 TIterator *nextfile = filemap->MakeIterator();
1212 while ((attributes = (TMap *) nextfile->Next())) {
1213 if (TString(attributes->GetName()) !=
"") {
1218 FindObject(GetSURL(attributes->GetName()))) {
1220 Info(
"CheckIfOnline",
"[%05u/%05u] <Online> : %s", fc,
1221 GetNofGroups() * GetNofGroupfiles(),
1222 GetLFN(attributes->GetName()));
1226 Info(
"CheckIfOnline",
"[%05u/%05u]<Offline> : %s", fc,
1227 GetNofGroups() * GetNofGroupfiles(),
1228 GetLFN(attributes->GetName()));
1235 TObject *delobject =
1237 GetValue(attributes->GetName()))->
1238 FindObject(
"online");
1240 TObject *keyobject = ((TPair *) delobject)->Key();
1242 GetValue(attributes->GetName()))->
1247 GetValue(attributes->GetName()))->
1248 Add(
new TObjString(
"online"),
new TObjString(
"1"));
1251 GetValue(attributes->GetName()))->
1252 Add(
new TObjString(
"online"),
new TObjString(
"0"));
1258 SafeDelete(onlinelist);
1259 SafeDelete(lookuplist);
1261 fHasOnline = kFALSE;
1279 Bool_t TAlienCollection::ExportXML(
const char *exporturl, Bool_t selected, Bool_t online,
1280 const char *name ,
const char *comment)
1285 if ((exporturl == 0) || (TString(exporturl) ==
"")) {
1286 if (!(exporturl = GetExportUrl())) {
1288 "You used the option to store to the collection export url, but this is not defined!");
1292 TUrl expfn(exporturl);
1293 TString options = expfn.GetOptions();
1294 if (options.Length()) {
1295 options +=
",filetype=raw";
1297 options =
"filetype=raw";
1299 expfn.SetOptions(options.Data());
1301 if (!(exportfile = TFile::Open(expfn.GetUrl(),
"RECREATE"))) {
1302 Error(
"ExportXML",
"Cannot open export URL %s", expfn.GetUrl());
1306 Bool_t expret = ExportXML(exportfile, selected, online, name, comment);
1307 exportfile->Close();
1314 Bool_t TAlienCollection::ExportXML(TFile * exportfile, Bool_t selected,
1315 Bool_t online,
const char *name,
1316 const char *comment)
1321 snprintf(outline,4096,
1322 "<?xml version=\"1.0\"?>\n<alien>\n <collection name=\"%s\">\n",
1324 if ((exportfile->WriteBuffer(outline, strlen(outline)))) {
1325 Error(
"ExportXML",
"Error writing XML to export file");
1326 exportfile->Close();
1330 TMap *oldcurrent = fCurrent;
1332 TIter *filegroups =
new TIter(fFileGroupList);
1333 filegroups->Reset();
1334 UInt_t groupcnt = 0;
1335 while ((nextgroup = (TMap *) filegroups->Next())) {
1337 isselected = kFALSE;
1339 TIterator *nextfile = nextgroup->MakeIterator();
1342 while ((attributes = (TMap *) nextfile->Next())) {
1343 if (TString(attributes->GetName()) !=
"") {
1344 fCurrent = nextgroup;
1345 if (IsSelected(attributes->GetName())) {
1351 if ((!selected) || isselected) {
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();
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()))) {
1370 snprintf(outline,4096,
" <file ");
1372 WriteBuffer(outline, strlen(outline)))) {
1374 "Error writing XML to export file");
1375 exportfile->Close();
1380 ((TMap *) nextgroup->
1381 GetValue(attributes->GetName()))->MakeIterator();
1383 TObjString *tagname = 0;
1384 TObjString *tagval = 0;
1385 while ((tagname = (TObjString *) mkeys->Next())) {
1386 Bool_t filtered = kFALSE;
1388 if (fTagFilterList) {
1389 TIter next(fTagFilterList);
1390 TObjString *filtertag;
1391 while ((filtertag = (TObjString *) next())) {
1392 if (TString(tagname->GetName()) ==
1393 TString(filtertag->GetName())) {
1401 (TObjString *) ((TMap *) nextgroup->
1402 GetValue(attributes->
1405 if (TString(tagname->GetName()) !=
"evlist") {
1406 snprintf(outline,4096,
"%s=\"%s\" ",
1411 TEntryList *xmlentrylist =
1412 (TEntryList *) tagval;
1416 for (Int_t i = 0; i < xmlentrylist->GetN(); i++) {
1419 slist += xmlentrylist->GetEntry(i);
1421 snprintf(outline,4096,
"%s=\"%s\" ",
1422 tagname->GetName(), slist.Data());
1426 WriteBuffer(outline, strlen(outline)))) {
1428 "Error writing XML to export file");
1429 exportfile->Close();
1436 snprintf(outline,4096,
"/>\n");
1438 WriteBuffer(outline, strlen(outline)))) {
1440 "Error writing XML to export file");
1441 exportfile->Close();
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();
1459 fCurrent = oldcurrent;
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();
1473 snprintf(outline,4096,
1474 " <info comment=\"%s\" />\n</collection>\n</alien>\n",
1476 if ((exportfile->WriteBuffer(outline, strlen(outline)))) {
1477 Error(
"ExportXML",
"Error writing XML to export file");
1478 exportfile->Close();
1490 Bool_t TAlienCollection::SetExportUrl(
const char *exporturl)
1493 fExportUrl = exporturl;
1495 if (fExportUrl ==
"") {
1497 "There is no remote url defined in this collection");
1517 const char *TAlienCollection::GetOutputFileName(
const char *infile,
1518 Bool_t rename,
const char* suffix)
1520 Bool_t first = kTRUE;
1529 TString s1(gSystem->DirName(GetLFN(
"")));
1530 TString s2(gSystem->BaseName(s1.Data()));
1531 TString s3(gSystem->DirName(s1.Data()));
1532 TString s4(gSystem->BaseName(s3.Data()));
1544 TString pcmd(
"ls ");
1547 FILE *fp = gSystem->OpenPipe(pcmd.Data(),
"r");
1549 char rootfile[4096];
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(
'.'));;
1557 TString newrootname;
1558 if (rootdir.Length()) {
1559 newrootname += rootdir;
1562 newrootname += rootbasenosuffix;
1564 newrootname += firstrun;
1566 newrootname += firstevent;
1568 newrootname += lastrun;
1570 newrootname += lastevent;
1572 newrootname += nevents;
1574 newrootname += suffix;
1575 Info(
"GetOutputFilename",
"Renaming File %s to %s", rootfile,
1576 newrootname.Data());
1577 fLastOutFileName = newrootname;
1579 gSystem->Rename(rootfile, newrootname.Data());
1582 gSystem->ClosePipe(fp);
1584 return fLastOutFileName.Data();
1594 TFileCollection *TAlienCollection::GetFileCollection(
const char* name,
const char* title)
const
1596 TFileCollection* collection =
new TFileCollection(name, title);
1598 TIter next(fFileGroupList);
1600 while ((group = dynamic_cast<TMap*>(next()))) {
1602 TObjString* key = 0;
1603 while ((key = dynamic_cast<TObjString*> (next2()))) {
1604 if (key->String().Length() == 0)
1607 TMap* file =
dynamic_cast<TMap*
> (group->GetValue(key));
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"));
1616 if (!turl || turl->String().Length() == 0)
1619 TFileInfo* fileInfo =
new TFileInfo(turl->String(), size->String().Atoi(), guid->String(), md5->String());
1620 collection->Add(fileInfo);
1624 collection->Update();