ATLAS Offline Software
Classes | Public Types | Static Public Member Functions | Static Protected Member Functions | List of all members
StandaloneDataIO Struct Reference

#include <StandaloneDataIO.h>

Collaboration diagram for StandaloneDataIO:

Classes

struct  ConstantInformation
 
struct  EventInformation
 
struct  FolderLoad
 
class  FolderLoadOptions
 

Public Types

enum  ErrorState { ErrorState::OK = 0, ErrorState::ReadError, ErrorState::WriteError }
 

Static Public Member Functions

static ErrorState prepare_folder_for_output (const std::filesystem::path &folder, const bool output_errors=true)
 
static std::string build_filename (const std::string &prefix, const std::string &text, const std::string &suffix, const std::string &ext)
 
static std::string build_filename (const std::string &prefix, const size_t event_number, const std::string &suffix, const std::string &ext, const unsigned int num_width=9)
 
static ErrorState save_constants_to_folder (const std::filesystem::path &folder, const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::GeometryArr > &geo, const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellNoiseArr > &noise, const std::string &prefix="", const std::string &suffix="", const bool output_errors=true)
 
static ErrorState save_event_to_folder (const size_t event_number, const std::filesystem::path &folder, const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellInfoArr > &cell_info, const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellStateArr > &cell_state, const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::ClusterInfoArr > &clusters, const std::string &prefix="", const std::string &suffix="", const unsigned int num_width=9, const bool output_errors=true)
 
static ErrorState save_cell_state_to_folder (const size_t event_number, const std::filesystem::path &folder, const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellStateArr > &cell_state, const std::string &prefix="", const std::string &suffix="", const unsigned int num_width=9, const bool output_errors=true)
 
static ErrorState save_cell_info_to_folder (const size_t event_number, const std::filesystem::path &folder, const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellInfoArr > &cell_info, const std::string &prefix="", const std::string &suffix="", const unsigned int num_width=9, const bool output_errors=true)
 
static ErrorState save_clusters_to_folder (const size_t event_number, const std::filesystem::path &folder, const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::ClusterInfoArr > &clusters, const std::string &prefix="", const std::string &suffix="", const unsigned int num_width=9, const bool output_errors=true)
 
template<class F >
static FolderLoad load_folder_filter (F &&filter_function, const std::filesystem::path &folder, int max_events=-1, const FolderLoadOptions &flo=FolderLoadOptions::None(), const bool output_messages=true)
 
static FolderLoad load_folder (const std::filesystem::path &folder, int max_events=-1, const FolderLoadOptions &flo=FolderLoadOptions::None(), const bool output_messages=true)
 

Static Protected Member Functions

static void report_error (const std::filesystem::path &file, const std::string &kind, const bool really_report=false)
 
static bool create_or_check_folder (const std::filesystem::path &folder, const bool output_errors=true)
 

Detailed Description

Definition at line 22 of file StandaloneDataIO.h.

Member Enumeration Documentation

◆ ErrorState

Enumerator
OK 
ReadError 
WriteError 

Definition at line 24 of file StandaloneDataIO.h.

25  {
26  OK = 0, ReadError, WriteError
27  };

Member Function Documentation

◆ build_filename() [1/2]

static std::string StandaloneDataIO::build_filename ( const std::string &  prefix,
const size_t  event_number,
const std::string &  suffix,
const std::string &  ext,
const unsigned int  num_width = 9 
)
inlinestatic

Definition at line 282 of file StandaloneDataIO.h.

287  {
288  std::ostringstream event_ID_format;
289  event_ID_format << std::setfill('0') << std::setw(num_width) << event_number;
290  const std::string event_ID = event_ID_format.str();
291  return build_filename(prefix, event_ID, suffix, ext);
292  }

◆ build_filename() [2/2]

static std::string StandaloneDataIO::build_filename ( const std::string &  prefix,
const std::string &  text,
const std::string &  suffix,
const std::string &  ext 
)
inlinestatic

Definition at line 273 of file StandaloneDataIO.h.

277  {
278  return prefix + (prefix.size() > 0 ? "_" : "") + text +
279  (suffix.size() > 0 ? "_" : "") + suffix + "." + ext;
280  }

