Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-10-15 08:17:18

0001 // Write "run segment entries path" for every outputCollect_<run>_<seg>.root in a Collect directory or in its
0002 // run-number subfolders (<dir>/<run>/, the ana573 layout from 2026-10-08), sorted by run then segment (numeric).
0003 // Called by make_lists.bash; output feeds make_lists.py.
0004 // runs = optional comma-separated run numbers (e.g. "81584,81585,81586"); empty = every run in dir.
0005 void count_entries(const char* dir, const char* out, const char* runs=""){
0006     TString rsel    = TString(",")+runs+",";
0007     std::vector<std::tuple<int,int,TString>> v;
0008     std::vector<TString> dirs   = { dir };
0009     {
0010         TSystemDirectory d("d",dir); TList* l = d.GetListOfFiles();
0011         TIter nx(l); TSystemFile* f;
0012         while ((f=(TSystemFile*)nx())){ TString n=f->GetName(); if (f->IsDirectory() && n.IsDigit()) dirs.push_back(TString(dir)+"/"+n); }
0013     }
0014     for (auto& dd : dirs){
0015         TSystemDirectory d("d",dd); TList* files = d.GetListOfFiles();
0016         if (!files) continue;
0017         TIter next(files); TSystemFile* f;
0018         while ((f=(TSystemFile*)next())){
0019             TString n=f->GetName();
0020             if (!n.BeginsWith("outputCollect_") || !n.EndsWith(".root")) continue;
0021             int run=0, seg=0;
0022             if (sscanf(n.Data(),"outputCollect_%d_%d.root",&run,&seg)!=2) continue;
0023             if (strlen(runs) && !rsel.Contains(Form(",%d,",run))) continue;
0024             v.push_back(std::make_tuple(run,seg,dd+"/"+n));
0025         }
0026     }
0027     std::sort(v.begin(),v.end());
0028     FILE* fo=fopen(out,"w");
0029     long tot=0; int nbad=0;
0030     for (auto& t : v){
0031         TFile* tf=TFile::Open(std::get<2>(t).Data());
0032         long ne=-1;
0033         if (tf && !tf->IsZombie()){ TTree* tr=(TTree*)tf->Get("outTree"); if (tr) ne=tr->GetEntries(); }
0034         fprintf(fo,"%d %d %ld %s\n",std::get<0>(t),std::get<1>(t),ne,std::get<2>(t).Data());
0035         if (ne>0) tot+=ne; else ++nbad;
0036         if (tf) tf->Close();
0037     }
0038     fclose(fo);
0039     printf("files=%zu total entries=%ld unreadable=%d\n",v.size(),tot,nbad);
0040 }