30 using namespace DD4hep;
31 using namespace DD4hep::Conditions;
40 ConditionsRepository::ConditionsRepository() {
44 ConditionsRepository::~ConditionsRepository() {
49 int createXML(
const string& output,
const AllConditions& all) {
50 const char comment[] =
"\n"
51 " +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
52 " ++++ Linear collider detector description LCDD in C++ ++++\n"
53 " ++++ DD4hep Detector description generator. ++++\n"
56 " ++++ M.Frank CERN/LHCb ++++\n"
57 " +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n ";
61 for(AllConditions::const_iterator i=all.begin(); i!=all.end(); ++i) {
64 ::snprintf(text,
sizeof(text),
"0x%08X",c.
key());
66 cond.setAttr(
_U(key), text);
67 cond.setAttr(
_U(name), c.
name());
70 printout(
ALWAYS,
"ConditionsRepository",
"++ Handled %ld conditions.",all.size());
71 if ( !output.empty() ) {
72 return docH.
output(doc, output);
85 void operator()(
xml_h element)
const {
86 string key = element.
attr<
string>(
_U(key));
87 size_t cap = data.capacity();
89 ::sscanf(key.c_str(),
"0x%08X",&e.
key);
92 if ( data.size() == cap ) data.reserve(cap+500);
102 int createText(
const string& output,
const AllConditions& all,
char sep) {
103 size_t siz_nam=0, siz_add=0, siz_tot=0;
104 char fmt[64], text[2*PATH_MAX+64];
105 ofstream out(output);
107 except(
"ConditionsRepository",
108 "++ Failed to open output file:%s [errno:%d %s]",
109 output.c_str(), errno, ::strerror(errno));
112 ::snprintf(fmt,
sizeof(fmt),
"%%08X%c%%s%c%%s%c",sep,sep,sep);
115 for(AllConditions::const_iterator i=all.begin(); i!=all.end(); ++i) {
117 size_t siz_n = c->
name.length();
118 size_t siz_a = c->
address.length();
119 if ( siz_nam < siz_n ) siz_nam = siz_n;
120 if ( siz_add < siz_a ) siz_add = siz_a;
121 if ( siz_tot < (siz_n+siz_a) ) siz_tot = siz_n+siz_a;
124 ::snprintf(fmt,
sizeof(fmt),
"%%08X %%-%lds %%-%lds",
long(siz_nam),
long(siz_add));
126 out <<
"dd4hep." << char(sep ? sep :
'-')
127 <<
"." << long(siz_nam)
128 <<
"." << long(siz_add)
129 <<
"." << long(siz_tot) << endl;
130 for(AllConditions::const_iterator i=all.begin(); i!=all.end(); ++i) {
132 ::snprintf(text,
sizeof(text), fmt, c.
key(), c.
name(), c.
address().c_str());
143 long siz_nam, siz_add, siz_tot;
144 char sep, c, text[2*PATH_MAX+64];
146 in >> c >> c >> c >> c >> c >> c >> c >> sep
151 in.getline(text,
sizeof(text),
'\n');
154 in.getline(text,
sizeof(text),
'\n');
158 text[8] = text[9+siz_nam] = text[10+siz_nam+siz_add] = 0;
161 if ( (idx=e.
name.find(
' ')) != string::npos )
163 if ( (idx=e.
address.find(
' ')) != string::npos )
169 if ( (idx=e.
name.find(sep)) != string::npos )
170 text[9+idx] = 0, e.
address=text+idx+10, e.
name=text+9;
171 if ( (idx=e.
address.find(sep)) != string::npos )
173 else if ( (idx=e.
address.find(
'\n')) != string::npos )
176 size_t cap = data.capacity();
177 ::sscanf(text,
"%08X",&e.
key);
178 if ( data.size() == cap ) data.reserve(cap+500);
181 }
while(in.good() && !in.eof() );
189 typedef vector<const IOVType*>
_T;
194 for( _T::const_iterator i = types.begin(); i != types.end(); ++i ) {
200 for (_E::const_iterator j=e.begin(); j != e.end(); ++j) {
204 for(_R::const_iterator ic=rc.begin(); ic!=rc.end(); ++ic)
205 all[(*ic).key()] = *ic;
211 if ( output.find(
".xml") != string::npos ) {
213 return createXML(output, all);
215 else if ( output.find(
".txt") != string::npos ) {
217 return createText(output, all, 0);
219 else if ( output.find(
".daf") != string::npos ) {
221 return createText(output, all, 0);
223 else if ( output.find(
".csv") != string::npos ) {
225 return createText(output, all,
';');
232 if ( input.find(
".xml") != string::npos ) {
233 return readXML(input, data);
235 else if ( input.find(
".txt") != string::npos ) {
236 return readText(input, data);
238 else if ( input.find(
".daf") != string::npos ) {
239 return readText(input, data);
241 else if ( input.find(
".csv") != string::npos ) {
242 return readText(input, data);
Document create(const char *tag, const char *comment=0) const
Create new XML document by parsing empty xml buffer.
virtual int output(Document doc, const std::string &fname) const
Write xml document to output file (stdout if file name empty)
virtual void select_all(RangeConditions &result)=0
Select all conditions contained.
const char * name() const
Access the object name (or "" if not supported by the object)
T attr(const Attribute a) const
Access typed attribute value by the XmlAttr.
std::string address
Condition address.
The data class behind a conditions handle.
Class to support the access to collections of XmlNodes (or XmlElements)
const std::string & address() const
Access the address string [e.g. database identifier].
Main condition object handle.
Elements elements
Container of IOV dependent conditions pools.
void append(Handle_t handle) const
Append a new element to the existing tree.
Class supporting the basic functionality of an XML document including ownership.
User abstraction class to manipulate XML elements within a document.
Handle_t root() const
Access the ROOT eleemnt of the DOM document.
int except(const std::string &src, const std::string &fmt,...)
Calls the display action with ERROR and throws an std::runtime_error exception.
T * ptr() const
Access to the held object.
static pair< TClass *, void * > load(TBranch *branch, int entry)
std::vector< Entry > Data
Manager class for condition handles.
std::string name
The object name.
std::map< IOV::Key, Element > Elements
Class describing the interval of validty type.
map< Condition::key_type, Condition > AllConditions
Class implementing the conditions collection for a given IOV type.
key_type key() const
Hash identifier.
XML::Collection_t xml_coll_t
Pool of conditions satisfying one IOV type (epoch, run, fill, etc)
std::vector< Condition > RangeConditions
ConditionsIOVPool * iovPool(const IOVType &type) const
Access conditions multi IOV pool by iov type.
Class to easily access the properties of single XmlElements.
Class supporting the basic functionality of an XML document.
void for_each(T oper) const
Loop processor using function object.
static const char * _T(const std::string &s)
int printout(PrintLevel severity, const char *src, const char *fmt,...)
Calls the display action with a given severity level.
Class supporting to read and parse XML documents.
const std::vector< const IOVType * > iovTypesUsed() const
Access the used/registered IOV types.