37 typedef std::map<dd4hep::Condition::key_type,dd4hep::Condition>
AllConditions;
49 int createXML(
const std::string& output,
const AllConditions& all) {
50 const char comment[] =
"\n"
51 " +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
52 " ++++ Linear collider detector description Detector in C++ ++++\n"
53 " ++++ dd4hep Detector description generator. ++++\n"
56 " ++++ M.Frank CERN/LHCb ++++\n"
57 " +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n ";
61 for(
const auto& i : all ) {
64 std::snprintf(text,
sizeof(text),
"0x%16llX",c.
key());
67 #if !defined(DD4HEP_MINIMAL_CONDITIONS)
72 dd4hep::printout(dd4hep::ALWAYS,
"ConditionsRepository",
"++ Handled %ld conditions.",all.size());
73 if ( !output.empty() ) {
74 return docH.
output(doc, output);
87 void operator()(
xml_h element)
const {
89 std::size_t cap = data.capacity();
91 ::sscanf(
key.c_str(),
"0x%16llX",&e.
key);
94 if ( data.size() == cap ) data.reserve(cap+500);
104 #if defined(DD4HEP_MINIMAL_CONDITIONS)
105 int createText(
const std::string& output,
const AllConditions&,
char)
107 int createText(
const std::string& output,
const AllConditions& all,
char sep)
110 std::ofstream out(output);
111 #if !defined(DD4HEP_MINIMAL_CONDITIONS)
112 std::size_t siz_nam=0, siz_add=0, siz_tot=0;
113 char fmt[64], text[2*PATH_MAX+64];
115 dd4hep::except(
"ConditionsRepository",
116 "++ Failed to open output file:%s [errno:%d %s]",
117 output.c_str(), errno, ::strerror(errno));
120 std::snprintf(fmt,
sizeof(fmt),
"%%16llX%c%%s%c%%s%c",sep,sep,sep);
123 for(
const auto& i : all ) {
125 std::size_t siz_n = c->name.length();
126 std::size_t siz_a = c->
address.length();
127 if ( siz_nam < siz_n ) siz_nam = siz_n;
128 if ( siz_add < siz_a ) siz_add = siz_a;
129 if ( siz_tot < (siz_n+siz_a) ) siz_tot = siz_n+siz_a;
132 std::snprintf(fmt,
sizeof(fmt),
"%%16llX %%-%lds %%-%lds",
long(siz_nam),
long(siz_add));
134 out <<
"dd4hep." << char(sep ? sep :
'-')
135 <<
"." << long(siz_nam)
136 <<
"." << long(siz_add)
137 <<
"." << long(siz_tot) << std::endl;
138 for(
const auto& i : all ) {
140 std::snprintf(text,
sizeof(text), fmt, c.
key(), c.
name(), c.
address().c_str());
141 out << text << std::endl;
150 std::size_t idx, siz_nam, siz_add, siz_tot;
151 char sep, c, text[2*PATH_MAX];
153 std::ifstream in(input);
155 in >> c >> c >> c >> c >> c >> c >> c >> sep
160 siz_nam = std::min(siz_nam, 1024UL);
161 siz_add = std::min(siz_add, 1024UL);
162 in.getline(text,
sizeof(text),
'\n');
163 text[
sizeof(text)-1] = 0;
166 in.getline(text,
sizeof(text),
'\n');
168 text[
sizeof(text)-1] = 0;
172 if ( 9+siz_nam <
sizeof(text) ) {
176 if ( 10+siz_nam+siz_add < (
long)
sizeof(text) ) {
177 text[10+siz_nam+siz_add] = 0;
179 if ( (idx=e.
name.find(
' ')) != std::string::npos && idx < e.
name.length() )
181 if ( (idx=e.
address.find(
' ')) != std::string::npos && idx < e.
address.length() )
185 dd4hep::except(
"ConditionsRepository",
"+++ Invalid record encountered. [Sever error]");
191 if ( (idx=e.
name.find(sep)) != std::string::npos && idx <
sizeof(text)-10 )
192 text[9+idx] = 0, e.
address=text+idx+10, e.
name=text+9;
193 if ( (idx=e.
address.find(sep)) != std::string::npos && idx < e.
address.length() )
195 else if ( (idx=e.
address.find(
'\n')) != std::string::npos && idx < e.
address.length() )
198 size_t cap = data.capacity();
199 ::sscanf(text,
"%16llX",&e.
key);
200 if ( data.size() == cap ) data.reserve(cap+500);
201 data.emplace_back(e);
203 }
while(in.good() && !in.eof() );
213 for(
const IOVType* type : types ) {
217 for(
const auto& cp : pool->
elements ) {
219 cp.second->select_all(rc);
220 for(
const auto&
cond : rc )
227 if ( output.find(
".xml") != std::string::npos ) {
229 return createXML(output, all);
231 else if ( output.find(
".txt") != std::string::npos ) {
233 return createText(output, all, 0);
235 else if ( output.find(
".daf") != std::string::npos ) {
237 return createText(output, all, 0);
239 else if ( output.find(
".csv") != std::string::npos ) {
241 return createText(output, all,
';');
248 if ( input.find(
".xml") != std::string::npos ) {
249 return readXML(input, data);
251 else if ( input.find(
".txt") != std::string::npos ) {
252 return readText(input, data);
254 else if ( input.find(
".daf") != std::string::npos ) {
255 return readText(input, data);
257 else if ( input.find(
".csv") != std::string::npos ) {
258 return readText(input, data);