12 typedef std::map<std::string, SniperJSON>::const_iterator
map_iterator;
27 bool isMap()
const {
return m_type == 1; }
78 typedef std::string::size_type StrCursor;
85 std::vector<SniperJSON> m_jvec;
87 std::map<std::string, SniperJSON> m_jmap;
90 static const std::string SPACES;
92 static const std::string DELIMITS;
95 SniperJSON(
const std::string &jstr, StrCursor &cursor);
98 void init(
const std::string &jstr, StrCursor &cursor);
101 char getValidChar(
const std::string &jstr, StrCursor &cursor);
104 void readObjectMap(
const std::string &jstr, StrCursor &cursor);
107 void readArrayVec(
const std::string &jstr, StrCursor &cursor);
110 void readStringStr(
const std::string &jstr, StrCursor &cursor);
113 void readScalarStr(
const std::string &jstr, StrCursor &cursor);
116 template <
typename T>
117 inline void toCppVar(T &var)
const;
120 template <
typename T>
121 inline void toCppVar(std::vector<T> &var)
const;
124 template <
typename K,
typename V>
125 inline void toCppVar(std::map<K, V> &var)
const;
128 class Exception :
public std::exception
131 Exception(
const std::string &msg);
132 Exception(
const std::string &jstr,
int cursor);
133 virtual ~Exception() throw();
134 const
char *what() const throw();
150inline void SniperJSON::toCppVar(T &var)
const
154 std::stringstream ss;
165 std::string(
"cannot set <") +
typeid(T).name() +
"> with '" + m_jvar +
"'");
169inline void SniperJSON::toCppVar<bool>(
bool &var)
const
173 if (m_jvar ==
"true")
178 else if (m_jvar ==
"false")
185 throw Exception(std::string(
"cannot set <bool> with '") + m_jvar +
"'");
189inline void SniperJSON::toCppVar<std::string>(std::string &var)
const
193 var = m_jvar.substr(1, m_jvar.size() - 2);
197 throw Exception(std::string(
"cannot set <std::string> with '") + m_jvar +
"'");
201inline void SniperJSON::toCppVar(std::vector<T> &var)
const
205 for (
vec_iterator it = m_jvec.begin(); it != m_jvec.end(); ++it)
207 var.push_back(it->get<T>());
212 throw Exception(std::string(
"not a valid vector"));
220 bool true_value::value =
true;
225 bool false_value::value =
false;
227 template<
typename,
typename>
234template <
typename K,
typename V>
235inline void SniperJSON::toCppVar(std::map<K, V> &var)
const
239 for (
map_iterator it = m_jmap.begin(); it != m_jmap.end(); ++it)
241 var.insert(std::make_pair(
245 it->second.get<V>()));
250 throw Exception(std::string(
"not a valid map"));
253const std::string SniperJSON::SPACES(
" \n\t\r");
254const std::string SniperJSON::DELIMITS(
", \n]}\t\r");
264 StrCursor cursor = 0;
267 cursor = jstr.find_first_not_of(SniperJSON::SPACES, cursor);
268 if (cursor != std::string::npos)
270 throw Exception(jstr, cursor);
282 if (m_type == 2 || m_type == 0)
284 m_jvec.push_back(var);
293 if (m_type == 1 || m_type == 0)
295 std::string _key =
'"' +
key +
'"';
296 m_jmap.insert(std::make_pair(_key, val));
315 return m_jmap.size();
317 else if (m_type == 2)
319 return m_jvec.size();
327 return m_jmap.at(
'"' +
key +
'"');
332 return m_jmap.at(
'"' +
key +
'"');
337 std::ostringstream oss;
340 return loads(oss.str());
348void SniperJSON::init(
const std::string &jstr, StrCursor &cursor)
350 switch (getValidChar(jstr, cursor))
353 readObjectMap(jstr, cursor);
357 readArrayVec(jstr, cursor);
361 readStringStr(jstr, cursor);
365 readScalarStr(jstr, cursor);
370char SniperJSON::getValidChar(
const std::string &jstr, StrCursor &cursor)
372 cursor = jstr.find_first_not_of(SPACES, cursor);
373 if (cursor != std::string::npos)
375 return jstr.at(cursor);
377 throw Exception(jstr, cursor);
380void SniperJSON::readObjectMap(
const std::string &jstr, StrCursor &cursor)
384 if (getValidChar(jstr, ++cursor) !=
'}')
389 readStringStr(jstr, ++cursor);
390 const std::string &
key = m_jvar;
391 if (
key.size() == 2 || getValidChar(jstr, cursor) !=
':')
396 m_jmap.insert(std::make_pair(
key,
SniperJSON(jstr, ++cursor)));
397 }
while (getValidChar(jstr, cursor) ==
',');
402 if (status && getValidChar(jstr, cursor) ==
'}')
408 throw Exception(jstr, cursor);
411void SniperJSON::readArrayVec(
const std::string &jstr, StrCursor &cursor)
413 if (getValidChar(jstr, ++cursor) !=
']')
419 }
while (getValidChar(jstr, cursor) ==
',');
422 if (getValidChar(jstr, cursor) ==
']')
428 throw Exception(jstr, cursor);
431void SniperJSON::readStringStr(
const std::string &jstr, StrCursor &cursor)
433 if (getValidChar(jstr, cursor) ==
'"')
435 StrCursor pstart = cursor;
436 cursor = jstr.find(
'"', pstart + 1);
437 if (cursor != std::string::npos)
440 m_jvar = jstr.substr(pstart, cursor - pstart);
445 throw Exception(jstr, cursor);
448void SniperJSON::readScalarStr(
const std::string &jstr, StrCursor &cursor)
450 StrCursor pstart = cursor;
451 cursor = jstr.find_first_of(DELIMITS, pstart + 1);
452 if (cursor != std::string::npos || pstart == 0)
454 m_jvar = jstr.substr(pstart, cursor - pstart);
458 throw Exception(jstr, cursor);
461SniperJSON::Exception::Exception(
const std::string &msg)
462 : m_msg(
"json error: ")
467SniperJSON::Exception::Exception(
const std::string &jstr,
int cursor)
468 : m_msg(
"invalid json:\n")
470 m_msg += jstr.substr(0, cursor + 1);
471 m_msg +=
" <<< parsing error";
474SniperJSON::Exception::~Exception() throw()
478const char *SniperJSON::Exception::what()
const throw()
480 return m_msg.c_str();
491 std::ifstream
f(conf.c_str());
497 it != c1[
"RunRanges"].
vec_end();
500 m_runRanges.push_back(std::make_pair(
501 (*it)[
"From"].get<int>(),
502 (*it)[
"To"].get<int>() ));
505 m_runs = c1[
"Runs"].
get<std::vector<int> >();
516 m_tRoundSwitch = json[
"TimeRoundSwitch"].
get<
int>();
526 bool goodFlag =
true;
529 if ( run == m_lastRun ) {
530 goodFlag = m_lastFlag;
533 for ( std::vector<std::pair<int, int> >::iterator it = m_runRanges.begin();
534 it != m_runRanges.end();
537 if ( run >= it->first && run <= it->second ) {
543 if ( goodFlag && std::find(m_runs.begin(), m_runs.end(), run) != m_runs.end() ) {
547 m_lastFlag = goodFlag;
550 m_t0Sec = header->
time();
566 long tNow = header->
time() - m_t0Sec;
567 unsigned long _ets1 = header->
etsT1();
568 long ets1NanoSec = _ets1 % 2000000;
571 long _shift0 = ets1NanoSec % 2000000;
572 if ( _shift0 > m_t0NanoShift0 ) {
573 m_t0NanoShift0 = _shift0;
576 else if ( tNow == 1 ) {
577 if ( m_t0NanoShift1 == -1 ) {
578 if ( ets1NanoSec > m_t0NanoShift0 ) {
579 m_t0NanoShift1 = ets1NanoSec;
585 if ( m_t0NanoShift1 > 0 && ets1NanoSec >= m_t0NanoShift1 ) {
589 unsigned long ets1 = tNow*2000000 + ets1NanoSec;
593 if ( labs(ets1-m_lastEts1) < 1000000 &&
abs(evtDiff) < 100 ) {
597 if ( ets1NanoSec > m_t0NanoShift0-200000 ) {
598 long tDiff = ets1NanoSec - m_lastEts1%2000000;
599 if ( tDiff > 1000000 ) {
600 if ( evtDiff < 100 ) {
601 tNow = m_lastEts1/2000000 - 1;
604 else if ( tDiff < -1000000 ) {
605 if ( evtDiff > 100 ) {
606 tNow = m_lastEts1/2000000 + 1;
610 tNow = m_lastEts1/2000000;
612 ets1 = tNow*2000000 + ets1NanoSec;
618 if (
abs(evtDiff) < 100 ) {
625 unsigned long _ets2 = header->
etsT2();
628 if ( _ets2 == m_lastEts2Old ) {
632 unsigned long ets1 = header->
etsT1();
633 long ets1NanoSec = ets1%2000000;
634 long tNow = ets1/2000000;
636 long ets2NanoSec = _ets2 % 2000000;
638 long tDiff = ets2NanoSec - ets1NanoSec;
639 if ( tDiff > 1000000 ) {
642 else if ( tDiff < -1000000 ) {
646 unsigned long ets2 = tNow*2000000 + ets2NanoSec;
649 m_lastEts2Old = _ets2;
650 m_lastEts2New = ets2;
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
*************DOUBLE PRECISION m_pi *DOUBLE PRECISION m_HvecTau2 DOUBLE PRECISION m_HvClone2 DOUBLE PRECISION m_gamma1 DOUBLE PRECISION m_gamma2 DOUBLE PRECISION m_thet1 DOUBLE PRECISION m_thet2 INTEGER m_IFPHOT *COMMON c_Taupair $ !Spin Polarimeter vector first Tau $ !Spin Polarimeter vector second Tau $ !Clone Spin Polarimeter vector first Tau $ !Clone Spin Polarimeter vector second Tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !phi of HvecTau1 $ !theta of HvecTau1 $ !phi of HvecTau2 $ !theta of HvecTau2 $ !super key
void fixHeader(Event::EventHeader *header)
OfflineRevise(const std::string &conf)
bool insert(const std::string &key, const SniperJSON &val)
std::vector< SniperJSON >::const_iterator vec_iterator
static SniperJSON loads(const std::string &jstr)
map_iterator find(const std::string &key) const
std::map< std::string, SniperJSON >::const_iterator map_iterator
map_iterator map_begin() const
bool push_back(const SniperJSON &var)
static SniperJSON load(std::istream &is)
SniperJSON & operator[](int index)
vec_iterator vec_end() const
map_iterator map_end() const
vec_iterator vec_begin() const
const SniperJSON & operator[](int index) const
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")