ATLAS Offline Software
RingerIOVarDepObj.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef RINGERSELECTORTOOLS_TOOLS_RINGERIOVARDEPOBJ_ICC
6 #define RINGERSELECTORTOOLS_TOOLS_RINGERIOVARDEPOBJ_ICC
7 
8 // STL includes:
9 #include <sstream>
10 #include <cctype>
11 
12 // Root includes:
13 #include <TFile.h>
14 
15 // Local includes:
16 #include "RingerSelectorTools/tools/RingerIOVarDepObj.h"
17 #include "RingerSelectorTools/tools/IOHelperFcns.icc"
18 
19 namespace Ringer {
20 
21 // =============================================================================
22 template < class CRTP >
23 std::string RingerIOVarDepObj<CRTP>::name() const
24 {
25  const std::string name = std::string(CRTP::base_t::procType()) +
26  this->VariableDependency::type();
27  return name;
28 }
29 
30 // =============================================================================
31 template < class CRTP >
32 CRTP* RingerIOVarDepObj<CRTP>::read(TDirectory *configDir)
33 {
34  CRTP* crtp = new CRTP;
35  try {
36  unsigned v = IOHelperFcns::getWrittenVersion(configDir);
37  CRTP::base_t::read(crtp, configDir, v );
38  VariableDependency::read(crtp, configDir, v );
39  return crtp;
40  } catch ( const std::runtime_error &e){
41  std::cerr << "Couldn't read object of type "
42  << CRTP::base_t::procType()
43  << ". Reason: " << e.what() << std::endl;
44  delete crtp;
45  return nullptr;
46  }
47 }
48 
49 // =============================================================================
50 template < class CRTP >
51 void RingerIOVarDepObj<CRTP>::write(TDirectory *baseDir, const char *idxStr)
52  const
53 {
54  typedef typename CRTP::base_t base_t;
55  typedef typename RingerProcedureType<base_t>::procEnum_t
56  procEnum_t;
57  // Create directory where we will add all configurable information:
58  TDirectory* configDir = IOHelperFcns::makeDir( baseDir,
59  (std::string(this->name()) + std::string(idxStr) ).c_str() );
60  // Write object version:
61  unsigned v = IOHelperFcns::version();
62  IOHelperFcns::writeVar( configDir, "writtenOnPkgVersion", v );
63  // Write object type:
64  procEnum_t procType = base_t::template procType<procEnum_t>();
65  IOHelperFcns::writeVar< const procEnum_t, const unsigned int>( configDir,
66  "procType",
67  procType );
68  // Now write BaseProcedure and VariableDependency information on it:
69  static_cast<const CRTP*>(this)->base_t::write(configDir, idxStr);
70  static_cast<const VariableDependency*>(this)->writeDepInfo(configDir);
71 }
72 
73 } // namespace Ringer
74 
75 #endif // RINGERSELECTORTOOLS_TOOLS_RINGERIOVARDEPOBJ_ICC