37 typedef std::map<dd4hep::Condition::key_type,dd4hep::Condition>
AllConditions;
49 int createXML(
const std::string& output,
const AllConditions& all) {
51 const char comment[] =
"\n"
52 " +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
53 " ++++ Linear collider detector description Detector in C++ ++++\n"
54 " ++++ dd4hep Detector description generator. ++++\n"
57 " ++++ M.Frank CERN/LHCb ++++\n"
58 " +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n ";
62 for(
const auto& c : all ) {
63 ::snprintf(text,
sizeof(text),
"0x%16llX",c.second.key());
66 cond.setAttr(
_U(name), c.second.name());
67 #if !defined(DD4HEP_MINIMAL_CONDITIONS)
68 cond.setAttr(
_U(ref), c.second.address());
71 dd4hep::printout(dd4hep::ALWAYS,
"ConditionsRepository",
"++ Handled %ld conditions.",all.size());
72 if ( !output.empty() ) {
73 return docH.
output(doc, output);
86 void operator()(
xml_h element)
const {
88 size_t cap = data.capacity();
90 ::sscanf(
key.c_str(),
"0x%16llX",&e.
key);
93 if ( data.size() == cap ) data.reserve(cap+500);
103 #if defined(DD4HEP_MINIMAL_CONDITIONS)
104 int createText(
const std::string& output,
const AllConditions&,
char)
106 int createText(
const std::string& output,
const AllConditions& all,
char sep)
109 std::ofstream out(output);
110 #if !defined(DD4HEP_MINIMAL_CONDITIONS)
111 std::size_t siz_nam=0, siz_add=0, siz_tot=0;
112 char fmt[64], text[2*PATH_MAX+64];
114 dd4hep::except(
"ConditionsTextRepository",
115 "++ Failed to open output file:%s [errno:%d %s]",
116 output.c_str(), errno, ::strerror(errno));
119 std::snprintf(fmt,
sizeof(fmt),
"%%16llX%c%%s%c%%s%c",sep,sep,sep);
122 for(
const auto& i : all ) {
124 std::size_t siz_n = c->name.length();
125 std::size_t siz_a = c->
address.length();
126 if ( siz_add < siz_a ) siz_add = siz_a;
127 if ( siz_nam < siz_n ) siz_nam = siz_n;
128 if ( siz_tot < (siz_n+siz_a) ) siz_tot = siz_n+siz_a;
131 ::snprintf(fmt,
sizeof(fmt),
"%%16llX %%-%lds %%-%lds",
long(siz_nam),
long(siz_add));
133 out <<
"dd4hep." << char(sep ? sep :
'-')
134 <<
"." << long(siz_nam)
135 <<
"." << long(siz_add)
136 <<
"." << long(siz_tot) << std::endl;
137 for(
const auto& i : all ) {
139 std::snprintf(text,
sizeof(text), fmt, c.
key(), c.
name(), c.
address().c_str());
140 out << text << std::endl;
151 std::size_t siz_nam, siz_add, siz_tot;
152 char sep, c, text[2*PATH_MAX+64];
153 std::ifstream in(input);
154 in >> c >> c >> c >> c >> c >> c >> c >> sep
159 in.getline(text,
sizeof(text),
'\n');
162 in.getline(text,
sizeof(text),
'\n');
164 std::size_t idx_nam = 9+siz_nam<
sizeof(text)-1 ? 9+siz_nam : 0;
165 std::size_t idx_add = 10+siz_nam+siz_add<
sizeof(text)-1 ? 10+siz_nam+siz_add : 0;
166 if ( 9+siz_nam >=
sizeof(text) )
167 dd4hep::except(
"ConditionsTextRepository",
"Inconsistent input data in %s: %s -> (%lld,%lld,%lld)",
168 __FILE__, input.c_str(), siz_nam, siz_add, siz_tot);
169 else if ( 10+siz_nam+siz_add >=
sizeof(text) )
170 dd4hep::except(
"ConditionsTextRepository",
"Inconsistent input data in %s: %s -> (%lld,%lld,%lld)",
171 __FILE__, input.c_str(), siz_nam, siz_add, siz_tot);
172 else if ( siz_tot ) {
174 text[8] = text[idx_nam] = text[idx_add] = 0;
177 if ( (idx=e.
name.find(
' ')) != std::string::npos )
179 if ( (idx=e.
address.find(
' ')) != std::string::npos )
185 if ( (idx=e.
name.find(sep)) != std::string::npos && idx+10 <
sizeof(text) )
186 text[9+idx]=0, e.
address=text+idx+10, e.
name=text+9;
187 if ( (idx=e.
address.find(sep)) != std::string::npos )
189 else if ( (idx=e.
address.find(
'\n')) != std::string::npos )
192 std::size_t cap = data.capacity();
193 std::sscanf(text,
"%16llX",&e.
key);
194 if ( data.size() == cap ) data.reserve(cap+500);
195 data.emplace_back(e);
197 }
while(in.good() && !in.eof() );
207 for(
const IOVType* type : types ) {
211 for (
const auto& cp : pool->
elements ) {
213 cp.second->select_all(rc);
221 if ( output.find(
".xml") != std::string::npos ) {
223 return createXML(output, all);
225 else if ( output.find(
".txt") != std::string::npos ) {
227 return createText(output, all, 0);
229 else if ( output.find(
".daf") != std::string::npos ) {
231 return createText(output, all, 0);
233 else if ( output.find(
".csv") != std::string::npos ) {
235 return createText(output, all,
';');
242 if ( input.find(
".xml") != std::string::npos ) {
243 return readXML(input, data);
245 else if ( input.find(
".txt") != std::string::npos ) {
246 return readText(input, data);
248 else if ( input.find(
".daf") != std::string::npos ) {
249 return readText(input, data);
251 else if ( input.find(
".csv") != std::string::npos ) {
252 return readText(input, data);