◆ create_or_check_folder()

static bool StandaloneDataIO::create_or_check_folder ( const std::filesystem::path &  folder,
const bool  output_errors = true 
)
inlinestaticprotected

Definition at line 238 of file StandaloneDataIO.h.

239  {
241  {
242  if (!std::filesystem::create_directory(folder))
243  {
244  if (output_errors)
245  {
246  std::cout << "ERROR: folder '" << folder << "' could not be created." << std::endl;
247  }
248  return false;
249  }
250  }
251  else if (!std::filesystem::is_directory(folder))
252  {
253  if (output_errors)
254  {
255  std::cout << "ERROR: folder '" << folder << "' is not a valid folder." << std::endl;
256  }
257  return false;
258  }
259  return true;
260  }

◆ load_folder()

static FolderLoad StandaloneDataIO::load_folder ( const std::filesystem::path &  folder,
int  max_events = -1,
const FolderLoadOptions flo = FolderLoadOptions::None(),
const bool  output_messages = true 
)
inlinestatic

Definition at line 634 of file StandaloneDataIO.h.

638  {
639  return load_folder_filter([&](const std::string &)
640  {
641  return false;
642  },
643  folder, max_events, flo, output_messages);
644  }

◆ load_folder_filter()

template<class F >
static FolderLoad StandaloneDataIO::load_folder_filter ( F &&  filter_function,
const std::filesystem::path &  folder,
int  max_events = -1,
const FolderLoadOptions flo = FolderLoadOptions::None(),
const bool  output_messages = true 
)
inlinestatic
Parameters
filter_functionreceives a std::string (the filename), returns true if the file should be filtered out.

Definition at line 489 of file StandaloneDataIO.h.

496  {
497  FolderLoad ret;
498  if (!std::filesystem::is_directory(folder))
499  {
500  if (output_messages)
501  {
502  std::cout << "ERROR: '" << folder << "' is not a valid folder." << std::endl;
503  }
504  return ret;
505  }
506  std::set<std::string> read_one_part_of_v1_cells;
507  int event_count = 0;
508  for (const std::filesystem::path & file : std::filesystem::directory_iterator(folder))
509  {
510  if ( max_events > 0 && event_count >= max_events &&
511  ret.geometry.size() > 0 && ret.noise.size() > 0 )
512  {
513  break;
514  }
515 
516  const bool can_load_events = (max_events < 0) || (event_count < max_events);
517  const std::string filename = file.stem().native();
518 
519  if (filter_function(filename))
520  {
521  continue;
522  }
523 
524  auto check_error = [&](const ErrorState & es, const std::string & str)
525  {
526  if (es == ErrorState::OK)
527  {
528  return false;
529  }
530  if (output_messages)
531  {
532  std::cout << "ERROR: '" << file << "' is not a valid " << str << " file (" << (int) es << ")." << std::endl;
533  }
534  return true;
535  };
536 
537  auto output_loading_message = [&](const std::string & str)
538  {
539  if (output_messages)
540  {
541  std::cout << "Loaded " << str << " from '" << file << "'." << std::endl;
542  }
543  };
544 
545  if (file.extension() == ".geometry")
546  {
547  if (!flo.load_geometry)
548  {
549  continue;
550  }
552  if (check_error(ConstantInformation::read_geometry(file, tempgeo), "geometry"))
553  {
554  continue;
555  }
556  ret.geometry[filename] = std::move(tempgeo);
557  output_loading_message("geometry");
558  }
559  else if (file.extension() == ".cellstate")
560  {
561  if (!flo.load_cell_state || !can_load_events)
562  {
563  continue;
564  }
566  if (check_error(EventInformation::read_cell_state(file, tempcellstate), "cell state"))
567  {
568  continue;
569  }
570  ret.cell_state[filename] = std::move(tempcellstate);
571  output_loading_message("cell state");
572  if ((ret.cluster_info.count(filename) > 0 || !flo.load_cluster_info) &&
573  (ret.cell_info.count(filename) > 0 || !flo.load_cell_info))
574  {
575  ++event_count;
576  }
577  }
578  else if (file.extension() == ".cellinfo")
579  {
580  if (!flo.load_cell_info || !can_load_events)
581  {
582  continue;
583  }
585  if (check_error(EventInformation::read_cell_info(file, tempcellinfo), "cell info"))
586  {
587  continue;
588  }
589  ret.cell_info[filename] = std::move(tempcellinfo);
590  output_loading_message("cell info");
591  if ((ret.cluster_info.count(filename) > 0 || !flo.load_cluster_info) &&
592  (ret.cell_state.count(filename) > 0 || !flo.load_cell_state))
593  {
594  ++event_count;
595  }
596  }
597  else if (file.extension() == ".clusterinfo")
598  {
599  if (!flo.load_cluster_info || !can_load_events)
600  {
601  continue;
602  }
604  if (check_error(EventInformation::read_cluster_info(file, tempclu), "cluster info"))
605  {
606  continue;
607  }
608  ret.cluster_info[filename] = std::move(tempclu);
609  output_loading_message("cluster info");
610  if ((ret.cell_state.count(filename) > 0 || !flo.load_cell_state) &&
611  (ret.cell_info.count(filename) > 0 || !flo.load_cell_info))
612  {
613  ++event_count;
614  }
615  }
616  else if (file.extension() == ".noise")
617  {
618  if (!flo.load_noise)
619  {
620  continue;
621  }
623  if (check_error(ConstantInformation::read_noise(file, tempnois), "noise"))
624  {
625  continue;
626  }
627  ret.noise[filename] = std::move(tempnois);
628  output_loading_message("noise");
629  }
630  }
631  return ret;
632  }

