3 #include "TObjString.h"
6 #include "AliMUONVTrackerData.h"
10 #include "TGridResult.h"
14 #include "TStopwatch.h"
15 #include "TGridCollection.h"
19 #include "TMethodCall.h"
21 void CopyFromRemote(Int_t runNumber, const char* period, const char* pass);
22 void CopyFromRemote(const TList& files);
23 TList* GetFileList(Int_t runNumber, const char* period, const char* pass);
24 void QAMerge(Int_t runNumber, const char* period, const char* pass);
25 void QAMerge(const TList& files, const char* outputfile);
27 ////______________________________________________________________________________
28 //AliMUONVTrackerData* GetTrackerData(TDirectory* dir, const char* trackerDataName)
30 // AliMUONVTrackerData* trackerData(0x0);
32 // TIter next(dir->GetListOfKeys());
35 // while ( ( key = static_cast<TKey*>(next()) ) && !trackerData )
37 // if ( key->IsFolder() )
39 // trackerData = GetTrackerData(static_cast<TDirectory*>(key->ReadObj()),trackerDataName);
43 // TString name(key->GetName());
45 // if ( name.Contains(trackerDataName) )
47 // trackerData = dynamic_cast<AliMUONVTrackerData*>(key->ReadObj());
52 // return trackerData;
56 ////______________________________________________________________________________
57 //AliMUONVTrackerData* GetTrackerData(const char* filename, const char* trackerDataName)
59 // TFile* file = TFile::Open(filename);
61 // cout << filename << endl;
63 // if (!file) return 0x0;
65 // AliMUONVTrackerData* trackerData = GetTrackerData(file,trackerDataName);
69 // return trackerData;
73 ////______________________________________________________________________________
74 //AliMUONVTrackerData* MergeTrackerData(const TList& filelist, const char* trackerDataName)
76 // TIter next(&filelist);
79 // s = static_cast<TObjString*>(next());
81 // AliMUONVTrackerData* d = GetTrackerData(s->String().Data(),trackerDataName);
85 // cout << Form("ERROR : no tracker data found in %s",s->String().Data()) << endl;
89 // AliMUONVTrackerData* merged = static_cast<AliMUONVTrackerData*>(d->Clone(Form("%s-MERGED",trackerDataName)));
91 // while ( ( s = static_cast<TObjString*>(next()) ) )
93 // d = GetTrackerData(s->String().Data(),trackerDataName);
98 // cout << "Merging " << s->String().Data() << " " << d->GetName() << " " << d->NumberOfEvents(-1) << endl;
100 // merged->Merge(&list);
105 // merged->SetName(Form("%s-MERGED-%d",trackerDataName,runNumber));
107 // merged->SetTitle(Form("%s merged for run %d",trackerDataName,runNumber));
113 //______________________________________________________________________________
114 void GenerateFileList(const char* runlist="philippe.runlist")
118 TGrid::Connect("alien://");
122 ifstream in(runlist);
129 TString basedir("/alice/data/2009/LHC09d/");
131 TString dir(Form("%s%09d/ESDs/pass1/*/Merged.QA.Data.root",basedir.Data(),run));
133 TGridResult* r = gGrid->Ls(dir.Data());
137 while ( r->GetFileName(i) )
139 cout << "alien://" << r->GetFileNamePath(i) << endl;
149 //______________________________________________________________________________
150 void CopyFromRemote(Int_t runNumber, const char* period, const char* pass)
152 TList* list = GetFileList(runNumber,period,pass);
155 CopyFromRemote(*list);
160 //______________________________________________________________________________
161 void CopyFromRemote(const TList& files)
168 while ( ( line = static_cast<TObjString*>(next()) ) )
170 TUrl url(line->String());
172 if ( TString(url.GetProtocol()) == "alien" )
176 TGrid::Connect("alien://");
179 cout << "Cannot get alien connection" << endl;
185 TString file(url.GetFile());
187 TString dir(gSystem->DirName(file));
189 gSystem->mkdir(dir.Data(),kTRUE);
191 if ( gSystem->AccessPathName(file.Data())==kFALSE)
193 cout << "Skipping copy of " << file.Data() << " as it already exists" << endl;
197 TFile::Cp(line->String().Data(),file.Data());
198 if ( line->String().Contains("root_archive.zip") )
200 gSystem->Exec(Form("unzip %s -d %s",file.Data(),gSystem->DirName(file.Data())));
201 gSystem->Exec(Form("rm %s",file.Data()));
209 //______________________________________________________________________________
210 TList* GetFileList(Int_t runNumber, const char* period, const char* pass)
212 if (!gGrid) TGrid::Connect("alien://");
220 TString speriod(period);
222 if (!speriod.BeginsWith("LHC"))
224 std::cerr << "Period not starting with LHC !" << std::endl;
228 year = 2000 + TString(speriod(3,3)).Atoi();
230 TString sbasedir(Form("/alice/data/%d/%s/%09d/ESDs/%s",year,period,runNumber,pass));
232 std::cout << sbasedir.Data() << std::endl;
234 TString search("Merged.QA.Data.root");
236 TGridResult* res = gGrid->Query(sbasedir.Data(),search.Data());
238 Int_t nFiles = res->GetEntries();
240 nFiles = res->GetEntries();
246 for (Int_t i = 0; i < nFiles; ++i)
248 Long64_t thisSize = TString(res->GetKey(i,"size")).Atoll();
250 // TUrl url(res->GetKey(i,"turl"));
255 files->SetOwner(kTRUE);
258 files->Add(new TObjString(res->GetKey(i,"turl")));
265 std::cout << Form("%d files for a total of %d MB",count,TMath::Nint(size/1024.0/1024)) << std::endl;
272 //______________________________________________________________________________
273 void QAMerge(Int_t runNumber, const char* period, const char* pass)
275 TList* list = GetFileList(runNumber,period,pass);
278 QAMerge(*list,Form("QA.%s.%s.%d.root",period,pass,runNumber));
284 //______________________________________________________________________________
285 TObject* GetObject(const char* filepath, const char* objectPath)
287 TFile* f = TFile::Open(filepath);
291 std::cerr << "Could not open file " << filepath << std::endl;
295 TObject* o = f->Get(objectPath);
299 std::cout << "Cannot get object " << objectPath << " from " << filepath << std::endl;
303 if ( o->InheritsFrom("TH1") )
305 TH1* h = static_cast<TH1*>(o);
314 //______________________________________________________________________________
315 TObject* Merge(const TList& files, const char* objectPath)
318 TObjString* filename;
320 filename = static_cast<TObjString*>(next());
322 TObject* d = GetObject(filename->String().Data(),objectPath);
326 cout << Form("ERROR : no object found in %s",filename->String().Data()) << endl;
330 TString oname(gSystem->BaseName(objectPath));
332 TObject* merged = d->Clone();
338 callEnv.InitWithPrototype(merged->IsA(), "Merge", "TCollection*");
341 if (!callEnv.IsValid())
343 std::cout << "callEnv invalid" << std::endl;
348 while ( ( filename = static_cast<TObjString*>(next()) ) )
350 // std::cout << filename->String().Data() << " : " << objectPath << std::endl;
352 d = GetObject(filename->String().Data(),objectPath);
361 callEnv.SetParam((Long_t) (&list));
362 callEnv.Execute(merged);
371 //______________________________________________________________________________
372 void QAMerge(const TList& files, const char* outputfile)
374 const char* eventSpecie = "HighMultiplicity";
376 TList objectsToMerge;
377 objectsToMerge.SetOwner(kTRUE);
379 objectsToMerge.Add(new TObjString(Form("MUON/Raws/%s/Expert/%s_hTrackerDDLNofEventsSeen",eventSpecie,eventSpecie)));
381 objectsToMerge.Add(new TObjString(Form("MUON/RecPoints/%s/Expert/%s_RecPoints",eventSpecie,eventSpecie)));
382 objectsToMerge.Add(new TObjString(Form("MUON/RecPoints/%s/Expert/%s_RecCharges",eventSpecie,eventSpecie)));
384 objectsToMerge.Add(new TObjString(Form("MUON/Raws/%s/Expert/%s_RawCharges",eventSpecie,eventSpecie)));
386 for ( Int_t i = 1; i <= 10; ++i )
388 objectsToMerge.Add(new TObjString(Form("MUON/RecPoints/%s/Expert/%s_hTrackerClusterHitMapForChamber%d",eventSpecie,eventSpecie,i)));
389 objectsToMerge.Add(new TObjString(Form("MUON/ESDs/%s/Expert/%s_hESDClusterHitMap%d",eventSpecie,eventSpecie,i)));
393 output.SetOwner(kTRUE);
395 TIter next(&objectsToMerge);
398 while ( ( s = static_cast<TObjString*>(next())) )
400 output.Add(Merge(files,s->String().Data()));
403 TFile* f = TFile::Open(outputfile,"recreate");
408 while ( ( s = static_cast<TObjString*>(next())) )
410 TObject* o = output.At(i);
413 TString dir = gSystem->DirName(s->String());
414 TString file = gSystem->BaseName(s->String());
415 TDirectory* tdir = static_cast<TDirectory*>(f->Get(dir.Data()));
418 f->mkdir(dir.Data()," ");
419 tdir = static_cast<TDirectory*>(f->Get(dir.Data()));
422 o->Write(file.Data());
434 //______________________________________________________________________________
435 void QAMerge(const char* inputfilelist, const char* mergedFile)
439 TGrid::Connect("alien://");
443 TString sinput(inputfilelist);
445 filelist.SetOwner(kTRUE);
447 if (sinput.Contains(".xml"))
449 TGridCollection *coll = reinterpret_cast<TGridCollection*>(gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\");", inputfilelist)));
452 ::Error("MergeOutput", "Input XML collection empty.");
455 // Iterate grid collection
458 filelist.Add(new TObjString(coll->GetTURL()));
463 ifstream in(inputfilelist);
466 while (in.getline(filename,1024,'\n'))
468 filelist.Add(new TObjString(filename));
472 if ( filelist.GetEntries()==0 )
474 std::cout << "No file to be merged !" << std::endl;
478 QAMerge(filelist,mergedFile);
482 out.open("outputs_valid_merge", ios::out);