1212#include "CCDB/BasicCCDBManager.h"
1313
1414#include <TAxis.h>
15+ #include <TFile.h>
16+ #include <TGrid.h>
1517#include <TH1.h>
18+ #include <TSystem.h>
1619
20+ #include <iostream>
21+ #include <regex>
22+ #include <set>
23+ #include <sstream>
1724#include <string>
25+ #include <vector>
1826
1927void getMenu (int runNumber , std ::string baseCCDBPath = "Users/m/mpuccio/EventFiltering/OTS/Chunked/" )
2028{
@@ -29,3 +37,87 @@ void getMenu(int runNumber, std::string baseCCDBPath = "Users/m/mpuccio/EventFil
2937 std ::cout << "Id " << i - 2 << ": " << axis -> GetBinLabel (i ) << "\n" ;
3038 }
3139}
40+
41+ std ::vector < std ::string > getMenuForPeriod (std ::string period )
42+ {
43+ std ::regex pattern (R "(LHC(\d{2})[A-Za-z]{1,2})" );
44+ std ::smatch match ;
45+
46+ int year {2000 };
47+ if (!std ::regex_match (period , match , pattern )) {
48+ std ::cout << "Invalid format for period: " << period << std ::endl ;
49+ return {};
50+ }
51+
52+ year += std ::stoi (match [1 ]);
53+ gSystem -> Exec (Form ("alien_find /alice/data/%i/%s/ ctf_skim_full/AnalysisResults_fullrun.root > list_tmp_%s.txt" , year , period .data (), period .data ()));
54+
55+ std ::ifstream file (Form ("list_tmp_%s.txt" , period .data ()));
56+ if (!file ) {
57+ std ::cerr << "Error: could not open file for period " << period << "\n" ;
58+ return {};
59+ }
60+
61+ std ::string firstLine ;
62+ if (!std ::getline (file , firstLine )) {
63+ std ::cerr << "Error: file is empty or read failed for period " << period << "\n" ;
64+ return {};
65+ }
66+
67+ TGrid ::Connect ("alien://" );
68+ TFile * scalersFile = TFile ::Open ((std ::string ("alien://" ) + firstLine ).data (), "READ" );
69+ TH1D * counters = (TH1D * )scalersFile -> Get ("central-event-filter-task/scalers/mFiltered" );
70+ TAxis * axis = counters -> GetXaxis ();
71+
72+ std ::vector < std ::string > binLabels (axis -> GetNbins () - 2 );
73+ for (int i = 2 ; i < axis -> GetNbins (); ++ i ) {
74+ binLabels [i - 2 ] = axis -> GetBinLabel (i );
75+ }
76+
77+ scalersFile -> Close ();
78+ delete scalersFile ;
79+ gSystem -> Exec (Form ("rm list_tmp_%s.txt" , period .data ()));
80+
81+ return binLabels ;
82+ }
83+
84+ void getMenu (std ::string periods )
85+ {
86+ std ::stringstream ss (periods );
87+ std ::string period ;
88+ std ::vector < std ::string > periodList ;
89+
90+ // Parse comma-separated periods
91+ while (std ::getline (ss , period , ',' )) {
92+ // Trim whitespace
93+ period .erase (0 , period .find_first_not_of (" \t" ));
94+ period .erase (period .find_last_not_of (" \t" ) + 1 );
95+ periodList .push_back (period );
96+ }
97+
98+ std ::map < std ::vector < std ::string > , std ::vector < std ::string >> menuGroups ;
99+
100+ // Get menus for each period
101+ for (const auto& p : periodList ) {
102+ auto menu = getMenuForPeriod (p );
103+ if (!menu .empty ()) {
104+ menuGroups [menu ].push_back (p );
105+ }
106+ }
107+
108+ // Report different menus
109+ int menuId = 1 ;
110+ for (const auto & [menu , periods ] : menuGroups ) {
111+ std ::cout << "\n=== Menu " << menuId ++ << " (periods: " ;
112+ for (size_t i = 0 ; i < periods .size (); ++ i ) {
113+ std ::cout << periods [i ];
114+ if (i < periods .size () - 1 )
115+ std ::cout << ", " ;
116+ }
117+ std ::cout << ") ===\n" ;
118+
119+ for (size_t i = 0 ; i < menu .size (); ++ i ) {
120+ std ::cout << "Id " << i << ": " << menu [i ] << "\n" ;
121+ }
122+ }
123+ }
0 commit comments