◆ prepare_folder_for_output()

static ErrorState StandaloneDataIO::prepare_folder_for_output ( const std::filesystem::path &  folder,
const bool  output_errors = true 
)
inlinestatic

Definition at line 264 of file StandaloneDataIO.h.

265  {
266  if (!create_or_check_folder(folder, output_errors))
267  {
268  return ErrorState::WriteError;
269  }
270  return ErrorState::OK;
271  }

◆ report_error()

static void StandaloneDataIO::report_error ( const std::filesystem::path &  file,
const std::string &  kind,
const bool  really_report = false 
)
inlinestaticprotected

Definition at line 31 of file StandaloneDataIO.h.

32  {
33  if (really_report)
34  {
35  std::cerr << "ERROR: when " << kind << " from '" << file << "'." << std::endl;
36  }
37  }

◆ save_cell_info_to_folder()

static ErrorState StandaloneDataIO::save_cell_info_to_folder ( const size_t  event_number,
const std::filesystem::path &  folder,
const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellInfoArr > &  cell_info,
const std::string &  prefix = "",
const std::string &  suffix = "",
const unsigned int  num_width = 9,
const bool  output_errors = true 
)
inlinestatic

Definition at line 391 of file StandaloneDataIO.h.

398  {
399  if (!create_or_check_folder(folder, output_errors))
400  {
401  return ErrorState::WriteError;
402  }
403 
404  std::ostringstream event_ID_format;
405  event_ID_format << std::setfill('0') << std::setw(num_width) << event_number;
406  const std::string event_ID = event_ID_format.str();
407 
408  auto filename = [&] (const std::string & ext)
409  {
410  return folder / build_filename(prefix, event_ID, suffix, ext);
411  };
412 
413  if (EventInformation::write_cell_info(filename("cellinfo"), cell_info) != ErrorState::OK)
414  {
415  return ErrorState::WriteError;
416  }
417  return ErrorState::OK;
418  }

◆ save_cell_state_to_folder()

static ErrorState StandaloneDataIO::save_cell_state_to_folder ( const size_t  event_number,
const std::filesystem::path &  folder,
const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellStateArr > &  cell_state,
const std::string &  prefix = "",
const std::string &  suffix = "",
const unsigned int  num_width = 9,
const bool  output_errors = true 
)
inlinestatic

Definition at line 362 of file StandaloneDataIO.h.

