File indexing completed on 2025-01-18 09:14:58
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include "PersistencySetup.h"
0016
0017
0018 #include "TFile.h"
0019
0020 using namespace std;
0021 using namespace dd4hep;
0022 using namespace PersistencyExamples;
0023
0024
0025 int dd4hep::PersistencyExamples::printCondition(Condition cond) {
0026 const BasicGrammar* gr = cond.data().grammar;
0027 int result = 0;
0028
0029 if ( gr->type() == typeid(int) )
0030 result += int(cond.get<int>());
0031 else if ( gr->type() == typeid(long) )
0032 result += int(cond.get<long>());
0033 else if ( gr->type() == typeid(float) )
0034 result += int(cond.get<float>());
0035 else if ( gr->type() == typeid(double) )
0036 result += int(cond.get<double>());
0037 else if ( gr->type() == typeid(string) )
0038 result += cond.get<string>().length();
0039 else if ( gr->type() == typeid(Delta) )
0040 { ++result; cond.get<Delta>(); }
0041 else if ( gr->type() == typeid(AlignmentData) ) {
0042 if ( dynamic_cast<detail::AlignmentObject*>(cond.ptr()) ) {
0043 AlignmentCondition ac = cond;
0044 bool ok = (void*)cond.data().ptr() == (void*)&ac->values();
0045 printout(ok ? INFO : ERROR,
0046 "Data","+++ %s +++ \t\tAlignmentCondition: %s [%p] -- %p %s",
0047 ok ? "SUCCESS" : "ERROR", cond.name(),cond.data().ptr(),&ac->values(),
0048 ok ? "[Good-payload-mapping]" : "[Bad-payload-mapping]");
0049 }
0050 ++result;
0051 cond.get<AlignmentData>();
0052 }
0053 else if ( gr->type() == typeid(vector<int>) )
0054 result += int(cond.get<vector<int> >().size());
0055 else if ( gr->type() == typeid(vector<long>) )
0056 result += int(cond.get<vector<long> >().size());
0057 else if ( gr->type() == typeid(vector<float>) )
0058 result += int(cond.get<vector<float> >().size());
0059 else if ( gr->type() == typeid(vector<double>) )
0060 result += int(cond.get<vector<double> >().size());
0061 else if ( gr->type() == typeid(vector<string>) )
0062 result += int(cond.get<vector<string> >().size());
0063
0064 else if ( gr->type() == typeid(map<string,int>) ) {
0065 const map<string,int>& mapping = cond.get<map<string,int> >();
0066 result += int(mapping.size());
0067 for(const auto& i : mapping ) {
0068 result += i.second;
0069 printout(INFO,"Data","\t\tMap: %s [%s] -> %d",cond.name(), i.first.c_str(),i.second);
0070 }
0071 }
0072 printout(INFO,"Data","Condition: [%016llX] %-24s -> %s",cond.key(), cond.name(), cond.data().str().c_str());
0073 return result;
0074 }
0075
0076
0077 PersistencyIO::PersistencyIO() {
0078 }
0079
0080
0081 PersistencyIO::~PersistencyIO() {
0082 }
0083
0084
0085 int PersistencyIO::write(const std::string& fname, const std::string& title, const std::type_info& typ, const void* object) {
0086 TFile* f = TFile::Open(fname.c_str(),"RECREATE");
0087 if ( f && !f->IsZombie()) {
0088
0089 int nBytes = f->WriteObjectAny(object,TBuffer::GetClass(typ),title.c_str());
0090 f->Close();
0091 return nBytes;
0092 }
0093 return 0;
0094 }