@@ -96,40 +96,17 @@ def describe_object(o):
9696 f"comment=\" { o .get ('comment' , '' )} \" " )
9797
9898
99- def main ():
100- parser = argparse .ArgumentParser (
101- description = "Estimate a CCDB TimeMachine not-after timestamp for a run+pass, "
102- "from AliEn catalog timestamps of that pass's own reco output." )
103- parser .add_argument ("--year" , default = os .environ .get ("ALIEN_JDL_LPMANCHORYEAR" ),
104- help = "data-taking year, e.g. 2023 (default: $ALIEN_JDL_LPMANCHORYEAR)" )
105- parser .add_argument ("--period" , default = os .environ .get ("ALIEN_JDL_LPMANCHORPRODUCTION" ),
106- help = "period name, e.g. LHC23s (default: $ALIEN_JDL_LPMANCHORPRODUCTION)" )
107- parser .add_argument ("--run" , default = os .environ .get ("ALIEN_JDL_LPMANCHORRUN" ),
108- help = "run number (default: $ALIEN_JDL_LPMANCHORRUN)" )
109- parser .add_argument ("--pass" , dest = "passname" , default = os .environ .get ("ALIEN_JDL_LPMANCHORPASSNAME" ),
110- help = "pass name, e.g. apass4 (default: $ALIEN_JDL_LPMANCHORPASSNAME)" )
111- parser .add_argument ("--samples" , type = int , default = 9 ,
112- help = "number of per-timeframe output files to sample (default: 9)" )
113- parser .add_argument ("--ccdb-check-path" , default = "TPC/Calib/CorrectionMapV2" ,
114- help = "CCDB path to cross-check the estimate against (default: TPC/Calib/CorrectionMapV2)" )
115- parser .add_argument ("--no-ccdb-check" , action = "store_true" ,
116- help = "skip the CCDB cross-check" )
117- args = parser .parse_args ()
118-
119- missing = [n for n in ("year" , "period" , "run" , "passname" ) if not getattr (args , n )]
120- if missing :
121- parser .error ("missing required value(s): " + ", " .join (missing ))
122-
123- pass_dir = f"/alice/data/{ args .year } /{ args .period } /{ args .run } /{ args .passname } /"
99+ def get_CCDBTimeMachineTS (year , period , run , passname , samples = 9 , ccdb_check_path = "TPC/Calib/CorrectionMapV2" , ccdb_check = True ):
100+ pass_dir = f"/alice/data/{ year } /{ period } /{ run } /{ passname } /"
124101 print (f"[getCCDBTimeMachineTimestamp] Looking for TF output under { pass_dir } " , file = sys .stderr )
125102
126- matches = find_tf_output_files (pass_dir , args . run )
103+ matches = find_tf_output_files (pass_dir , run )
127104 if not matches :
128- sys .exit (f"[getCCDBTimeMachineTimestamp] No o2_ctf_run{ int (args . run ):08d} _orbit* output found "
129- f"under { pass_dir } . Check year/period/run/pass, or this run+pass may not use this "
130- f"catalog layout. Refusing to guess a timestamp." )
105+ sys .exit (f"[getCCDBTimeMachineTimestamp] No o2_ctf_run{ int (run ):08d} _orbit* output found "
106+ f"under { pass_dir } . Check year/period/run/pass, or this run+pass may not use this "
107+ f"catalog layout. Refusing to guess a timestamp." )
131108
132- sampled = sample_evenly (matches , args . samples )
109+ sampled = sample_evenly (matches , samples )
133110 ctimes = []
134111 for lfn in sampled :
135112 ctime = stat_ctime (lfn )
@@ -139,7 +116,7 @@ def main():
139116
140117 if len (ctimes ) < 2 :
141118 sys .exit (f"[getCCDBTimeMachineTimestamp] Only got { len (ctimes )} usable timestamp(s) out of "
142- f"{ len (sampled )} sampled files ({ len (matches )} found in total); refusing to guess." )
119+ f"{ len (sampled )} sampled files ({ len (matches )} found in total); refusing to guess." )
143120
144121 not_after = int (statistics .median (ctimes ))
145122 spread_h = (max (ctimes ) - min (ctimes )) / 3.6e6
@@ -148,24 +125,54 @@ def main():
148125 print (f"[getCCDBTimeMachineTimestamp] Recommended not-after: { not_after } ({ human (not_after )} )" ,
149126 file = sys .stderr )
150127
151- if not args . no_ccdb_check :
152- check = ccdb_cross_check (args . ccdb_check_path , not_after )
128+ if ccdb_check :
129+ check = ccdb_cross_check (ccdb_check_path , not_after )
153130 if check is None or "error" in check :
154131 reason = check ["error" ] if check else "unknown error"
155- print (f"[getCCDBTimeMachineTimestamp] CCDB cross-check on { args . ccdb_check_path } skipped: { reason } " ,
132+ print (f"[getCCDBTimeMachineTimestamp] CCDB cross-check on { ccdb_check_path } skipped: { reason } " ,
156133 file = sys .stderr )
157134 elif check ["as_of" ] is None :
158- print (f"[getCCDBTimeMachineTimestamp] CCDB cross-check on { args . ccdb_check_path } : no object "
135+ print (f"[getCCDBTimeMachineTimestamp] CCDB cross-check on { ccdb_check_path } : no object "
159136 f"existed yet at the recommended timestamp (earliest is { describe_object (check ['newest' ])} )" ,
160137 file = sys .stderr )
161138 else :
162- print (f"[getCCDBTimeMachineTimestamp] CCDB cross-check on { args . ccdb_check_path } : as-of object is "
139+ print (f"[getCCDBTimeMachineTimestamp] CCDB cross-check on { ccdb_check_path } : as-of object is "
163140 f"{ describe_object (check ['as_of' ])} " , file = sys .stderr )
164141 if check ["outdated" ]:
165142 print (f"[getCCDBTimeMachineTimestamp] note: CCDB's current object for this window is newer "
166143 f"({ describe_object (check ['newest' ])} ) - it postdates this pass's processing and was "
167144 f"not what this run actually saw." , file = sys .stderr )
168145
146+ return not_after
147+
148+
149+ def main ():
150+ parser = argparse .ArgumentParser (
151+ description = "Estimate a CCDB TimeMachine not-after timestamp for a run+pass, "
152+ "from AliEn catalog timestamps of that pass's own reco output." )
153+ parser .add_argument ("--year" , default = os .environ .get ("ALIEN_JDL_LPMANCHORYEAR" ),
154+ help = "data-taking year, e.g. 2023 (default: $ALIEN_JDL_LPMANCHORYEAR)" )
155+ parser .add_argument ("--period" , default = os .environ .get ("ALIEN_JDL_LPMANCHORPRODUCTION" ),
156+ help = "period name, e.g. LHC23s (default: $ALIEN_JDL_LPMANCHORPRODUCTION)" )
157+ parser .add_argument ("--run" , default = os .environ .get ("ALIEN_JDL_LPMANCHORRUN" ),
158+ help = "run number (default: $ALIEN_JDL_LPMANCHORRUN)" )
159+ parser .add_argument ("--pass" , dest = "passname" , default = os .environ .get ("ALIEN_JDL_LPMANCHORPASSNAME" ),
160+ help = "pass name, e.g. apass4 (default: $ALIEN_JDL_LPMANCHORPASSNAME)" )
161+ parser .add_argument ("--samples" , type = int , default = 9 ,
162+ help = "number of per-timeframe output files to sample (default: 9)" )
163+ parser .add_argument ("--ccdb-check-path" , default = "TPC/Calib/CorrectionMapV2" ,
164+ help = "CCDB path to cross-check the estimate against (default: TPC/Calib/CorrectionMapV2)" )
165+ parser .add_argument ("--no-ccdb-check" , action = "store_true" ,
166+ help = "skip the CCDB cross-check" )
167+ args = parser .parse_args ()
168+
169+ missing = [n for n in ("year" , "period" , "run" , "passname" ) if not getattr (args , n )]
170+ if missing :
171+ parser .error ("missing required value(s): " + ", " .join (missing ))
172+
173+ not_after = get_CCDBTimeMachineTS (args .year , args .period , args .run , args .passname , args .samples ,
174+ args .ccdb_check_path , not args .no_ccdb_check )
175+
169176 print (not_after )
170177
171178
0 commit comments