369  {
370  if (!create_or_check_folder(folder, output_errors))
371  {
372  return ErrorState::WriteError;
373  }
374 
375  std::ostringstream event_ID_format;
376  event_ID_format << std::setfill('0') << std::setw(num_width) << event_number;
377  const std::string event_ID = event_ID_format.str();
378 
379  auto filename = [&] (const std::string & ext)
380  {
381  return folder / build_filename(prefix, event_ID, suffix, ext);
382  };
383 
384  if (EventInformation::write_cell_state(filename("cellstate"), cell_state) != ErrorState::OK)
385  {
386  return ErrorState::WriteError;
387  }
388  return ErrorState::OK;
389  }

◆ save_clusters_to_folder()

static ErrorState StandaloneDataIO::save_clusters_to_folder ( const size_t  event_number,
const std::filesystem::path &  folder,
const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::ClusterInfoArr > &  clusters,
const std::string &  prefix = "",
const std::string &  suffix = "",
const unsigned int  num_width = 9,
const bool  output_errors = true 
)
inlinestatic

Definition at line 420 of file StandaloneDataIO.h.

427  {
428  if (!create_or_check_folder(folder, output_errors))
429  {
430  return ErrorState::WriteError;
431  }
432 
433  std::ostringstream event_ID_format;
434  event_ID_format << std::setfill('0') << std::setw(num_width) << event_number;
435  const std::string event_ID = event_ID_format.str();
436 
437  auto filename = [&] (const std::string & ext)
438  {
439  return folder / build_filename(prefix, event_ID, suffix, ext);
440  };
441 
443  {
444  return ErrorState::WriteError;
445  }
446  return ErrorState::OK;
447  }

◆ save_constants_to_folder()

static ErrorState StandaloneDataIO::save_constants_to_folder ( const std::filesystem::path &  folder,
const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::GeometryArr > &  geo,
const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellNoiseArr > &  noise,
const std::string &  prefix = "",
const std::string &  suffix = "",
const bool  output_errors = true 
)
inlinestatic

Definition at line 295 of file StandaloneDataIO.h.

301  {
302  if (!create_or_check_folder(folder, output_errors))
303  {
304  return ErrorState::WriteError;
305  }
306 
307  auto filename = [&] (const std::string & text, const std::string & ext)
308  {
309  return folder / build_filename(prefix, text, suffix, ext);
310  };
311 
313  {
314  return ErrorState::WriteError;
315  }
317  {
318  return ErrorState::WriteError;
319  }
320  return ErrorState::OK;
321  }

◆ save_event_to_folder()

static ErrorState StandaloneDataIO::save_event_to_folder ( const size_t  event_number,
const std::filesystem::path &  folder,
const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellInfoArr > &  cell_info,
const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellStateArr > &  cell_state,
const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::ClusterInfoArr > &  clusters,
const std::string &  prefix = "",
const std::string &  suffix = "",
const unsigned int  num_width = 9,
const bool  output_errors = true 
)
inlinestatic

Definition at line 323 of file StandaloneDataIO.h.

332  {
333  if (!create_or_check_folder(folder, output_errors))
334  {
335  return ErrorState::WriteError;
336  }
337 
338  std::ostringstream event_ID_format;
339  event_ID_format << std::setfill('0') << std::setw(num_width) << event_number;
340  const std::string event_ID = event_ID_format.str();
341 
342  auto filename = [&] (const std::string & ext)
343  {
344  return folder / build_filename(prefix, event_ID, suffix, ext);
345  };
346 
347  if (EventInformation::write_cell_info(filename("cellinfo"), cell_info) != ErrorState::OK)
348  {
349  return ErrorState::WriteError;
350  }
351  if (EventInformation::write_cell_state(filename("cellstate"), cell_state) != ErrorState::OK)
352  {
353  return ErrorState::WriteError;
354  }
356  {
357  return ErrorState::WriteError;
358  }
359  return ErrorState::OK;
360  }

