@@ -31,11 +31,6 @@ using namespace o2::phos;
3131void PHOSEnergyCalibDevice::init (o2::framework::InitContext& ic)
3232{
3333 o2::base::GRPGeomHelper::instance ().setRequest (mCCDBRequest );
34- mOutputDir = ic.options ().get <std::string>(" output-dir" );
35- mOutputDir = o2::utils::Str::rectifyDirectory (mOutputDir );
36- mMetaFileDir = ic.options ().get <std::string>(" meta-output-dir" );
37- mMetaFileDir = o2::utils::Str::rectifyDirectory (mMetaFileDir );
38- LOG (info) << " Meta dir=" << mMetaFileDir ;
3934
4035 mPtMin = ic.options ().get <float >(" ptminmgg" );
4136 mEminHGTime = ic.options ().get <float >(" eminhgtime" );
@@ -51,6 +46,7 @@ void PHOSEnergyCalibDevice::init(o2::framework::InitContext& ic)
5146 LOG (info) << " Emin for LG time=" << mEminLGTime ;
5247 LOG (info) << " Emin for out digits=" << mEDigMin ;
5348 LOG (info) << " Cluster Emin for out digits=" << mECluMin ;
49+ LOG (info) << " Root output dir=" << mOutputDir ;
5450
5551 mCalibrator = std::make_unique<PHOSEnergyCalibrator>();
5652
@@ -64,6 +60,7 @@ void PHOSEnergyCalibDevice::init(o2::framework::InitContext& ic)
6460 mHasCalib = true ;
6561 }
6662 mCalibrator ->setCuts (mPtMin , mEminHGTime , mEminLGTime , mEminHGTime , mEminLGTime );
63+ mCalibrator ->setUpdateAtTheEndOfRunOnly ();
6764
6865 // Create geometry instance (inclusing reading mis-alignement)
6966 // instance will be pick up by Calibrator
@@ -148,14 +145,17 @@ void PHOSEnergyCalibDevice::fillOutputTree()
148145
149146 LOG (info) << " Filling tree with " << mOutputDigits .size () << " digits" ;
150147 if (!mFileOut ) { // create file and tree
151- mFileName = mOutputDir + fmt::format (" PHOS_CalibDigits_{}.root" , mRunNumber );
152- LOG (info) << " Creating new tree for PHOS calib digits, output file=" << mFileName ;
153- mFileOut = std::make_unique<TFile>(mFileName .c_str (), " recreate" );
148+ if (mWriteRootOutput ) {
149+ mFileName = mOutputDir + fmt::format (" PHOS_CalibDigits_{}.root" , mRunNumber );
150+ LOG (info) << " Creating new tree for PHOS calib digits, output file=" << mFileName ;
151+ mFileOut = std::make_unique<TFile>(mFileName .c_str (), " recreate" );
152+ mFileMetaData = std::make_unique<o2::dataformats::FileMetaData>();
153+ mHistoFileName = mOutputDir + fmt::format (" PHOS_CalibHistos_{}.root" , mRunNumber );
154+ mHistoFileOut = std::make_unique<TFile>(mHistoFileName .c_str (), " recreate" );
155+ mHistoFileMetaData = std::make_unique<o2::dataformats::FileMetaData>();
156+ }
157+ // else Tree will be memory resident
154158 mTreeOut = std::make_unique<TTree>(" phosCalibDig" , " O2 PHOS calib tree" );
155- mFileMetaData = std::make_unique<o2::dataformats::FileMetaData>();
156- mHistoFileName = mOutputDir + fmt::format (" PHOS_CalibHistos_{}.root" , mRunNumber );
157- mHistoFileOut = std::make_unique<TFile>(mHistoFileName .c_str (), " recreate" );
158- mHistoFileMetaData = std::make_unique<o2::dataformats::FileMetaData>();
159159 }
160160 auto * br = mTreeOut ->GetBranch (" PHOSCalib" );
161161 auto * pptr = &mOutputDigits ;
@@ -172,6 +172,9 @@ void PHOSEnergyCalibDevice::fillOutputTree()
172172
173173void PHOSEnergyCalibDevice::writeOutFile ()
174174{
175+ if (!mWriteRootOutput ) {
176+ return ;
177+ }
175178 // write collected vector and metadata
176179 if (!mTreeOut ) { // nothing to write,
177180 return ;
@@ -192,15 +195,19 @@ void PHOSEnergyCalibDevice::writeOutFile()
192195
193196 std::string metaFileNameTmp = mMetaFileDir + fmt::format (" PHOS_CalibDigits_{}.tmp" , mRunNumber );
194197 std::string metaFileName = mMetaFileDir + fmt::format (" PHOS_CalibDigits_{}.done" , mRunNumber );
195- try {
196- std::ofstream metaFileOut (metaFileNameTmp);
197- metaFileOut << *mFileMetaData .get ();
198- metaFileOut.close ();
199- std::filesystem::rename (metaFileNameTmp, metaFileName);
200- } catch (std::exception const & e) {
201- LOG (error) << " Failed to store PHOS meta data file " << metaFileName << " , reason: " << e.what ();
198+ if (mMetaFileDir .compare (" /dev/null" )) {
199+ try {
200+ std::ofstream metaFileOut (metaFileNameTmp);
201+ metaFileOut << *mFileMetaData .get ();
202+ metaFileOut.close ();
203+ std::filesystem::rename (metaFileNameTmp, metaFileName);
204+ } catch (std::exception const & e) {
205+ LOG (error) << " Failed to store PHOS meta data file " << metaFileName << " , reason: " << e.what ();
206+ }
207+ LOG (info) << " Stored metadate file " << mFileName << " .done" ;
208+ } else {
209+ LOG (info) << " Scipped storing metafile as meta-dir=" << mMetaFileDir ;
202210 }
203- LOG (info) << " Stored metadate file " << mFileName << " .done" ;
204211 mFileMetaData .reset ();
205212
206213 LOG (info) << " Writing calibration histograms" ;
@@ -217,18 +224,20 @@ void PHOSEnergyCalibDevice::writeOutFile()
217224
218225 metaFileNameTmp = mMetaFileDir + fmt::format (" PHOS_CalibHistos_{}.tmp" , mRunNumber );
219226 metaFileName = mMetaFileDir + fmt::format (" PHOS_CalibHistos_{}.done" , mRunNumber );
220- try {
221- std::ofstream metaFileOut (metaFileNameTmp);
222- metaFileOut << *mHistoFileMetaData .get ();
223- metaFileOut.close ();
224- std::filesystem::rename (metaFileNameTmp, metaFileName);
225- } catch (std::exception const & e) {
226- LOG (error) << " Failed to store PHOS histos meta data file " << metaFileName << " , reason: " << e.what ();
227+ if (mMetaFileDir .compare (" /dev/null" )) {
228+ try {
229+ std::ofstream metaFileOut (metaFileNameTmp);
230+ metaFileOut << *mHistoFileMetaData .get ();
231+ metaFileOut.close ();
232+ std::filesystem::rename (metaFileNameTmp, metaFileName);
233+ } catch (std::exception const & e) {
234+ LOG (error) << " Failed to store PHOS histos meta data file " << metaFileName << " , reason: " << e.what ();
235+ }
236+ LOG (info) << " Stored histos metadate file " << mHistoFileName << " .done" ;
227237 }
228- LOG (info) << " Stored histos metadate file " << mHistoFileName << " .done" ;
229238 mHistoFileMetaData .reset ();
230239}
231- o2::framework::DataProcessorSpec o2::phos::getPHOSEnergyCalibDeviceSpec (bool useCCDB)
240+ o2::framework::DataProcessorSpec o2::phos::getPHOSEnergyCalibDeviceSpec (bool useCCDB, const std::string& outputDir, const std::string& metaFileDir, bool writeRootOutput )
232241{
233242
234243 std::vector<InputSpec> inputs;
@@ -252,13 +261,11 @@ o2::framework::DataProcessorSpec o2::phos::getPHOSEnergyCalibDeviceSpec(bool use
252261 return o2::framework::DataProcessorSpec{" PHOSEnergyCalibDevice" ,
253262 inputs,
254263 outputs,
255- o2::framework::adaptFromTask<PHOSEnergyCalibDevice>(useCCDB, ccdbRequest),
264+ o2::framework::adaptFromTask<PHOSEnergyCalibDevice>(useCCDB, ccdbRequest, outputDir, metaFileDir, writeRootOutput ),
256265 o2::framework::Options{
257266 {" ptminmgg" , o2::framework::VariantType::Float, 1 .5f , {" minimal pt to fill mgg calib histos" }},
258267 {" eminhgtime" , o2::framework::VariantType::Float, 1 .5f , {" minimal E (GeV) to fill HG time calib histos" }},
259268 {" eminlgtime" , o2::framework::VariantType::Float, 5 .f , {" minimal E (GeV) to fill LG time calib histos" }},
260269 {" ecalibdigitmin" , o2::framework::VariantType::Float, 0 .05f , {" minimal digtit E (GeV) to keep digit for calibration" }},
261- {" ecalibclumin" , o2::framework::VariantType::Float, 0 .4f , {" minimal cluster E (GeV) to keep digit for calibration" }},
262- {" output-dir" , VariantType::String, " ./" , {" ROOT trees output directory" }},
263- {" meta-output-dir" , VariantType::String, " ./" , {" metafile output directory" }}}};
270+ {" ecalibclumin" , o2::framework::VariantType::Float, 0 .4f , {" minimal cluster E (GeV) to keep digit for calibration" }}}};
264271}
0 commit comments