The documentation for this struct was generated from the following file:
StandaloneDataIO::build_filename
static std::string build_filename(const std::string &prefix, const std::string &text, const std::string &suffix, const std::string &ext)
Definition: StandaloneDataIO.h:273
hotSpotInTAG.suffix
string suffix
Definition: hotSpotInTAG.py:186
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
StandaloneDataIO::ErrorState::WriteError
@ WriteError
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
StandaloneDataIO::EventInformation::write_cell_info
static ErrorState write_cell_info(std::filesystem::path file, const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellInfoArr > &cell_info, const bool report=false)
Definition: StandaloneDataIO.h:202
CaloRecGPU::Helpers::SimpleHolder
Holds one objects of type \T in memory context Context.
Definition: Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h:1067
StandaloneDataIO::EventInformation::read_cluster_info
static ErrorState read_cluster_info(const std::filesystem::path &file, CaloRecGPU::Helpers::CPU_object< CaloRecGPU::ClusterInfoArr > &clusters, const bool report=false)
Definition: StandaloneDataIO.h:115
StandaloneDataIO::ConstantInformation::read_noise
static ErrorState read_noise(const std::filesystem::path &file, CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellNoiseArr > &noise, const bool report=false)
Definition: StandaloneDataIO.h:62
python.TrigInDetArtSteps.max_events
max_events
Definition: TrigInDetArtSteps.py:30
StandaloneDataIO::ErrorState::OK
@ OK
StandaloneDataIO::EventInformation::write_cell_state
static ErrorState write_cell_state(std::filesystem::path file, const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellStateArr > &cell_state, const bool report=false)
Definition: StandaloneDataIO.h:218
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
file
TFile * file
Definition: tile_monitor.h:29
MakeFileForMJB.ext
string ext
Definition: Moriond2016/MakeFileForMJB.py:41
StandaloneDataIO::load_folder_filter
static FolderLoad load_folder_filter(F &&filter_function, const std::filesystem::path &folder, int max_events=-1, const FolderLoadOptions &flo=FolderLoadOptions::None(), const bool output_messages=true)
Definition: StandaloneDataIO.h:489
StandaloneDataIO::EventInformation::write_cluster_info
static ErrorState write_cluster_info(std::filesystem::path file, const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::ClusterInfoArr > &clusters, const bool report=false)
Definition: StandaloneDataIO.h:179
StandaloneDataIO::ConstantInformation::read_geometry
static ErrorState read_geometry(const std::filesystem::path &file, CaloRecGPU::Helpers::CPU_object< CaloRecGPU::GeometryArr > &geo, const bool report=false)
Definition: StandaloneDataIO.h:47
StandaloneDataIO::ErrorState
ErrorState
Definition: StandaloneDataIO.h:25
StandaloneDataIO::EventInformation::read_cell_info
static ErrorState read_cell_info(const std::filesystem::path &file, CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellInfoArr > &cell_info, const bool report=false)
Definition: StandaloneDataIO.h:149
StandaloneDataIO::create_or_check_folder
static bool create_or_check_folder(const std::filesystem::path &folder, const bool output_errors=true)
Definition: StandaloneDataIO.h:238
StandaloneDataIO::ConstantInformation::write_noise
static ErrorState write_noise(std::filesystem::path file, const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellNoiseArr > &noise, const bool report=false)
Definition: StandaloneDataIO.h:93
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
LArCellConditions.geo
bool geo
Definition: LArCellConditions.py:46
StandaloneDataIO::EventInformation::read_cell_state
static ErrorState read_cell_state(const std::filesystem::path &file, CaloRecGPU::Helpers::CPU_object< CaloRecGPU::CellStateArr > &cell_state, const bool report=false)
Definition: StandaloneDataIO.h:164
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
CaloCondBlobAlgs_fillNoiseFromASCII.folder
folder
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:56
makeTransCanvas.text
text
Definition: makeTransCanvas.py:11
str
Definition: BTagTrackIpAccessor.cxx:11
python.dummyaccess.exists
def exists(filename)
Definition: dummyaccess.py:9
WriteCellNoiseToCool.noise
noise
Definition: WriteCellNoiseToCool.py:380
StandaloneDataIO::ConstantInformation::write_geometry
static ErrorState write_geometry(std::filesystem::path file, const CaloRecGPU::Helpers::CPU_object< CaloRecGPU::GeometryArr > &geo, const bool report=false)
Definition: StandaloneDataIO.h:77